Skip to main content
Visitor II
August 3, 2023
Solved

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

  • August 3, 2023
  • 3 replies
  • 4003 views

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)

Please help me understand how to convert the raw values to engineering values. 

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?

CNBharadwaj_0-1691082496369.png

 

Thank you, 
C N Bharadwaj.

    This topic has been closed for replies.
    Best answer by TDK

    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.

    3 replies

    TDKAnswer
    Super User
    August 3, 2023

    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.

    Visitor II
    August 3, 2023

    Thank you for replying. 

    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.

    Visitor II
    August 3, 2023

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

    Explorer
    August 3, 2023

    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.

    Visitor II
    August 3, 2023

    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
    August 4, 2023

    Hi @C N Bharadwaj ,

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

    Niccolò

     

    Visitor II
    August 8, 2023

    Once again Thank you, everyone, for your replies. I was able to solve the issue.