EmbDev.net

Forum: µC & Digital Electronics Arduino Uno Wifi Rev 2/ATMEGA4809 : Watchdog always restarts whole system


Author: mtimotic (Guest)
Posted on:

Rate this post
0 useful
not useful
Today at 12:11 pm
Hello,

after i managed to set the Arduino to sleeping mode, the Watchdog 
restarts the whole system after 8 seconds. So far so good. But instead 
of restarting the complete system I would like to continue after the 
"sleeping line" to repeat the sleeping phase 5 more times. I already 
checked out the ATMEGA4809 Datasheet, but didn't find anything to deal 
with this issue. On the other hand I found some sample codes from other 
ATMEGA microcontroler models where it seems to be possible. For example 
here:
http://shelvin.de/arduino-in-den-sleep_mode_pwr_down-schlaf-modus-setzen/

Here is the source of the datasheet I used as a reference:
http://ww1.microchip.com/downloads/en/DeviceDoc/40002015A.pdf

Here is my code. Thanks in advance for your help!

Regards,

Manuel


#include <avr/sleep.h>

int count = 0;
void setup() 
{
  //Waiting time
  Serial.begin(9600);
}

void loop() 
{
  for(int i = 0; i < 5; i++){
    delay(1000);
    Serial.println(count++);
  }
  watchdogOn();
  Serial.println("Continue here with operation to set the Arduino again in sleep mode");
  //watchdogOn();
  //watchdogOn();
}

//Set Watchdog active to 8s and go to sleep
void watchdogOn() {
  WDT.STATUS = WDT.STATUS & 01111111;
  while (!(WDT.STATUS == 0)){
      Serial.println("...");
  }
  CPU_CCP = 0xD8; //unlock...
  WDT.CTRLA = 0xB; //set WDT to 8 seconds
  Serial.println("Watchdog active...and going to sleep");
  delay(100);
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_mode();
  sleep_disable();
  delay(100);
}

void watchdogOff() {
  WDT.STATUS = WDT.STATUS & 01111111;
  while (!(WDT.STATUS == 0)){
      Serial.println("...");
  }
  CPU_CCP = 0xD8;
  WDT.CTRLA = 0x0;
  Serial.println("Watchdog disabled...");
}


Author: void (Guest)
Posted on:

Rate this post
0 useful
not useful
Hello Manuel,

mtimotic wrote:
> but instead of restarting the complete system I would like to continue after the
> "sleeping line" to repeat the sleeping phase 5 more times.

I'm not sure, if you just did not got the point, because it was 
commented in the link you provided in German language. Actually the 
solution was in it and is quite simple.

This repeats a sleep cycle for 'sekunden' times, after being waken up by 
the watchdog. The watchdog is set to trigger a wake-up once each second.
-> Did you noticed the for loop?
void pwrDown(int sekunden) {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // den tiefsten Schlaf auswählen PWR_DOWN
  for(int i=0; i < sekunden; i++) {
    sleep_enable(); // sleep mode einschalten
    sleep_mode(); // in den sleep mode gehen
    sleep_disable(); // sleep mode ausschalten nach dem Erwachen
  }
}

Author: mtimotic (Guest)
Posted on:

Rate this post
0 useful
not useful
Hello void,

thanks for the answer!

Yes, I also tried the for loop, but the problem is the watchdog doesn't 
bring me back to the loop but resets the whole system instead, like it 
is described in the datasheet. My guess is that there must be a bit to 
set, to enable interrupts instead of system restarts, but I didn't find 
where :-(

In the datasheet it's described like this:

In Normal mode operation, a single time-out period is set for the WDT. 
If the WDT is not reset from software using the WDR any time before the 
time-out occurs, the WDT will issue a system Reset.

I am grateful for every hint...

regards,

Manuel

Author: void (Guest)
Posted on:

Rate this post
0 useful
not useful
mtimotic wrote:
> the problem is the watchdog doesn't
> bring me back to the loop but resets the whole system instead

Your guess may be right.

In the example you pointed to they handle the WDE bit in the WDTCSR 
register accordingly to get the WDT interrupt, but no WDT reset.

It seems that with the ATMEGA4809 (0-series AVR) they have changed the 
WDT module
and that this one does not allow the 'design flaw' to wake-up the MCU by 
interrupt, but not issue WDT reset.

If you check table 10-1 (page 95) you can see that the WDT is also not 
mentioned as wake-up source (anymore).
I guess you need to setup the Periodic Interrupt Timer to wake-up from 
power-down mode instead of (ab)using the WDT.

Author: mtimotic (Guest)
Posted on:

Rate this post
0 useful
not useful
Thanks for your researching, I will try that!

regards,

Manuel

Author: void (Guest)
Posted on:

Rate this post
0 useful
not useful
The hunt to setup the Periodic Interrupt Timer to wake-up from 
power-down mode goes on here (in German language)
Beitrag "Arduino (ATMEGA4809) wacht nicht mehr auf aus Power Down Sleep Mode"

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.