Hot!watchdog timer coneptual questions

Page: < 12 Showing page 2 of 2
Author
serge313
Junior Member
  • Total Posts : 91
  • Reward points : 0
  • Joined: 2017/09/04 21:22:10
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/17 07:01:14 (permalink)
0

Whatever combination of prescalers you select does all the counting required.
 

Is it typically like that across different micros, with watchdog timers not having counters so that the time to wait is the period of the input clock * pre-scalar. As I was reading, petting the dog would make the value go back to a certain value, like 5000 for example, and then count down from there such that when it got to 0, the micro would reset. The point is that it was counting down according to the text. Considering a watchdog timer is a timer, that's why I assumed it had a counter.
 

The second one can be used be either TMR0 or the WDT, selected by the PSA bit.

I understand.
 

yes.

Ok, I see where I was misinterpreting now but it's still confusing why a watchdog timer doesn't have a counter haha.
 




 
post edited by serge313 - 2018/04/17 07:15:32
#21
serge313
Junior Member
  • Total Posts : 91
  • Reward points : 0
  • Joined: 2017/09/04 21:22:10
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/17 07:17:15 (permalink)
0

Observation of the WDT implementation of the PIC16F690.

See TABLE 17-2: OSCILLATOR PARAMETERS

Parameter: OS09, LFOSC, Internal Uncalibrated LFINTOSC Frequency

Maximum count of WDT = 8388608 @ 15,000Hz timeout in 559.240 seconds
Maximum count of WDT = 8388608 @ 31,000Hz timeout in 270.600 seconds
Maximum count of WDT = 8388608 @ 45,000Hz timeout in 186.413 seconds

The maximum count for the WDT use the 16-bit WDT prescaler plus the TIMER0 8-bit prescaler.

As a note only 7 of the 8-bits of the TIMER0 prescaler are available to the WDT count chain.

This yields a ripple counter of 23-bit for use as a WDT timeout duration counter.

No matter how the WDT counter is configured the execution of the CLRWDT, or SLEEP opcode will clear this ripple counter.

Changes to the configuration of the WDT prescalers while the WDT is enabled can result in an WDT reset.

You need to take note that the LFOSC frequency varies over a range of ±50% depending on VDD voltage and die temperature.

This means that the WDT timeout interval is not usually a suitable method to measure long term event related to the way people think of time.

For example if you need your controller to wake up every 24 hours to do something but you use only the WDT timeout interval the the time of day the controller will wake up will vary by as much as 12 hours and may gain or lose up to 12 hours each time.

In projects where lowest average power usage is essential this kind of temporal drift can be acceptable.


Very informative. I agree that WDT shouldn't be used as a replacement for a timer since it isn't as precise.
post edited by serge313 - 2018/04/17 07:19:48
#22
Mysil
Super Member
  • Total Posts : 2595
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: online
Re: watchdog timer coneptual questions 2018/04/17 08:48:13 (permalink)
+1 (1)
Hi,
WDT isn't about precision, it is about reliability,
whatever rouge code may be running in the microcontroller, WDT should function.
As such, Program code should have as little interaction with the WDT as possible.
The LPRC oscillator is designed to function at all times with Low power consumption,
with reliable oscillation much more important than frequency precision,
and to work independent of other oscillators in the chip.
 
In the WDT we have been discussing, the Prescaler is the Counter.
That Application code have no way to Write or Read the WDT counter value is deliberate.
 
Even the WDTCON register with possibility to change or disable the watchdog,
may be argued by some, as a Reliability disadvantage.
Thus, in more modern PIC devices,
you may see that the WDT prescaler selection may be specified in Configuration bits,
and then WDT may be configured to Not be Disabled or changed by running code.
 
   Mysil
#23
jack@kksound
code tags!
  • Total Posts : 2446
  • Reward points : 0
  • Joined: 2014/05/14 10:03:19
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/17 09:54:57 (permalink)
+1 (1)
Ok, I see where I was misinterpreting now but it's still confusing why a watchdog timer doesn't have a counter haha.

It should be remembered that the "prescaler" is a counter however that does NOT mean you have access to reading or writing the individual sections (bits) of the counter. In the WDT case you definately do not have that type of access (for reasons like pointed out by Mysil above). So how the WDT is actually implimented in hardware really has very little to do with how you access it and use it and how it ultimately operates in your pic and with your code.
#24
qɥb
Monolothic Member
  • Total Posts : 2125
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: online
Re: watchdog timer coneptual questions 2018/04/17 13:20:15 (permalink)
+1 (1)
serge313
...
As I was reading, petting the dog would make the value go back to a certain value, like 5000 for example, and then count down from there such that when it got to 0, the micro would reset.

