Watchdog timer in PIC

Status
Not open for further replies.

elexhobby

New Member
Can somebody please explain me the concept of watchdog timer in PIC?
What does it do? It is said that before sleep the watchdog timer should be cleared, & it can ‘wake up’ the uC from sleep. But how does it decide the delay after which it should wake up the uC?
I can’t understand why Watchdog timer is necessary to wake up the uC, if any other interrupt can.
Also, is there any other ingenious application of the Watchdog timer besides during sleep operation.
I have read that it resets the uC whenever it goes in an infinite loop.
But how does the watchdog timer inintiate itself (how does it know that the uC has crashed). If my program consists of some periodic activity, say transferring data serially, the watchdog timer may feel this is an infinite loop - since I am repeating the same task.
In such a case won't the programmer have the headache of continuously resetting the watchdog timer after every few instructions to prevent resetting the uC
Kindly help…
 
Watchdog is an Independent oscilator+timer, that will reset (or wake-up) the PIC if you don't clear the timer value. This has do be done regulary in your PIC software by calling CLRWDT instruction. Watchdog prevents your program do be locked in loop, because if it would get stuck, the CLRWDT instruction wouldn't get exectued and the PIC will reset and get out from the loop. Or you can use Watchdog to periodicaly wake the PIC up from sleep, and thus it saves one precious Timer (that can be used elsewere).

Is this clear?
 
One point that hasn't been mentioned?, the WDT is a crude RC oscillator, it's accuracy is very poor, and highly dependent on external factors such as temperature. However, this doesn't matter for it's designed purpose as a watchdog.
 
yep, I didn't think that this was important to tell him,

I will take your post and add it to the Sticky. (I hope you don't mind)
 
Jay.slovak said:
yep, I didn't think that this was important to tell him,

I will take your post and add it to the Sticky. (I hope you don't mind)

Nope, feel free!.
 
Thanks Jay.Slovak. I now have a better idea of the purpose of the WDT.
But I have a few doubts... If one program cycle is longer than WDT timer overflow period, are two CLRWDT instructions used?
If the program gets stuck within a loop that contains the CLRWDT instruction, it wouldn't reset the PIC, right?
Also, can I use the WDT as a fourth timer (I know this would be rare) & writing an interrupt service routine at 0000h itself, which checks the status of TO(bar) in status register, to know whether a WDT overflow occurred? As Nigel said, since it is a crude oscillator, it can't be used as an accurate timer..

The other doubt I have has nothing to do with WDT...

In Using Timer0 with External Clock, it is said that

The synchronization of T0CKI with the internal phase clocks is accomplished
by sampling the prescaler output on the Q2 and
Q4 cycles of the internal phase clocks. Therefore, it is
necessary for T0CKI to be high for at least 2 TOSC (and
a small RC delay of 20 ns) and low for at least 2 TOSC
(and a small RC delay of 20 ns).

Similarly, in T1CON register, you have a Timer1 External Clock Input Synchronization Control bit.
How is this synchronisation done & why is it necessary...

Please help if you know the solutions...
Thank You...
 
You got the Idea of WDT right.

"If one program cycle is longer than WDT timer overflow period, are two CLRWDT instructions used? " Yes, one at the beginning and one in the middle of the program (to extend the Time-out 1.5x times)

"If the program gets stuck within a loop that contains the CLRWDT instruction, it wouldn't reset the PIC, right?" No it won't, you have to be carefull when placing the CLRWDT instruction(s)

"Also, can I use the WDT as a fourth timer (I know this would be rare) & writing an interrupt service routine at 0000h itself, which checks the status of TO(bar) in status register, to know whether a WDT overflow occurred? As Nigel said, since it is a crude oscillator, it can't be used as an accurate timer.. "
It is possible, but it will be very impractical to work with, and will destroy Values of PORTs, USART, ADC ... I would never use WDT as another timer through RESET. But I would use it to wake the PIC up, this is used pretty often.
 

Attachments

  • reset_table.png
    63.2 KB · Views: 1,169
Nigel Goodwin said:
One point that hasn't been mentioned?, the WDT is a crude RC oscillator, it's accuracy is very poor, and highly dependent on external factors such as temperature. However, this doesn't matter for it's designed purpose as a watchdog.

Some are more accurate than others. PIC18F1320 I'm working with right now is guaranteed +/-2% over the entire rated temp range.

In cases of less accurate WDTs, one must be careful to ensure the code can provide CLRWDT frequently enough for the minimum period that WDT may use. This is a difficult question since having it working on the bench does not prove it will work with all part lot #s at all temps, and if not it's not just going to be less accurate than intended, it's going to reset the code.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…