Using the XMega128A1 RTC without using any interrupts?

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

Anyone using the XMega128A1 RTC without using any interrupts or events?

The manual tells us this:

Quote:
17.2.2 Interrupts and events The RTC can generate both interrupts and events. The RTC will give a compare interrupt request and/or event when the counter value equals the Compare register value. The RTC will give an overflow interrupt request and/or event when the counter value equals the Period register value. The overflow will also reset the counter value to zero.

I can't find anything in the documentation that says what happens with the RTC if you do not enable RTC interrupts or events.

I made the apparently invalid assumption that the counter would continue to count after it overflowed. What I am seeing is that the counter stops as some arbitrarily small value generally less than 100 counts, probably due to the clock domain synchronization. It takes 3 CPU clocks to read from the RTC clock domain, takes 3 RTC clocks to write to the RTC domain; note the difference between the two easy to miss.

Can anyone confirm this is how the part is, or is meant to operate, and the documentation is just a bit lacking in this case?

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

bpaddock wrote:

Can anyone confirm this is how the part is, or is meant to operate, and the documentation is just a bit lacking in this case?

Bob,

I just disabled interrupts. The RTC keeps counting from 0 to RTC_CYCLES_1S (PER register) based on the example. In my case, RTC_CYCLES is 63. Are you using a larger value?

RTC_Initialize( RTC_CYCLES_1S, 0, 0, RTC_PRESCALER_OFF_gc );

Let me know if you want me to try something else.

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

telliott wrote:

RTC_Initialize( RTC_CYCLES_1S, 0, 0, RTC_PRESCALER_OFF_gc );

PRESCALER_OFF? That stops the RTC.

  CLKSYS_RTC_ClockSource_Enable( CLK_RTCSRC_TOSC_gc ); /* 1024 Hz = 32kHz external crystal /32 */
  while( RTC_Busy() )
    ;
  RTC.PER  = 2;
  RTC.COMP = 2;
  RTC.CNT  = 1234;
  //  RTC.CTRL = RTC_PRESCALER_DIV1024_gc; /* Rollover in 18 hours and 12 minutes */
  RTC.CTRL = RTC_PRESCALER_DIV1_gc; /* Rollover at 64 seconds */

Is what I have, was not using the rtc_driver code other than for busy().

Unit just ended the 18 hour cycle, where it stopped counting.

Must stop on match, regardless of interrupts or events being used.

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

bpaddock wrote:
telliott wrote:

RTC_Initialize( RTC_CYCLES_1S, 0, 0, RTC_PRESCALER_OFF_gc );

Quote:
PRESCALER_OFF? That stops the RTC.

yeah.. I was just looking at the PER value. I stop the RTC before intializing it in my code. Here is what I have. It keeps rolling over in my case, but I'm setting RTC.COMP to 0 (not sure if that matters). The manual does mention

Quote:
If the COMP value is higher than the PER value, no RTC Compare Match interrupt requests or events will ever be generated.


do {
      /* Wait until RTC is not busy. */
} while ( RTC_Busy() );
RTC_Initialize( RTC_CYCLES_1S, 0, 0, RTC_PRESCALER_OFF_gc );

/* Set internal 32kHz oscillator as clock source for RTC. */
CLK.RTCCTRL = CLK_RTCSRC_RCOSC_gc | CLK_RTCEN_bm;
do {
  /* Wait until RTC is not busy. */
} while ( RTC_Busy() );

/* Configure RTC period to 1 second. */
RTC_Initialize( RTC_CYCLES_1S, 0, 0, RTC_PRESCALER_DIV1_gc );


/* Turn on internal 32kHz. */
OSC.CTRL |= OSC_RC32KEN_bm;

do {
   /* Wait for the 32kHz oscillator to stabilize. */
} while ( ( OSC.STATUS & OSC_RC32KRDY_bm ) == 0);

....

enable interrupts...