Arduino UNO WDT Not Working

Hello. I'm dealing with WDT. I wrote a simple test program but WDT is not working. What would be the reason? Note: I am using hex without bootloader.

<#include <avr/wdt.h>

const byte led = 2;

void setup() {
    pinMode(led, OUTPUT);
    digitalWrite(led, HIGH);
    delay(1000);
    digitalWrite(led, LOW);   
    wdt_disable();
    wdt_enable(WDTO_8S);
    wdt_reset();
}

void loop() {
    delay(9000); //test delay
    wdt_reset();
}

This test I wrote a while back worked fine for me. When the blink interval got up to 500 milliseconds, the system reset.

//  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

void toggle_led()
{
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}

void setup()
{
  wdt_disable();
  ToggleDelay = 10;   // Start with a very short delay
  pinMode(LED_BUILTIN, OUTPUT);
  wdt_enable(WDTO_500MS);  // Set watchdog to 1/2 second
}

void loop()
{
  wdt_reset();
  
  toggle_led();   // Blinking goes slower and slower until the WDT causes reset, then starts over.
  delay(ToggleDelay);
  ToggleDelay += 10;   // Increase the delay by 10 milliseconds.
}
1 Like

So you're uploading using a progammer? Is there a reason why you don't use the USB interface for sketch upload? Does your sketch work if you upload that way?

Yes I am installing with a programmer. Since the rx-tx pins are reserved for another function in my circuit, it is troublesome to load them with uart.

The wdt_reset() after wdt_enable() isn't necessary as wdt_enable() includes a reset of the timer.

You should reset MCUSR before everything else. (MCUSR = 0;)

Try to use a value of WDTO_4S for wed_enable() without chaning anything else in the code. Does that work?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.