Watchdog timer doesn't restart

Combining the power of the ATmega2560 MCU with onboard Ethernet, a microSD card slot, an efficient switchmode power supply, and a small prototyping area. [Product page]
Post Reply
User avatar
valorous
Posts: 3
Joined: Tue Aug 20, 2013 6:53 am
Location: Auckland, New Zealand

Watchdog timer doesn't restart

Post by valorous » Tue Aug 20, 2013 7:38 am

When the watchdog timer times out on my EtherMega it doesn't reset the board but appears to lock it up until the power is cycled.

The relevent code in my sketch is as follows:

Code: Select all

#include <avr/wdt.h> 

void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));

void wdt_init(void)
{
  MCUSR = 0;
  wdt_disable();
}

void setup()
{
  wdt_init(); // disable the watchdog timer

// other setup code to initialise Ethernet etc.
...

  wdt_enable(WDTO_2S); // enable the watchdog timer with a 2 second timeout
}


void loop()
{
  wdt_reset(); // reset the watchdog timer to start another 2 second timeout

// other loop code to montor sensors and send results via Ethernet.
...

// simulate a lockup by entering an endless loop
  while (true); // EtherMega should be reset by the watchdog timer within two seconds
}


By printing a count to Serial every 100ms within the 'while (true)' loop I can see that the board stops executing instructions after approximately 2.3 seconds but does not reset.

Does anyone know how to get it to reset?

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Watchdog timer doesn't restart

Post by andrew » Tue Aug 20, 2013 8:20 am

The standard Arduino Mega2560 bootloader (also used on the EtherMega) doesn't support watchdog timers, you need to use a different bootloader.
You may find this of interest:
http://www.desert-home.com/2012/05/ardu ... oader.html

User avatar
valorous
Posts: 3
Joined: Tue Aug 20, 2013 6:53 am
Location: Auckland, New Zealand

Re: Watchdog timer doesn't restart

Post by valorous » Wed Aug 21, 2013 1:54 am

Thanks for your help, John. I'll try the different bootloader.

B.T.W. I assume both the EtherTen and LeoStick would have the same problem with the watchdog timer. Is there any solution you know of for them?

User avatar
valorous
Posts: 3
Joined: Tue Aug 20, 2013 6:53 am
Location: Auckland, New Zealand

Re: Watchdog timer doesn't restart

Post by valorous » Wed Aug 21, 2013 3:04 am

Just noticed that the bootloader "stk500boot_v2_mega2560.hex" referred to by http://www.desert-home.com/2012/05/ardu ... oader.html (and available from https://github.com/arduino/Arduino-stk5 ... odHexFiles) appears to now be included in the Arduino download for Windows (as of version 1.0.4). It can be found in "%ProgramFiles%\Arduino\hardware\arduino\bootloaders\stk500v2" after installing version 1.0.4 or later.

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Watchdog timer doesn't restart

Post by andrew » Wed Aug 21, 2013 6:03 am

valorous wrote:Thanks for your help, John. I'll try the different bootloader.

B.T.W. I assume both the EtherTen and LeoStick would have the same problem with the watchdog timer. Is there any solution you know of for them?
AFAIK the Uno/Leonardo bootloaders are fine. However as it isn't in the standard Arduino language or libraries it's technically unsupported.

Post Reply