How do I setup a hardware watch dog timer with an Arduino?
-
2I think you should choose the other answer as the Arduino has the watchdog built in. – Matt Williamson Mar 24 '11 at 15:59
3 Answers
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
}

- 1,008
- 7
- 12
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

- 214
- 1
- 3
-
1phooky 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. – jonoxer Nov 17 '09 at 03:41
-
2letting 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. – Nick T Mar 22 '11 at 17:22
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

- 1,027
- 1
- 7
- 11