cancel
Showing results for 
Search instead for 
Did you mean: 

LSM303AGR: Interpreting the values read

Theresa Lichtenberger
Associate II
Posted on February 28, 2018 at 18:37

Hey there!

Can anyone explain to me how to calculate the correct acceleration values in mg for various resolutions and scales?

For example, I am currently reading acceleration values with  ODR set to 0110, which is  HR / Normal / Low-power mode (200 Hz). The Full scale selection is set to +/-2g for this example. 

0690X00000609qfQAA.png

As both the LPen and the HR bit are set to 0, I am in Normal mode with a 10-bit data output. If I shift the values >> 4, I am getting values which seem to be correct. For example 1000 mg (= 1g) on the z-axis, which makes sense I guess, as it is 1*gravitational acceleration.

On the right of the table above is written: +/- 2 g [mg/digit]. What does that mean? How am I able to convert the values I read into mg? Not only for +/- 2g, but for a fullscale of +/-4g or +/-8g or +/-16g too?

#lsm303agr-value-calculation #accelerometer #acceleration #lsm303agr
5 REPLIES 5
Posted on February 28, 2018 at 18:57

16 infers you're immediately throwing away 4-bits of precision, and 4 for 2-bits

You must take your signed integer value and scale it into the range you've selected.

For 12-bit I'd assume +/-2048 translates to +/-2g in that mode, unless some specific scaling value is called out

int X;

double x;

x = (double)X * (2.0 / 2048.0); // Value in G

x = (double)X * (2000.0 / 2048.0); // Value in mG

x = (double)X * (2.0 / 32768.0); // Value in G if value in X is left-aligned within a 16-bit integer

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 28, 2018 at 20:45

Turvey.Clive

First of all, thank you for your fast answer!

For my better understanding:

If I have, for example, set fullscale to +/- 2g and 10 bit data output, then I will have to shift the value >> 6. Then I will have to do this: x = (double)X*(2.0 / ((2^10)/2) ); // Value in G

Or if I have set fullscale to +/-8g and 8 bit data output, I will have to shift the value >> 8. Then I will have to do:

x = (double)X*(8.0 / ((2^8)/2) ); // Value in G

I think I haven't still understood it to the fullest.

Warm regards

Posted on February 28, 2018 at 22:10

The value which describes relation between raw data and acceleration in g is sensitivity. You can find the values in Table 3  if datasheet for all full scales and modes.

The output value is left justified in the output 16 bit register, so you have to first shift the value right according to selected mode (8, 10, 12 bit).

You can do it for example like that:

int16_t result_lsb;

float result_mg

;

result_lsb = ((int16_t)high_byte<<8)+(uint16_t)low_byte;

result_lsb = result >> 4; // in case of high resolution mode = 12bit output

result_mg = result_lsb * sensitivity; // LSB to mg, see sensitivity in datasheet

0690X00000609qoQAA.png
Posted on March 04, 2018 at 13:59

Batek.Miroslav

‌: Hey Miroslav. Do I have to shift result_lsb >> 8 if the resolution mode = 8bit output (low-power mode)?

And is result_mg = result_lsb * 7.82 if I assume that wie have FS = +/-4g in normal mode? Thanks for your help!

Posted on March 06, 2018 at 09:10

Yes, you are correct.

low-power mode ... >> 8 bits shift

normal mode ... >> 6 bits shift

high-resolution ... >> 4 bits shift