RTC AFAIK only ticks and updates on the seconds - at least directly ...
THOUGH - after writing the following an old sketch was pulled up - with
THREAD LINK: millisecond-precision-from-Teensy-3*-RTC that may provide a better answer and direct solution.
EDIT: - though using that to read can be gone a long time ... maybe that is just the 1062 version that runs differently ... and doesn't return ms as linked below ...
The Teensy counts time with milliseconds - gets 1K updates each 'teensy second'. Anything disabling interrupts can skew that counting toward the next second update if one 1/1000th tick is missed.
Seems the RTC uses a unique crystal - so the two may diverge with each crystal being unique.
Watching the RTC for change in second and coordinating that with ARM_DWT_CYCCNT there will be some similar count diff between subsequent ARM_DWT_CYCCNT readings - that should be close to the F_CPU, perhaps 180 MHz.
That will change over time and temp where the observed count will have minor fluctuations from dozens in the short term to perhaps hundreds in a 24 hour period.
But for short timing periods, knowing the current RTC second and ARM_DWT_CYCCNT the offset from that last pairing will give the part of a second into the current second toward the next second.
Note the T_3.6 doesn't have the ARM_DWT_CYCCNT running by default, so this code will start it if it isn't started already:
Code:
if ( ARM_DWT_CYCCNT == ARM_DWT_CYCCNT ) { // Enable CPU Cycle Counter
ARM_DEMCR |= ARM_DEMCR_TRCENA; // enable debug/trace
ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; // enable cycle counter
}
Finding the diff in ARM_DWT_CYCCNT is easy with uint32_t's - as long as the F_CPU cycle count doesn't overflow the 32 bit unsigned int:
Code:
uint32_t startCNT = ARM_DWT_CYCCNT;
// do some delay( 10 );
uint32_t endCNT = ARM_DWT_CYCCNT;
uint32_t diffCNT = endCNT - startCNT;
Seems there was a way to get an interrupt trigger on RTC second change? In looking for that in old sketches - the above link was found ... ANd it might be a direct working answer for the T_3.6?
EDIT: For T_4's 1062 RTC seems Manitou did it again (Sep 19, 2019):
github.com/manitou48/teensy4/blob/master/rtc.ino