2

Is there any good way to calibrate the watchdog timer? I'm trying to use it as a time source, even when asleep, but it's woefully inaccurate. Some simple testing showed it loosing 2 minutes every hour!

1 Answer 1

4

Not only is it uncalibrateable, but it's actually pretty rubbish (as you've discovered). If you check the datasheet you'll see that it can vary between about 109kHz and 119kHz, even though its nominal frequency is 128kHz.

With the ATmegaXX8(A/P) you can reconfigure the system to run its CPU off the internal RC oscillator and timer 2 from a crystal across TOSC1/TOSC2 (pins 9/10 [DIP] or 7/8 [TQFP]) by setting ASSR[6:5] to 0b01 and changing the CKSEL[3:0] fuse bits to 0b0010. Take careful note of the warning on AS2 in the datasheet though. If you want to use a watch crystal instead of prescaling the existing crystal on an Arduino board then you'll need some soldering skill as well.

If you need crystal accuracy for the CPU as well then you'll need to move up to an AVR family that has a separate asynchronous timer that can be supplied with a watch crystal, such as the ATmegaXX4(P) (Sanguino) or ATmegaXXX0 (Mega/Mega 2560).

5
  • Supposedly the regular 328p can handle a watch crystal in place of the 8/16Mhz crystal. I've been looking into that as an option, but can't really find any good documentation.
    – Adam Haile
    Commented Apr 9, 2014 at 3:44
  • That will slow down your entire system though; you may as well just turn on the prescaler in that case. Commented Apr 9, 2014 at 3:45
  • Also, section 9 of the datasheet, "System Clock and Clock Options". Commented Apr 9, 2014 at 3:45
  • According to the datasheet you can use the XTAL/TOSC pins in asynchronous low frequency timer mode but then use the internal crystal for system time.
    – Adam Haile
    Commented Apr 9, 2014 at 3:46
  • You're correct; I'll amend my answer. Commented Apr 9, 2014 at 3:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.