"Petting the dog" is executing the CLRWDT instruction.
As its name would suggest, it CLEARS the counter, i.e. all bits revert back to zero.
Like all the other PIC timers, it counts UP, not down. When it overflows = "rolls over back to zero", it triggers a WDT reset.
 

The point is that it was counting down according to the text.

Where does it say it counts DOWN ?
 

Considering a watchdog timer is a timer, that's why I assumed it had a counter.

As already mentioned above, a prescaler IS a counter.
 

PicForum "it just works"
#25
serge313
Junior Member
  • Total Posts : 91
  • Reward points : 0
  • Joined: 2017/09/04 21:22:10
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/18 08:43:24 (permalink)
0
Mysil
Hi,
WDT isn't about precision, it is about reliability,
whatever rouge code may be running in the microcontroller, WDT should function.
As such, Program code should have as little interaction with the WDT as possible.
The LPRC oscillator is designed to function at all times with Low power consumption,
with reliable oscillation much more important than frequency precision,
and to work independent of other oscillators in the chip.
 
In the WDT we have been discussing, the Prescaler is the Counter.
That Application code have no way to Write or Read the WDT counter value is deliberate.
 
Even the WDTCON register with possibility to change or disable the watchdog,
may be argued by some, as a Reliability disadvantage.
Thus, in more modern PIC devices,
you may see that the WDT prescaler selection may be specified in Configuration bits,
and then WDT may be configured to Not be Disabled or changed by running code.
 
   Mysil


I understand that WDT is a timer for reliability, to run at all times. But, can you say that the WDT is also unreliable, since when used for timing, as mentioned, it can be as much as 50% off.
#26
jack@kksound
code tags!
  • Total Posts : 2446
  • Reward points : 0
  • Joined: 2014/05/14 10:03:19
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/18 08:57:06 (permalink)
0
I understand that WDT is a timer for reliability, to run at all times. But, can you say that the WDT is also unreliable, since when used for timing, as mentioned, it can be as much as 50% off.

Reliability is generally a different concept then accuracy and repeatability. The WDT is not particularly repeatable in the time-out period (due to the preveously mentioned reasons) however it is not intended to be a precise timer but rather a reliable timer (it should always function), different purpose so you should expect different characteristics.
Bottom line: expecting something from a perripheral that it was not designed to do is foolish.
#27
serge313
Junior Member
  • Total Posts : 91
  • Reward points : 0
  • Joined: 2017/09/04 21:22:10
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/18 08:58:09 (permalink)
0

It should be remembered that the "prescaler" is a counter however that does NOT mean you have access to reading or writing the individual sections (bits) of the counter. In the WDT case you definately do not have that type of access (for reasons like pointed out by Mysil above). So how the WDT is actually implimented in hardware really has very little to do with how you access it and use it and how it ultimately operates in your pic and with your code.


Is not being able to write to the WDT PIC specific? Some WDT are designed such that you write a certain value to them, then starting from that value, they begin to count down. Upon reaching zero is when the micro resets so if you continuously set the value and don't let the counter reach 0, then the application software is working.
 
The confusion for a WDT without a counter came from a different timer, like TMR1 having a counter as part of its hardware implementation. So the amount of time it takes TMR1 to overflow is: 1/TMR1 clock speed * pre-scalar * 2^n, where n is register size. 1/TMR1 clock speed * pre-scalar is the amount of time it takes per tick (increment), and it needs 2^n increments to overflow. A WDT, by hardware implementation doesn't seem to operate that way. Instead, to calculate the amount of time it takes to reset the micro is: 1 / WDT clock speed * pre-scalar. So a pre-scalar of 32 internally means that the counter in it has to reach to 32 before it can signal the WDT to reset. But in TMR1 case, the pre-scalar simply increments the counter by 1. Since WDT is said to be a "counter", I thought "counter" referred to the counter like TMR1, not the pre-scalar counter.
post edited by serge313 - 2018/04/18 10:49:34
#28
serge313
Junior Member
  • Total Posts : 91
  • Reward points : 0
  • Joined: 2017/09/04 21:22:10
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/18 09:04:07 (permalink)
0
Where does it say it counts DOWN ? 
There are several websites on the web that describe a WDT as a counter counting down.
According to: https://www.embedded.com/electronics-blogs/beginner-s-corner/4023849/Introduction-to-Watchdog-Timers
In the link, it says:Generally speaking, a watchdog timer is based on a counter that counts down from some initial value to zero. The embedded software selects the counter's initial value and periodically restarts it. If the counter ever reaches zero before the software restarts it, the software is presumed to be malfunctioning and the processor's reset signal is asserted. 
As already mentioned above, a prescaler IS a counter. 

Yes, it is but there's an additional counter in normal timers, that count up to the register size. So an 8 bit counter would count from 0 - 255. That counter isn't in the WDT but it is in TMR0, even if both are said to be "timers".
post edited by serge313 - 2018/04/18 09:08:52
#29
jack@kksound
code tags!
  • Total Posts : 2446
  • Reward points : 0
  • Joined: 2014/05/14 10:03:19
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/18 09:34:09 (permalink)
+1 (1)
In the link, it says:Generally speaking

This is an important "clue" in the article you referrenced, it is telling you that they are discussing a "general" case that may not be the way all wdt circuits are designed but gives you some idea of basic funtionality. Assuming that is how they all work and wondering why a specific pic wdt does not work that way will get you into trouble usually. I suggest that the datasheet be the guide, it will tell you what the wdt does, how you can interract with it and what to expect from it (in most cases - sometimes they mess up some details - errors happen). In order to know what it does for you and how to get the most from it you must read all the info the datasheet provides.
Some "other' microcontrollers (non pic) have a wdt that is designed closer to the method described in the article you linked.
#30
Gort2015
Klaatu Barada Nikto
  • Total Posts : 2265
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/18 10:04:30 (permalink)
+2 (2)
Why are you making a big thing about it?
Some chips might have post-scalers and pre-scalers or even more than one WDT.
It doesn't matter if it counts down, up or sideways, who cares.
 
Just look in the datasheet for the chip you are using and use the parameters provided.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#31
serge313
Junior Member
  • Total Posts : 91
  • Reward points : 0
  • Joined: 2017/09/04 21:22:10
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/19 11:02:44 (permalink)
0
jack@kksound
This is an important "clue" in the article you referrenced, it is telling you that they are discussing a "general" case that may not be the way all wdt circuits are designed but gives you some idea of basic funtionality. Assuming that is how they all work and wondering why a specific pic wdt does not work that way will get you into trouble usually. I suggest that the datasheet be the guide, it will tell you what the wdt does, how you can interract with it and what to expect from it (in most cases - sometimes they mess up some details - errors happen). In order to know what it does for you and how to get the most from it you must read all the info the datasheet provides.
Some "other' microcontrollers (non pic) have a wdt that is designed closer to the method described in the article you linked.


I see, I understand. This is exactly what I needed to hear. Thank you.
post edited by serge313 - 2018/04/19 11:16:25
#32
serge313
Junior Member
  • Total Posts : 91
  • Reward points : 0
  • Joined: 2017/09/04 21:22:10
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/19 11:15:53 (permalink)
0
Gort2015
Why are you making a big thing about it?
Some chips might have post-scalers and pre-scalers or even more than one WDT.
It doesn't matter if it counts down, up or sideways, who cares.
 
Just look in the datasheet for the chip you are using and use the parameters provided.


I'm not making a big deal out of it. I was just trying to understand the discrepancies I found between my understanding and other articles to better understand how the peripherals work, especially when first learning about them. If this isn't the first time I'm working with the WDT then I'd agree. I don't believe that abstracting the details of how modules or peripherals work is a good idea. Having the bigger picture and seeing how other micros go about implementing a peripheral different from the PIC is good to know.
#33
jack@kksound
code tags!
  • Total Posts : 2446
  • Reward points : 0
  • Joined: 2014/05/14 10:03:19
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/19 11:24:57 (permalink)
+1 (1)
 Having the bigger picture and seeing how other micros go about implementing a peripheral different from the PIC is good to know.

I will agree with you that the knowledge is a good thing however as you can see from this specific topic you must be careful when trying to apply general concepts to specific implementations, it can lead you down a confusing path. 
#34
serge313
Junior Member
  • Total Posts : 91
  • Reward points : 0
  • Joined: 2017/09/04 21:22:10
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/19 14:52:13 (permalink)
0
jack@kksound
 Having the bigger picture and seeing how other micros go about implementing a peripheral different from the PIC is good to know.

I will agree with you that the knowledge is a good thing however as you can see from this specific topic you must be careful when trying to apply general concepts to specific implementations, it can lead you down a confusing path. 


It can definitely lead to confusion unfortunately, that's why I created this thread in the first place. How else is someone supposed to learn about a peripheral online. The resources start to become very limited when looking at tutorials very specific to the micro and when learning about a different micro, the focus was so much based about how it worked somewhere else that it's like learning about it the peripheral all over again. Having the big picture like:
 
"A WDT contains a counter either counting up or down depending on micro, but specifically for the PIC, the WDT is counting up and when it reaches the pre-scalar value, the micro resets. The WDT itself does not contain a counter on the hardware itself, so once the count reaches to the pre-scalar, it signals the micro to reset. The register is not writable so petting the dog would mean resetting the timer which is done by calling the clearWDT() function. In other micros, petting the dog is setting it to another value so that you prevent it from getting to zero as its counting down."
 
This helps much more than "The PIC's WDT is a counter counting up. The amount of time it takes to reset is 1/WDT clock speed * pre-scalar value because that's what the datasheet says."
 
There's a big difference among the two. That's why I appreciate everyone's input on this thread. It makes me understand more about the peripheral.
 
Because explaining it like the second way makes me question things I've questioned like:
"But a timer contains another counter like TMR1, independent of the pre-scalar counter. So for TMR1 to reset, it would take 1/TMR1 clock speed * pre-scalar * 2^16, where 16 is TMR1 register size. 1/TMR1 clock speed * pre-scalar is only 1 tick but you need 2^16 ticks to reset, but where's the 2^16 ticks for the WDT if it really is a timer.
 
Looking at the datasheet is no good when learning. The datasheet is not a tutorial, it's a manual about how the micro works. Once having an understanding about the peripheral's functionality, it's good to check out the datasheet to understand exactly how that peripheral works for that micro.
 
I don't know, maybe my philosophy on learning isn't the best, but that's just how I think of it.
#35
qɥb
Monolothic Member
  • Total Posts : 2125
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: online
Re: watchdog timer coneptual questions 2018/04/19 15:38:32 (permalink)
0
Whatever works for you.
For me, the datasheet rules.
Whenever you get a conflict between a general description, and the datasheet, then the datasheet has priority.
The very rare times I start with a new family,  I read one of the datasheets from start to end to see what's there.
Thereafter, for working with new family members, I'll study just the peripherals I am interested in to see if anything is different.
 

PicForum "it just works"
#36
dan1138
Super Member
  • Total Posts : 2706
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/19 17:55:39 (permalink)
0
serge313,
 
You may have something like a blind spot when it comes to finding the concepts within a collection of facts.
 
It is easy to find the facts you need within the data sheets of a microcontroller.
 
Distilling the concepts usually requires experience.
 
In this specific example the WDT concepts are elementary but no less essential to all embedded applications. Apart from the system clock source there are few more crucial functions to really understand.
 
Possible the single most useful thing you can learn to do is to find the concepts buried under a pile of facts.
#37
jack@kksound
code tags!
  • Total Posts : 2446
  • Reward points : 0
  • Joined: 2014/05/14 10:03:19
  • Location: 0
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/20 09:09:55 (permalink)
+1 (1)
There are times when you need to know how a peripheral does it's job and there are times you only need to kow how to use it (a "black box"). Knowing which is which takes experience which unfortunately takes time and effort.
#38
JorgeF
Super Member
  • Total Posts : 2912
  • Reward points : 0
  • Joined: 2011/07/09 11:56:58
  • Location: PT/EU @ Third rock from the Sun
  • Status: offline
Re: watchdog timer coneptual questions 2018/04/20 14:46:18 (permalink)
+2 (2)
Hi
serge313
....
"A WDT contains a counter either counting up or down depending on micro, but specifically for the PIC, the WDT is counting up and when it reaches the pre-scalar value, the micro resets. The WDT itself does not contain a counter on the hardware itself, so once the count reaches to the pre-scalar, it signals the micro to reset. The register is not writable so petting the dog would mean resetting the timer which is done by calling the clearWDT() function. In other micros, petting the dog is setting it to another value so that you prevent it from getting to zero as its counting down."

Who cares !
 
For a basic PIC16 device the datasheet says the WDT its something that resets the PIC if not cleared for more than "18ms", with some 10% precision or alike.
Good enought, I know my program has to clear it at intervals bellow 16ms.
In a more advanced PIC it will have a thing called a prescaller that allows me to extend the 18ms a number of times. In an even more advanced PIC it might have also a post-scaller. In a high end PIC it might be windowed.
 
Besides that, it can be made with 1, 2, 3, as many as someone decided, counters (*), an RC circuit, a shift register, a set of clock gears, a glass of water with a calibrated hole in it, whatever, it won't make any difference.
 
The day someone asks me to design a watchdog timer, then I will make my own project decisions.
As long as it meets the required specifications, its up to me.
 
 
Anything else is no more than an academic discution that, like all other academic discutions, as limited contact with the real world.
And then you have a specific device to work with, and you meet the real world in the form of a datasheet, stating how to use something that has been designed by someone somewere in time.
 
 
(*) BTW pre-scallers and post-scaller are also counters.
 
 
Best regards
Jorge
post edited by JorgeF - 2018/04/20 14:48:06
#39
Page: < 12 Showing page 2 of 2
Jump to:
© 2018 APG vNext Commercial Version 4.5