PDA

View Full Version : ADIS16250: Help with setting up SPI



InitialDriveGTR
- 21st September 2006, 20:23
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

Raflex
- 22nd September 2006, 05:36
Hello, the reset pin must be high or low, try adding RST=1 or RST=0

Payatronico
- 22nd September 2006, 05:53
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

InitialDriveGTR
- 22nd September 2006, 13:07
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

Raflex
- 22nd September 2006, 17:46
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).

InitialDriveGTR
- 22nd September 2006, 19:25
How does one go about decreasing the SPI clock speed?

Thanks,
Benjamin B. Roy

Raflex
- 23rd September 2006, 00:21
Hello. add this line to your code:

DEFINE SHIFT_PAUSEUS ms

ms is the time in milliseconds between clock pulses

InitialDriveGTR
- 23rd September 2006, 01:39
What would be a good pause time? (Note that I am completely new to this)a

Raflex
- 23rd September 2006, 05:50
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.

InitialDriveGTR
- 23rd September 2006, 21:31
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

Raflex
- 23rd September 2006, 23:45
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.

InitialDriveGTR
- 24th September 2006, 17:29
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

arniepj
- 25th September 2006, 19:40
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

InitialDriveGTR
- 26th September 2006, 20:07
With shiftout, how can you use binary format instead of hex? Is there a method for translating binary into hex on the PIC?

InitialDriveGTR
- 26th September 2006, 22:08
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>

Raflex
- 27th September 2006, 00:25
Good job!!

InitialDriveGTR
- 28th September 2006, 03:51
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

mister_e
- 28th September 2006, 04:08
Look fine but there's 2 mistake in this


DEFINE HSER_CLOERR 1


should be


DEFINE HSER_CLROERR 1

__________________________________________________


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

InitialDriveGTR
- 28th September 2006, 04:16
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.

mister_e
- 28th September 2006, 04:23
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 (http://www.picbasic.co.uk/forum/attachment.php?attachmentid=981&d=1153512406)

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 :D

InitialDriveGTR
- 28th September 2006, 22:39
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

SteveB
- 29th September 2006, 04:01
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 (http://www.analog.com/UploadedFiles/Data_Sheets/ADIS16250.pdf) to keep others from having to search for it.

mister_e
- 29th September 2006, 04:47
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 :D

InitialDriveGTR
- 17th November 2006, 23:19
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

Payatronico
- 21st November 2006, 14:22
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.

InitialDriveGTR
- 22nd November 2006, 00:46
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

SteveB
- 22nd November 2006, 00:56
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 (http://www.picbasic.co.uk/forum/showthread.php?t=1942)
Retrieving 32bit Multiply Result (http://www.picbasic.co.uk/forum/showthread.php?t=24)
Retrieving Div32 Remainder (http://www.picbasic.co.uk/forum/showthread.php?t=48)

Steve

InitialDriveGTR
- 22nd November 2006, 03:52
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?

SteveB
- 22nd November 2006, 18:38
Check out the threads I linked my previous post. The Hourmeter (http://www.picbasic.co.uk/forum/showthread.php?t=1942) 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. :D

HTH,
Steve