ATtiny416 RTC clock

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

The datasheet says:

 

23.2.3.1 "System clock (CLK_PER) is required to be at least four times faster than RTC clock (CLK_RTC) for reading counter
value, and this is regardless of the RTC_PRESC setting."
 

 

Does anyone know if this applies only to the actual  RTC counter (RTC_CNT) or if it means any of the RTC 16-bit or 8-bit registers?  And does it apply only to reading, or also to writing?  I don't need to read the RTC_CNT.  I could just write once to RTC_PER and then poll the overflow interrupt flag to keep track of time.

 

Also, the block diagram in the ATtiny416 clock section (10.2.1) clearly shows a 32.768 kHz external signal going to both CLK_PER and CLK_RTC. But the datasheet says:

 

23.8 "Both the RTC and the PIT are asynchronous, operating from a different clock source (CLK_RTC) independently of
the main clock (CLK_PER)."

 

If I want to run the entire chip at 32.768 kHz, do I need to use the internal 32 kHz oscillator for CLK_PER and the external 32 kHz crystal for the RTC?

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

I have a mega4809 curiosity board with a ext 32k crystal, and I would think any 1 series would act the same.

 

Quick test-

 

int main(){
    Port<PINS::PF5, PINS::OUTL> led;
    Clkctrl::setup( Clkctrl::XOSC32K, Clkctrl::PREOFF, 32768 ); //main clock
    for(;;){
        led.toggle();
        Delay::wait( 1_ms ); //always get multiples of 2 sec no matter what
    }
}

 

I use the rtc as the delay source and time source with a rollover at 2 seconds. The counter is used for the 16bit fraction of 2 seconds and the overflow interrupt counts 2 seconds for date/time use. The above test results in a 2sec on, 2sec off blink of led. The counter is not being read and the only resolution I can get is from the overflow (2 seconds).

 

So, the overflow works, reading the counter does not. I have some 416 boards and an 817 board, but no crystals on them. I would assume they act the same way.

 

 

This is slowest I can do (>4x rtc), which works ok-

 

int main(){
    Port<PINS::PF5, PINS::OUTL> led;
    Clkctrl::setupHiSpeed<312500_Hz>(); // >4x rtc
    for(;;){
        led.toggle();
        Delay::wait( 500_ms ); //works
    }
}

 

Unless you do not have a crystal, you could also just run your own tests.

Last Edited: Mon. Feb 24, 2020 - 04:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks.  This is helpful.   I'll run some tests; I just wanted to make sure what I was doing was allowed and doesn't just work some of the time.  So you run both the main clock and the RTC clock with just the external crystal?

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

That is, CLK_MAIN, CLK_PER, and CLK_RTC?

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

Yes. The main clock has xosc32k selected, and the rtc does also. CLK_PER has the same source as CLK_CPU, so they are the same up until one of them is shut off because of a sleep mode or I suppose if per has no one requesting its use. CLK_MAIN is only accessible by the main clock prescaler so only indicates which main clock is selected.

 

Although it cannot be seen in the example, any use of Delay starts the rtc if not already started/setup and in this case the xosc32k is specified for the rtc since the board has the crystal.

Last Edited: Mon. Feb 24, 2020 - 05:45 PM