EmbDev.net

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


von mtimotic (Guest)


Rate this post
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:
1
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:
1
http://ww1.microchip.com/downloads/en/DeviceDoc/40002015A.pdf

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

Regards,

Manuel
1
#include <avr/sleep.h>
2
3
int count = 0;
4
void setup() 
5
{
6
  //Waiting time
7
  Serial.begin(9600);
8
}
9
10
void loop() 
11
{
12
  for(int i = 0; i < 5; i++){
13
    delay(1000);
14
    Serial.println(count++);
15
  }
16
  watchdogOn();
17
  Serial.println("Continue here with operation to set the Arduino again in sleep mode");
18
  //watchdogOn();
19
  //watchdogOn();
20
}
21
22
//Set Watchdog active to 8s and go to sleep
23
void watchdogOn() {
24
  WDT.STATUS = WDT.STATUS & 01111111;
25
  while (!(WDT.STATUS == 0)){
26
      Serial.println("...");
27
  }
28
  CPU_CCP = 0xD8; //unlock...
29
  WDT.CTRLA = 0xB; //set WDT to 8 seconds
30
  Serial.println("Watchdog active...and going to sleep");
31
  delay(100);
32
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
33
  sleep_enable();
34
  sleep_mode();
35
  sleep_disable();
36
  delay(100);
37
}
38
39
void watchdogOff() {
40
  WDT.STATUS = WDT.STATUS & 01111111;
41
  while (!(WDT.STATUS == 0)){
42
      Serial.println("...");
43
  }
44
  CPU_CCP = 0xD8;
45
  WDT.CTRLA = 0x0;
46
  Serial.println("Watchdog disabled...");
47
}

von void (Guest)


Rate this post
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?
1
void pwrDown(int sekunden) {
2
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // den tiefsten Schlaf auswählen PWR_DOWN
3
  for(int i=0; i < sekunden; i++) {
4
    sleep_enable(); // sleep mode einschalten
5
    sleep_mode(); // in den sleep mode gehen
6
    sleep_disable(); // sleep mode ausschalten nach dem Erwachen
7
  }
8
}

von mtimotic (Guest)


Rate this post
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

von void (Guest)


Rate this post
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.

von mtimotic (Guest)


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

regards,

Manuel

von void (Guest)


Rate this post
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"

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.