10
AVR 132 Application Note
2551A–AVR–11/03
Using the WDT as a
System Reset Source
This example implements the structure described in “Figure 2. Main loop when using the
WDT System Reset Mode.”, with an initialization routine and a main loop with three rou-
tines and a health check at the end. Each routine has its own health flag to indicate that
everything is ok. The three routines get a command, parse and execute it, respectively.
Initialization
The initialization routine has two main purposes: initializing peripherals and handling
reset flags. Its flowchart is shown in Figure 8 on page 10. The parts inside the dashed
frames are only used in the Combined Operation code example and are described later.
Figure 8. Initialization Routine When Using the WDT as a System Reset Source
A n y re s e t
f la g s s e t ?
I n it ia liza t io n
S a v e M C U s t a t u s re g is t e r
a n d c le a r re s e t f la g s
E n a b le W a t c h d o g
I n t e rru p t M o d e
I n f in it e lo o p wa it in g f o r
W D T S y s t e m R e s e t
No
Y e s
W D T R e s e t
F la g s e t ?
Y e s
No
I n c re m e n t W a t c h d o g
R e s e t c o u n t e r
W rit e
C o m p le t e F la g
s e t ?
Y e s
No
R e s t o re p a ra m e t e r
a n d c le a r W rit e
C o m p le t e F la g
R e s e t
c o u n t lim it
e x c e e d e d ?
Y e s
No
R e t u rn wit h e rro r c o d e
P o we r-u p
o r E x t . R e s e t
F la g s e t ?
C le a r W a t c h d o g
R e s e t c o u n t e r
Y e s
No
R e t u rn
E n a b le W D T S y s t e m R e s e t
M o d e a n d s e t t im e o u t p e rio d
O n ly w h e n u s in g
P a ra m e t e r B a c k u p
O n ly wh e n u s in g
P a ra m e t e r
B a c k u p