Today 19:18
Forum: Proton Plus Compiler v3
Starter: evoortman
Views: 0
Replies: 2
Today 18:21
Forum: Proton Plus Compiler v3
Starter: xldaedalus
Views: 0
Replies: 36
Today 18:12
Forum: The Lounge
Starter: basparky
Views: 0
Replies: 10
Go to last post By: yvesmazzon
Today 16:43
Forum: The Lounge
Starter: rverm
Views: 5528
Replies: 12
Today 16:34
Forum: Proton Plus Compiler v3
Starter: gtv_pic
Views: 0
Replies: 10
Today 15:31
Forum: Absolute Beginners Section
Starter: amod
Views: 0
Replies: 13
Today 14:42
Forum: Projects discussion
Starter: steyn
Views: 0
Replies: 4
Today 13:05
Forum: Proton Plus Compiler v3
Starter: evoortman
Views: 0
Replies: 20
+ Reply to Thread
Results 1 to 8 of 8

Thread: Watchdog timer28 days old

  1. #1
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,353
    Thumbs Up
    Received: 84
    Given: 23
    Total Downloaded
    4.01 GB

    1 Not allowed!

    Default Watchdog timer

    I have a code that basically looks for four input and four outputs, depends on various timing and input conditions. I use interrupt and some delays in main code.

    I was thinking to add a watchdog timer, but to be honest, I do not know why it will reset a PIC nor it's benefits in a code, as I never ever used a watchdog.

    So basically please, I am asking three things: -

    1) What will make the watchdog to reset the PIC?

    2) How I should implement a watchdog in my code?

    3) What are the benefits of using a watchdog?

    Thanks
    Regards

    Joseph

  2. #2
    Junior Member Dave Purola's Avatar
    Join Date
    Jul 2004
    Posts
    26
    Thumbs Up
    Received: 9
    Given: 0
    Total Downloaded
    68.55 MB

    0 Not allowed!

    Default Re: Watchdog timer

    Joesaliba, For starters a watchdog timer is used for a safety critical piece of code you are executing. Say for instance an alarm system. You wouldn't want the code to stop executing if for instance you encountered an endless loop accidentally. So what you would do is set a bit in the main module and then in an timed interrupt routine you would do something similar to:

    DOGTIME = DOGTIME + 1 'INCREMENT WATCHDOG TIMER
    IF DOGTIME > WATCHDOG THEN 'CHECK FOR WATCHDOG TIMEOUT
    @ RESET ;IF NO FOOD THEN BITE ME....
    ELSE
    IF PATDOG = ON_ THEN 'FEED THE DOG
    DOGTIME = 0 'reset the watchdog counter
    PATDOG = OFF_ 'clear the watchdog flag
    ENDIF
    ENDIF

  3. #3
    Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    379
    Thumbs Up
    Received: 68
    Given: 0
    Total Downloaded
    118.16 MB

    0 Not allowed!

    Default Re: Watchdog timer

    Most PICs (all?) include a builtin hardware watchdog timer module.
    You typically enable it via config settings, and tickle it with a CLRWDT instruction.

    That way you're not dependent on interrupts, timer settings, etc.

  4. #4
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,353
    Thumbs Up
    Received: 84
    Given: 23
    Total Downloaded
    4.01 GB

    0 Not allowed!

    Default Re: Watchdog timer

    @Dave: - Thanks for that. So I assume that DOGTIME is the time the watchdog is set.

    @Tumbleweed: - I am able to set it via the config settings, what I am unsure is if I have to place the CLRWDT just at the beginning of the code or everywhere in the code.
    Regards

    Joseph

  5. #5
    Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    379
    Thumbs Up
    Received: 68
    Given: 0
    Total Downloaded
    118.16 MB

    0 Not allowed!

    Default Re: Watchdog timer

    You have to continuously execute a CLRWDT at least once before every timeout period or the watchdog will fire and reset the pic.

    You should probably start with one CLRWDT in your main program loop... after that it depends on what you're doing and when it's appropriate to reset it.

    For example, one of the LAST places you'd want to put one is in a timer interrupt. Your main software could be totally bonkers but the timer ISR would keep running and reset the WDT. This is a bit different than the way Dave's software-driven watchdog code works.

  6. #6
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    408
    Thumbs Up
    Received: 28
    Given: 5
    Total Downloaded
    2.08 GB

    0 Not allowed!

    Default Re: Watchdog timer

    A watchdog timer is just like any other timer, it has a size (Byte or Word) and prescallers so that you can set the Watchdog timer to overflow at a time period of your choice, 10uS, 100mS, 1S and so on.
    Its purpose is to act as a fail safe, restarting the PIC when the Watchdog timer overflows, this should only occur when program execution stops for any reason as somewhere in your code you should be regularly clearing the watchdog timer value. Generally as tumbleweed said a good place to clear it is at the top of your main code loop although you can clear it anywhere you want and even in multiple places in your code.

    You do not have to use a Watchdog timer, for example if it is constantly under user control/monitoring and there is clear visual indication that code execution has stopped (i.e. LED not flashing or a display not updating) you can let the user manually reset the PIC. However, if the application does not generally require human interaction or is operating in a remote location then it can be useful to implement the Watchdog timer to ensure near continuous operation should code execution stop for any reason.
    Although an automatic restart may sound desirable and is usually a good thing there may be instances where it is not. For example if the PIC is controlling machinery an automatic reset my try and set the machinery to a specific initial state, is that desirable considering the possible state it may be at the time and any potential damage that may result from returning it to that state without a human checking first for any possible obstructions/existing damage.

  7. #7
    Senior Member Mellbreak's Avatar
    Join Date
    Jun 2012
    Posts
    475
    Thumbs Up
    Received: 49
    Given: 20
    Total Downloaded
    2.00 GB

    0 Not allowed!

    Default Re: Watchdog timer

    Nice summary Stephen.

  8. #8
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,353
    Thumbs Up
    Received: 84
    Given: 23
    Total Downloaded
    4.01 GB

    0 Not allowed!

    Default Re: Watchdog timer

    Thank you all for your help.

    I couldn't agree more with Mellbreak, nice summary Stephen, thanks.
    Regards

    Joseph

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Watchdog timer
    By grahamg in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 15th June 2012, 12:16
  2. WatchDog Timer
    By Peter D in forum Proton Plus Compiler v3
    Replies: 24
    Last Post: 14th February 2012, 12:54
  3. Watchdog Timer
    By geoff_c in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 19th August 2010, 23:01
  4. Watchdog Timer, and how to use it.
    By petec in forum Proton Plus Compiler v3
    Replies: 12
    Last Post: 18th June 2010, 14:14
  5. About Watchdog timer !!!
    By eleckits in forum Proton Plus Compiler v3
    Replies: 6
    Last Post: 1st March 2008, 00:22

Members who have read this thread : 62

Actions :  (Set Date)

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts