2019-09-12 07:08 AM
Hi
I am working with LIS2DH12 accelerometer. I want to read and calibrate the raw x,y,z axis data. For the scale level 2g, 4g, 8g, I am getting the accurate readings(At stable position, Z is 1g for above scale levels). But when I change my scale level to 16g, my z-axis is only reading 0.62g value instead of 1g.
Here are the register configurations that I am using:
/*variables to store values in registers*/
uint8_t value_ctrl_reg1 = 0x47; // Turn on the sensor, enable X, Y, and Z, Low Power mode, ODR = 100Hz
uint8_t value_ctrl_reg2 = 0x00;
uint8_t value_ctrl_reg3 = 0x00;
uint8_t value_ctrl_reg4 = 0x88; // FS = ±8g
/*Read Accelerometer*/
uint8_t data[6];
#define Scaling_Fac_ACC 2048
vTWI_Read(LIS2DH12_OUT_X_L , &data[0]);
vTWI_Read(LIS2DH12_OUT_X_H , &data[1]);
vTWI_Read(LIS2DH12_OUT_Y_L , &data[2]);
vTWI_Read(LIS2DH12_OUT_Y_H , &data[3]);
vTWI_Read(LIS2DH12_OUT_Z_L , &data[4]);
vTWI_Read(LIS2DH12_OUT_Z_H , &data[5]);
x_axis = (float)((int16_t)(data[1] << 8 | data[0]));
y_axis = (float)((int16_t)(data[3] << 8 | data[2]));
z_axis = (float)((int16_t)(data[5] << 8 | data[4]));
/*converting raw data using scaling factor for 16g i.e. sensitivity 2096*/
x_axis = x_axis / Scaling_Fac_ACC;
y_axis = y_axis / Scaling_Fac_ACC;
z_axis = z_axis / Scaling_Fac_ACC;
Please advice me what I am doing wrong in my code to calibrate the raw axis data.
Any help is much appreciated.
Solved! Go to Solution.
2019-09-13 08:41 AM
Hi @manjot , where did you take this conversion factor for 16g FS?
/*converting raw data using scaling factor for 16g i.e. sensitivity 2096*/
You can simply multiply the raw value for 192 mg/digit in case of Low power mode.
Regards
2019-09-13 08:41 AM
Hi @manjot , where did you take this conversion factor for 16g FS?
/*converting raw data using scaling factor for 16g i.e. sensitivity 2096*/
You can simply multiply the raw value for 192 mg/digit in case of Low power mode.
Regards
2019-09-16 08:19 AM
Hi Eleon
Thank you for correcting me.
I got that conversion formula from general accelerometer code. But now I followed your advice and it is actually giving the accurate results for all scale levels at low power mode.