View previous topic :: View next topic |
Author |
Message |
starfire151
Joined: 01 Apr 2007 Posts: 195
|
WDT questions |
Posted: Sun Jul 03, 2016 2:51 pm |
|
|
V5.044 PCWHD
Windows 10
I'm writing a program for a PIC16LF1705 that uses a watchdog timer to allow it to sleep, wake periodically, do some work, then go back to sleep.
I will eventually want the sleep period to be about 10 - 30 minutes. I set up a test program with a #fuses WDT statement and the following in the main code:
Code: |
setup_wdt(WDT_1S);
while(TRUE)
{
restart_wdt(); // restart WDT for full count
...
wdtLoopCntr = 0;
while(wdtLoopCntr < 10) // effectively multiplies WDT_1s by 10)
{
restart_wdt(); // sync WDT to restart timeout now
sleep();
wdtLoopCntr++;
}
setup_wdt(WDT_OFF); // disable WDT to do some functions
... do some functions that take a while (several 10s of seconds)
setup_wdt(WDT_1S);
}
|
The variable wdtLoopCntr is used to count the number of WDT timeouts to the max needed. Obviously in this test case I could have just used a longer WDT constant but I will eventually want to set it up with 30 loops of WDT_64S for about 30 minutes delay.
My problem is the program apparently doesn't recognize the setup_wdt(WDT_OFF). The program runs OK until it gets to this point then it resets. I tried changing the setup_wdt(WDT_OFF) to setup_wdt(WDT_256S) for a long delay and the program works OK.
What do I need to do to get the WDT to disable while I do some long-term functions and then re-enable it?
Is there an example of what I'm trying to do?
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 03, 2016 3:12 pm |
|
|
Quote: | I set up a test program with a #fuses WDT statement. |
Below are the available fuse options for the Watchdog for the 16LF1705.
Code: | NOWDT, WDT_SW, WDT_NOSL, WDT |
Which one would be best if you want SoftWare on/off control of the Watchdog ? |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Sun Jul 03, 2016 3:22 pm |
|
|
OK... yeah... I get it.
Changed the #fuses to WDT_SW and it works fine.
Thanks. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9279 Location: Greensville,Ontario
|
|
Posted: Sun Jul 03, 2016 5:38 pm |
|
|
Hope you're aware that the WDT is NOT and accurate 'timer'. If you need exactly 30 minutes, it's best to go with an external RTC chip like the DS1307. That way you have precise control of when it'll wakeup.
Mpw different PICs have better or worse timing for WDT, just be sure to read the datasheet! Also, time will vary with temperature and even PICs of the same type, different batches WILL be different.
Jay |
|
|
|