![Atmel AVR132 Скачать руководство пользователя страница 4](http://html1.mh-extra.com/html/atmel/avr132/avr132_application-note_3003535004.webp)
4
AVR 132 Application Note
2551A–AVR–11/03
Most embedded systems consist of some initialization code and a main loop. This con-
struction is also the most effective setup for use with a watchdog. An example for using
the WDT with such systems is shown in Figure 2.
Figure 2. Main loop when using the WDT System Reset Mode
Note that if the timeout period is chosen very tight, an unusual number of interrupts
could cause a WDT System Reset. This must be taken into consideration when choos-
ing the timeout period.
The ‘Everything ok ?’ check at the end of the loop is the part of the loop deciding
whether the application is operating correctly or not. One solution is to use flags that are
set in different parts of the main loop to indicate ‘good health’, or that vital parts of the
code have been visited. The final check tests all flags and resets the WDT and the flags
if everything is ok. If not, a timeout will eventually occur.
The initialization code should check the WDT Reset Flag and take appropriate actions.
This is covered in more detail in the “Startup considerations” section.
Everything ok ?
No
Yes
WDR
Initialization
Routine 1
Routine 2
Routine 3
Interrupt Handlers
STARTUP
WDR
Wait for
WDT System Reset