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

BHY2.update() not producing sensor data at even time intervals #111

Open
perry-tcircuits opened this issue Aug 16, 2023 · 0 comments
Open

Comments

@perry-tcircuits
Copy link

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).

image

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);
  }

}
@perry-tcircuits 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant