A Question About the Watchdog Timer

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
I have never used the WDT, but figured it's kind of one of those fundamental type things that I should know. With that in mind, I'm wondering about those of you who routinely include the use of the WDT in your programs, what method do you typically employ to reset it? Periodic clearing of the WDT throughout the program? Or perhaps as part of a regular Timer interrupt sequence?

Is one way considered more "this is the way professionals do it" than another way?

Thank you all for your constant insight into my queries.
Best,
 
Last edited:

MrChips

Joined Oct 2, 2009
30,621
Your main program should be looping around periodically.
Trigger the watchdog timer in the main loop.

You don't want to use a timer to trigger the WDT. That defeats its purpose.
 

joeyd999

Joined Jun 6, 2011
5,220
This professional has used PICs for commercial equipment since 1992. I've never used the WDT hardware.

Supposedly, if your code runs off into la la land, the WDT will reset the MCU to get it on track.

IMHO, I think it's better to write code (and design hardware) that doesn't run off the tracks -- and test, test, test to confirm it.

Perhaps for mission critical stuff, the WDT could potentially save a life -- but only if the WDT reset is properly handled to warn that "Hey, I broke. Don't stake your life on me."
 

MrChips

Joined Oct 2, 2009
30,621
Along joey's line of thinking, disable the watchdog timer and debug and test your system with it disabled. The idea is your system must be 100% reliable without the WDT.

Then enable WDT to catch catastrophic failures.
 

MaxHeadRoom

Joined Jul 18, 2013
28,576
Your PC uses a watch dog timer.
CNC systems and commercial electronic systems have used it for decades, if the main trajectory controller should fail and the watch dog times out then the system shuts down.
Max.
 

ErnieM

Joined Apr 24, 2011
8,377
A watchdog timer is a "belt and suspender" type of thing, one extra layer of safety. It is only of use if making your device reset is preferable over just letting it sit there stuck in an infinite loop doing absolutely nothing.

I’ve used it professionally in a qualified medical device. In the main loop that completed in 10mS or so the watchdog was cleared each time thru. Thus if this code for “some unexplained reason” got stuck somewhere the device would reset. My fault tree showed no path to this failure but I stuck it in there anyway “as good practice.”

This particular device had a built in test to validate the output under certain conditions; that test alone would catch a device that was stuck (and hopefully take appropriate action as the device was used in human life critical equipment.
 

joeyd999

Joined Jun 6, 2011
5,220
There are additional uses for a WDT. For instance, a WDT could be used to wake a MCU periodically to take some measurement, store the data, and then quickly go back to sleep. This would keep power consumption at a bare minimum (as opposed to an external crystal or RC, or external clock or interrupt).

But, AFAIK, most/all(?) WDTs are implemented as an RC oscillator, so timing accuracy will limit the applications that can use this approach.
 
Top