jrowberg / i2cdevlib

I2C device library collection for AVR/Arduino or other C++-based MCUs
http://www.i2cdevlib.com
3.95k stars 7.51k forks source link

MPU6050 setRate() seems to get half the rate specified ... (MPU6050_DMP6) #363

Open HughAndersonNUS opened 6 years ago

HughAndersonNUS commented 6 years ago

Hi, I am confused by the behaviour of the MPU6050. It seems to have an interrupt rate sample rate that is one half what is expected from the data sheets. For example, if I take the MPU6050_DMP6 example, the default sample/interrupt rate appears to be 100Hz (even though the sample rate divisor is set in the initialization (MPU6050_6Axis_MotionApps20.h) to give a sample rate of 200Hz). If I add in mpu.setRate(9) in the initialization:

    mpu.initialize();
    pinMode(INTERRUPT_PIN, INPUT);
    mpu.setRate(9);      // 1000/(1+9) should be 100Hz

I now get 50Hz interrupts! Has anyone else noticed this effect? Does it happen only when using DMP? I have a few different systems here, and they all seem to act in this way. Cheers Hugh

HughAndersonNUS commented 6 years ago

Hi - I will answer my own question. It turns out that if you use DMP, the interrupt rate is determined by more than just the sample rate divisor. The last byte in the dmpConfig array in MPU6050_6Axis_MotionApps20.h also affects it. If it is 0x01: ........ 0x02, 0x16, 0x02, 0x00, 0x01 // D_0_22 inv_set_fifo_rate then mpu.setRate(9) results in 50Hz, not 100Hz. On the other hand, if it is 0x00: ........ 0x02, 0x16, 0x02, 0x00, 0x00 // D_0_22 inv_set_fifo_rate then mpu.setRate(9) results in 100Hz. Hooray! Cheers Hugh