Electronic – Why do programs stop watchdog timer on MSP430

msp430

Many sample programs for the MSP430 have their first line as:

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

Why do they do this?

Best Answer

The watchdog timer (WDT) is on by default, it's a useful thing to have in more complex applications, but trips a lot of new people up. They often will not service the WDT in their code or include an interrupt service routine (ISR) to handle the WDT event, so, when their chip keeps resetting they become very frustrated. Additionally, the sample programs are, for the most part, not trying to demonstrate the WDT so it's turned off.

Edit: The watchdog timer could have been named "dead man's switch". Its default behavior is to reset the microcontroller unless the firmware periodically lets it know everything is running fine. This is known as "feeding the dog" or "kicking the dog". This way, if your firmware gets stuck in a loop or otherwise stops operating as expected, the watchdog is not fed and will reset the chip (hopefully to a fresh, working state).

You can also use the WDT as periodic interrupt to perform other tasks, whatever you can imagine. You just have to write the relevant ISR.