Skip to content

Commit d7bd411

Browse files
committed
Update Example10_DMP_FastMultipleSensors.ino
1 parent 8b14eb1 commit d7bd411

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

examples/Arduino/Example10_DMP_FastMultipleSensors/Example10_DMP_FastMultipleSensors.ino

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,12 @@ ICM_20948_Status_e ICM_20948::initializeDMP(void)
316316
// Enable accel and gyro sensors through PWR_MGMT_2
317317
// Enable Accelerometer (all axes) and Gyroscope (all axes) by writing zero to PWR_MGMT_2
318318
result = setBank(0); if (result > worstResult) worstResult = result; // Select Bank 0
319-
uint8_t pwrMgmt2 = 0x40; // Set the reserved bit 6
319+
uint8_t pwrMgmt2 = 0x40; // Set the reserved bit 6 (pressure sensor disable?)
320320
result = write(AGB0_REG_PWR_MGMT_2, &pwrMgmt2, 1); if (result > worstResult) worstResult = result; // Write one byte to the PWR_MGMT_2 register
321321

322-
// Configure I2C_Master/Gyro/Accel in Low Power Mode (cycled) with LP_CONFIG
323-
result = setSampleMode((ICM_20948_Internal_Mst | ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), ICM_20948_Sample_Mode_Cycled); if (result > worstResult) worstResult = result;
322+
// Place _only_ I2C_Master in Low Power Mode (cycled) via LP_CONFIG
323+
// The InvenSense Nucleo example initially puts the accel and gyro into low power mode too, but then later updates LP_CONFIG so only the I2C_Master is in Low Power Mode
324+
result = setSampleMode(ICM_20948_Internal_Mst, ICM_20948_Sample_Mode_Cycled); if (result > worstResult) worstResult = result;
324325

325326
// Disable the FIFO
326327
result = enableFIFO(false); if (result > worstResult) worstResult = result;
@@ -343,6 +344,11 @@ ICM_20948_Status_e ICM_20948::initializeDMP(void)
343344
// dps2000
344345
result = setFullScale((ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), myFSS); if (result > worstResult) worstResult = result;
345346

347+
// The InvenSense Nucleo code also enables the gyro DLPF (but leaves GYRO_DLPFCFG set to zero = 196.6Hz (3dB))
348+
// We found this by going through the SPI data generated by ZaneL's Teensy-ICM-20948 library byte by byte...
349+
// The gyro DLPF is enabled by default (GYRO_CONFIG_1 = 0x01) so the following line should have no effect, but we'll include it anyway
350+
result = enableDLPF(ICM_20948_Internal_Gyr, true); if (result > worstResult) worstResult = result;
351+
346352
// Enable interrupt for FIFO overflow from FIFOs through INT_ENABLE_2
347353
// If we see this interrupt, we'll need to reset the FIFO
348354
//result = intEnableOverflowFIFO( 0x1F ); if (result > worstResult) worstResult = result; // Enable the interrupt on all FIFOs
@@ -364,8 +370,12 @@ ICM_20948_Status_e ICM_20948::initializeDMP(void)
364370
// Set gyro sample rate divider with GYRO_SMPLRT_DIV
365371
// Set accel sample rate divider with ACCEL_SMPLRT_DIV_2
366372
ICM_20948_smplrt_t mySmplrt;
367-
mySmplrt.g = 4; // ODR is computed as follows: 1.1 kHz/(1+GYRO_SMPLRT_DIV[7:0]). 4 = 220Hz
368-
mySmplrt.a = 4; // ODR is computed as follows: 1.125 kHz/(1+ACCEL_SMPLRT_DIV[11:0]). 4 = 225Hz
373+
//mySmplrt.g = 19; // ODR is computed as follows: 1.1 kHz/(1+GYRO_SMPLRT_DIV[7:0]). 19 = 55Hz. InvenSense Nucleo example uses 19 (0x13).
374+
//mySmplrt.a = 19; // ODR is computed as follows: 1.125 kHz/(1+ACCEL_SMPLRT_DIV[11:0]). 19 = 56.25Hz. InvenSense Nucleo example uses 19 (0x13).
375+
mySmplrt.g = 4; // 225Hz
376+
mySmplrt.a = 4; // 225Hz
377+
//mySmplrt.g = 8; // 112Hz
378+
//mySmplrt.a = 8; // 112Hz
369379
result = setSampleRate((ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), mySmplrt); if (result > worstResult) worstResult = result;
370380

