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