Page Links
MSP430F5529LP Hardware Library: WATCHDOG


This webpage provides information about the WATCHDOG timer hardware library created for the MSP430F5529LP Development Board.


These files are optional. They only need to be included if the watchdog timer functionality is desired. If they are not included, the watchdog timer module will remain disabled.

When included, the MSP430F5529LP_WDT.h/c files configure the watchdog timer as an interval timer that generates an interrupt once per second. This interrupt is not visible at the application level, but is used to provide the capability to register very long timeouts. When the registered timeout expires, the call back function registered with that timer will be executed. The maximum timeout duration is 18.20 hours.

Public Definitions

typedef void (*WDT_Callback) (void); 
 This definition is required for the compiler to recognize the data type of WDT_Callback used as a function parameter in Set_WDT_Timer is a function pointer. This has no other purpose. 

Public Functions

 Calling this function initializes the watchdog timer module as a 1 second interval timer. The watchdog interrupt is enabled, but global interrupts are not. After all initialization is completed, the application must enable global interrupts using "__enable_interrupt();" to begin operation of the interval timer. 
        uint16_t index, 
        uint16_t timeout_in_sec, 
        WDT_Callback callback); 
 Calling this function registers a new watchdog timer at the index provided. When the requested timeout has expired, the callback function will be executed. The number of timers that can be registered is defined by MAX_WDT_TIMERS in the MSP430F5529LP_WDT.c file. The default value is 3. If more timers are required this number can be increased. It is recommended however that it only be increased as needed, as each index, used or unused, will still be processed for each watchdog interrupt. The legal index values are from 0 to MAX_WDT_TIMERS-1, or in the default case: 0, 1, and 2. If an illegal index value is passed, no action is taken. If an index of an active timer is re-registered, the new timer registration will overwrite the old one. 

Example Code

The following example code is provided to demonstrate the functionality of this library. All examples are presented as main.c files, which are available on GitHub. In order to build the example projects, follow the instructions here for how to create and configure a new project.

Example Summary Description
Using the Watchdog interval timer This example uses the Watchdog hardware library to generate an interval timer that blinks the LEDs. The Watchdog library provides the capability to register a timer and a callback function that is executed when the timer expires. This example uses the callback to re-register a new timer, creating a continuously running interval timer.
Requires: Only the MSP430F529LP development board.

Things to Consider

Timeout Accuracy

As with all timers, caution needs to be taken when using very small timeout values. When a timer is registered, and it is not synchronized, the actual timeout will be anywhere from N to N-1, where N is the requested timeout value. This means that for a 1 second timeout, the actual timeout is anywhere between 1 second and 0 seconds. Obviously not good if this delay is critical. The reason for this is that the next time the 1 second watchdog interrupt will execute is unknown. If it just executed, the delay will be nearly 1 second until the next time it executes, but if it is just about to execute, the delay could be nearly 0 seconds.

One might ask then why does the example code work? Clearly the LEDs are toggling every second. The reason is that the first delay which is unsynchronized is not obvious, and all future timers are synchronized because the timers are being re-registered by callback function, which is called by the ISR. This demonstrates that the watchdog timer can be used to create repetitive timeouts, even small ones like 1 - 10 seconds, with good accuracy.

This doesn't mean that unsycnhronized timers are not useful, it is just important to understand the accuracy, and make sure it is acceptable. For a 1 minute unsynchronized timer (60 seconds), the error is anywhere from 0 to -1/60 seconds, or -1.7%. For longer delays, like 1 hour, this is reduced to -1/3600, or just -0.028%. If better accuracy is needed, consider synchronizing the timer registration if possible.