finani / ICM42688

Arduino library for communicating with the InvenSense ICM42688 nine-axis IMUs.
MIT License
47 stars 21 forks source link

FIFO fixes per datasheet #14

Closed FaaizMemonPurdue closed 2 months ago

FaaizMemonPurdue commented 3 months ago

Part 1: [35fcc48]

Bug: FIFO_EN had the old value (0x23) from ICM20689 Fix: updated per 42688 datasheet

Part 2 [16486a2, 8dda68c]

Context:

There are only four valid packet structures which the ICM42688 FIFO may emit (datasheet section 6.1): image

Note: Structure 3 and 4 are the only two which pass both accelerometer and gyroscope data, the only difference being that structure 4 adds high-resolution (16 -> 20-bit for accel/gyro, 8 -> 16 for temp). This library does not yet support the high-resolution mode in general and adding support will require several changes in data organization and function signatures. Accordingly, if both gyroscope and accelerometer data are expected, the subsequent code assumes Structure 3.

Bug: FIFO packets were being read as if the structure could be any subsequence from [6 Byte Accel, 2 Byte Temp, 6 Byte Gyro]. This was not valid as:

Fix 1: ReadFifo now accounts for the header byte and correctly orders temperature after accelerometer and/or gyro Fix 2: Calling enableFifo now sets internal parameters forcing adherence to the best fitting of the valid Packet Structures 1-3 (cannot support Packet 4 as there is no high-resolution argument)

Optimizations: Precalculate numFrames and data indices within each packet once per FIFO read. The current method performed the same static calculation every packet. This is redundant unless the structure is calculated by each packet's header, but this is not reliable as a header does not entirely convey the size.

Part 3 [11d65de]

Feature: Added function to set the FIFO mode to "Stream-To-FIFO". In my testing, this was necessary to collect any data and appears to be required under most (if not all) sensor configurations.