LIS2DH12 giving Z = 0.62g instead of 1g at rest position only when scale is set to 16g
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.
