Seconds Clock using RTC Compare

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

I am using an xmega256a3u with the RTC running off an external oscillator with one second being equivalent to 1024 counts (so the RTC rolls after 64 seconds).  I would like to use RTC compare to count the seconds using an interrupt:

ISR(RTC_COMP_vect) {
	SecondsClock++;
	RTC.COMP += 1024;
}

I typically would check the RTC status before changing the RTC compare:

while (RTC.STATUS & RTC_SYNCBUSY_bm);
RTC.COMP += 1024;

Will I get dinged occasionally for not checking RTC status or can I "cheat" since I am in the ISR?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Datasheet says this:

 

But none of those things (wake or register write) have just occurred have they?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank for the quick response and the datasheet information.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you don't need the counter to roll over every 64 seconds, you could just set the period to 1023, enable the overflow interrupt, and be done with it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When my RTC interrupt occurs, it can wake up the CPU from a power save sleep which disables the PER clock.   

 

Last Edited: Fri. Jun 3, 2016 - 01:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have done this myself and it works reliably. I put in the STATUS check, because sometimes I was waking up from sleep on the second tick interrupt.