Hello Everyone, I am working on a timing sensitive Project, in which I use the Arduino GIGA board as a trigger for external applications. I outsourced parts of the code to the M4 core, so that this part can run on it uninterrupted by other parts of the code.
I noticed a delay (only on the M4 core) in this minimal example of my code.
This is the M7 Sketch:
#include<RPC.h>
void setup() {
Serial.begin(57600);
RPC.begin();
}
void loop() {
}
This is the M4 Sketch:
#include<RPC.h>
const int TRIGGER_FLASH = 2;
void setup() {
// Serial.begin(57600);
pinMode(TRIGGER_FLASH, OUTPUT);
RPC.begin();
}
long FLASH_DURATION_TIME = 300; // High time of signal in µs
long FLASH_OFF_TIME = 200; // Low time of signal in µs
void loop() {
while (true) {
digitalWrite(TRIGGER_FLASH, HIGH);
delayMicroseconds(FLASH_DURATION_TIME);
digitalWrite(TRIGGER_FLASH, LOW);
delayMicroseconds(FLASH_OFF_TIME);
}
}
This should produce a Period uf 500 µs. I measure a period of 780µs however. When setting the period to 2 ms in the sketch I can measure a value of 3.12 ms. After repeating this for a couple of different values, I calculated a factor of about 1.5 to 1.6 offset in the period.
Does anybody know whre this offset is coming from?