Hey everyone, I'm writing code to communicate with DAC and ADC chips. I want to have buffer ramps with microsecond precision, which I was able to do easily on the M7 processor, but not the M4. In fact, the M4 can be off by many microseconds, inconsistently off too. I understand that the clock speed of the M4 is half as fast as the M7 but shouldn't that contribute to latency on the order of tens of nanoseconds, not tens of microseconds? Here's a test program I wrote in loop() (nothing going on in setup except for setup RPC). Note that all code I'm writing is with Platformio, if that means anything:
unsigned long times[10];
void loop() {
for (int i = 0; i < 10; i++) {
times[i] = micros();
}
for (int i = 0; i < 9; i++) {
Serial.println(times[i + 1] - times[i]);
}
Serial.println("done");
}
This is something I've done on the M4 and M7, with Serial.println replaced with RPC.write on the M4, obviously. On the M7, you only get 1us difference between loop runs. On the M4, this value ranges between 2 and 19us. Very inconsistently.
I honestly have no idea why this is happening. Can anyone please help, I'm a very desperate undergrad ![]()