I'm using the IMU for sensor fusion on the Nano 33. I'm running the SensorFusion library (GitHub - aster94/SensorFusion: A simple implementation of some complex Sensor Fusion algorithms) available in Arduino IDE -> Manage Libraries. It is based on Paul Stoffregen's IMU library GitHub - PaulStoffregen/MadgwickAHRS.
I'm trying to time how long it takes to run the MadgwickUpdate routine using micros(). But micros() is usually returning the same result before and after the call. Presuming this is incorrect.
code snippet (full .ino attached):
#ifdef DEBUG_SF_TIMING
SFthen = micros();
#endif
//choose only one of these two:
//fusion.MahonyUpdate(gx, gy, gz, ax, ay, az, deltat); //Mahony is suggested if there isn't the mag and the mcu is slow
fusion.MadgwickUpdate(gx, gy, gz, ax, ay, az, mx, my, mz, deltat); //else use the Madgwick. It is slower but more accurate
#ifdef DEBUG_SF_TIMING
SFnow = micros();
Serial.print("SensorFusion elapsed time (uS): ");
SFelapsedus = (SFnow - SFthen); //uS
Serial.println(SFelapsedus, 3);
Serial.println(SFnow);
Serial.println(SFthen);
Serial.println();
#endif
The sensorfusion algorithm is working well when output to Processing (after many days of work). Output of timestamps to serial monitor looks like:
Orientation:, 25, -7, -3
SensorFusion elapsed time (uS): 0.000
96490295
96490295
Orientation:, 25, -7, -3
SensorFusion elapsed time (uS): 0.000
96497253
96497253
Orientation:, 25, -7, -3
SensorFusion elapsed time (uS): 31.000
96503113
96503082
Orientation:, 25, -7, -3
SensorFusion elapsed time (uS): 0.000
96510040
96510040
Orientation:, 25, -7, -3
SensorFusion elapsed time (uS): 0.000
96515899
96515899
where you can see the timestamp pairs returned by micros() are often identical uS so elapsed is 0.
I am not aware of any interrupts anywhere, that would stop micros() from working.
I'm planning to post a tutorial on running sensorfusion on the Nano 33 after it's all working. 3DOF orientation tracking is pretty good at this point but I'm failing on timing the execution.
BTW, I have modified LSM9DS1.cpp to change IMU sensor frequencies as shown here: LSM9DS1: how to change sampling frequency and acceleration ranges - #7 by mathlete - Nano 33 BLE Sense - Arduino Forum.
Thanks for having a look!
IMU-SensorFusion-Nano33.ino (7.12 KB)