Go Down

Topic: Is there a way to read the WDT timer/counter value? (Read 134 times) previous topic - next topic

BogdanF77

Greetings everybody!

I apologize if this was asked before; this is the problem (for atmega 1284P):

1. I enable the watchdog (8 seconds)
2. I put the device (atmega1284P) to sleep in power-down or power-save mode.
3. A PCINT wakes it up before the 8 second timeout.
4. 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:

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

Budvar10

#1
Oct 12, 2017, 01:48 pm Last Edit: Oct 12, 2017, 01:50 pm by Budvar10
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.
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

BogdanF77

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

olf2012

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

Smajdalf

WDT is not very precise. Use asynchronous timer with watch crystal.
On 8-bit (i.e. Uno) use "byte" instead of "int" if possible - it is faster and saves resources!

Go Up