AVR132: Using the Enhanced Watchdog Timer
Features
•
Watchdog System Reset Source
•
Parameter Backup Prior to Watchdog System Reset
•
Wakeup Timer from all Sleep Modes
•
Using the Watchdog for Both Wakeup and System Reset
•
Handling the Watchdog Reset Flag
•
Changing the Watchdog Configuration
•
Flowcharts for Watchdog Operation
•
Example Source Code
Introduction
“Well designed watchdog timers fire off every day, quietly saving systems and lives
without the esteem offered to human heroes.” - Jack Ganssle
No piece of software, save the very smallest, is free from bugs. The application could
get stuck in endless loops. Unexpected error codes could cause serious problems if
not handled correctly. Electrical noise or an unusual sequence of external events
could put the system in a state not thought of by the designers. All these cases could
potentially hang the system forever or cause serious damage to its surroundings.
Automatic handling and recovery of such cases is the job of a watchdog timer.
The Enhanced Watchdog Timer (WDT) runs independent of the rest of the system,
causing system resets whenever it times out. However, the application software
should ensure that the timeout never occurs by resetting the WDT periodically as long
as the software is in a known healthy state. If the system hangs or program execution
is corrupted, the WDT will not receive its periodic reset, and will eventually time out
and cause a system reset.
The WDT in all new AVR devices also has the ability to generate interrupts instead of
resetting the device. Since the WDT runs from its own independent clock, it can be
used to wake up the AVR from all sleep modes. This makes it an ideal wakeup timer,
easily combined with ordinary operation as a system reset source. The interrupt can
also be used to get an early warning of a upcoming Watchdog System Reset, so that
vital parameters can be backed up to non-volatile memory.
8-bit
Microcontrollers
Application Note
Rev. 2551A–AVR–11/03