You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to collect accelerometer data at about 166 Hz so that I can perform a spectral analysis on it, but to do this I need to have data coming in at even time intervals. I've created a simple timing structure to log the acceleration and time every 6 ms over Serial communication, I find that BHY.update() takes variable amounts of time on each loop, which is not ideal. In the code that I've included below, the interval between time points can be up to 10 ms. While i'd expect the interval to between 6 and 7 ms per point, I'm not sure why the delay gets above these values, here's a graph showing how the interval changes suring a 20 second experiment (forgive the x axis being negative, I normalized it incorrectly).
Target(s) affected by this defect ?
Nicla Sense ME
Toolchain(s) (name and version) displaying this defect ?
What version of Mbed-os are you using (tag or sha) ?
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
How is this defect reproduced ?
#include "Nicla_System.h"
#include "Arduino_BHY2.h"
SensorXYZ accelerometer(SENSOR_ID_ACC);
// SensorBSEC bsec(SENSOR_ID_BSEC);
void setup(){
Serial.begin(115200);
//Sensors initialization
// BHY2.begin(NICLA_STANDALONE);
BHY2.begin();
// accelerometer.begin(1000,0);
accelerometer.begin();
}
void loop(){
static unsigned long previousMillis = 0;
const unsigned long interval = 6;
unsigned long currentMillis = millis();
BHY2.update(); // I've tried putting this both within and outside of the if-block
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis; // Save the current time
float x = accelerometer.x();
float y = accelerometer.y();
float z = accelerometer.z();
float time = currentMillis;
Serial.println();
Serial.print(x);
Serial.print(", ");
Serial.print(y);
Serial.print(", ");
Serial.print(z);
Serial.print(", ");
Serial.print(time);
}
}
The text was updated successfully, but these errors were encountered:
perry-tcircuits
changed the title
BHY.update() not producing sensor data at even time intervals
BHY2.update() not producing sensor data at even time intervals
Aug 16, 2023
Description of defect
I would like to collect accelerometer data at about 166 Hz so that I can perform a spectral analysis on it, but to do this I need to have data coming in at even time intervals. I've created a simple timing structure to log the acceleration and time every 6 ms over Serial communication, I find that BHY.update() takes variable amounts of time on each loop, which is not ideal. In the code that I've included below, the interval between time points can be up to 10 ms. While i'd expect the interval to between 6 and 7 ms per point, I'm not sure why the delay gets above these values, here's a graph showing how the interval changes suring a 20 second experiment (forgive the x axis being negative, I normalized it incorrectly).
Target(s) affected by this defect ?
Nicla Sense ME
Toolchain(s) (name and version) displaying this defect ?
What version of Mbed-os are you using (tag or sha) ?
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
How is this defect reproduced ?
The text was updated successfully, but these errors were encountered: