gyroscope scale factor...

Please help to understand how to convert gyroscope output to get it ratiometric.

I have a gyroscope: ADXRS401 from SparkFun connected to Arduino.
I read this piece of code from someones' program, who unfortunately didn't like to use parentheses!

conversion = 5.0 / 1024.0 * 1000 / 15 / 57.29578;
gyro = analogRead(gyroPin);
gyro = (gyro - 512.0) * conversion;

from the datasheet of the gyroscope:
Scale Factor: 15mV/deg/sec.

I only know that 5.0/1024.0 is for 4.88mV per bit ADC, and 57.29578 to convert from radian to degree and 1000 is to cancel 'm' which is milli(volt). I am confused by the order of operations: why it is multiplied by 1000/15, shouldn't be 15/1000 as it is the scale factor?

please explain the conversion formula!
Thanks! :slight_smile:

I hate it when the programmers leave out the parens like that -- it's bad form and makes the code harder to read.

As far as figuring out what he is doing, dimensional analysis is your friend. What we need is a conversion factor that changes a given number of LSB units (least significant bit unit) to the related number of radians per second. I.e rad/(s*LSB), so when I multiply it by a given number of LSBs, I get rad/s.

(5 V / 1024 LSB) * 1000 mV/V gives us a value of 4.88 mV/LSB. We know the conversion factor from mV to deg/s is 15 (mVs)/deg. The unit we want out of combining these numbers is deg/(sLSB). In order for that to happen, I need to multiply mV/LSB by a number with units of deg/(mVs)... which means divide by the number 15 in this case. Does that make sense? You can then multiply that by the conversion factor from degrees to radians to get the units you originally wanted, rad/(sLSB).

yes, it's now clear to me, thank you for nice post :wink:

well, so there is a multiplier of “1000” in his conversion formula:

conversion = 5.0 / 1024.0 * 1000 / 15 / 57.29578;
gyro = analogRead(gyroPin);
gyro = (gyro - 512.0) * conversion;

which is wrong, isn’t it? well, say x is our LSB output of gyro, then considering:
[ (x LSB) * (4.88 mV/LSB) ] / (15 mVs/deg) = (4.88x)/15 deg/s

and we don’t need that “1000” multiplier. Why he wrote it?!

The 1000 is required to convert volts into millivolts.

do you mean I missed something here:
[ (x LSB) * (4.88 mV/LSB) ] / (15 mVs/deg) = (4.88x)/15 deg/s

or, where should I include that missed "1000"? :slight_smile:

I think you should be good without the 1000, with the thousand you would be dividing volts/mV, which doesn't work very well.