Electrical – How to compute acceleration from accelerometer raw data

accelerometerfloating pointi2cmicrocontroller

I'm working on a project based on NXP accelerometer MMA8653.

This is a I2C, 3-axial accelerometer with 10-bit resolution.

Actually I can read the accelerometer registers and I'm able to configure it.
I configured the accelerometer with full scale equal to 2G and the sensitivity associated to this full scale is 256 conts/g

Reading the register I obtain three 16bit signed variables that correspond to each axis.

Which is the formula to compute the acceleration on the three axis?

My MCU has not a floating point unit, so I want to avoid divisions. It's possible to obtain acceleration in mg (millig – 1^10-3 g)?

Thanks for the help!

Best Answer

As far as I understand, you will get the acceleration in [g] on each axis by dividing each of the 3 values you obtained by 256 (because your sensitivity is 256 counts/g).

To avoid any problems with the division of integer numbers, I suggest you to do in this order, for each value:

  • Convert the number into a signed long, to avoid any overflow in the future
  • Multiply the value by 1000
  • Divide the value by 256: you will then obtain the acceleration value in milli-g, rounded to the lowest mg.

Tip: if you want to round it to the nearest mg (instead of the lowest), you can add 128 (half the number of count / mg) before you divide the value, but after you multiplied it by 1000.

Tip 2: as you mentioned in your comment, you can use a bitshift of 8 instead of the division by 256 to improve the efficiency of the calculation (there is a chance that your compiler would optimise the code by automatically doing it anyway)