cancel
Showing results for
Did you mean:

# How to convert raw data to engineering values (in mg) from LIS2DH12 Accelerometer sensor?

Associate II

Hello,

We are using the LIS2DH12TR sensor in our project.

As per the datasheet, I understand that it always shows +1g on the +Z-axis when the IC is at rest.

We are operating the sensor in HR mode under different modes  2g, 4g, 8g and also in 16g mode. But strangely the raw values are always near 16384 (0x4000). I tried the same experiment with Low power mode and also normal mode. Still, the values are the same. I tried tilting the board making the X-axis and also Y-axis point to the sky, in that case, the respective axis shows a raw value near 16384 always.

If the respective axis is pointed towards the earth, then the sensor reads a value near -16384 (0xC000)

It would be really helpful if anyone could break down the calculations for 4g. 8g and 16g (as I have gone through the 2g example), like what values should we expect when the board is kept at rest where Z-axis is pointing upwards and the sensor is operated in 4g, 8g and 16g?

Thank you,

1 ACCEPTED SOLUTION

Accepted Solutions
Guru

Either the sensor is completely broken or you haven't switched it out of ±2g mode. Your values are exactly as expected for the force due to gravity when right side up (0x4000) and upside down (0xC000) per the table.

Calculations in higher modes are literally the same except a multiplier is used at the end (x2, x4, or x8 for 4g, 8g, or 16g modes, respectively).

Expected values of ±1g in ±4g mode would be 0x2000 and 0xE000.

9 REPLIES 9
Guru

Either the sensor is completely broken or you haven't switched it out of ±2g mode. Your values are exactly as expected for the force due to gravity when right side up (0x4000) and upside down (0xC000) per the table.

Calculations in higher modes are literally the same except a multiplier is used at the end (x2, x4, or x8 for 4g, 8g, or 16g modes, respectively).

Expected values of ±1g in ±4g mode would be 0x2000 and 0xE000.

Associate III

I just went through this yesterday for my LSM6DSR part, so had this information at hand.
It is from the STMems_Standard_C_drivers repository.

git clone https://github.com/STMicroelectronics/LIS2DH12-PID/

That will contain:

/**
* @defgroup LIS2DH12_Sensitivity
* @brief These functions convert raw-data into engineering units.
* @{
*
*/

float_t lis2dh12_from_fs2_hr_to_mg(int16_t lsb)
{
return ((float_t)lsb / 16.0f) * 1.0f;
}

float_t lis2dh12_from_fs4_hr_to_mg(int16_t lsb)
{
return ((float_t)lsb / 16.0f) * 2.0f;
}

etc. in about ~20 other functions for the various scales.

Associate II

Small doubt, if the sensor is broken, I should not be able to read values in the negative axis also right?

And also in my testing, I was changing the CTRL_REG values to 88 (2g), 98 (4g), A8(8g) and B8(16g).

I hope the above information is correct, please correct me if I'm wrong.

Associate II

*CTRL_REG4 (forgot to mention the number :relieved_face:)

Associate II

Thank you for the response.

I am using the same formula but I am unable to figure out why the raw values are not changing for different modes.

It is always at 0x4000 in all modes when the board is at rest and the Z axis looking towards the sky.

ST Employee

could you read back CTRL_REG4 right after you change FS, just to be sure that the write operation was performed correctly?

Niccolò

Associate II

Hi! TDK

I was able to solve the issue, the CTRL_REG4 (0x23h) was not updated properly. Thank you for helping us out.

Thank you,

Associate II