103/317
5 - Peripherals
This bit is set whenever the last reset was triggered by the Watchdog. This allows the program
to check whether the current start is a fresh one, or results from the recovering from an error
condition.
5.4.3 Using the Watchdog to protect an application
The right value for the watchdog time-out is always difficult to find, except when the rewinding
is performed in the service routine of a timer interrupt, that occurs at a fixed frequency. This is
not the best way to use the watchdog, considering what has been said above, since it is likely
that a timer interrupt will keep on being serviced even when the main program has crashed.
If the rewinding is done in the main program, it is often difficult to estimate the greatest pos-
sible interval between rewindings, since this time may vary depending on the various events
that may occur. Here are two pieces of advice for anyone wanting use the watchdog timer:
Do not activate the watchdog timer while debugging the program. Otherwise you may get
some unexpected resets that may fool the in-circuit emulator.
When the program is fully debugged, try several values by dichotomy. First set the value to
half the maximum. If the reset occurs (which is detected by putting a breakpoint at the entry
point of the main program), double this value and try again. If no reset occurs, take the value
at midway and try again. Reduce the value this way as much as possible, each time using
the program with all its features if possible. When you think you have found the smallest
value that never produces a reset, multiply this value by a safety factor and keep it.
The safety factor depends on how much opportunity you had to actually test the program
through all its paths, nooks and crannies. If this were actually possible, a factor of 1.5 may be
sufficient. Otherwise, a factor of 2 or more is advisable. The terms of the trade-off are, on one
hand, getting unwanted resets when nothing goes wrong, and in the other hand, reducing the
efficiency of the safety device.
On models that have a WDOGF bit in the watchdog status register, the program may be
written so that it behaves differently if the restart has been caused by a previous malfunction.
5.5 16-BIT TIMER
This peripheral is a powerful piece of hardware that illustrates the ideas put forth in the intro-
duction of this chapter. Its purpose is to handle time-related events, such as pulse counting,
frequency measurement, interval measurement, and pulse generation, either single or peri-
odic. Good quality processing of such events usually implies a time accuracy in the micro-
second range. This is out of reach for a low-end, 8-bit microcontroller. This is where the timer
comes in to play: it does the time-related processing, and frees the core from stringent timing
constraints.
Содержание ST7 Series
Страница 1: ...ST7 8 BIT MCU FAMILY USER GUIDE JANUARY 1999 1 ...
Страница 238: ...238 317 8 C Language and the C Compiler 08 Burn bmp Then use the EPROMer programmer software as described in Chapter 7 ...
Страница 289: ...289 317 10 Second Application a Sailing Computer 10 befor Bs Rw Vw VMG AlphaR AlphaV Before the wind ...