The watchdog timer device is used to perform a specific operation after a defined period of time if something goes wrong with an electronic system and the system does not recover on its own. For example, if an application goes into an unpredictable state the watchdog timer could be programmed to perform a system reset. The watchdog device can be an external device or a part of a microprocessor.

The watchdog is a digital counter counting cycles of a predefined oscillator, as soon as it will reach a predefined value it performs the reset of the microprocessor or it can generate an interrupt (not all watchdog devices can generate interrupt).

To prevent a system reset or the generation of an interrupt, an application shall reset periodically the watchdog counter (refresh operation) before the timeout value is reached.

The “refresh” is achieved through a read / write in a specific register of the device or through the execution of a particular sequence of instructions.

It’s very important to note that it’s preferable to execute the refresh operation out of an ISR because, if the interrupts are the cause of the fault and the Interrupt Service Routine is always executed, the watchdog will be always refreshed and the system will never reset.

Several microprocessors and watchdog devices have the feature to remember if the last system reset was generated by itself so that the watchdog could be identified like the system reset cause. This is very useful during the debugging stage of an application or to identify the reason of the system reset.

If the system doesn’t need of the watchdog safety, it’s “better” to disable the watchdog so to reduce the power consumption and to remove the needed of the refresh operation in the application code (less power and less code).

If the watchdog device can generate an interrupt or a signal, without the generation of the system reset, the watchdog can be used as a general purpose timer. Some specialized operations could be performed like the safety shutdown of the system or the kill of an operation if this operation takes too many time to be completed.

In the next few articles will be briefed the watchdogs of several ATMEL microcontrollers.

Stay tuned 😉