A Question About the Watchdog Timer

Discussion in 'Programmer's Corner' started by ke5nnt, Jan 28, 2015.

  1. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    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: Jan 29, 2015
  2. MrChips

    Moderator

    Oct 2, 2009
    12,431
    3,360
    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.
     
  3. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,675
    2,724
    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."
     
    panic mode likes this.
  4. MrChips

    Moderator

    Oct 2, 2009
    12,431
    3,360
    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.
     
  5. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    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.
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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.
     
  7. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,675
    2,724
    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.
     
  8. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    Okay excellent. Thank you all very much for your responses. Very insightful.
     
Loading...