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 CCS Technical Support

Sleep interrupted by Portb, can I find out sleep time left?

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



Joined: 09 Oct 2008
Posts: 15

View user's profile Send private message

Sleep interrupted by Portb, can I find out sleep time left?
PostPosted: Wed Dec 21, 2011 9:58 am     Reply with quote

I'm doing the age old thing of going to sleep and using the WDT to wake up PIC. I count n goes and then trundle off and do something useful.

I've now had to add a change on port B event to wake from sleep. I need to service that event and then continue sleeping until the sleep count expires to do the useful stuff as before.

I can detect the difference between being woken up from the Port B Interrupt and from the WDT timeout. However if I count the Port B events I do my useful stuff too early and if I ignore the Port B events for my loop counter then I'm late.

Is there a timer or other register that I can read and see how much of my WDT period was left when I get woken up by the port b int? I could then take into account these partial periods and still do my useful stuff at about the same time.

TIA
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Dec 21, 2011 11:50 am     Reply with quote

You'll surely have noticed, that there's no elapsed time information available from the WDT. The only practical method without starting a real timer is to split the WDT period into smaller slices and count these events, start the original wakeup code every 8, 16 or so events.
picnic



Joined: 09 Oct 2008
Posts: 15

View user's profile Send private message

PostPosted: Thu Dec 22, 2011 2:54 am     Reply with quote

That was my conclusion but I had hoped I had missed something. Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Thu Dec 22, 2011 3:17 am     Reply with quote

Worth realising that the watchdog does not give anything approaching an accurate time anyway. On 90% of chips it varies by as much as 300% depending on temperature, and supply voltage... On these chips the WDT, is just a capacitor discharge circuit.
On some later chips the WDT instead uses a counter running from the LF internal clock. On these there is a counter, but not available to you.
If pins are available, the only way to get this type of functionality, is to add a watch crystal to timer1, don't use the watchdog, and instead wake on the timer. This can then be read to see how long remains.

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