Dear all,
For a while now I have been using the data-forwarder to acquire data in edge-impulse.
Initially I wrote a simple piece of firware to forward x, y and z accelerometer values at 100Hz. The forwarder detected 101Hz, which was weird, but maybe it was because of my simplistic firmware.
Now, a few months later I had the problem with the spectrogram (see my previous post), so that frequency of 101Hz kept giving issues.
I have refined my piece of code and wrote it in two ways (mbed), once with a ticker, once with an event queue. I post the code with the event queue below.
I tried out different call times and checked the detected frequency of the data forwarder:
- 10ms --> 101Hz
- 20ms --> 51Hz
- 1000ms --> freq should be higher than 2Hz
- 500ms --> 3Hz
I still doubted about my code, so I measured the on- and off-time of the LED on the device with a scope, which shows that it is actually exactly 500ms! (when configuring 500ms).
Photo of the scope:
Code:
#include "mbed.h"
#include "USBSerial.h"
#include "LSM303AGRAccSensor.h"
USBSerial serial;
DigitalOut led((PinName)0x6C);
EventQueue queue(32 * EVENTS_EVENT_SIZE);
SPI devSPI(PB_15, NC, PB_13); // 3-wires SPI on SensorTile
static LSM303AGRAccSensor accelerometer(&devSPI, PC_4);
FileHandle *mbed::mbed_override_console(int) {
return &serial;
}
void toggleLed() {
led = !led;
}
void initializeAccelerometer() {
uint8_t id;
int32_t axes[3];
accelerometer.init(NULL);
accelerometer.enable();
accelerometer.read_id(&id);
//printf("LSM303AGR accelerometer = 0x%X\r\n", id);
accelerometer.get_x_axes(axes);
//printf("LSM303AGR [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
}
void readAccelerometer() {
int32_t axes[3];
accelerometer.get_x_axes(axes);
printf("%ld,%ld,%ld\n\r",axes[0],axes[1],axes[2]);
toggleLed();
}
int main(void)
{
led = 1;
initializeAccelerometer();
queue.call_every(500ms, readAccelerometer);
queue.dispatch_forever();
}
Is it possible that the data forwarder adds one Hz too much?
Or when looking at the actual software, does it count one “\n” too much in 1000ms?
Is the best way to go to always override the detected frequency with the --frequency option?
Best regards,
Jonas