What is a Watchdog timer in embedded systems

Embedded Systems Topics
Post Reply
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

What is a Watchdog timer in embedded systems

Post by Neo » Sun Apr 18, 2010 8:00 pm

A watchdog timer is a hardware or software timer that triggers a system reset or other corrective action if the main program, due to some fault condition, such as a hang, neglects to regularly service the watchdog (writing a "service pulse" to it, commonly referred as "feeding the watchdog"). The intention is to bring the system back from the non-responsive state into normal operation.

In embedded processors (like microcontrollers, DPSs, etc...) we usually have a hardware watchdog timer. Think of this as a countdown timer which triggers something (usually reset) upon reaching zero and you always need to avoid it reaching zero by writing a register from the main program. If we set this to say 10 seconds, it will cunt like 9, 8, 7 .....3, 2, 1, 0. Upon reaching zero usually we reset the chip.

I'll give you an example for the usual case.
  1. We setup the Watchdog timer to be say 10 seconds.
  2. From our main routine, we write a defined value to a special register or memory location related to the watchdog timer repeatedly (say in 5 seconds intervals). This value and the register is defined in the datasheet of the chip. As soon as we write to this register, the Watchdog timer will get refreshed and start counting from beginning.
  3. Say our program got stuck somewhere due to an error and we were unable to write to this register within 10 seconds. Then the Watchdog timer will reach 0 (timeout situation) and then the chip will get reset. (That means everything will start from the beginning).
Say you are driving a motor attached to pair of blades with a microcontroller. If your program get stuck while cutting some sheets, the blades will continue to cut and this could be dangerous, isn't it?. So if you have enabled your watchdog, it would have reset the chip which will immediately cancel the operation by switching off the motors and taking the blades to a rest position.

This is just an example. Watchdog is an important unit which will give you lots of benefits if used carefully.
Post Reply

Return to “Embedded Systems”