I'm testing the watchdog code that is posted at the page.
I' using the same code & libraries into a Wiring 1.0 Mega128 STKV2 boot-loader and works great.
Now using this int a Arduuno pro (3V3-8Mhz) if i not reset the wdt it reset the CPU but when it restart the CPU goes into a infinite loop.
If I change the voltaje form 3V3 to 5V the CPU starts one time, the watchdog trigger and go again into this infinite loop.
I test to reseting the wdt at the first thing at the setup() function.
Looks like the fuses are wrong seted, some ideas to fix this detail?
The watchdog timer works fine on my Arduino UNO R2 with the latest bootloader from Arduino 1.0. Have you tried burning a fresh bootloader?
// Watchdog Timer Example
#include <avr/wdt.h>
unsigned long ToggleDelay; // When this delay grows to longer than the WDT interval the WDT resets the Arduino
const int LEDpin = 13;
void toggle_led()
{
digitalWrite(LEDpin, !digitalRead(LEDpin));
}
void setup()
{
wdt_disable();
ToggleDelay = 1; // Start with a very short delay
pinMode(LEDpin, OUTPUT);
wdt_enable(WDTO_250MS); // Set watchdog to 1/4 second
}
void loop()
{
wdt_reset();
toggle_led(); // Blinking goes slower and slower until the WDT causes reset, then starts over.
delay(ToggleDelay);
ToggleDelay += 5; // Increase the delay by 5 milliseconds.
}
Interesting. I just discovered this thread while trying to figure out why the watchdog doesn't appear to work on either of my boards (Mega2560 and Nano). I essentially wrote the exact same sketch as a test, and both my sketch and the one posted here have the exact same behavior: the watchdog times out as expected, but then the yellow led starts blinking very rapidly (10 Hz or so) and that's it...stuck.
I'm guessing that the bootrom doesn't like the watchdog reset. If I remove and re-apply power then the whole thing starts over again (works the first time, but gets stuck after watchdog reset).
gbaker:
Interesting. I just discovered this thread while trying to figure out why the watchdog doesn't appear to work on either of my boards (Mega2560 and Nano). I essentially wrote the exact same sketch as a test, and both my sketch and the one posted here have the exact same behavior: the watchdog times out as expected, but then the yellow led starts blinking very rapidly (10 Hz or so) and that's it...stuck.
I'm guessing that the bootrom doesn't like the watchdog reset. If I remove and re-apply power then the whole thing starts over again (works the first time, but gets stuck after watchdog reset).
You are correct, some bootloaders handle WDT interrupts correctly and others do not because they don't diable the WDT interrupts and their wait time for checking on new upload request can exceed the WDT time out value. There are people who have 'corrected' this for meg boards and such, but so far I don't think they have become the official distribution with the IDE nor are new mega boards shipping with upgraded bootloaders. There is stuff in the forum on this subject if you check around.
Allmost in my Arduino PRO the problem was that for some reason the function that reset the watchdog was commented out. I correct and compile the bootloader and now is working.