how to calculate G-force using LIS331HH 3-axis accelerometer axes values ?
Below are the settings used :
FS : +-6g
sensitivity : 3 mg/digit
here is the sampling code which i am working on reading the axes values.
uint16_t temp_x=0,temp_y=0,temp_z=0;
void Accel_Read_XYZ_Axis(void)
{
uint8_t OUT_X_H=0,OUT_X_L=0;
uint8_t OUT_Y_H=0,OUT_Y_L=0;
uint8_t OUT_Z_H=0,OUT_Z_L=0;
uint8_t command = 0xA8;
uint8_t data=0; //0b11101000;
//Reading Byte by Byte separately
OUT_X_L = send_command(0xA8,data);
OUT_X_H = send_command(0xA9,data);
OUT_Y_L = send_command(0xAA,data);
OUT_Y_H = send_command(0xAB,data);
OUT_Z_L = send_command(0xAC,data);
OUT_Z_H = send_command(0xAD,data);
temp_x = (((OUT_X_H) << 8) | (OUT_X_L));
temp_y = (((OUT_Y_H) << 8) | (OUT_Y_L));
temp_z = (((OUT_Z_H) << 8) | (OUT_Z_L));
if(0x8000 & temp_x) //Checking whether the number is negative or not
{
temp_x = ((~temp_x) & 0x0FFF)+1; //Doing 2's complement to the 12 bit number of the read X-axis data
x_axis = ((temp_x * 3.0f)/1000)*(-1.0); //Multiplying the sensitivity in mG to raw value
}
else
{
temp_x = ((~temp_x) & 0x0FFF)+1;
x_axis = ((temp_x * 3.0f)/1000); //Multiplying the sensitivity in mG to raw value
}
if(0x8000 & temp_y)
{
temp_y = ((~temp_y) & 0x0FFF)+1;
y_axis = ((temp_y * 3.0f)/1000)*(-1.0); //Multiplying the sensitivity in mG to raw value
}
else
{
temp_y = ((~temp_y) & 0x0FFF)+1;
y_axis = ((temp_y * 3.0f)/1000); //Multiplying the sensitivity in mG to raw value
}
if(0x8000 & temp_z)
{
temp_z = ((~temp_z) & 0x0FFF)+1;
z_axis = ((temp_z * 3.0f)/1000)*(-1.0); //Multiplying the sensitivity in mG to raw value
}
else
{
temp_z = ((~temp_z) & 0x0FFF)+1;
z_axis = ((temp_z * 3.0f)/1000); //Multiplying the sensitivity in mG to raw value
}
}
Check the if-else statements whether the process is correct or not. Suggest me if any changes needs to be done.
Note:: Please give me a solution in calucating the G_Force using these three axes values.
