CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Read WDT time

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
strsh



Joined: 16 Jul 2013
Posts: 37

View user's profile Send private message

Read WDT time
PostPosted: Tue Oct 25, 2016 11:36 am     Reply with quote

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: 19366

View user's profile Send private message

PostPosted: Tue Oct 25, 2016 11:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 25, 2016 12:14 pm     Reply with quote

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: 19366

View user's profile Send private message

PostPosted: Tue Oct 25, 2016 12:44 pm     Reply with quote

As I already said:

"Always tell us the PIC involved (features change from chip to chip)"
strsh



Joined: 16 Jul 2013
Posts: 37

View user's profile Send private message

PostPosted: Tue Oct 25, 2016 12:58 pm     Reply with quote

Sorry.Embarassed
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: 19366

View user's profile Send private message

PostPosted: Tue Oct 25, 2016 1:03 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 25, 2016 1:33 pm     Reply with quote

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: 19366

View user's profile Send private message

PostPosted: Wed Oct 26, 2016 12:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 26, 2016 3:03 am     Reply with quote

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: 19366

View user's profile Send private message

PostPosted: Wed Oct 26, 2016 3:09 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 26, 2016 3:17 am     Reply with quote

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. Very Happy
Ttelmah



Joined: 11 Mar 2010
Posts: 19366

View user's profile Send private message

PostPosted: Wed Oct 26, 2016 3:29 am     Reply with quote

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: 9173
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Oct 26, 2016 1:21 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group