Description
The function "imu.setLPF();" does not set the Accel Low Pass register but only the Gyro and Temperature Lowpass. i thing that is due to the difference to the very similar MPU6050 where both accel and gyro LP are set in the same register.
Hier the incorrect function call from the Example Library
// setLPF() can be used to set the digital low-pass filter
// of the accelerometer and gyroscope. (<- This is Wrong)
// Can be any of the following: 188, 98, 42, 20, 10, 5
// (values are in Hz).
imu.setLPF(42); // Set LPF corner frequency to 5Hz
The correct way to set the Accel Low Pass is to write to the MPU9250_ACCEL_CONFIG_2 register.
1.) Disable Bypass by setting the bypass bit to 0 (it is inverted from the given table in the datasheet
2.) Set lowpass config bits to the desired value.
here is an example code:
void MPU9250Class::setAccelLowPass(int f_cutoff)
{
#define REG_MASK_ACCEL_LP 0b1111
#define REG_VAL_ACCEL_LP_218Hz 0
#define REG_VAL_ACCEL_LP_99Hz 2
#define REG_VAL_ACCEL_LP_44Hz 3
#define REG_VAL_ACCEL_LP_21Hz 4
#define REG_VAL_ACCEL_LP_10Hz 5
#define REG_VAL_ACCEL_LP_5Hz 6
uint8_t data = 0;
if (f_cutoff >= 218)
data = REG_VAL_ACCEL_LP_218Hz;
else if (f_cutoff >= 99)
data = REG_VAL_ACCEL_LP_99Hz;
else if (f_cutoff >= 44)
data = REG_VAL_ACCEL_LP_44Hz;
else if (f_cutoff >= 21)
data = REG_VAL_ACCEL_LP_21Hz;
else if (f_cutoff >= 10)
data = REG_VAL_ACCEL_LP_10Hz;
else
data = REG_VAL_ACCEL_LP_5Hz;
imu.write_mask(mpu9250_register::MPU9250_ACCEL_CONFIG_2, REG_MASK_ACCEL_LP, data);
}
The write_mask function is one I have added to make the i2c function accessible from the outside to implement further functions but the logic should be clear.
It should also me noted that setLPF should be called after setting the sample rate because setting the samplerate changes the LPF to half the sample frequency.
That is also a bug in the basic example:
// setLPF() can be used to set the digital low-pass filter
// of the accelerometer and gyroscope.
// Can be any of the following: 188, 98, 42, 20, 10, 5
// (values are in Hz).
imu.setLPF(5); // Set LPF corner frequency to 5Hz
// The sample rate of the accel/gyro can be set using
// setSampleRate. Acceptable values range from 4Hz to 1kHz
imu.setSampleRate(10); // Set sample rate to 10Hz