|
|
View previous topic :: View next topic |
Author |
Message |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
watchdog "autostart" |
Posted: Wed Jun 29, 2011 1:57 pm |
|
|
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
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
|
Re: watchdog "autostart" |
Posted: Wed Jun 29, 2011 6:11 pm |
|
|
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
|
Re: watchdog "autostart" |
Posted: Wed Jun 29, 2011 10:35 pm |
|
|
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: 19496
|
|
Posted: Thu Jun 30, 2011 2:17 am |
|
|
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
|
|
Posted: Thu Jun 30, 2011 9:35 am |
|
|
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! I didnt' find that anywhere in the documentation...
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
|
|
Posted: Thu Jun 30, 2011 10:11 am |
|
|
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: 19496
|
|
Posted: Thu Jun 30, 2011 3:20 pm |
|
|
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 |
|
|
|
|
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
|