Asynch timer2 vs timer1 for RTC applications

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

For applications which require a real time clock on smaller AVRs (such as M168), there are two techniques for generating a 1Hz interrupt that I know of: external 32.768khz crystal clocking timer2 in asynchronous mode or load TCNT1 with the proper value inside your TOVF1 interrupt. I have used both of these and both work fine for generating a 1Hz interrupt. However, in my way of thinking, the 32khz method is the poorer choice. It forces you to use the internal oscillator for the system clock, which can only be set to a few values, and really limits your possible UART baudrates.

Am I alone in thinking this or is there some benefit to the 32khz crystal method that I'm missing?

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

Quote:

However, in my way of thinking, the 32khz method is the poorer choice. It forces you to use the internal oscillator for the system clock, which can only be set to a few values, and really limits your possible UART baudrates.

Actually, it makes it quite nice. If you keep the external 32kHz running, then you can tune the internal oscillator to very near 3.6864MHz or 7.3728MHz.

But unless you need to stop the oscillator for power-down, why not just use a nice crystal that divides to what you want?

Are you waking up with the timer overflow/compare match? If not, then an 8-bit timer with counting fractions of seconds would work just fine.

Tell more about the compelling reasons.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Hmm, okay I think I see the light now. My app is long term battery powered datalogging... This means the 32khz crystal is the better choice since it must remain running even during sleep for the RTC. I think that was the key point I was missing. I can still get the 115.2 kbps UART, 1Hz interrupts, and sub-1Hz interrupts that I want, but the power consumption will be lower overall running with the 32khz crystal + internal oscillator. Sound right?

Edit: I also forgot you can tune the internal osc to those baudrates, that helps tremendously.

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

Quote:

but the power consumption will be lower overall running with the 32khz crystal + internal oscillator. Sound right?

Dunno; would have to check the datasheet. We wanted to run "forever" on our battery, so we needed to get down to a few uA during power-down. IIRC you will be at about 100uA if you keep the timer running, plus the draw of the 32kHz crystal. You might want to evaluate the power draw of [say] a DS1305 which runs virtually forever on a button cell and can wake you periodically.

It will depend on your app. But you can definitely tune the internal oscillator to real close to the magic frequencies to get reliable serial comms if you have a definitive time base like the 32kHz. (And you only need to re-tune periodically if you want.)

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.