![Atmel AVR132 Скачать руководство пользователя страница 7](http://html1.mh-extra.com/html/atmel/avr132/avr132_application-note_3003535007.webp)
7
AVR 132 Application Note
2551A–AVR–11/03
Using the WDT in
Combined Operation
It is also possible to set up the WDT to work as a wakeup timer when entering sleep
mode, and switch to WDT System Reset operation when back in active mode. With this
setup there is no need for disabling the WDT Interrupt Mode, as it is automatically dis-
abled by the hardware. To use the WDT as a periodic wakeup source, the application
therefore has to enable the WDT Interrupt Mode prior to entering sleep mode every
time.
Re-enabling the WDT Interrupt Mode inside the interrupt handler is not recommended,
as it could cause the WDT to get stuck in WDT Interrupt Mode, if some parts of the code
fail.
When the CPU is back in active mode, the WDR instruction is used for resetting the
WDT inside the main loop as described earlier. With WDT Interrupt Mode disabled, the
WDT functions just as it did without the wakeup functionality.
If timeout warning prior to system reset is needed for parameter backup etc., the WDT
Interrupt handler needs some slight changes. The interrupt handler must use a flag to
decide whether it should serve a wakeup interrupt or a timeout warning interrupt. An
example interrupt handler is shown in Figure 5.
Figure 5. Dual purpose WDT Interrupt Handler
Note that the wakeup flag must be set manually prior to entering sleep mode to ensure
that the correct part of the handler is executed on wakeup. The WDT Interrupt Mode
must be re-enabled outside the interrupt handler after serving the wakeup interrupt.
The right branch of the flowchart is described in the section on parameter backup.
Startup Considerations
When designing for devices having the Enhanced Watchdog Timer, it is important to
evaluate the WDT Reset Flag in the startup code. This applies even if the application
never intends to use the WDT. If the WDT System Reset Mode should unintentionally
be enabled and cause a system reset, the WDT Reset Flag will be set and the WDT
System Reset Mode is kept enabled after the system reset. Therefore the startup code
should check the WDT Reset Flag and disable the WDT System Reset Mode if it is
enabled but never used. These considerations apply when the WDTON fuse is unpro-
Backup vital
parameters
WDT Interrupt Handler
WDT Interrupt Mode
disabled
Set Write Complete
Flag
Infinite loop
Wakeup Flag
set ?
Clear Wakeup Flag
Return
No
Yes
Re-enable WDT
Interrupt Mode
SLEEP
Set Wakeup Flag
Continue
Section from main code
where entering sleep