Study how watchdog timers monitor system operation to detect failures and trigger corrective actions to enhance device reliability.
A thermostat in a greenhouse stops responding and no one notices: the heating stays on for hours. The watchdog timer serves to prevent this: it is a counter independent of the program, which must be periodically reset by the software. If the program freezes and stops signaling that it is active, the counter reaches the limit and restarts the system or generates an alarm [1][2][3][4].
The watchdog counts on its own, powered by its own oscillator. The software resets it with an operation called *kick* or *service* at intervals shorter than the timeout. If the program enters an infinite loop or an error, the counter is not reset, expires, and produces a reset of the system or an alarm signal. The system thus restarts from a known state, without human intervention: it is essential in devices installed in hard-to-reach locations [1][2][3].
The timeout must be longer than the longest normal interval between two resets to avoid unnecessary resets, but short enough to limit the damage of a freeze. With a $n$-bit counter and a $f$ clock, the maximum time is $2^n/f$; a prescaler allows extending it. Many microcontrollers allow choosing among a few values [1][2][4].
The reset must be placed at a point that proves the entire program is running, and not in an interrupt routine, which would continue to function even if the main loop is blocked. Correct use first verifies that the main tasks have completed their work and then resets the timer. Many microcontrollers have a dedicated internal oscillator, so the watchdog works even if the main clock stops. A windowed watchdog signals an error even if the reset occurs too early, because it only allows the reset within a defined time window [1][2][3][4].
At restart, it is advisable to read a register indicating the cause of the reboot and log the event, so that repeated resets are a fault signal and not an invisible event. In critical systems, the output is brought to a safe state before or during the reset [2][3][4].
1. $16$-bit counter with $32\,768\ \mathrm{Hz}$ oscillator: maximum time $65\,536/32\,768 = 2\ \mathrm{s}$.
2. The program resets the watchdog every $500\ \mathrm{ms}$: margin of $1.5\ \mathrm{s}$ before reset.
3. If the main loop sometimes takes $800\ \mathrm{ms}$ the system is still safe; if a task lasts $3\ \mathrm{s}$ the watchdog intervenes erroneously, so the limit is extended or the timer is reset inside the task.
4. $8$-bit counter with $1\ \mathrm{kHz}$ clock: maximum time $256/1000 = 0.256\ \mathrm{s} = 256\ \mathrm{ms}$.
5. $16$-bit counter with internal $128\ \mathrm{kHz}$ oscillator: maximum time $65\,536/128\,000 = 0.512\ \mathrm{s}$.
6. Windowed watchdog with reset allowed between $200\ \mathrm{ms}$ and $500\ \mathrm{ms}$ from the last: a reset at $100\ \mathrm{ms}$ or $600\ \mathrm{ms}$ causes the reset.
Embedded systems, industrial controllers, medical devices, vehicles, satellites and distant probes, routers and equipment in remote locations.
The watchdog does not correct the cause of the fault, and an application that blindly resets the timer renders it useless. A reset can cause loss of unsaved data and interrupt an operation halfway.
[1] Wikipedia (it): Watchdog
[2] Wikipedia (en): Watchdog timer
[3] Wikipedia (de): Watchdog
[4] Wikipedia (en): Embedded system
Generating summary…