Why is RTC.CNT getting reset?

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

I'm running on an ATtiny3217.  I'd like to configure the RTC to count up continually, rolling over (of course) after 0xffff.

 

Instead, it seems to get reset after reaching 0x0001.  My test case is more or less:

 

volatile uint16_t a, b;  // volatile to avoid optimizing away

while(1) {
    a = RTC.CNT;
    do {
        // loop until RTC.CNT changes
        b = RTC.CNT;
    } while (b == a);
    asm("nop");          // breakpoint here
}

I observe a=0, b=1 the first time through the loop, and a=1, b=0 the next time through the loop.

 

There's no other code (at least that I've written) that modifies RTC.CNT.  I've read the docs, and if there is something that resets RTC.CNT, I missed it. 

 

So: What might be causing RTC.CNT to get reset to zero?

 

Update:

 

Standby -- I think I see what I missed in the docs.  I'll add comment once I verify it...

 

This topic has a solution.
Last Edited: Sun. Mar 13, 2022 - 05:34 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Right.  The bit I missed in the document was:

 [The RTC] will generate ... an overflow interrupt and/or event at the first count after the counter value equals the Period register value. The overflow will reset the counter value to zero.

So setting RTC.PER = 0xffff appears to be the solution.

 

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

RTC.PER is already 0xFFFF out of reset.