Skip to main content
Visitor II
September 28, 2016
Question

LIS3DH wrong out value +-16g

  • September 28, 2016
  • 3 replies
  • 2774 views
Posted on September 28, 2016 at 12:35

Hi,

LIS3DH, I don't move it. Sampling rate 400 Hz, CTRL_REG2=0.

+-2g full scale : (0g;0g;1g) out value

+-4g full scale : (0g;0g;1g) out value

+-8g full scale : (0g;0g;1g) out value

+-16g full scale : (0g;0g;0,67g) out value

 

What is going wrong?
    This topic has been closed for replies.

    3 replies

    ST Employee
    October 4, 2016
    Posted on October 04, 2016 at 11:16

    Can you please share you code how do you convert the raw data from sensor to g values?

    Best regards

    Miroslav

    Visitor II
    January 18, 2017
    Posted on January 18, 2017 at 10:20

    Hi Miroslav,

    I also experienced the same problem

    .

    Are there any mistakes in this code?

     // power-on

     :

     // 2G-100Hz

     delay_100ms();        // delay 100ms

     i2c_write(CTRL_REG1, 0x57);

     i2c_write(CTRL_REG4, 0x00);    // 2g

     delay_100ms();        // delay 100ms

     x = i2c_read(OUT_X_H)<<8 | i2c_read(OUT_X_L);

     y = i2c_read(OUT_Y_H)<<8 | i2c_read(OUT_Y_L);

     z = i2c_read(OUT_Z_H)<<8 | i2c_read(OUT_Z_L);

     printf('x:%d y:%d: z:%d\r\n', x, y, z);            --> 'x:0 y:0 z:16448' ==> 1.004g

     // 4G-100Hz

     delay_100ms();        // delay 100ms

     i2c_write(CTRL_REG1, 0x57);

     i2c_write(CTRL_REG4, 0x10);

     delay_100ms();        // delay 100ms

     x = i2c_read(OUT_X_H)<<8 | i2c_read(OUT_X_L);

     y = i2c_read(OUT_Y_H)<<8 | i2c_read(OUT_Y_L);

     z = i2c_read(OUT_Z_H)<<8 | i2c_read(OUT_Z_L);

     printf('x:%d y:%d: z:%d\r\n', x, y, z);            --> 'x:0 y:0 z:8064' ==> 0.984g

     // 8G-100Hz

     delay_100ms();        // delay 100ms

     i2c_write(CTRL_REG1, 0x57);

     i2c_write(CTRL_REG4, 0x20);

     delay_100ms();        // delay 100ms

     x = i2c_read(OUT_X_H)<<8 | i2c_read(OUT_X_L);

     y = i2c_read(OUT_Y_H)<<8 | i2c_read(OUT_Y_L);

     z = i2c_read(OUT_Z_H)<<8 | i2c_read(OUT_Z_L);

     printf('x:%d y:%d: z:%d\r\n', x, y, z);            --> 'x:0 y:0 z:3968' ==> 0.969g

     // 16G-100Hz

     delay_100ms();        // delay 100ms

     i2c_write(CTRL_REG1, 0x57);

     i2c_write(CTRL_REG4, 0x30);

     delay_100ms();        // delay 100ms

     x = i2c_read(OUT_X_H)<<8 | i2c_read(OUT_X_L);

     y = i2c_read(OUT_Y_H)<<8 | i2c_read(OUT_Y_L);

     z = i2c_read(OUT_Z_H)<<8 | i2c_read(OUT_Z_L);

     printf('x:%d y:%d: z:%d\r\n', x, y, z);            --> x:0 y:0 z:1216 ==> 0.593g
    ST Employee
    January 18, 2017
    Posted on January 18, 2017 at 11:27

    Hello,

    unfortunately in your code is not seen how do you convert the raw value to acceleration in g unit. I will try to explain it.

    It seems you are using High Resolution mode. In this mode the output is 12-bit left-justified (in 2 x 8bit = 16 bit output register). So you have to divide the value by 16 (or shift right by 4 digits) and them multiplied by proper sensor sensitivity. The sensitivity is in datasheet in Table 4.

    Examples for you cases:

    FS=2g: raw value 16448 ... 16448 / 16 = 1028, 1028 * 1mg/digit = 1028mg = 1.028g

    FS=4g

    raw value 8064 ... 8064 / 16 = 504, 504 * 2

    mg/digit

    = 1008mg = 1.008g

    FS=8g: raw value 3968 ... 3968 / 16 = 248, 248 * 4mg/digit = 992mg = 0.992g

    FS=16g: raw value 1216 ... 1216 / 16 = 76, 76 * 12mg/digit = 912mg = 0.912g

    Visitor II
    May 3, 2018
    Posted on May 03, 2018 at 17:02

    Hello, 

    I face the same issue and i just use this methode:

    for(i=0; i<3; i++)

    {

        valueinfloat = ((buffer[(i<<1) + 1] << 8) + buffer[i<<1]) * sensitivity;

        pData[i] = (int16_t)valueinfloat;

    }

    where the sensitivity is given by the datasheet 

    /* 0.06 mg/digit*/ for the 2G FS

     /* 0.12 mg/digit*/ for the 4G FS

     /* 0.18 mg/digit*/ for the 6G FS

     /* 0.24 mg/digit*/ for the 8G FS

    /* 0.73 mg/digit*/ for the 16G FS

    the data with 16G FS can exceed the 20G with is wrong as i expect and i do not think i did a shock of 20G.
    ST Employee
    May 6, 2018
    Posted on May 06, 2018 at 14:28

    ahmed.benamara

    ‌ please specify the issue it is not clear.

    I explained how to convert raw values into g unit value in my previous posts.

    Visitor II
    May 6, 2018
    Posted on May 06, 2018 at 16:06

    Sorry , the ic was LIS3DSH, in the lis3dsh i used the function below to convert raw values however when i was testing i give some shocks to the lis3dsh and read the values i saw the values exceed 16g and reach 20g i do not think my shock exceed 8g because when i tested with 8g full scale the values do not exceed 8g. could you please check if i had done a fault in converting raw data?

    Visitor II
    March 6, 2019

    Hello

    A bit late to the party but since i didn't find an answer, here's my scenario:

    LIS3DSH configured at high resolution mode, being polled at 40 Hz

    I read ZH=A6(166), ZL=F0 (240)

    Converted to 16 bit, I get num=(A6<<8 )+ (F0)

    I shift by 4: num=num>>4, i get 2671

    then i get the signed value: -1425

    Then i multiply by 12 mg/digit, the sensitivity, i get -17.1 g

    The value in itself is not necessarily wrong (the sensor is subjected to shocks higher than 16g), but the question is why does the sensor report a higher value.

    thank you