So I have recently been using an accelerometer ADXL362 for my project and have it communicating over SPI with an UNO. On testing the registers the values seem correct and the tilt test to see the effect of gravity on each axis is working.
Using the a library from Github I am reading the values from the XDATA_L and XDATA_H registers (plus Y and Z) and combining them into int16_t X. The values which I get are in accordance with the gravity. But my question is this: Why does the int16_t XValue never reach a maximum?.
For clarity the maximum would be 2^(12) = 4096, rather than 2^(16) = 65536 since only 4 bits are active in the XDATA_H register and not all 8.
The typical values I get when the accelerometer is stuck to a (almost flat) surface:
X = -4.069
Y = 30.723
Z = 1143.128
These are the average of raw data and hasn't accounted for the offset. Regardless, why do I not get 4096 for any axis when it's in line with gravity? (In the results above Z is in the direction of gravity.) Am I losing bits somewhere or does this seem fine to you?
Additional details: the adxl362 is a 3 axis accelerometer and I am using it in the +/-2g sensitivity. The accelerometer can go up to +/-8g. In the +/- 8g mode the maximum magnitude is roughly divided by 4 as compared to that of the +/-2g region.
For a signed 12-bit number the range is -2048 to +2047. If you are in +/-2g mode that range represents -2g to +2g. If you want to hit 2047 you need a 2g acceleration. The earth's gravity field is 1g which is why you are getting roughly 1024.
If you flip your accelerometer over you should get a reading of roughly -1024.
johnwasser:
For a signed 12-bit number the range is -2048 to +2047. If you are in +/-2g mode that range represents -2g to +2g. If you want to hit 2047 you need a 2g acceleration. The earth's gravity field is 1g which is why you are getting roughly 1024.
If you flip your accelerometer over you should get a reading of roughly -1024.
Make sure you sign-extend the 4-bit value.
Thanks for the reply! I tested it again and this time I shook it up and down and got a maximum value of 1871. There's some offset which needs to be accounted for but it would make sense that the 4096 is spread over the + and - ranges.
Just need to double check the sign-extending. What exactly do I need to do to those additional 4 bits? I concatenate the Xdata_H and Xdata_L together, coming to a total of 16 bits with the sign extend. Is there anything more I need to do?
According to the datasheet (http://goo.gl/RoIi7w), Table 1, p 4, sensitivity for 3 axis is 1 mg/LSB if you select the +/- 2g range, 2 mg/LSB if you select the +/- 4g range and 8 mg/LSB if you select the +/- 8g range.
Assuming you are using the +/- 2g range, +1000 adc counts result in 1g (1000 mg) and -1000 adc counts result in -1g (-1000 mg). In other words, the absolute limits in the +/- 2 g range are +2.048 g down to -2.048 g. This little excess is pretty convenient for overcoming the small residual offsets while still achieving +/- 2 g range.
Pending works on this matter on www.arduinoos.com. Check this blog in the next coming days.
HTH