I am using an attiny which only needs to wake-up once a day.
However, watchdog timer allows only to sleep for 8s. I read somewhere that using a for-loop to run watchdog part multiple time can extend the time.
My question is, will it able to extend it for 24 Hr (by running for-loop 10800 times in the main loop of the code)?
Does extending the time using for loop still wakes it up at 8 seconds and check some counter itself?
When you say low-powered mode/pause, I fully acknowledge it.
But when someone says wake up, I am inclined to align it with sleep. It is my understanding (I may be wrong) that the MCU does not execute any instruction in the sleep mode like the HLT condition of 80x86 where it waits for interrupt. I also understand that the Watchdog Timer is an independent agent with its own clock and intellect, and it has the ability to interrupt the MCU to wake it up from sleep when the 'set time' expires.
This is possible, but consider 5 to 10% deviation from real time. Is this OK for you?
Yes, it is fine. I just require it to roughly check once a Day.
I am planning to use the following code
// Example of sleeping and saving power
//
// Author: Nick Gammon
// Date: 25 May 2011
#include <avr/sleep.h>
#include <avr/wdt.h>
#define LED 13
// watchdog interrupt
ISR(WDT_vect)
{
wdt_disable(); // disable watchdog
}
void myWatchdogEnable(const byte interval)
{
MCUSR = 0; // reset various flags
WDTCSR |= 0b00011000; // see docs, set WDCE, WDE
WDTCSR = 0b01000000 | interval; // set WDIE, and appropriate delay
wdt_reset();
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
sleep_mode(); // now goes to Sleep and waits for the interrupt
}
void setup()
{
pinMode (LED, OUTPUT);
} // end of setup
void loop()
{
digitalWrite (LED, HIGH); // awake
delay (2000); // ie. do stuff here
digitalWrite (LED, LOW); // asleep
for (int i=0;i<10800;i++)
myWatchdogEnable (0b100001); // 8 seconds
} // end ofloop
// sleep bit patterns:
// 1 second: 0b000110
// 2 seconds: 0b000111
// 4 seconds: 0b100000
// 8 seconds: 0b100001
Yes, that’s the trick. But power consumption for updating a counter is almost negligible
For my application, every uA counts. Do you think the power will be further reduced if I decrease the internal clock frequency for the small period of time it executes the function myWatchdogEnable()?
For my application, every uA counts. Do you think the power will be further reduced if I decrease the internal clock frequency for the small period of time it executes the function myWatchdogEnable()?
This will not help. What needs to be done needs to be done. If you need to increment a counter it will take double the time if you are running at half the speed. Power consumption increases almost linear with clock frequency
Running at lover voltage definitely saves a lot. But running from WD oscillator saves little to nothing. In my Datasheet in typical current consumption @5V is about 120uA for 128kHz WD oscillator and about 5.5mA for 8MHz oscillator. That means both need about 1uA per 1kHz. When running from WD oscillator you save current because the main oscillator is stopped but you need more current for static dissipation of the CPU etc.