371381
// Setup DMP start address through PRGM_STRT_ADDRH/PRGM_STRT_ADDRL
@@ -436,7 +446,7 @@ ICM_20948_Status_e ICM_20948::initializeDMP(void)
436446
// 0=1125Hz sample rate, 1=562.5Hz sample rate, ... 4=225Hz sample rate, ...
437447
// 10=102.2727Hz sample rate, ... etc.
438448
// @param[in] gyro_level 0=250 dps, 1=500 dps, 2=1000 dps, 3=2000 dps
439-
result = setGyroSF(4, 3); if (result > worstResult) worstResult = result; // 0 = 225Hz (see above), 3 = 2000dps (see above)
449+
result = setGyroSF(4, 3); if (result > worstResult) worstResult = result; // 4 = 225Hz (see above), 3 = 2000dps (see above)
440450

441451
// Configure the Gyro full scale
442452
// 2000dps : 2^28
@@ -448,17 +458,20 @@ ICM_20948_Status_e ICM_20948::initializeDMP(void)
448458

449459
// Configure the Accel Only Gain: 15252014 (225Hz) 30504029 (112Hz) 61117001 (56Hz)
450460
//const unsigned char accelOnlyGain[4] = {0x03, 0xA4, 0x92, 0x49}; // 56Hz
451-
const unsigned char accelOnlyGain[4] = {0x00, 0xE8, 0xBA, 0x2E}; // InvenSense Nucleo example uses 225Hz
461+
const unsigned char accelOnlyGain[4] = {0x00, 0xE8, 0xBA, 0x2E}; // 225Hz
462+
//const unsigned char accelOnlyGain[4] = {0x01, 0xD1, 0x74, 0x5D}; // 112Hz
452463
result = writeDMPmems(ACCEL_ONLY_GAIN, 4, &accelOnlyGain[0]); if (result > worstResult) worstResult = result;
453464

454465
// Configure the Accel Alpha Var: 1026019965 (225Hz) 977872018 (112Hz) 882002213 (56Hz)
455466
//const unsigned char accelAlphaVar[4] = {0x34, 0x92, 0x49, 0x25}; // 56Hz
456467
const unsigned char accelAlphaVar[4] = {0x3D, 0x27, 0xD2, 0x7D}; // 225Hz
468+
//const unsigned char accelAlphaVar[4] = {0x3A, 0x49, 0x24, 0x92}; // 112Hz
457469
result = writeDMPmems(ACCEL_ALPHA_VAR, 4, &accelAlphaVar[0]); if (result > worstResult) worstResult = result;
458470

459471
// Configure the Accel A Var: 47721859 (225Hz) 95869806 (112Hz) 191739611 (56Hz)
460472
//const unsigned char accelAVar[4] = {0x0B, 0x6D, 0xB6, 0xDB}; // 56Hz
461473
const unsigned char accelAVar[4] = {0x02, 0xD8, 0x2D, 0x83}; // 225Hz
474+
//const unsigned char accelAVar[4] = {0x05, 0xB6, 0xDB, 0x6E}; // 112Hz
462475
result = writeDMPmems(ACCEL_A_VAR, 4, &accelAVar[0]); if (result > worstResult) worstResult = result;
463476

464477
// Configure the Accel Cal Rate

0 commit comments

Comments
 (0)