Jump to main content

##

# 3.31.27 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.

The Watchdog timer is a 12-bit down counter that allows a watchdog period of up to 16 seconds with a 32kHz slow clock. It should be fed periodically before it counts down to zero. If the timer counts down to zero, it can either reset the device or generate an interrupt.

## 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. The upper boundary is specified by a 12-bit Watch dog period value.

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

    while ( true )
    {
        // Application Code

        WDT_Clear();
    }

## Library Interface

Watchdog Timer peripheral library provides the following interfaces:

Functions

Name | Description
--- | ---
WDT_Initialize | Initializes given instance of the WDT peripheral
WDT_Clear | Restart the WDT counter
WDT_CallbackRegister | Sets the pointer to the function (and it's context) to be called when the Timeout events occur

Data types and constants

Name | Type | Description
--- | --- | ---
WDT_CALLBACK | Typedef | Defines the data type and function signature for the WDT peripheral callback function