cancel
Showing results for 
Search instead for 
Did you mean: 

LIS3DSH DATA FORMAT

jbeltran
Associate II
Posted on November 17, 2014 at 11:45

I get wrong accelerometer's values. 

I have concatenated xMSB+xLSB, yMSB+yLSB and zMSB+zLSB. Then I verify if the resulting valor is negative, 

in such case I substract 2^16 to convert from 2's complement number to decimal. Finally I multiply each axis valor by 0.00006 to obtain acceleration values in g units. What I'm doing wrong? What is the effective number of bits? 

Thanks!

6 REPLIES 6
jbeltran
Associate II
Posted on December 11, 2014 at 13:56

I can't understand how so many people have problems about LIS3DSH and any ST's moderator responds.

jbeltran
Associate II
Posted on December 17, 2014 at 10:28

Problem solved. The code was correct, the incorrect functioning was due to a bad connection to one accelerometer's ground pin. If anyone has problems using LIS3DSH by I2C I could help them.

k88joshi
Associate II
Posted on December 18, 2014 at 21:27

Hi Juan,

What do you do to convert the int16 word to engineering units ?  I am using LIS331HH sensor for reading the accelerometer.

I am able to read the two registers OUT_X_H & OUT_X_L and combine them into an int16 word.  however, I am not sure how to convert it into gs of acceleration.  Would -32768 to 32767 correspond to -12g to +12g ? 

Please advise.

Thanks,

Kamal Joshi

jbeltran
Associate II
Posted on December 28, 2014 at 12:55

Sorry for the delay. Here's an example for you to understand it better.

uint8_t xLSB = 0;              // LSB x-axis acceleration value

uint8_t xMSB = 0;            // MSB x-axis acceleration value

uint8_t yLSB = 0;             // LSB y-axis acceleration value

uint8_t yMSB =0;            // MSB y-axis acceleration value

uint8_t zLSB =0;             // LSB z-axis accelerationvalue

uint8_t zMSB =0;            // MSB z-axis acceleration value

short xint =0;                     //x-axis acceleration value without format

short yint =0;                     //y-axis acceleration value without format

short zint =0;                     //z-axis acceleration value without format

float x =0;                         //x-axis acceleration value

float y = 0;                        // y-axisacceleration value

float z = 0;                        // z-axisacceleration value

/* Accelerationvalue reading */

I2C_Read6_LIS3DSH(OUT_X_L,&xLSB, &xMSB, &yLSB, &yMSB, &zLSB, &zMSB);

xint =((xMSB<<8)|xLSB);         //Concatenating MSB & LSB (x-axis)

yint =((yMSB<<8)|yLSB);         //Concatenating MSB & LSB (y-axis)

zint =((zMSB<<8)|zLSB);          //Concatenating MSB & LSB (z-axis)

/* Multiply for0.00006 to obtain g units (+/-2g) */ 

x =xint*0.00006;                                                          

y = yint*0.00006;

z = zint*0.00006;

I hope this will be useful foryou. 

Best regards.

Juan

k88joshi
Associate II
Posted on January 05, 2015 at 21:33

Thank You Juan ! This was helpful !

Posted on January 22, 2015 at 13:04

That is ok but by multiplying by a float with one digit of precision your output accuracy in g's is a bit off.  you get the .00006 (approx.) by dividing 2G'sby 2^^15 (16 bits precision signed) which yields .0000610352, which is about 2% off if you care.  you could use 6.10352E-5 for a truer representation of 1G, or divide by 32k