10
\$\begingroup\$

How do I setup a hardware watch dog timer with an Arduino?

\$\endgroup\$
1
  • 2
    \$\begingroup\$ I think you should choose the other answer as the Arduino has the watchdog built in. \$\endgroup\$ Mar 24, 2011 at 15:59

3 Answers 3

7
\$\begingroup\$

There are a number of dedicated hardware watchdog chips available, but it's easy enough to do using a regular 555 timer IC and a couple of supporting parts. With the 555 configured in astable mode with a very long "HIGH" period and a relatively short (perhaps 0.3 seconds) "LOW" period, the output can be connected to the Arduino's reset pin via a diode to make the watchdog an open-collector device. The Arduino can then periodically reset the watchdog using a digital output to turn on a transistor that discharges the timing capacitor attached to the 555, preventing it ever reaching a trigger point that will cause it to reset the Arduino.

Some basic information about a project to do this is available at http://www.practicalarduino.com/news/id/471

\$\endgroup\$
2
  • 1
    \$\begingroup\$ phooky is absolutely correct, but the internal WDT has limitations: it can't run for more than about 6 seconds (depends on CPU model) and there's no way to do a clean "reboot" purely from software. You can tell the CPU to jump to position 0 and restart the bootloader, but then you may be left with dodgy stuff in RAM and things like interrupt flags still set in the CPU. Asserting RESET in hardware ensures the Arduino will come up with a clean environment. \$\endgroup\$
    – jonoxer
    Nov 17, 2009 at 3:41
  • 2
    \$\begingroup\$ letting the WDT time out will cause a "clean reset" as all registers will be guaranteed to start up in a defined state. Accomplishing it in software is as simple as disabling interrupts and endlessly looping. \$\endgroup\$
    – Nick T
    Mar 22, 2011 at 17:22
16
\$\begingroup\$

There's already a watchdog timer built into the atmega chip; you can use avr/wdt.h to manipulate it.

A quick example:

#include <avr/wdt.h>

void setup() {  
  wdt_enable(WDTO_500MS); // have the wdt reset the chip
  // if 500ms passes without a reset
}

void loop() {   
  wdt_reset(); // reset the wdt
}
\$\endgroup\$
4
\$\begingroup\$

I have heard about some problems being reported with the WDT and the regular bootloader, so you may want to try another bootloader with it, for eg Adaboot.

Also, you can do a bunch more stuff with the WDT besides just a reset. I recommend http://www.atmel.com/dyn/resources/prod_documents/doc2551.pdf

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.