English
Language : 

M38203M4 Datasheet, PDF (299/344 Pages) Mitsubishi Electric Semiconductor – 8-BIT SINGLE-CHIP MICROCOMPUTER
APPENDIX
3.2 Countermeasures against noise
3.2.7 Providing of watchdog timer function by
software
If a microcomputer runs away because of noise or
others, it can be detected by a software watchdog
timer and the microcomputer can be reset to nor-
mal operation. This is equal to or more effective
than program runaway detection by a hardware watch-
dog timer. The following shows an example of a
watchdog timer provided by software.
In the following example, to reset a microcomputer
to normal operation, the main routine detects errors
of the interrupt processing routine and the interrupt
processing routine detects errors of the main rou-
tine.
This example assumes that interrupt processing is
repeated multiple times in a single main routine
processing.
<The main routine>
qAssigns a single byte of RAM to a software watch-
dog timer (SWDT) and writes the initial value N in
the SWDT once at each execution of the main
routine. The initial value N should satisfy the fol-
lowing condition:
N+1 ≥ (Counts of interrupt processing executed in
each main routine)
As the main routine execution cycle may change be-
cause of an interrupt processing or others, the initial
value N should have a margin.
<The interrupt processing routine>
qDecrements the SWDT contents by 1 at each
interrupt processing.
qDetermins that the main routine operates normally
when the SWDT contents are reset to the initial
value N at almost fixed cycles (at the fixed inter-
rupt processing count).
qDetects that the main routine has failed and de-
termines to branch to the program initialization
routine for recovery processing in the following
case:
xIf the SWDT contents are not initialized to the
initial value N but continued to decrement and if
they exceed the limit (and reach 0 or less)
Main routine
(SWDT)← N
CLI
Interrupt processing routine
(SWDT) ← (SWDT) – 1
Interrupt processing
Main processing
N (SWDT)
= N?
=N
(SWDT) > 0
≤ 0?
≤0 RTI
Return
qWatches the operation of the interrupt process-
ing routine by comparing the SWDT contents with
countsof interrupt processing after the initial value
N has been set.
qDetects that the interrupt processing routine has
failed and determines to branch to the program
initialization routine for recovery processing in the
following cases:
xIf the SWDT contents do not change after inter-
rupt processing
If the changed SWDT contents are abnormal (In
Figure 3.2.9, the main routine determines that
the interrupt processing routine has failed only
if the SWDT contents do not change).
Interrupt processing
routine errors
Main routine
errors
Fig. 3.2.9 Watchdog timer by software
3820 GROUP USER’S MANUAL
3–15