Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 4th November 2005, 05:58 AM   (permalink)
New Member
elexhobby is on a distinguished road
Default Watchdog timer in PIC

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…
elexhobby is offline   Reply With Quote
Old 4th November 2005, 07:45 AM   (permalink)
Super Moderator
 
Jay.slovak is just really niceJay.slovak is just really niceJay.slovak is just really nice
Default

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?
__________________
"I share, thus I am"
Jay.slovak
Read this!
ICD2 Clone
Best PIC/DsPIC Bootloader

Read my Inchworm ICD2 review!
Jay.slovak is offline   Reply With Quote
Old 4th November 2005, 08:14 AM   (permalink)
Super Moderator
 
Nigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to behold
Default

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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 4th November 2005, 08:21 AM   (permalink)
Super Moderator
 
Jay.slovak is just really niceJay.slovak is just really niceJay.slovak is just really nice
Default

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)
__________________
"I share, thus I am"
Jay.slovak
Read this!
ICD2 Clone
Best PIC/DsPIC Bootloader

Read my Inchworm ICD2 review!
Jay.slovak is offline   Reply With Quote
Old 4th November 2005, 10:14 AM   (permalink)
Super Moderator
 
Nigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to behold
Default

Quote:
Originally Posted by Jay.slovak
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!.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 5th November 2005, 05:21 AM   (permalink)
New Member
elexhobby is on a distinguished road
Default

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...
elexhobby is offline   Reply With Quote
Old 5th November 2005, 10:34 AM   (permalink)
Super Moderator
 
Jay.slovak is just really niceJay.slovak is just really niceJay.slovak is just really nice
Default

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.
Attached Images
File Type: png reset_table.png (63.2 KB, 351 views)
Jay.slovak is offline   Reply With Quote
Old 6th November 2005, 02:51 AM   (permalink)
Experienced Member
 
Oznog is just really niceOznog is just really niceOznog is just really nice
Send a message via AIM to Oznog
Default

Quote:
Originally Posted by Nigel Goodwin
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.
__________________
I thought what I'd do was I'd pretend I was one of those deaf-mutes.
Oznog is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 05:01 PM.


Electronic Circuits  |  Radio Controlled
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.