watchdog timer wake-up

I tried Nick Gammon's excellent tutorial on power saving, using sleep and waking up using the watchdog timer
what's not clear to me is this:
do I have to keep restarting the clock or does it tick continuously?

the ideal would be a watchdog timer that wakes me up every four seconds (fairly easy)
but keeps ticking while I'm doing stuff,
so the next wakeup tick is 4 seconds after the previous
not four seconds + how ever long it took me to do what I need to do
hope that makes sense?

cheers

As long as the WDT is not reset or disabled, it should generate an interrupt or reset on a regular basis regardless of other processing. Be aware however, that the WDT is not a precise timing source. My measurements indicate that the WDT tends to run 12-16% slow. I believe this is by design. So if it's configured for four seconds, I'd expect it to be more like 4.5s.

Jack
thanks
maybe that's what I'm seeing!

Sure thing, let us know if you don't get it sorted. The other thing, the "4 second" setting is actually 512K cycles of the WDT oscillator, which runs at 128kHz. So that's 4.096s assuming 128kHz, but the oscillator runs slow on top of that.

...and the tick-rate varies by temperature and voltage (from my testing the datasheet time-vs-whatever charts are fairly accurate). And there is a small amount of jitter.

As long as the WDT is not reset or disabled, it should generate an interrupt or reset on a regular basis regardless of other processing.

It does.

I was playing the other day, using the WDT oscillator as the clock source, and setting the CKOUT fuse bit so I could measure it. No scientific analysis, but just watching the frequency counter, it looked like the watchdog oscillator had significantly less jitter than the RC oscillator.

ATmega328P?

Yes and also a tiny84 and/or tiny85. I suppose I should write these things down.

But then you have to remember where you wrote it down. :wink:

Indeed! :smiley:

Ok a supplementary question!
Does the timer behind millis() keep going during a sleep, or does it sleep too?
Cheers

Idle Mode the timers run. All other sleep modes the timers stop. In the table, clkIO is the key.

I still had the code and parts mostly laying around, so I did a few measurements. Looks to me like the WDT oscillator is roughly an order of magnitude more stable than the RC oscillator.

Aha thanks for that!