2023-12-08 05:59 AM - edited 2023-12-11 12:21 AM
Hello everyone,
I am currently trying to use a LSM6DSL (accelerometer and gyroscope) but only the accelerometer works.
I am using a NUCLEO-L476RG with a LSM6DSL from a STEVAL-MKI178V2 with the st library : lsm6dsl.c/h and lsm6dsl_reg.c/h
After the init I get the correct values from the acc but not from the gyro (out of scale values when I am expecting close to 0).
So I have implemented the self tests given int he application notes (attached file) p.96-99.
The accelerometer passes its test but not the gyroscope, which have deltas over 300K dps.
Here is my gyro's self-test :
bool pSensorTask_GYRO_SelfTest(void){
bool status = false;
LSM6DSL_Axes_t axes_delta = {0};
LSM6DSL_Axes_t axes_withoutSelf = {0};
LSM6DSL_Axes_t axes_withSelf = {0};
LSM6DSL_AxesRaw_t axes_raw = {0};
LSM6DSL_Axes_t mAxesRaw_withoutSelf = {0};
LSM6DSL_Axes_t mAxesRaw_withSelf = {0};
float sensitivity;
uint8_t nb_data = 0;
uint8_t drdy = 0;
LSM6DSL_Write_Reg(&MotionSensor, LSM6DSL_CTRL1_XL, 0x00);
LSM6DSL_Write_Reg(&MotionSensor, LSM6DSL_CTRL2_G, 0x5c);
LSM6DSL_Write_Reg(&MotionSensor, LSM6DSL_CTRL3_C, 0x44);
LSM6DSL_Write_Reg(&MotionSensor, LSM6DSL_CTRL4_C, 0x00);
LSM6DSL_Write_Reg(&MotionSensor, LSM6DSL_CTRL5_C, 0x00);
LSM6DSL_Write_Reg(&MotionSensor, LSM6DSL_CTRL6_C, 0x00);
LSM6DSL_Write_Reg(&MotionSensor, LSM6DSL_CTRL7_G, 0x00);
LSM6DSL_Write_Reg(&MotionSensor, LSM6DSL_CTRL8_XL, 0x00);
LSM6DSL_Write_Reg(&MotionSensor, LSM6DSL_CTRL9_XL, 0x00);
LSM6DSL_Write_Reg(&MotionSensor, LSM6DSL_CTRL10_C, 0x00);
HAL_Delay(150);
do{
LSM6DSL_GYRO_Get_DRDY_Status(&MotionSensor, &drdy);
HAL_Delay(1);
}while(drdy != true);
LSM6DSL_GYRO_GetAxesRaw(&MotionSensor, &axes_raw); /* Clear DRDY */
for(nb_data = 0; nb_data < 5; nb_data++)
{
do{
LSM6DSL_GYRO_Get_DRDY_Status(&MotionSensor, &drdy);
HAL_Delay(1);
}while(drdy != true);
LSM6DSL_GYRO_GetAxesRaw(&MotionSensor, &axes_raw);
mAxesRaw_withoutSelf.x += axes_raw.x;
mAxesRaw_withoutSelf.y += axes_raw.y;
mAxesRaw_withoutSelf.z += axes_raw.z;
}
mAxesRaw_withoutSelf.x /= 5;
mAxesRaw_withoutSelf.y /= 5;
mAxesRaw_withoutSelf.z /= 5;
LSM6DSL_Write_Reg(&MotionSensor, LSM6DSL_CTRL5_C, 0x04);
HAL_Delay(50);
do{
LSM6DSL_GYRO_Get_DRDY_Status(&MotionSensor, &drdy);
HAL_Delay(1);
}while(drdy != true);
LSM6DSL_GYRO_GetAxesRaw(&MotionSensor, &axes_raw); /* Clear DRDY */
for(nb_data = 0; nb_data < 5; nb_data++)
{
do{
LSM6DSL_GYRO_Get_DRDY_Status(&MotionSensor, &drdy);
HAL_Delay(1);
}while(drdy != true);
LSM6DSL_GYRO_GetAxesRaw(&MotionSensor, &axes_raw);
mAxesRaw_withSelf.x += axes_raw.x;
mAxesRaw_withSelf.y += axes_raw.y;
mAxesRaw_withSelf.z += axes_raw.z;
}
mAxesRaw_withSelf.x /= 5;
mAxesRaw_withSelf.y /= 5;
mAxesRaw_withSelf.z /= 5;
LSM6DSL_GYRO_GetSensitivity(&MotionSensor, &sensitivity);
axes_withoutSelf.x = (int32_t)((float)((float)mAxesRaw_withoutSelf.x * sensitivity));
axes_withoutSelf.y = (int32_t)((float)((float)mAxesRaw_withoutSelf.y * sensitivity));
axes_withoutSelf.z = (int32_t)((float)((float)mAxesRaw_withoutSelf.z * sensitivity));
axes_withSelf.x = (int32_t)((float)((float)mAxesRaw_withSelf.x * sensitivity));
axes_withSelf.y = (int32_t)((float)((float)mAxesRaw_withSelf.y * sensitivity));
axes_withSelf.z = (int32_t)((float)((float)mAxesRaw_withSelf.z * sensitivity));
axes_delta.x = axes_withSelf.x - axes_withoutSelf.x;
axes_delta.y = axes_withSelf.y - axes_withoutSelf.y;
axes_delta.z = axes_withSelf.z - axes_withoutSelf.z;
if((abs(axes_delta.x) >= 150) && (abs(axes_delta.x) <= 700) && \
(abs(axes_delta.y) >= 150) && (abs(axes_delta.y) <= 700) && \
(abs(axes_delta.z) >= 150) && (abs(axes_delta.z) <= 700))
{
status = true;
}
LSM6DSL_Write_Reg(&MotionSensor, LSM6DSL_CTRL2_G, 0x00); /* Disable Sensor */
LSM6DSL_Write_Reg(&MotionSensor, LSM6DSL_CTRL5_C, 0x00); /* Disable self test */
return status;
}
I seriously doubt that the hardware is the issue as the acc is perfectly fine.
Can anyone help me ?
Don't hesitate to ask me if I have forgot any information.
Thanks in advance.
Regards,
MARIE
Solved! Go to Solution.
2023-12-11 02:17 AM
Hi !
I have found the solution.
I had misinterpreted the lsm6 documentation (attached file).
At page 22, the min/max values of the accelerometer are in mg while the gyroscope's one are in dps :
But the returned value from the gyro are in mdps, not dps !
So the comparison of the deltas must be in mdps : 150,000 < deltas < 700,000.
I fixed it in my code and it's now working !
2023-12-11 02:17 AM
Hi !
I have found the solution.
I had misinterpreted the lsm6 documentation (attached file).
At page 22, the min/max values of the accelerometer are in mg while the gyroscope's one are in dps :
But the returned value from the gyro are in mdps, not dps !
So the comparison of the deltas must be in mdps : 150,000 < deltas < 700,000.
I fixed it in my code and it's now working !