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 timer wake up problem for 12hrs

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



Joined: 02 Aug 2016
Posts: 4

View user's profile Send private message

watchdog timer wake up problem for 12hrs
PostPosted: Sat Sep 03, 2016 1:41 am     Reply with quote

hi

I have faced a problem in watchdog timer wake up for 12hrs once.
Code:

#include <16LF1825.h>

#FUSES WDT                   //Watch Dog Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOSTVREN                 //Stack full/underflow will not cause reset

#use delay(internal=4000000,restart_wdt)

#users232(baud=9600,parity=N,xmit=PIN_C4,rcv=PIN_C5,bits=8,stream=PORT1,restart_wdt)

void main()
{
   WDTCON=0X24; // 256sec         
   SWDTEN=0;     
        while(true)
        {         
           SWDTEN=0;             
           printf("awake...");                             
           SWDTEN=1;
           printf("sleep..");   
           DELAY_MS(10);   
           for(slp=0;slp<169;slp++){       //12hrs (432000/256=168.75==>169) // but 12 hr wakeup happens when slp<154
            SLEEP();         
            delay_cycles(1);
           } 
        }
}

In the above code i configured watchdog timer for 256 seconds time.
Every 256 seconds once controller wake up and went to sleep.
For a 12hr time period we calculated the loop count value with reference of watchdog timer configuration at 256 seconds.
For a 12hr time period we got a loop count value is 169.

I programmed the above program in two microcontrollers,
but i got a different results. The time difference between 12hrs once data extended to 13hrs or some time value above 12hrs.

Anyone please suggest to rectify this problem.
temtronic



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

View user's profile Send private message

PostPosted: Sat Sep 03, 2016 5:06 am     Reply with quote

This is probably simple basic 'timing'... though I haven't run your code, I see you're using internal oscilllator and WDT.

You have to read the 500+ pages of the datasheet and find the 'accuracy' or 'range' or 'nominal' specifications for both the WDT and the internal RC oscillator. Important specs to read...'somewhere'...
In the past, the WDT was +-50 to 100% of the value. Say the WDT is set for 1 second. Valid, by the book, numbers would be 1/2 to 2 seconds ! I don't use that PIC and heaven't looked for the spec but I assum it's fairly 'wide'.
Also the Internal clock is NOT exactly 4,000,000.000000000 Hz! Again due to the RC nature,even though laser trimmed, it is NOT precise. So since every clock cycle is just a 'little' off what you think it should be ,or observe, over time it all adds up. In your case the clock may be running fast, so the WDT resets sooner than the calculation says it should. Added to this is the temperature factor. The 'specs' are at a certain temperature and the actual performance WILL be different as the PIC heats up(during lots of use) and slows down( when it's asleep). This is normal and the effect will be different on every PIC,although same batch PICs tend to be very close.
You could run several 'timing tests' and fine tune the WDT counter variable to get the WDT to trigger when you want. you'll need a LOT of time to run these tests though. I don't think it will matter if you,for instance, set the WDT for 1 second and externally counter 256, interrupts versus setting the WDT for 256 seconds and see 1 interrupt. In the first case the PIC is internally counting, in the second you are.
The only easy and accurate way to get precise timing is by using an external crystal/caps clock.


Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19329

View user's profile Send private message

PostPosted: Sat Sep 03, 2016 6:06 am     Reply with quote

Temtronic has given the basic answer.

Critical thing is that if you read the data sheet line about using the watchdog, it says:

"Configurable time-out period is from 1 ms to 256
seconds (typical)".

Note the 'typical'.

Then parameter 31, Table 30-5:
Low-Power Watchdog Timer
Time-out Period min 12, Typ 16, Max 20.

So the nominal 256 seconds could be anything from 192, to 320 seconds.

This is far tighter than many of the older watchog's, that had figures like 7 to 28mSec.

The watchdog is not designed as an accurate timer. If you want accurate times, you need to use something like an external crystal based RTC.

As a comment, your clearing SWDTEN does nothing. You have the watchdog fuse set, and when this is set, the SWDTEN bit is disabled. Again in the data sheet. The WDTE bits in configuration word 1. To allow the watchdog to be controlled by SWDTEN, instead of the fuse 'WDT', you need the fuse 'WDT_SW' which sets the watchdog so it can be software controlled.
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