cancel
Showing results for 
Search instead for 
Did you mean: 

How to understand Accelerometer LIS2DH12 output value, and how to configure the INT1_THS register

BPapp.2
Associate II

I have question regarding the accelerometer LIS2DH12.

I'm trying to configure the interrupt, to trigger when e.g. the x-axis goes above a threshold value. Not sure what to put in the INT1_THS register?

and, in the output registers (OUT_X_L and OUT_X_H) what's the value/unit? is it in g, mg or m/s2?

Looked in the datasheet and looks like when the sensor is configured in Normal Mode with +-2g sensitivity, each digit is equal to 4mg?

So if I read out for example the raw value '2000' from x-axis, this should be:

2000x4 = 8000mg = 8g?

How can it be 8g when the measurement range is +-2g?

1 ACCEPTED SOLUTION

Accepted Solutions
Eleon BORLINI
ST Employee

Hi @BPapp.2​ ,

you are dividing by 16, not by 16mg, in the high resolution formula.

The step-by-step procedure for the data in HP mode:

  • concatenate OUT_X_L and OUT_X_H;
  • convert the hexadecimal/binary value into signed integer 16 bits (int16_t), in two's complement;
  • since the value has to be expressed on 12 bits, you have to shift the 16bit value by 4 position, i.e. divide for 16 in decimal, and multiply for the sensitivity (1mg/LSB).

You can for sure use those drivers.

Hope this can help.

-Eleon

View solution in original post

5 REPLIES 5
Eleon BORLINI
ST Employee

Hi @BPapp.2​ ,

The raw output of OUT_X_L, OUT_X_H... registers is in LSB, that can be converted into milli-g by applying the sensitivities you can find the the datasheet, p.10, or in the Github C driver repository (lis2dh12_reg.c).

For the specific case of +-2mg, you can refer to the following formula:

// High resolution mode
float_t lis2dh12_from_fs2_hr_to_mg(int16_t lsb)
{
  return ((float_t)lsb / 16.0f) * 1.0f;
}
 
// Normal Mode
float_t lis2dh12_from_fs2_nm_to_mg(int16_t lsb)
{
  return ((float_t)lsb / 64.0f) *  4.0f;
}
 
// Low power mode
float_t lis2dh12_from_fs2_lp_to_mg(int16_t lsb)
{
  return ((float_t)lsb / 256.0f) * 16.0f;
}

This means, in your case:

2000LSB --> 2000/16 mg = 0.125g

Please remember that in the High-resolution mode, the data output is on 12 bits, in Normal mode is on 10 bits, while in Low-power mode is on 8 bits (datasheet p.16).

-Eleon

BPapp.2
Associate II

Thanks for the response!

But why are you divi​ding by 16mg, when it says 4mg/LSB for +-2g in Normal Mode? Not quite sure I understand.

But, the numbers are adding up when dividing by 16mg, cause when the x-axis are pointing down with no movement, I read out the raw value ~15000.

15000/16mg ~= 1000mg = 1g.

Thats sounds logic, but why does it say 4mg/LSB in 2g Normal mode in Datasheet?

And also, in Normal mode (10bit) shouldnt the maximum value be ​1024, which in 2 complement form is -512 to + 512?

Should add that I use a driver from Zephyr RTOS, maybe the conversion from raw values to 2's complement float​ number is wrong..​

BR

Eleon BORLINI
ST Employee

Hi @BPapp.2​ ,

you are dividing by 16, not by 16mg, in the high resolution formula.

The step-by-step procedure for the data in HP mode:

  • concatenate OUT_X_L and OUT_X_H;
  • convert the hexadecimal/binary value into signed integer 16 bits (int16_t), in two's complement;
  • since the value has to be expressed on 12 bits, you have to shift the 16bit value by 4 position, i.e. divide for 16 in decimal, and multiply for the sensitivity (1mg/LSB).

You can for sure use those drivers.

Hope this can help.

-Eleon

BPapp.2
Associate II

Ok, but you wrote

2000LSB --> 2000/16 mg = 0.125g

So assumed that it was dividing by mg. But maybe not your intention.

I'm using Normal Mode (10bits), so I should right shift by 6 then?

15000 >> 4 = 234mg = 0.234g ?

Doesn't look correct.

BPapp.2
Associate II

Sorry, just saw the multiplication by 4 to convert it to mg

So first get the LSB correct converting from 16bit to 10bit (Normal mode) by right shift by 6.

This value is still in LSB, then multiply by 4 (because 4mg/LSB) to get it to mg.

Then divide by 1000 to get g.

Got it, thanks!

��