Arduino gets reset continuously when using watchdog timer

Hi,

while scrolling through a few posts I learnt that watchdog timers can be used to reset arduino from software.
i tried using the following code.
but once the code reaches wdt_enable() function, the arduino gets reset and then repeatedly lt gets reset on its own until power is removed and put again.
the code says

#include <avr/wdt.h>
#include <LiquidCrystal.h>

void setup()
{

    lcd.begin(16, 2);
    lcd.print("Hello");
    delay(1000);


}

void loop()
{
  elasped=millis()/1000;
  lcd.clear();
  lcd.print(millis()/1000);
  if(elasped>60)
   { wdt_enable(WDTO_15MS); 
     for(;;){}
   }
  delay(1000);
}

Try disabling the watchdog as the very first thing you do in setup()...

tried that...

added wdt_disable() in setup.. did i do it right ?

You enable the WD then sit in a busy loop, what did you expect to happen?

wdt_enable(WDTO_15MS);

You've got 15mS to "pat the dog" or it's goodnight nurse, doesn't matter what you have in setup() because you enable the WD in loop().


Rob

Hi, thanks for the reply. i wish to implement software reset... i want to reset the arduino after every minute, and so i am not giving "pat" on dog.. ideally, it should reset the controller, it does resets the controller, but goes into infinite loop of reset.

This works fine on my UNO R2:

#include <avr/wdt.h>

void setup()
{
  Serial.begin(9600);
  Serial.println("Boot");
}

void loop()
{
  if(millis()/1000 > 10) { 
    wdt_enable(WDTO_15MS); 
    for(;;);
   }
  delay(1000);
}

Resets every 10 seconds, and prints “Boot” on the serial console.

npn7805: Hi, thanks for the reply. i wish to implement software reset... i want to reset the arduino after every minute, and so i am not giving "pat" on dog.. ideally, it should reset the controller, it does resets the controller, but goes into infinite loop of reset.

That could be because of the what board you are using as some of the bootloaders do not handle WDT resets correctly and can cause the continuous 'tight loop' condition you might be experiencing. A 15millisec WDT interrupt is too fast for the bootloader to finish and pass control to your setup function to reset the WDT.

The present Uno board handles WDT resets correctly, the existing mega2560 board does not unless updated with a newer booloader. So what hardware are you working with? Lefty

In addition to those valid points - why do you wish to reset the Arduino after every minute?