AVR® Watchdog Timer

AVR® devices have an Enhanced Watchdog Timer (WDT) that runs on a separate oscillator from the main instruction clock. The WDT is essentially a counter that increments based on the clock cycles of an on-chip 128kHz oscillator. The WDT forces an interrupt or a system reset when the counter reaches a given time-out value. In normal operation mode, the application code needs to issue a Watchdog Timer Reset (WDR) instruction to restart the counter before the time-out value is reached. If the system doesn't restart the counter, an interrupt or system reset will be issued.


Brief WDT Summary

WDT Features:

  • Clocked from separate On-chip Oscillator.
  • Three operating modes:
    • Interrupt
    • System Reset
    • Interrupt and System Reset
  • Selectable Time-out period from 16 milliseconds to 8 seconds.
  • Optional Hardware fuse Watchdog always on (WDTON) for fail-safe mode.

Interrupt Mode

In Interrupt mode, the WDT forces an interrupt when the timer expires. This interrupt can be used to wake the device from any of the sleep-modes, and also as a general system timer. One example is to limit the maximum time allowed for certain operations, forcing an interrupt when the operation has run longer than expected. This is enabled by setting the Interrupt mode bit (WDIE) in the Watchdog Timer Control Register (WDTCSR).

System Reset

In System Reset mode, the WDT forces a reset when the timer expires. This is typically used to prevent system hang-up in the case of runaway code. This is enabled by setting the System Reset mode bit (WDE) in the Watchdog Timer Control Register (WDTCSR).

Interrupt and System Reset Mode

Interrupt and System Reset mode combines the other two modes by first forcing an interrupt and then switching to the System Reset mode. This mode will offer a safe shutdown by allowing time to save critical parameters before a system reset. This is enabled when both the WDTIE and WDTE are set.

WDT Time-out Period

The Watchdog Timer Prescale bits (WDP[3:0]) of the WDTCSR determine the WDT delay when the WDT is running. The different prescaling values and their corresponding timeout periods are shown in the following table.



The WDTON fuse, if programmed, will force the WDT into System Reset mode. With the fuse programmed, the WDE bit and WDIE bit are locked to 1 and 0 respectively.

Watchdog System Reset Flag

The Watchdog System Reset Flag (WDRF) bit in the MCU Status Register (MCUSR) is set if a Watchdog System Reset occurs. The WDRF bit is cleared by a Power-on Reset or by writing '0' to it. To identify a reset condition, the user should read and then reset the WDRF as early as possible in the program. If the register is cleared before another reset occurs, the source of the reset can be found by examining the Reset Flags.

MCU Status Register

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.