Shop OBEX P1 Docs P2 Docs Learn Events
using the serial protocol with the MLX90316 — Parallax Forums

using the serial protocol with the MLX90316

FranciscoFrancisco Posts: 26
edited 2010-01-13 17:22 in Propeller 1
hello, i am trying to interface the propeller with the MLX90316 to get rotary angle info. Can anybody spot what i may be doing wrong in my code:


''SPI Setup
  ''SPI.start(ClockDelay, ClockState)
    SPI.start(15,1)           '' Initialize SPI Engine with Clock Delay of 15us and Clock State of 1


''MLX90316 Setup
      DATA_IN_OUT    := 0         '' Set MLX90316 Data Pin
      CLK   := 1                  '' Set MLX90316 Clock Pin
      Reset := 3                  '' Set MLX90316 Reset Pin


' -----[noparse][[/noparse] Program Code ]----------------------------------------------------
      repeat
        LOW(Reset)                                     '' alert the MLX90316

        SPI.SHIFTOUT(DATA_IN_OUT, CLK, SPI#MSBFIRST , 8, $AA)  '' send 1 byte of $AA
        SPI.SHIFTOUT(DATA_IN_OUT, CLK, SPI#MSBFIRST , 72, $FF)  '' send 9 bytes of $FF


        a := SPI.SHIFTIN(DATA_IN_OUT, CLK, SPI#MSBPRE, 16)

        angle := SPI.SHIFTIN(DATA_IN_OUT, CLK, SPI#MSBPRE, 16)

        inv_angle := SPI.SHIFTIN(DATA_IN_OUT, CLK, SPI#MSBPRE, 16)

        b := SPI.SHIFTIN(DATA_IN_OUT, CLK, SPI#MSBPRE, 32)

        HIGH(Reset)                                      '' release the MLX90316
    





i am printing out the a, angle, inv_angle, and b variables in binary to see what i'm getting but instead either they are all zeros or all ones when i turn the knob--so i'm pretty sure at least my physical setup is working.

Do you know how important my clock frequency here is? its set to:


  _clkmode      = xtal1 + pll8x
  _xinfreq      = 10_000_000 






I ask because i am using the propeller backpack and i think it needs those settings for the overlay to work properly.

I am attaching the timing diagram for the mlx90316 if you can help thanks a bunch.

or here is the full datasheet: www.melexis.com/Asset/MLX90316_DataSheet_DownloadLink_4834.aspx
842 x 685 - 112K

Comments

  • FranciscoFrancisco Posts: 26
    edited 2010-01-13 07:21
    turn.gif It looks like the chip that I received was in analog mode, bummer!

    However, i'm now using the correct one in serial mode and using the same program code, but I'm still having problems.

    I managed to get the signal on an oscilloscope(picture attached, 1v intervals). The first half on the screen is the SHIFTOUT that i am sending to the mlx90316 to request the angle. The second half on the screen is the SHIFTIN from the mlx90316. It seems like the signal that the mlx90316 is responding with "looks" like a bunch of 1s to the propeller since the "low" signals don't seem to go below the necessary threshold to indicate a zero.

    Unless i'm mistaken on how serial communication works, does anyone have an idea why the "zero" signal from the mlx90316 is not dropping low enough during its serial output?
    1600 x 1200 - 702K
  • AleAle Posts: 2,363
    edited 2010-01-13 12:20
    Are you using the same pin ?... then you may want to be sure it is not an output during the receive phase...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit some of my articles at Propeller Wiki:
    MATH on the propeller propeller.wikispaces.com/MATH
    pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL020
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU
  • FranciscoFrancisco Posts: 26
    edited 2010-01-13 17:22
    Ale said...
    Are you using the same pin ?... then you may want to be sure it is not an output during the receive phase...

    Hi Ale, yes i'm using the same pin input/output.

    In my code i make use of the SPI object in which it uses SHIFTIN and SHIFTOUT. After I do the SHIFTOUT I immediately start the SHIFTIN on the same pin. I assumed that the object handles preparing the pin for SHIFTIN operations. Is this not the case? Do I need to do something else before the SHIFTIN? Thanks.
Sign In or Register to comment.