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

watchdog "autostart"

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



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

watchdog "autostart"
PostPosted: Wed Jun 29, 2011 1:57 pm     Reply with quote

Hi There,

I wanna use the watchdog timer on a pic18f86k22.
I have following fuses:
Code:
#fuses WDT1024,WDT_SW

which requires me to manually start the timer by calling
Code:
setup_wdt(WDT_ON);

in my code. How can autostart the watchdog with out the need to explicitly start it?

Thanks,
Ron
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: watchdog "autostart"
PostPosted: Wed Jun 29, 2011 6:11 pm     Reply with quote

cerr wrote:
How can autostart the watchdog with out the need to explicitly start it?

Ron, are you concerned that your program will get stuck (which would require a reset by watchdog) before it gets to setup_wdt(WDT_ON) ?

- Nick
_________________
Read the label, before opening a can of worms.
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

Re: watchdog "autostart"
PostPosted: Wed Jun 29, 2011 10:35 pm     Reply with quote

kender wrote:
cerr wrote:
How can autostart the watchdog with out the need to explicitly start it?

Ron, are you concerned that your program will get stuck (which would require a reset by watchdog) before it gets to setup_wdt(WDT_ON) ?

- Nick


Yep, what e.g if #use rs232 doesn't initialize properly?
Ttelmah



Joined: 11 Mar 2010
Posts: 19331

View user's profile Send private message

PostPosted: Thu Jun 30, 2011 2:17 am     Reply with quote

OK.
First, #use RS232, only writes to registers, doesn't poll or check anything, so really cannot fail. So it is not really a problem.

However you can enable the watchdog in the fuses.
There are a series of basic 'modes' for the 86K watchdog:

1) No watchdog (NOWDT).
2) Watchdog disabled in sleep (WDT_NOSLEEP)
3) Watchdog controlled by software (WDT_SW)
4) Watchdog enabled by the hardware (WDT)

These correspond to the low two bits in the config2h register.

So if you compile with (say):

#fuses WDT1024,WDT

The watchdog is enabled straight away.
You can test this by checking the bit pattern put into config2h, at the end of the listing file.

So, with this setting, word 2, is given as 1F7E, while with WDT_SW selected, it changes to 1E7E.
Caveat though. Don't use #ZERO_RAM... This takes a long time, and if the watchdog is enabled during boot up, you may well find the chip will never actually boot!....

Best Wishes
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Thu Jun 30, 2011 9:35 am     Reply with quote

Ttelmah wrote:
OK.
First, #use RS232, only writes to registers, doesn't poll or check anything, so really cannot fail. So it is not really a problem.

However you can enable the watchdog in the fuses.
There are a series of basic 'modes' for the 86K watchdog:

1) No watchdog (NOWDT).
2) Watchdog disabled in sleep (WDT_NOSLEEP)
3) Watchdog controlled by software (WDT_SW)
4) Watchdog enabled by the hardware (WDT)

These correspond to the low two bits in the config2h register.

So if you compile with (say):

#fuses WDT1024,WDT

The watchdog is enabled straight away.
You can test this by checking the bit pattern put into config2h, at the end of the listing file.

So, with this setting, word 2, is given as 1F7E, while with WDT_SW selected, it changes to 1E7E.
Caveat though. Don't use #ZERO_RAM... This takes a long time, and if the watchdog is enabled during boot up, you may well find the chip will never actually boot!....

Best Wishes


Thanks buddy!
This worked out nicely! Great, that probably saved my long weekend! Smile I didnt' find that anywhere in the documentation... Sad
It wouldn't make sense to call #ZERO_RAM and WDT together anyways, would it? #ZERO_RAM would turn it off again and you have to start it manually by calling setup_wdt(), or am I understanding #ZERO_RAM wrongly?

Thanks,
Ron
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Thu Jun 30, 2011 10:11 am     Reply with quote

Oh Also,

I just realized that I can't turn the WDT off anymore with
Code:
setup_wdt(WDT_OFF);
which is a problem. I need the possibility to turn off the WDT while waiting for user input e.g. or while sleeping...
Please advise!

Thank you!
Ttelmah



Joined: 11 Mar 2010
Posts: 19331

View user's profile Send private message

PostPosted: Thu Jun 30, 2011 3:20 pm     Reply with quote

You can't. Read the data sheet.
If enabled by the hardware fuse, the software bit is ignored. You can only control it with software, if you use the software enable mode.

Best Wishes
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