Greetings everybody!
I apologize if this was asked before; this is the problem (for atmega 1284P):
- I enable the watchdog (8 seconds)
- I put the device (atmega1284P) to sleep in power-down or power-save mode.
- A PCINT wakes it up before the 8 second timeout.
- I need to know how log it slept.
I'd really like to avoid using the Timer2, since it can only count a maximum of 256 * 1024 MCU cycles (it has an 8 bit resolution and a maximum pre-scale factor of 1024).
The code looks something like this:
wdt_enable(WDTO_8S);
sleep_cpu();
...
ISR(WDT_vect)
{
// Here's where I need to know how long the device slept. I need milliseconds, or MCU cycles, or Watchdog oscillator ticks, or whatever else.
}
Thanks a lot!
Bogdan.
No, there is no way to read WDT counter. You can just to reset it. Maybe you could describe your motivation.
Normally you should do the WDR (reset) immediately. Why to wait?
OR
Remember the seconds or time just before the WDR call.
Maybe you could describe your motivation.
I have to measure the duration of some external events (PCINT), and I also need to put the device to sleep as often as possible while doing this.
How precise do you need it to be? You could set the WDT to e.g. 250ms and count the wake events until your external interrupt fires. This would give you a resolution of 0.25 seconds without introducing much time awake.
Also take into account that the WD timer is not very precise compared to the normal processor clock
[EDIT] set the WDT to interrupt mode, of course
WDT is not very precise. Use asynchronous timer with watch crystal.