uint32_t begin_cycles = ARM_DWT_CYCCNT;
// do something that takes time
uint32_t end_cycles = ARM_DWT_CYCCNT;
Serial.print("cycles = ");
Serial.println(end_cycles - begin_cycles);
as long as the "do something that takes time" does not takes longer than the roll-over timeSubtracting this way automatically handles the roll over case, so it's really very simple to use.
which is about 7 seconds at 600 MHzas long as the "do something that takes time" does not takes longer than the roll-over time
On Teensy 4.x at the default 600MHz it thus rolls over to zero about every 7 seconds.
as long as the "do something that takes time" does not takes longer than the roll-over time
which is about 7 seconds at 600 MHz
The problem remembering the 7 second limit. It is easy/efficient to use ARM_DWT_CYCCNT 'all the time' - but keeping in mind that after 32 bit rollover the results are bad.measure period bigger than 7s, with 1.6ns resolution