Skip to Main Content

Introduction


A Watchdog Timer is a failsafe mechanism which resets a system in case it gets stuck (hangs / freezes). In other words, it is an automatic 'Have you tried turning it off and back on again?' tool.

In an ideal world, watchdog timers should never be needed, as most of the time their purpose is to recover from system hangs caused by programming bugs. They can also however recover systems from glitches due to voltage spikes; which could be caused by ElectroMagnetic Interference (EMI), an unstable power-supply, static electricity, and even radiation.

How they Work


The way that Watchdog Timers work is very simply that if they are not refreshed within a set time period then they will reset the system (like pressing the reset button). Put another way, if the Watchdog is not fed in time, then it will sound the alarm (reset the system).

Many microcontrollers include built-in watchdog peripherals, however there are also external dedicated watchdog timer chips available; these have an output which connects to the ‘Reset’ pin of another IC or similar (perhaps a transistor which controls power to the system).

Configuration


Watchdog timers are normally enabled in code at system startup and refreshed at the end of the main system loop. The timeout period of the watchdog should obviously be set to something more than the maximum iteration time of the main loop. If the code gets stuck in a subroutine anywhere, then the watchdog will kick in and reset the system. Care should be taken not to place watchdog-refresh calls in too many places in the code (or in an interrupt routine), as the system could potentially get stuck in a sub-loop which includes a watchdog-refresh call and which would then defeat the purpose of the watchdog timer.

Watchdog timers are usually driven from a separate clock source to the main system clock, for additional independence and robustness.

For in-circuit-debugging (ICD), most microcontrollers include a facility to 'pause' the watchdog timer when debugging.

For microcontrollers with built-in watchdog timers, a flag (bit in memory) is usually available which survives the reset process and which can be used to determine if a watchdog-reset occurred.

Windowed Watchdog Timer


Some microcontrollers also include a type of watchdog timer called a windowed watchdog timer – this type of watchdog timer must not only be refreshed not-too-late but also not-too-early. This type of watchdog is usually intended for use in systems incorporating a Real-Time Operating System (RTOS).

Summary


Watchdog timers are a must-have for any system with even moderate reliability requirements, and are generally always a good feature to incorporate if time allows.

All content Copyright Labcenter Electronics Ltd. 2024. Please acknowledge Labcenter copyright on any translation and provide a link to the source content on www.labcenter.com with any usage.

Find the right package for you

Product Wizard Try Proteus