Hi,I am a newbie, I try to upload program using usbasp and it works fineunfortunately I find that my arduino become no bootloader.The problem is without bootloader, watchdog does not work.I use barbone arduino board with atmega328.

Please let me know, how to program using usbasp and still keep bootloader.

As johnwasser says, you don't need the bootloader to use the watchdog timer. HOWEVER, there is a problem you may have run into that the bootloader "solves". The problem is that when the watchdog timer expires and causes a reset, the watchdog is still enabled. The processor needs to complete the data initialization that occurs before setup() is called, before the timer expires again. Otherwise the watchdog will cause another reset, and this will repeat so that your sketch never gets the chance to reset the timer. The bootloader "solves" this by disabling the watchdog.

So it comes down to what you have in your sketch whose static initialization takes longer than the watchdog interval. The usual culprit is the LiquidCrystal library, which has a totally unnecessary "begin" call in its constructor, taking 60ms to execute (longer than the longest available watchdog interval). If you are using the LiquidCrystal library in your sketch, you need to remove this call from the LiquidCrystal library source code, otherwise you can't use the watchdog timer.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

(well, if you're using something outside of Arduino, you can merge the .hex files for the bootloader and your application. Or you can set things up so that you burn the bootloader and then burn the app, or vis-versa, but overwriting an existing application always involves an "Erase all" step that will wipe out the bootloader.)

(well, if you're using something outside of Arduino, you can merge the .hex files for the bootloader and your application. Or you can set things up so that you burn the bootloader and then burn the app, or vis-versa, but overwriting an existing application always involves an "Erase all" step that will wipe out the bootloader.)

also just to follow up on this comment, if you do decide to merge the two hex files together, the programming process will take very long and get annoying.

Thanks, I finally find that without bootloader watchdog still work.Anyway please see what worng with my code that causes watchdog stop working.I know that it will work if I just comment out blink led in setup,but I do not know why.

void setup(){ wdt_disable(); pinMode(13, OUTPUT); digitalWrite(13, HIGH); // without this line, work fine delay(100); // without this line, work fine digitalWrite(13, LOW); // without this line, work fine delay(100); // without this line, work fine wdt_enable(WDTO_4S); wdt_reset();}

void loop(){ digitalWrite(13, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(13, LOW); // set the LED off delay(1000); // wait for a second wdt_reset(); digitalWrite(13, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(13, LOW); // set the LED off delay(1000); // wait for a second wdt_reset(); digitalWrite(13, HIGH); // set the LED on delay(5000); // wait for 5 second to test watchdog wdt_reset();}

As johnwasser says, you don't need the bootloader to use the watchdog timer. HOWEVER, there is a problem you may have run into that the bootloader "solves". The problem is that when the watchdog timer expires and causes a reset, the watchdog is still enabled. The processor needs to complete the data initialization that occurs before setup() is called, before the timer expires again. Otherwise the watchdog will cause another reset, and this will repeat so that your sketch never gets the chance to reset the timer. The bootloader "solves" this by disabling the watchdog.

So it comes down to what you have in your sketch whose static initialization takes longer than the watchdog interval. The usual culprit is the LiquidCrystal library, which has a totally unnecessary "begin" call in its constructor, taking 60ms to execute (longer than the longest available watchdog interval). If you are using the LiquidCrystal library in your sketch, you need to remove this call from the LiquidCrystal library source code, otherwise you can't use the watchdog timer.

Your answer make me clear, Thanks you so much.Anyway I think there will be no watchdog interval left if it start working (it start because it reach the interval, am I right?),In this case, what is the longest time left for me to use?The problem is I need time not only for liquidcrystal but eeprom initializing as well.

Atmel recommends that you always reset the watchdog before disabling it. Possibly the wdt_disable function does this already, but try inserting a call to wdt_reset before the call to wdt_disable, in case it doesn't.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Atmel recommends that you always reset the watchdog before disabling it. Possibly the wdt_disable function does this already, but try inserting a call to wdt_reset before the call to wdt_disable, in case it doesn't.

I have tested 4 atmega328 chips with various delay values and I found thatwatchdog stopped working when used delay value between 17 - 18.(2 chips fail when use delay(17) and the others fail when use delay(18))here is my code.

void loop(){ digitalWrite(13, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(13, LOW); // set the LED off delay(1000); // wait for a second wdt_reset(); digitalWrite(13, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(13, LOW); // set the LED off delay(1000); // wait for a second wdt_reset(); digitalWrite(13, HIGH); // set the LED on delay(5000); // wait for 5 second to test watchdog wdt_reset();}

BTW there was no problem even included liquidcrystal library and initialized it.For safety, operating time in setup function shall not longer than 15 ms for watchdog to work properly.Hope this will help someone who have same problem as mine.