Robustness: Watchdog Timer

Imagine that you had an indicator light on some device that blinks every five seconds as a signal that the device is working properly. After some time, you notice that the indicator light has stopped blinking. The natural assumption is that the device has stopped working for some reason. As such, you power off the device and then turn it back on. The indicator light blinks normally again, indicating that the problem has now been resolved. This behavior is very similar to what the watchdog timer does.


The watchdog timer is a timer that resets the processor upon expiration. The watchdog timer is a count-down timer, and when it reaches 0, the watchdog timer resets the processor. This may not seem very intuitive at first, but the idea is to periodically reset the watchdog timer to indicate that the program is working as expected. If the watchdog timer rolls over, it assumes the worst and resets the processor.


In a sense, the watchdog timer is almost like a heartbeat for the program. Reloading the watchdog timer is like pumping blood back into the system, and it needs to be done periodically to ensure that the program is healthy. You may not have worried about this when writing programs before since we usually disabled the watchdog timer during the initialization. However, the watchdog timer can be a nice way for the microcontroller to troubleshoot itself. If the code gets stuck somewhere, it fails to reset the watchdog timer. As a result, the processor restarts, restoring the microcontroller to a state where everything should be working fine. There’s a saying in this class about watchdog timers and how to use them: “Reset the watchdog timer, otherwise it will reset you.