RTC periodic event / interrupt

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using the RTC in a SAML21 to keep track of time. It is using the OSCULP32K 1 kHz output as the driving clock for the RTC. I also have TC4 set up as a 16-bit counter also using the OSCULP32K clock, routed through GCLK3. The desire is to reset/restart TC4 each second so I can have sub-second timestamps.

 

I initially set up the RTC as an event generator, using the 7th periodic event. TC4 consumes the event and restarts. The frequency of the TC4 reset was 1Hz as desired, but the resets did not line up with the RTC counts. When looking at the values TC4 resets about halfway through the RTC seconds. The same thing happens if I clear the TC4 count value from an interrupt using the 7th periodic event.

 

This seems strange since the 7th periodic event/interrupt is generated by the 10th bit of the RTC pre-scaler, dividing the RTC input by 10.... which is the same way the seconds are counted in the RTC??

 

Am I wrong to presume that the 7th periodic interrupt should happen at the top of each RTC second and not somewhere in the middle of the second?

 

Any advice on this would be appreciated.

Last Edited: Sat. Jun 2, 2018 - 07:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Skip the TC4 reset.  Setup TC4 as a 1ms free running timer with a very simple interrupt that increments an unsigned counter variable.  Then when you need sub-seconds with your timestamp, use the TC4 counter variable mod 1000 to get milliseconds (milliseconds = Counter % 1000)

 

For less resolution setup TC4 for a slower period at X milliseconds per interrupt.  Increment the counter every interrupt.  Then calculate sub-seconds with milliseconds = (Counter * X) % 1000.

Last Edited: Mon. Jun 4, 2018 - 01:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is not really an option, since the system needs to sleep for the majority of the time. I actually tried this (with the slower period/lower resolution) just to see because it is the obvious solution but it more than doubled my average power consumption.