Skip to content

Watchdog Timer

Overview

  • Watchdog Timer: component of a microcontroller to monitor and supervise the functions of other system components and the program
  • In case of an error an interrupt or a system reset can be executed.
  • The watchdog timer needs to be resetted continuously, otherwise the interrupt or reset will be executed.
  • If there is a error and the program holds, the watchdog is no longer resetted and restarts the program.
  • The WDT of the MSP430 can be used as a continuous interrupt generator in the so-called interval mode.
  • When ever you want to change the value of the WDTCTL register, you need to set the WDTPW bit to the correct value. Otherwise an MSP430 will be resetted.

alt: "Register of the Watchdog Timer of the MSP430", src: "Family Guide, page 347", w:70

Watchdog Mode

Watchdog Mode of the MSP430 Watchdog Timer
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;    // stop watchdog timer

    P1DIR |= BIT0;
    P1OUT |= BIT0;
    __delay_cycles(100000L);
    P1OUT &= ~BIT0;

    P1DIR &= ~BIT3;
    P1OUT |= BIT3;
    P1REN |= BIT3;
    P1IES |= BIT3;
    P1IFG &= ~BIT3;
    P1IE |= BIT3;

    WDTCTL = WDTPW + WDTCNTCL + WDTSSEL;

    __enable_interrupt();

    while (1) {
        __low_power_mode_3();
    }
}

#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR() {
    if (P1IFG & BIT3) {
        P1IFG &= ~BIT3;
        WDTCTL = WDTPW + WDTCNTCL + WDTSSEL;
    }
}
  • LED on P1.0 will blink only on the beginning of the program.
  • When the LED blinks the MSP430 was resetted by the Watchdog Timer
  • WDTCTL = WDTPW + WDTCNTCL + WDTSSEL;
    • The Watchdog Timer is enabled.
    • As clock source the ACLK is used (WDTSSEL).
    • After 32768 clock cycles = 1 second the watchdog timer will trigger the reset.
  • When the button on P1.3 is pressed an interrupt will be executed.
  • This interrupt resets the Watchdog Timer.
  • You need to press the button once every, otherwise the MSP430 will be resetted.

Interval Mode

Interval Mode of the MSP430 Watchdog Timer
int main(void) {
    WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer

    P1DIR |= BIT0;
    P1OUT &= ~BIT0;

    WDTCTL = WDTPW + WDTTMSEL + WDTCNTCL + WDTSSEL;
    IE1 |= WDTIE;

    __enable_interrupt();

    while (1) {
        __low_power_mode_3();
    }
}

#pragma vector=WDT_VECTOR
__interrupt void WDT_ISR() {
  P1OUT ^= BIT0;
}
  • After 32 768 clock cycles = 1 second og the Watchdog Timer the WDT_ISR() is executed.
  • The LED is toggled once every second.

Info

Watchdog Timer Interval Select

WDTISx Divider Interval @ACLK=32.768 kHz Interval @SMCLK=1 MHz
00 /32768 1000 ms 32.768 ms
01 /8192 250 ms 8.192 ms
10 /512 15.625 ms 512 µs
11 / 64 ≈ 1.95 ms 64 µs

Question

Modify the previous program. Change the LED toggling period to 250 ms.

Solution

WDTCTL = WDTPW + WDTTMSEL + WDTCNTCL + WDTSSEL + WDTIS0;