1.20.22 Watchdog Timer (WDT)

The Watchdog timer (WDT) is designed to give an added level of safety in critical systems, to ensure a system reset is triggered in the case of a deadlock or other software malfunction that prevents normal device operation.

It operates from the internal Low-Power Oscillator (LPRC) clock source. Various WDT time-out periods can be selected using the WDT postscaler. The WDT can also be used to wake the device from Sleep or Idle mode.

The following are some of the key features of the WDT module:

  • Configuration or software controlled

  • User-configurable time-out period

  • Can wake the device from Sleep or Idle

Using The Library

The Watchdog Timer (WDT) runs independent of the rest of the system, causing system resets whenever it times out. However, the application software should ensure that the timeout never occurs by resetting the WDT periodically as long as the software is in a known healthy state.

If the system hangs or program execution is corrupted, the WDT will not receive its periodic reset, and will eventually time out and cause a system reset.

In many systems, there is an obvious upper boundary to the amount of time each iteration of the main application loop can be expected to run, before a malfunction can be assumed (either due to a deadlock waiting on hardware or software, or due to other means).

When the Watchdog is configured with a timeout period equal to this upper boundary, a malfunction in the system will force a full system reset to allow for a graceful recovery.

Here is an example code to enable watchdog timer and keep clearing at regular intervals

WDT_Enable();

while ( true )
{
    // Application Code

    WDT_Clear();
}

Library Interface

Watchdog Timer peripheral library provides the following interfaces:

Functions

Name Description
WDT_Enable Enables the WDT peripheral
WDT_Disable Disables the WDT peripheral
WDT_Clear Restarts the WDT counter