bolderflight / invensense-imu

Arduino and CMake library for communicating with the InvenSense MPU-6500, MPU-9250 and MPU-9255 nine-axis IMUs.
MIT License
508 stars 213 forks source link

Sampling rate, interrupt #72

Closed i17brn closed 3 years ago

i17brn commented 4 years ago

Hi, I would like to fill a buffer data, I create a timer in order to sampling 200 sampler per second, I would like to get this data from the accelerometer, but always is the same data in the 200 samples. could you help me?

void IRAM_ATTR TimerHandler0(void) { //sampling function IMU.readSensor(); myBufferX[pos] = IMU.getAccelX_mss(); myBufferY[pos] = IMU.getAccelY_mss(); myBufferZ[pos] = IMU.getAccelZ_mss(); pos++;
}

flybrianfly commented 3 years ago

Really hard to say without seeing more code, understanding the microcontroller this is used on, or the wiring between the microcontroller and the sensor.

I would also recommend using the sample rate divider to set the desired output rate and then using the interrupt generated from the IMU to trigger your ISR. Then you're guaranteed to always have data ready at the desired rate.