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

WDT questions

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



Joined: 01 Apr 2007
Posts: 195

View user's profile Send private message

WDT questions
PostPosted: Sun Jul 03, 2016 2:51 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jul 03, 2016 3:12 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jul 03, 2016 3:22 pm     Reply with quote

OK... yeah... I get it. Laughing

Changed the #fuses to WDT_SW and it works fine.

Thanks.
temtronic



Joined: 01 Jul 2010
Posts: 9169
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jul 03, 2016 5:38 pm     Reply with quote

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