// Output is probably enabled by dac_init or dac_enable but otherwise it must be done also.
Init1msClock();
}// end init
voidInit1msClock(void)
{
next_ms=rtc_count_get_count(&rtc_instance_struct)+1;// 1 ms from now.
}
voidUpdate1msClock(void)
{
// Create a 1 ms clock (0.9765625 ms). Counts in 64 bit mode so it will last to the end of the world.
// To not create unnecessary large disturbance on the application this is not interrupt driven.
// The counter is supposed to count exact ms but the result from the crystal driven counter will meet exactly only once every second. (32768 = 2^15)
// Instead it will check the RTC timer and increment the ms counter several steps as needed if it misses because of longer delays.
// The counter is supposed to count exact ms but the result from the crystal driven counter will give exact match only once every second. (32768 = 2^15)
// This results in that the ms counter will count a little to slow.
// Therefore the ms counter is optionally error compensated once every second.
// Turning it on results in that 7 (false) ms is removed every second.
...
...
@@ -226,8 +234,10 @@ void Update1msClock(void)
#endif
rtc_64_bit_counter=rtc_count_get_count(&rtc_instance_struct);// This is the time right now. Can lock 30.5 s to synchronize the system clock to the slower RTC clock
// Check for wrap-around. (There is a small risk that a wrap around happens just between reading RTC value and the check).
if(RTC->MODE0.INTFLAG.bit.OVF!=0)
// Check for wrap-around of RTC clock. Since the RTC clock is 32 bits this will happen after a little more than 1 hour for a 1 ms timer.
// To avoid the (unlikely) situation that there is an overflow just after the reading of the RTC counter, it also check if the value was 0xFFFFFFFF