Deep Sleep mode + WDT

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello I need

invent MegaMCU in deep power consumption mode
device will wake up from ext.INT (button)
but I need there Watchdog how to glue both
in one project

device may sleep weeks but wdt maximum interval is 3-5minutes.

I need prevent mcu for freezing
device will be in -20`C to 40-50`C temperatures which ATmega IC will you recommend?

Thank you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

device may sleep weeks but wdt maximum interval is 3-5minutes.


So wake up every 3-5 minutes and if nothing's happening go back to sleep.

But why even use WDT? Why not just rely on the ext-int to wake after several weeks? Are you using the WDT to measure elapsed time or something?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dxr wrote:
invent MegaMCU in deep power consumption mode
device will wake up from ext.INT (button)
but I need there Watchdog how to glue both
in one project

You should not "glue" all together at the same time.
Simple develop your application in this order:
1. implement the full function
2. add sleep mode
3. add watchdog.

dxr wrote:
I need prevent mcu for freezing
device will be in -20`C to 40-50`C temperatures which ATmega IC will you recommend?

Since you give no informations, any AVR (ATtiny13 .. ATmega2560) may do the job.

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I need wake-up often then is external int event present.
Measuring time for ignoring Ext INT button
(in my design is no RTC module)

I need protect one expensive device before stupid human operators.

Inteligent Reset button - button can be pressed many times but reset signal send only 1x time and then is any other pressed button ignored for 10minutes.

Power is injected over ethernet cable and DC source are batteries in house I need spare energy.

Thank you for answers to all.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Yes, I need wake-up often then is external int event present.

Why do you need to wakeup to check the ext-int? Surely you use the ext-int (probably low level) itself *AS* the wakeup source?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dxr wrote:
Inteligent Reset button - button can be pressed many times but reset signal send only 1x time and then is any other pressed button ignored for 10minutes.

Then use the pin change interrupt to awake the AVR.
And the watchdog timer interrupt to debounce the key and count the 10min dead time.
Then stop the watchdog timer and enable pin change interrupt again.

E.g. the ATtiny13 was fully sufficient to do this task.

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello all!

 

I am also interested to use the WDT along with sleeping. For example, I am putting uC to sleep and waking via interrupt (other device), however, I want to runt the WDR on uC either in awake or sleep mode. How to do this? At the moment the WDT hangs in sleep mode... 

 

Best.

Bravo!!!

Last Edited: Sun. Jan 20, 2019 - 05:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

mu234 wrote:
At the moment the WDT hangs in sleep mode...

Huh?  Hangs?

Please post a small complete code that demo's the problem!

 

Jim

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Jim, maybe hangs is not the right word, anyway, does not want to boot up in right order, it hangs somewhere... below is the code... best

 

//ISR
ISR (PCINT0_vect)
{
  sleep_disable();
  power_all_enable();    // power everything back on

  // also "wake up" enable the wdt

  //wdt_enable(WDTO_2S);
  wdt_reset();

  //  //////////////////////////////// END OF START FROM INTERRUPT VARIABLES SETUP

  if (Sensor.getProximity() > HT) {
    currentState = WAITING_BELOW;
  }
  else {
    currentState = WAITING_ABOVE;
  }

  // turn LED on
  ledState = true;

} //end of ISR

 

void setup() {

  pinMode(ledPin, OUTPUT);
  pinMode(ledSigPin, OUTPUT);

  // pin change interrupt (example for D3)
  PCMSK  |= bit (PCINT3);  // want pin D3 / pin 2
  GIFR   |= bit (PCIF);    // clear any outstanding interrupts
  GIMSK  |= bit (PCIE);    // enable pin change interrupts

  delay(200);
  setI(HT); // enable and set interrupt 

  delay(200);

  // *** new state machine project ***
  if (Sensor.getProximity() > HT) {
    currentState = WAITING_BELOW;
  }
  else {
    currentState = WAITING_ABOVE;
  }

  //currentState = WAITING_ABOVE;
  // *** end of new state machine project ***

  myWDTsetup();

  startTime = millis();

  ledState = false;

  myCount = 0; //counter for going to sleep

}//end of setup

 

void loop() { //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  //reset the WDT
  //wdt_reset();

 
}
// **********************    WDT setup and function ***********************

// wdt setup
void myWDTsetup(){

  //cli();

  bitClear(MCUSR, WDRF);
  
  wdt_reset(); //need to reset the WDT timer before you start usinging it, because you want to have a clean slate!

//   // Reset the watchdog reset flag
//  bitClear(MCUSR, WDRF);

  // WDTCSR configuration, be aware AT Tiny has a different name for this register, check the datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet.pdf#page42
  // WDIF, WDIE, interupt stuff
  // WDCE, WDE,  There isnʼt really any logic behind this, you just have to set WDCE and WDE to ʻ1ʼ to enter a sort of ʻsetup modeʼ in the watchdog timer.
  // WDP3, WDP2, WDP1, WDP0... how long the timer will count for before resetting (between 16 and 8000ms)

  // Enter Watchdog Configuration mode: 
  WDTCR |= (1<<WDCE) | (1<<WDE);
  
  // WDIE = 0 : Interrupt disable
  // WDE = 1  : Reset enable 
  

  // Set Watchdog settings

    //WDP3 - WDP2 - WPD1 - WDP0 - time
  // 0      0      0      0      16 ms
  // 0      0      0      1      32 ms
  // 0      0      1      0      64 ms
  // 0      0      1      1      0.125 s
  // 0      1      0      0      0.25 s
  // 0      1      0      1      0.5 s
  // 0      1      1      0      1.0 s
  // 0      1      1      1      2.0 s
  // 1      0      0      0      4.0 s
  // 1      0      0      1      8.0 s

  WDTCR = (0<<WDIE) | (1<<WDE) |  // using reset!
   (0<<WDP3) | (1<<WDP2) | (1<<WDP1) | (1<<WDP0); //my time 

  // the same would be the binary approach:
  //
  // Enter Watchdog Configuration mode:   WDTCSR |= B00011000;
  // Set Watchdog settings:               WDTCSR = B01001110;
  
  //enalbe interrupt
  //sei();
}



 

 

 

Bravo!!!

Last Edited: Tue. Jan 22, 2019 - 08:28 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One thing to note when using the WDT for resets:

If WDT is enabled, and trips a reset, note in data sheet, the default timeout for the WDT is reset to 16ms!!!

This means you have only 16ms to either disable the WDT, reset the timeout, or set the timeout to a longer period, else.....

the chip resets again, and again, and again, every 16ms....  (looks like it is hung!)

 

Jim

 

 

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cheers Jim, never thought about that, anyway, below is the code ( cheers to drAzzy) that I was missing in the beginning of the setup and works now, yes, the WDT is on 2sec... 

 

 

  wdt_reset(); 
  MCUSR &= ~(1<<WDRF);
  wdt_enable(WDTO_2S);

 

Best.

Bravo!!!