By default in official Arduino documentation no any information about WatchDog timer. WatchDog timer (WDT in short) – is a hardware external timer that reset the microcontroller if the main program crashed or go to the infinite loop or etc error action.
How does it work? Need set interval (for example, 1 second), during which the main program must reset the timer. If timer didn’t reset – watchdog will restart controller.
For Arduino, need to add additional library wdt.h, set timer interval and add reset function (wdt_reset()) to the main loop.
Sample:
#include "avr/wdt.h"
void setup() {
wdt_enable(WDTO_4S);
}
void loop() {
wdt_reset();
}
Table with constants for wdt_enable function.
Constant name | Constant value | Delay |
---|---|---|
WDTO_15MS | 0 | 15 MS |
WDTO_30MS | 1 | 30 MS |
WDTO_60MS | 2 | 60 MS |
WDTO_120MS | 3 | 120 MS |
WDTO_250MS | 4 | 250 MS |
WDTO_500MS | 5 | 500 MS |
WDTO_1S | 6 | 1 S |
WDTO_2S | 7 | 2 S |
WDTO_4S | 8 | 4 S |
WDTO_8S | 9 | 8S |