Wierd gyro code problems...pls help

Hi, i’ve coded a VERY simple code for a gyro … the gyro outputs 10bits so i shifted 2…but now the gyro stays at 135 even when not moving or being shaked etc… I can’t figure out the problem…the gyro is working (we monitored voltage)

can you please read the code and help thank you :confused:



if(heading>turn-error)   //error is a tolerance!!!! i set it to 400

Thank You
Salik Syed Team 701
btw we are using the BEI gyro from 2k3 (we know…its not allowed…we’ll get another gyro soon)

you cant equate the gyro to the analog input - you have to use the Get_Analog_Value() function like this:

gyro1 = Get_Analog_Value( rc_ana_in01);

its detailed in the 2004 Programming Reference Manual from innovationfirst.com - page 16

and if you want to shift it down to 8 bits its the other way

gyro1 = gyro1>>2;


You will find your answer on page 16 of the 2004 Programming Reference guide, or in several other threads here on chiefdelphi.

edit: Ken beat me by seconds :stuck_out_tongue:

haha …lol i’m a noob…thanx both of you

one more question…you know how it says : gyro1=>>gyro1 (or whatever) … will it shift every time the cycle loops…like one loop it is 8 bit then 6 then 4???I hope not!..we have the shift in our program loop (outside of initilization) because we have to shift it after making it equal to the analog …is that correct?

only if you stop reading it in with the Get_analog statement in each loop.

if you put shift right (gyro>>2) statements after each other, then yes, each statement will shift it right another two places

but in your code Im sure you are reading in new data on each loop, the old data is overwritten, so the new data is whats getting shifted.