View previous topic :: View next topic |
Author |
Message |
picnic
Joined: 09 Oct 2008 Posts: 15
|
Sleep interrupted by Portb, can I find out sleep time left? |
Posted: Wed Dec 21, 2011 9:58 am |
|
|
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
|
|
Posted: Wed Dec 21, 2011 11:50 am |
|
|
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
|
|
Posted: Thu Dec 22, 2011 2:54 am |
|
|
That was my conclusion but I had hoped I had missed something. Thanks. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Thu Dec 22, 2011 3:17 am |
|
|
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 |
|
|
|