Author Topic: How to change the reset time of Watchdog Timer  (Read 5442 times)

hung

  • Sr. Member
  • ****
  • Posts: 26
    • View Profile
How to change the reset time of Watchdog Timer
« on: June 28, 2007, 12:39:41 AM »
I have set up a watch dog timer as below:

Code: [Select]
WDTCON = 0b00000001;

I want to change the reset time of Watchdog Timer to 15 minutes if some errors occurs in the ethernet board, causing the program to stop, it can automatically reset the ethernet board. How to change the reset time?  :?

(it seems that the default watchdog time is about 4 to 5 hours. It too long for my application.) :oops:

niroblock

  • Hero Member
  • *****
  • Posts: 140
    • View Profile
Re: How to change the reset time of Watchdog Timer
« Reply #1 on: July 02, 2007, 09:13:22 AM »
Hi,


1 associates an counter to timer1.

      static long count=0;

2 inside timer1 reset to the WDT.

      void timer1 (void) // interrupt with tick of 1000ms
      {
           count++;                                                                             // increases accountant
      if (count<=900) {                                                                      //15min
            ClrWdt (); // reset to the WDT
      }                                                                                              //if the WDT does not work I enter of 16min
      else if (count>960) {
               reset (); //force reset
     }
 }


 in main loop…

 count=0;

//------------------------------------------------------------------

   
WDTCON = 0b00000001; that he is this?


TABLE 12-7: SUMMARY OF WATCHDOG TIMER REGISTERS     in datasheet 18f6680 microchip

Address            Name                Bit 7             Bit 6            Bit 5          Bit 4           Bit 3         Bit 2          Bit 1        Bit 0
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2007h         Config. bits               (1)     BODEN(1)            CP1            CP0       PWRTE(1)   WDTE       FOSC1        FOSC0
81h,181h     OPTION_REG         RBPU        INTEDG           T0CS          T0SE          PSA         PS2            PS1           PS0

//-----------------------------------------------------------------------
bye.
do not make any questions, if you already have the answer!

sparkcatcher

  • Sr. Member
  • ****
  • Posts: 31
    • View Profile
Re: How to change the reset time of Watchdog Timer
« Reply #2 on: January 07, 2008, 04:53:10 PM »
>>WDTCON = 0b00000001; that he is this?

This command apparently controls the operation of the built-in watchdog timer on the pic processor when the WDT configuration bit is OFF.

Specifically, this command sets then SWDTEN bit (SW WDT ENable) in the WDTCON register allowing software control of the built-in watchdog timer (WDT).

I was under the impression that the built-in watchdog timer would be enabled by default because of all of the FAST_USER_PROCESS commands interspersed throughout the code, but it appears that it is not enabled by default and you have to add the above code line in order to enable it. 

I have been getting some intermittent stoppages in my application, averaging about 1 every 7 days or so, when the application is in the main loop.  I'm hoping that enabling this timer will automatically reset the board when this happens.

If you have an especially long process you can turn the watchdog timer off with:

WDTCON = 0b00000000;

and then turn it back on with
WDTCON = 0b00000001;

when the long process is complete.  This watchdog timer is much more reliable as far as resetting under many differerent glitch causes, and so should most likely be used if possible.


sparkcatcher,

niroblock

  • Hero Member
  • *****
  • Posts: 140
    • View Profile
Re: How to change the reset time of Watchdog Timer
« Reply #3 on: January 09, 2008, 05:03:38 AM »
hi,

Optimal explanation, Bit 0 of WDTCON

But in my opinion turning on and off control WDT can generate errors if you forget to change your status, or simply any exception hasen you leave the cycle

Why I use the example timer1 to reset the WDT
To get a time constant of 1000ms

And the main change is a time variable from 0 to 15000ms

To execute code processes throughout the long or short

So thank you all for your contribution.

Surely my method is not the most elegant

But I have several of SBC modtronix, transmitting data and continuously for more than 6 months and none of it has stopped broadcasting ...

byee.
do not make any questions, if you already have the answer!

sparkcatcher

  • Sr. Member
  • ****
  • Posts: 31
    • View Profile
Re: How to change the reset time of Watchdog Timer
« Reply #4 on: January 19, 2008, 09:17:55 AM »
niroblock:

>>Surely my method is not the most elegant

Your method is good, IMO.

I've implemented a variation of your method as a second watchdog timer in my application.

The first WDT, the one built into the chip, seems have a built-in time limit that seems to average somewhere less than 500 milliseconds.

If everything is working well within the application, then this might be all you need.  However, if say you are expecting a reply from a server on the Internet, and the reply never comes, or only half of the reply is transmitted and you are waiting for the other hald, you could be stuck in an infinite loop where your code resets the built-in WDT as it should, but application never returns to the main loop because it is waiting for an answer (calling stktsk() and fast user process while waiting for the response).

I'm using a variation of your timer1 method as a watchdog to protect the main loop.  So, if control doesn't come back to the main loop within, in my case 5 minutes, then something is wrong, and board resets.

So, what is better than 1 watchdog timer?  How about 2?  8-)

Thanks for posting your idea.

sparkcatcher

niroblock

  • Hero Member
  • *****
  • Posts: 140
    • View Profile
Re: How to change the reset time of Watchdog Timer
« Reply #5 on: January 23, 2008, 04:48:59 AM »
Hi,

Certainly 2 is always better than 1

Quote from: my previus post

....And the main change is a time variable from 0 to 15000ms


!error!   
0-15min is:

    time variable from 0 to 900000ms

Sorry

byee.
do not make any questions, if you already have the answer!