ADIS16250: Help with setting up SPI


Closed Thread
Results 1 to 29 of 29
  1. #1

    Default ADIS16250: Help with setting up SPI

    Hello, I have two ADIS16250 Gyros from analog. I have spent abu thte last 3 days trying to figure out how to use them, but the datasheet is way too complicated for me. I have tried:

    <code>
    DEFINE OSC 20
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_SPBRG 21 ' 57600 Bauds
    DEFINE HSER_CLOERR 1

    INCLUDE "modedefs.bas"

    Hserout ["ACTIVE",13]

    RST var portd.0
    SCLK var portd.1
    CS var portd.2
    DOUT var portd.3 'data from PIC to Gyro
    DIN var portd.4 'data from gyro to PIC

    temp var word'(2)
    index var word

    High SCLK
    High CS

    pause 1000

    main:
    low CS
    Shiftout DOUT, SCLK, 1, [$04,$00]
    high cs
    pause 100

    low CS
    SHIFTIN DIN, SCLK, 2, [temp\14]
    high CS
    pause 100

    HSEROUT ["Temp: ",HEX temp,13]
    pause 100
    goto main
    </code>

    But, it doesn't work. I would really appreciate it if someone could give me an example, or set me off in the right direction.

    Thanks,
    InitialDriveGTR

  2. #2
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    Hello, the reset pin must be high or low, try adding RST=1 or RST=0

  3. #3
    Payatronico's Avatar
    Payatronico Guest


    Did you find this post helpful? Yes | No

    Talking no no no

    muchacho amigo mio

    RST must be high, RST=1.
    maybe the problem is the crystal, try with a 4mhz cristal and more slowly speed of comunication, quiza asi se solucione tu problema chico

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Are the data adresses that I am shifting out correct? That is what I think I am doing wrong. I couldn't fully understand the datasheet's SPI output.

    Thanks,
    InitialDriveGTR

  5. #5
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    The data adresses is ok. However, the ADIS16250 SPI clock speed is 2.5 MHz, you need to decrease your clock speed in order to transfer data between devices.

    Try reading the status register of the ADIS16250 ($3C).

  6. #6


    Did you find this post helpful? Yes | No

    Default

    How does one go about decreasing the SPI clock speed?

    Thanks,
    Benjamin B. Roy

  7. #7
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    Hello. add this line to your code:

    DEFINE SHIFT_PAUSEUS ms

    ms is the time in milliseconds between clock pulses

  8. #8


    Did you find this post helpful? Yes | No

    Default

    What would be a good pause time? (Note that I am completely new to this)a

  9. #9
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    To obtain clock speed:

    Freq [Hz] = 1/period[seconds]

    Test it with 1 ms (about 1Khz).

    If it doesnt work try with another SPI mode, remember MSB first.

  10. #10


    Did you find this post helpful? Yes | No

    Default

    This is my code:

    <code>
    DEFINE OSC 20
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_SPBRG 21 ' 57600 Bauds
    DEFINE HSER_CLOERR 1
    DEFINE SHIFT_PAUSEUS 1000

    INCLUDE "modedefs.bas"

    Hserout ["ACTIVE",13]

    RST var portd.0
    SCLK var portd.1
    CS var portd.2
    DOUT var portd.3 'data from PIC to Gyro
    DIN var portd.4 'data from gyro to PIC

    temp var word'(2)
    index var word

    High SCLK
    High CS
    high RST

    pause 1000

    main:
    low CS
    Shiftout DOUT, SCLK, 1, [$3C,$00]
    high cs
    pause 100

    low CS
    SHIFTIN DIN, SCLK, 2, [temp\16]
    high CS
    pause 100

    HSEROUT ["Temp: ",HEX4 temp,13]
    pause 100
    goto main
    </code>

    And the output I am getting out is (HEX):

    ACTIVE
    Temp: 0000
    Temp: 0900
    Temp: 0900
    Temp: 0900
    Temp: 0900

    Thanks

  11. #11
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    Is it correct? Does it work?

    Take a look on Table 41 STATUS Bit descriptions (Datasheet pp. 30):

    Address 0x3D, 0x3C
    Default 0x0000
    Default is valid only until the first register write cycle.

    Try reading X-Axis data or another register.

  12. #12


    Did you find this post helpful? Yes | No

    Default

    I tried reading the 0x04 register, and it just simply gives me 0x0000. I'm relatively sure my connections are right, but I could be wrong. Do I need any pull-ups? Are there any connections I need other than the SPI, reset, and power connections? Thanks
    Last edited by InitialDriveGTR; - 24th September 2006 at 17:35.

  13. #13
    Join Date
    Aug 2005
    Posts
    57


    Did you find this post helpful? Yes | No

    Default

    I have found that shiftin/out will not work with some devices,its the clock pulse timing I believe.Using the MSSI spi hardware port is an option,more involved though or write your own routine.Below is a sample I used with a Maxim 1270 A/D on a 16F877.

    DataAcquisition:
    for Indexer = 12 to 0 step -1 ' Output data,13 clock pulses
    portc.2 = SerialDataOut.0[Indexer] ' Output data port
    gosub Clockout ' Output clock pulse
    next Indexer ' Next data bit,next clock pulse

    for Indexer = 1 to 12 ' Read data,12 clock pulses
    SerialDataIn = SerialDataIn * 2 ' Shift each bit to the left
    SerialDataIn = SerialDataIn + portc.3 ' Data in port
    gosub Clockout ' Output clock pulse
    next Indexer ' Next data bit,next clock pulse
    return ' Complete return to main

    Clockout: ' Clock pulse
    pulsout portc.0,5 ' Clock pulse port, 1 msec
    return

  14. #14


    Did you find this post helpful? Yes | No

    Default

    With shiftout, how can you use binary format instead of hex? Is there a method for translating binary into hex on the PIC?

  15. #15


    Did you find this post helpful? Yes | No

    Default

    Hello all, I finally got it working. I fixed it by changing the settings for the SHIFTOUT and SHIFTIN commands. Here is my source:

    <code>
    DEFINE OSC 20
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_SPBRG 21 ' 57600 Bauds
    DEFINE HSER_CLOERR 1
    DEFINE SHIFT_PAUSEUS 1000

    INCLUDE "modedefs.bas"

    Hserout ["ACTIVE",13]

    RST var portd.0
    SCLK var portd.1
    CS var portd.2
    DIN var portd.3 'data from PIC to Gyro
    DOUT var portd.4 'data from gyro to PIC

    temp1 var word
    index var word

    high RST

    pause 1000

    main:
    low CS
    Shiftout DOUT, SCLK, 5, [$04\8,$00\8]
    high cs
    pause 10
    low CS
    SHIFTIN DIN, SCLK, 6, [temp1\16]
    high cs

    HSEROUT ["Temp1: 0x",dec temp1,13]
    pause 100
    goto main
    </code>

  16. #16
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    47


    Did you find this post helpful? Yes | No

    Talking

    Good job!!

  17. #17


    Did you find this post helpful? Yes | No

    Default

    I wrote up some new code that is meant to use two ADIS16250 Gyros. Once I figure out what LSB (Not Least signifigant bit)(I think), I will use them in a RC Helicopter Navigation system.
    <a href="http://initialdrivegtr.po.gs/SourceCode-2.htm">http://initialdrivegtr.po.gs/SourceCode-2.htm</a>

    I hope this helps anyone that has had any trouble with these gyros too. Thanks for all your help!

    InitialDriveGTR

  18. #18
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Look fine but there's 2 mistake in this
    Code:
         DEFINE HSER_CLOERR 1
    should be
    Code:
         DEFINE HSER_CLROERR 1
    __________________________________________________
    Code:
       INCLUDE "modedefs.bas"
    Nowhere in your code you're using MSBPRE, LSBPRE or else, you're using the SHIFTIN/SHIFTOUT mode # instead. You can remove this INCLUDE line.
    __________________________________________________

    Just for safety sake, you should set CS0, CS1 to high before the main loop. Just before the PAUSE 1000
    Last edited by mister_e; - 28th September 2006 at 04:16.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  19. #19


    Did you find this post helpful? Yes | No

    Default

    The Defines for the Hardware serial were generated using a program I found here. So, I honestly didn't even know what it was(or at least I didn't put much thought into them). As for the MSBPRE, etc. I found I fould change between using the numeric values and the text versions, so I just left it there.

  20. #20
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    DOH! so it was partially my fault. You used the old version of the SPBRG calc... wich is mine... i thought i sent the updated one seems not. BTW.. you're not using HSERIN so it doesn't cause any problem

    Anyways here's the corrected version

    EDIT: i remind to have posted an update... but on a USB thread. DOH!

    Anyways, there's another applet comming soons including Timer calc, Reverse timer calc, SPBRG and HPWM. Still on test as now.

    I don't want to do the same mistake twice
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  21. #21


    Did you find this post helpful? Yes | No

    Default

    Do you know what the "LSB" is on the ADIS16250 datasheet? I think it is being used as a unit. Thanks

    PS mister_e, I could host your calculator software on my website if you would like

  22. #22
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by InitialDriveGTR
    Do you know what the "LSB" is on the ADIS16250 datasheet? I think it is being used as a unit. Thanks
    Yes, it is. See Table 6. On the far right, it shows that each bit, for the different outputs, represents a particular values. For instance, each bit of the GYRO_OUT register is equal to 0.07326°/sec (when scaling is set to 320°/sec). So, if this register was %0000 0111 1101 0000 (2000), it would mean a value of 2000 * 0.07326 = 146.52°/sec.

    If you look at table 1, you see the SENSITIVITY parameters (Compare this to table 7):
    Range = 320°/sec, LSB is 1/13.65 = 0.07326 °/sec
    Range = 160°/sec, LSB is 1/27.30 = 0.03663 °/sec
    Range = 080°/sec, LSB is 1/54.60 = 0.018315 °/sec
    EDIT: These numbers are also presented in the text below table 12


    HTH,
    Steve

    EDIT: Here is a link to the datasheet to keep others from having to search for it.
    Last edited by SteveB; - 29th September 2006 at 14:23.

  23. #23
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by InitialDriveGTR
    PS mister_e, I could host your calculator software on my website if you would like
    I have no problem with that. Another site already did it without my permission anyway

    If you get cash from it, i'm also wide open
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  24. #24


    Did you find this post helpful? Yes | No

    Default

    Hello, I am working trying to display the degrees per second on an LCD. I want to have accuracy with the displayed value, but for now would be happy with just integers. Can someone help me figure it out? Thanks

  25. #25
    Payatronico's Avatar
    Payatronico Guest


    Did you find this post helpful? Yes | No

    Default But...

    Hey, how do you want to aquire the temperature? and I can't understand how do you want to calculate degrees per second? explain me better and I will try to solve your problem. If you don't have an idea I can give you some ones.

  26. #26


    Did you find this post helpful? Yes | No

    Default

    I have a LCD connected to my PIC, and I wish to display the rotation of the Gyro in degrees per second. I need decimals, and I am having trouble working out the math without maxing out the word variables. Thanks

  27. #27
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Give us a little more information or an example of what you are trying to do. With the DIV32 command in PBP, you can work around a lot of math issues by shifting the decimal point to the right before you do the math. By keeping track of the magnitude of your decimal shift, you can display the result as needed.

    Here are a couple of nice threads by Darrel Taylor dealing with exploiting PBP's integer math:
    32-bit Variables and DIV32, Hourmeter 99999.9
    Retrieving 32bit Multiply Result
    Retrieving Div32 Remainder

    Steve

  28. #28


    Did you find this post helpful? Yes | No

    Default

    Lets say I was rotating my Gyro at 600 degrees per second. The sensor's output would be 8191 in decimal according to the datasheet. Now lets say that the sensor is outputing 856 in decimal format. The sensor works at 0.07326 degrees per LSB. That means 0x0000 is 0, 0x0001 is 0.07326, 0x0002 is .14652 and so on. In order to use integer math, I need to use 7326.

    100000 * .07326 = 7326

    7326 * 856 = 6271056

    One problem is 2 digits are cut off. How do I get around this?

  29. #29
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Check out the threads I linked my previous post. The Hourmeter should be particularly helpful. If I get some free time soon, I can try to give you a more specific response if your still stumped. But I bet you will be able to come up with something on you own if you read carefully.

    HTH,
    Steve

Similar Threads

  1. Winbond ISD1700 Voice Recorder
    By RFEFX in forum mel PIC BASIC Pro
    Replies: 58
    Last Post: - 22nd April 2014, 10:00
  2. PICKit2 - warning about configuration words
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 4th August 2009, 14:01
  3. Using SPI with External Interrupts
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th June 2008, 04:08
  4. 16-bit SPI problem
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th June 2008, 15:42
  5. How to configure SPI in PICBASIC PRO?
    By moogle in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th April 2007, 18:31

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts