View previous topic :: View next topic |
Author |
Message |
strsh
Joined: 16 Jul 2013 Posts: 37
|
Read WDT time |
Posted: Tue Oct 25, 2016 11:36 am |
|
|
Hello.
I'm interested in where they can see how much time I have left to reset WDT?
I turned WDT and defined time reset.
#FUSES WDT setup_wdt (WDT_2304MS);
I wish, before there is a reset, execute a command.
Thanks in advance. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Tue Oct 25, 2016 11:49 am |
|
|
Generally you can't.
Always tell us the PIC involved (features change from chip to chip), but on most PIC's the watchdog counter is not available to the code. It is not designed as a general timer, but a 'backstop', and if you need to do jobs by a particular time, you should be using another timer for this, with it's timings set so that your events happen before the shortest watchdog, and then reset this if things are OK. |
|
|
strsh
Joined: 16 Jul 2013 Posts: 37
|
|
Posted: Tue Oct 25, 2016 12:14 pm |
|
|
Thank you for your prompt response.
It would be easier to read the time in a register for WDT. I turned on a timer (timer1). I thought not include other timer (timer0), If there is no other solution, I'm going.
If it's not a problem if you can write me a simplest loop for a period of 5 seconds(no delay_ms(5000))? Clock is set to 8MHz. I'm stuck.
Thanks in advance. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Tue Oct 25, 2016 12:44 pm |
|
|
As I already said:
"Always tell us the PIC involved (features change from chip to chip)" |
|
|
strsh
Joined: 16 Jul 2013 Posts: 37
|
|
Posted: Tue Oct 25, 2016 12:58 pm |
|
|
Sorry.
The PIC 16f688.
I wanted to use the command for (k = 0; k <255; k ++), but the time is long (5 seconds).
Not a problem, if the question is too simple, you do not answer. I will not be mad because you gave me the answer to my first question.
Thanks and sorry on my bad English. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Tue Oct 25, 2016 1:03 pm |
|
|
Why are you using the watchdog?.
You need to understand that just enabling the watchdog, adds basically nothing to the reliability of the chip. To use a watchdog properly, requires quite sophisticated code, that verifies the chip is doing what it should be doing, and only if it is, then resets the watchdog. Enabling it otherwise, is pointless.... |
|
|
strsh
Joined: 16 Jul 2013 Posts: 37
|
|
Posted: Tue Oct 25, 2016 1:33 pm |
|
|
I ran with the idea that if there is a confusion of the program (communicate with RS232 port) WDT reset the PIC, although I have in #use RS232 (timeout = 400, errors). Some kind of extra protection. I may be wrong but I was told that the WDT mandatory. If you write code with the command for (5 sec), then I'm going to turn off the WDT.
I need to reset the PIC at one point. Since the WDT is turned ... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Oct 26, 2016 12:49 am |
|
|
A search here (and elsewhere on line), will find a lot about why this approach to using the watchdog is totally pointless.
A watchdog used properly is a powerful tool, but added without full code is more likely to cause problems than reduce them....
Now you can stop the watchdog resetting in a 5 second delay, by adding the instruction 'RESTART_WDT' to your #use delay declaration. Problem is that this means the watchdog is automatically reset in every delay. If the code gets hung waiting for something to happen, and is using a delay in the loop while it waits, this will stop the watchdog from ever triggering. So the watchdog becomes useless. Effectively disabled all the time.... |
|
|
strsh
Joined: 16 Jul 2013 Posts: 37
|
|
Posted: Wed Oct 26, 2016 3:03 am |
|
|
You're right. Since I was not good at programming, I will turn off the WDT.
I managed to do a loop:
for (unsigned long long aa = 0; aa <0x24800; aa ++) ...
but I think this is just a bad solution, and that there are better than this.
Where can I read (teach) how to use the WDT?
Thanks.
Last edited by strsh on Wed Oct 26, 2016 3:09 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Oct 26, 2016 3:09 am |
|
|
As I said a search here will find lots of threads where this is discussed.
On the web, some good overviews:
<https://betterembsw.blogspot.co.uk/2014/05/proper-watchdog-timer-use.html>
<http://www.embedded.com/design/debug-and-optimization/4402288/Watchdog-Timers>
Key thing is to look at the part in the second article about 'sanity checks'. Without these, the watchdog becomes very little use at all... |
|
|
strsh
Joined: 16 Jul 2013 Posts: 37
|
|
Posted: Wed Oct 26, 2016 3:17 am |
|
|
I know that literature has on the Internet a lot, but I'm more interested that you use, because I believe that you have chosen the right.
Thanks for the advice and I hope that in the future I can count on this forum.
Bye. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Oct 26, 2016 3:29 am |
|
|
Handling a watchdog properly is completely dependant on the project. No universal solutions. Has to involve sitting down and working out how long things can accept a failure for, and what parts of the code are 'mission critical'. The watchdog must be set to timeout quicker than the minimum acceptable time, and only kicked if every mission critical part is working properly. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Oct 26, 2016 1:21 pm |
|
|
One other point about the WDT on most PICs is that it is NOT accurate ! It's one of the important details you MUST read and understand !! Even within 'batches' of PICs the timing can be off, so if you base your WDT code based on one PIC, the other 10,100,1000 won't be the same.
Also it's temperature sensitive, so if the product has to go outside the lab (always a comfy 72*F ot 22*C), again timing will be off.
Just something else to consider....
Jay |
|
|
|