![Atmel AVR132 Application Note Download Page 5](http://html1.mh-extra.com/html/atmel/avr132/avr132_application-note_3003535005.webp)
5
AVR 132 Application Note
2551A–AVR–11/03
Parameter Backup Prior
to WDT System Reset
The method described in the previous section does not give any warning of a coming
WDT System Reset. The application has no means of handling a timeout in software
before the system reset occurs. However, by using the WDT Interrupt Mode, the appli-
cation can use the WDT Interrupt handler for backing up vital parameters before the
actual reset.
By enabling both WDT System Reset Mode and WDT Interrupt Mode, the first timeout
will disable the WDT Interrupt Mode and run the interrupt handler. The second timeout
then causes a system reset. The interrupt handler then has one timeout period for back-
ing up parameters, for example, to EEPROM. The sequence of events is shown in
Figure 3. The dotted boxes describe actions performed by the system. The solid lined
boxes describe actions to be performed by the application
Figure 3. Parameter Backup Prior to WDT System Reset
The Write Complete Flag could be a byte in EEPROM indicating whether the backup
operation was finished before the system reset. This flag is checked in the startup code
if the WDT Reset Flag is set, and the backed up parameters can be used for restoring
system state or debugging purposes. The flag should be cleared during initialization to
invalidate the parameters if other types of resets occur.
Note that there is no guarantee that the interrupt handler is executed prior to a WDT
System Reset. If interrupts are disabled too long, the interrupt handler will never execute
before the second timeout. Runaway pointers or electrical noise could also unintention-
ally disable the WDT Interrupt Mode. Therefore the Write Complete Flag is our means of
knowing if the stored parameters are valid or not.
The infinite loop at the end of the interrupt handler prevents the main code from poten-
tially causing more damage.
Backup vital
parameters
1st WDT timeout
WDT Interrupt Mode
disabled
2nd WDT timeout
WDT System Reset
STARTUP
Set Write Complete
Flag
Infinite loop
WDT Reset Flag set
WDT System Reset
Mode enabled