sleep for 24 Hr using watchdog timer in Attiny20 or attiny25?

Hi,

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?

The eight seconds is fairly imprecise in my experience, so if you want exactly 24 hours, you may want to look at an RTC with an alarm output.

No, I do not want it to be exact 24hr and I can not also use external rtc as it will consume a lot of power.

You're going have to consider other solutions.

At the moment, there is an option for about 9 hours delay on ATtiny85 architecture (not tested).

1. External Y1= 32.768 Khz clock crystal (readily available)
2. Get: clkSYS = Y1/256 via CLKPR Register
3. Configure TC1 to generate TOV1 interrupt at 9 hrs delay. clkTC1 = clkSYS/16384 (via prescaler).
4. Put Attiny85 into sleep.

** clkTc1 = 32768/(256*16384) = 0.0078125 Hz**
*Max Time Delay using 8-bit TC1 = 1/(0.0078125)256 = 32768 sec =~ 9 hrs

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)?

This is possible, but consider 5 to 10% deviation from real time. Is this OK for you?

Does extending the time using for loop still wakes it up at 8 seconds and check some counter itself?

Yes, that's the trick. But power consumption for updating a counter is almost negligible

When the question is to wake up the MCU -- it means the MCU is sleeping!

When the MCU is sleeping -- how can it do works?

When the MCU is unable to do works in sleep mode -- it means it cannot execute the for() loop!

GolamMostafa:
When the question is to wake up the MCU -- it means the MCU is sleeping!

When the MCU is sleeping -- how can it do works?

When the MCU is unable to do works in sleep mode -- it means it cannot execute the for() loop!

The for loop,.sleep and watchdog is a fairly standard way of generating long, relatively low-powered pauses.

@AWOL

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()?

varangupta:
I can not also use external rtc as it will consume a lot of power.

This is NOT true! Good RTC consumes under 1 uA. Watchdog Oscillator consumes about 4 uA. In fact you save power by using RTC.

EDIT: For example look at PCF8563.

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

olf2012:
This will not help.

You perspective is too myopic. There are two ways a lower clock frequency can dramatically reduce power consumption...

  1. Lowering the clock frequency makes it possible to also lower the voltage.

  2. AVR processors can run from the watchdog oscillator. If the processor runs from the watchdog oscillator the 8 MHz oscillator can be turned off.

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.

Smajdalf:
This is NOT true! Good RTC consumes under 1 uA. Watchdog Oscillator consumes about 4 uA. In fact you save power by using RTC.

EDIT: For example look at PCF8563.

Thank you. I'll look into it.

varangupta:
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





Hello

i this code what i have to change if it should wake up every 2 hours and wait for 1 min and goes back to sleep