Arduino Long Time Hardware Watchdog

There are times You need to be sure your application is always up and running, so You need a tool that resets the board if something goes wrong (crashes, infinite loops … and so on).
This kind of tool is called “Watchdog” and is a piece of independent hardware that monitors in some way the status of your application, detecting if something is going wrong.

Usually a watchdog is a timer that the application must periodically reinitialize to avoid the triggering of  system reset.

AVR microcontrollers have an embedded hardware watchdog, but requires to be enabled by programming a “fuse bit” and has limited timing capabilities: the timeout expires after some seconds, too short for some applications.
A strategy may be to reinitialize the timer in more than one place in the software, but this must be done carefully avoiding to introduce weakness in problems detection.

As I needed a long time watchdog I’ve build this simple one from some spare parts I had in my lab.

Watchdog Schematics

The schematics is very simple and is built around a LM555 timer configured for astable operation.

Let’s see how it works.
Remember that to reset the Arduino Board the RST line must be pulled Low for some time.
When the power is applied, Q is high and C1 starts charging through R1+R2; when the voltage on C1 reaches 2/3 of the power supply voltage the 555 pulls down the DIS line dicharging C1 through R2 until it reaches 1/3 of the power supply voltage. At this point the 555 stops discharging and the charge cycle starts again.
While C1 is discharging the Q line is pulled low resetting the Arduino board through D1.
As the RST line of the Arduino is involved in the firmware upload process, D1 prevents  forcing high the RST line all the time failing to enter the programming mode.
The Arduinio D0 line is used to reinitialize the timer. During normal operation the D0 line must be disconnected (Hi-Z state) to not interfere with the capacitor charging process, while must be pulled low to reinitialize the timer discharging C1 through R3 that limits to 9mA the current the Arduino must sink (R3 value can be lowered: the lower the value the shorter the pulse needed to discharge che capacitor).
Doing this requires a little software trick

void ResetWatchdog()
{
    pinMode(D0, OUTPUT); //The D0 line goes Low
    delay(200);          //Wait for capacitor discharge
    pinMode(D0, INPUT);  //The d0 line goes Hi-Z
}

To calculate timings You can use these formulas:

T_charge = 1.01 (R_1+R_2) C
T_discharge = 0.693 R_2 C

With values from the schematics:
T_charge = 1.01 (1,000,000+3,300) 0.000220 = 242.5 sec
T_discharge = 0.693 (1,000,000+3,300) 0.000220 = 0.294 sec

The magic constants 1.01 and 0.693 depends on the voltage the capacitor must have at the end of the charge or discharge process. If You’re interested in formulas take a look here.

Tcharge must be calculated with some margin to avoid unintentional resets

Watchdog Breadboard

 

Stay tuned, more Arduino stuff is on the way :)

This entry was posted in Arduino Projects, Hardware. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


two + = 7

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>