Skip to content
UPEEC

Watchdog Timer

A safety timer that resets the microcontroller if the software stops responding.

Easy
Comments 0

The program must "kick" (refresh) the watchdog regularly. If code hangs — an infinite loop, a deadlock, a crashed peripheral — the watchdog times out and resets the chip.

wdt_enable(WDTO_2S);     // AVR: reset if not refreshed within 2 s
while (1) {
    do_work();
    wdt_reset();         // "I'm still alive"
}

Kick it only from the main loop when everything is healthy — never from a timer interrupt, which could keep running while the main code is stuck.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.