Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sampling Rate Does Not Match Configured Value (800 Hz) #48

Open
dirkniemann opened this issue Dec 5, 2024 · 0 comments
Open

Sampling Rate Does Not Match Configured Value (800 Hz) #48

dirkniemann opened this issue Dec 5, 2024 · 0 comments
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@dirkniemann
Copy link

Description:

When using the example script provided with the Arduino_BMI270_BMM150 library and setting the accelerometer sampling rate to 800 Hz in the BMI270.cpp file, the actual output on the Serial Monitor does not reach 800 Hz. Instead, the sampling appears to max out at approximately every 4 ms (~250 Hz).

The issue seems related to the time it takes for the IMU.readAcceleration() function to execute, which I measured to take around 4 ms per call.

The sample rate is being correctly set in the library as IMU.accelerationSampleRate() correctly returns 800. However, the observed behavior indicates that the IMU.readAcceleration() function might be causing the bottleneck.

Steps to Reproduce:

  1. Modify the BMI270.cpp file to set the accelerometer sampling rate to 800 Hz:
sens_cfg[0].cfg.acc.odr = BMI2_ACC_ODR_800HZ; // Set to 800 Hz
sens_cfg[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4; // Use normal avg4
sens_cfg[0].cfg.acc.range = BMI2_ACC_RANGE_2G; // Set range to 2G

change conversion factor:

#define INT16_to_G   (16384.0f) //for 2G range
  1. Upload the provided example code Arduino BMI270 - Simple Accelerometer with the above library modifications.
  2. Observe the Serial Monitor output.

Observed Behavior:

The serial output only updates approximately every 8 ms. By editing the code and using buffer before printing I could speed the serial output to approximately every 4 ms.
The actual sampling rate is far lower than the configured 800 Hz.

Expected Behavior:

The accelerometer sampling rate should match the configured value of 800 Hz.
Code Example:

#include "Arduino.h"
#include "Arduino_BMI270_BMM150.h"

void setup() {
  Serial.begin(9600);
  while (!Serial);
  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
    while (1);
  }
  Serial.print("Accelerometer sample rate = ");
  Serial.println(IMU.accelerationSampleRate());
}

void loop() {
  float x, y, z;
  int timestamp = millis();
  if (IMU.accelerationAvailable()) {
    IMU.readAcceleration(x, y, z);
    Serial.print(timestamp);
    Serial.print("\t");
    Serial.print(x);
    Serial.print("\t");
    Serial.print(y);
    Serial.print("\t");
    Serial.println(z);
  }
}

Enviroment

  • Board: Arduino Nano 33 BLE Sense Rev2
  • Library: Arduino_BMI270_BMM150
  • using VSCode with PlatformIO

Additional Notes:

This issue seems to stem from the time required for the IMU.readAcceleration() function to complete. At higher sample rates, this latency is significant enough to prevent achieving the configured rate.

Could this be optimized in the library, or is there a limitation in the sensor or library design that I should consider? Any guidance or fixes would be appreciated.

Thank you!

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants