STEVAL-MKI109V3 and STEVAL-MKI197V1 IMU data rate to 6667Hz
Motherboard: STEVAL-MKI109V3 (STM32F401VETX)
IMU board: STEVAL-MKI197V (LSM6DSOX)
Hello, I have ran into trouble setting the LSM6DSOX data rates of the XL and GY to 6667Hz in a custom STM32 project. The data is still fetched at a lower rate of around 1667Hz.
Project:
I used STMems_Standard_C_drivers/_prj_MKI109V3/_prj_MKI109V3.ioc and STMems_Standard_C_drivers/tree/master/lsm6dsox_STdC as the basis for the project (github.com/STMicroelectronics/STMems_Standard_C_drivers). I have created my project based on the example lsm6dsox_read_data_drdy.c
It is pretty straightforward. There are two functions:
1)
void lsm6dsox_read_data_drdy(void) {}2)
void lsm6dsox_read_data_drdy_handler(void) {}The first function is used to setup the IMU and to call the lsm6dsox_read_data_drdy_handler() function in a while loop. The second function is where the XL and GY data is read from the registers.
I have set the data rates the following:
lsm6dsox_xl_data_rate_set(&dev_ctx, LSM6DSOX_XL_ODR_6667Hz);
lsm6dsox_gy_data_rate_set(&dev_ctx, LSM6DSOX_GY_ODR_6667Hz);For some reason, the data is still fetched from the registers with lower rates, around 1667Hz.
The IMU sends data to USB serial in following format:
ax[mg], ay[mg], az[mg], gx[dps], gy[dps], gz[dps], timestamp[],The userspace program reads the data from USB serial, converts the values and calculates Mahony yaw, pitch, roll, and outputs the following format:
readout[#], timestamp[], ax[m/s^2], ay[m/s^2], az[m/s^2], gx[rad/s], gy[rad/s], gz[rad/s], yaw[Euler deg]. pitch[Euler deg]. roll[Euler deg]There's some confusion around the timestamp unit. Timestamp is fetched using lsm6dsox_timestamp_raw_get() function. It's called at the same time XL and GY data is fetched from the registers.
Here are 2 samples:
34, 158680, 0.271585, -0.399003, 9.97987, 0.018326, -0.0293215, -0.00122173, 0.00672745, -0.0258199, -0.0297815
35, 158705, 0.241077, -0.482752, 9.95414, 0.0256563, -0.0146608, -0.00122173, 0.00668611, -0.0257625, -0.0306921First sample timestamp is 158680, and second is 158705, and the difference is 25. What is the unit? What conversion is needed to ms or us?
What I've tried:
1) Set various modes for the IMU. No change.
lsm6dsox_xl_power_mode_set(&dev_ctx, LSM6DSOX_HIGH_PERFORMANCE_MD);
lsm6dsox_gy_power_mode_set(&dev_ctx, LSM6DSOX_GY_HIGH_PERFORMANCE);
lsm6dsox_aux_mode_set(&dev_ctx, LSM6DSOX_MODE_4_GY_XL);
lsm6dsox_spi_mode_set(&dev_ctx, LSM6DSOX_SPI_4_WIRE);
lsm6dsox_aux_spi_mode_set(&dev_ctx, LSM6DSOX_AUX_SPI_4_WIRE);
lsm6dsox_ois_mode_set(&dev_ctx, LSM6DSOX_OIS_CTRL_UI_AUX_DATA_UI_AUX);2) used polling method instead of interrupt. Does not matter, can't get a faster data rate.
3) suspected that something is off with the project generated from _prj_MKI109V3.ioc using STM32CubeMX. I left default settings for everything, and STM32F401VETX drivers were automatically downloaded and included. Should it be manually configured?
4) Tried to max out USB speed, as I suspected that USB serial can't buffer the data, but that didn't matter, as USB serial should always be at max speed anyway. Sample time is measured in the IMU, so all the data is received from USB serial.
TL;DR: trying to read XL ang GY data from registers at rate of 6667Hz, but can't achieve it. There is some confusion how to accurately read the sample time unit. The data rate error is really apparent at the output, where i run the data through Mahony algorithm using 6667Hz, where I get a wrong calculation results, but get right calculation results when I set the algorithm speed to 1667Hz.
Any insight is welcome.
