WDT Reset


i'm trying figure out how enable wdt reset on (atm) pro-mini 328.  conceptually seems simple enough, still managed fail after trying several code variations.  using code below, triggers reset after specified time, instead of program running again, pin 13 led flashes furiously , can pulled out of reloading different sketch (which has timed right load).

obviously i'm missing something....
code: [select]

#include <avr/wdt.h>


const int onboardled = 13;

void setup() {

    int k;
    cli();
    wdt_disable();

    delay(2l * 1000l);
   
    wdt_enable(wdto_4s);

    pinmode(onboardled, output);

    // @ bootup, flash led 3 times quick know reboot has occurred.
    (k = 1; k <= 3; k++) {
        digitalwrite(onboardled, high);
        delay(250l);
        digitalwrite(onboardled, low);
        delay(250l);
        }

    // delay bit more clear done setup
    delay(750l);

    sei();
    }

void loop() {

    int                                    k;

    // loop turns led on , waits k*250ms. k increases, amount of time
    // increases. until watch dog timer doesn't reset enough.
    (k = 1; k<= 10000; k++) {
        wdt_reset();
        digitalwrite(onboardled, high);
        delay(k*250l);
        digitalwrite(onboardled, low);
        delay(250l);
        }
    }


same results code well:
code: [select]

#include <avr/wdt.h>
 
void setup()
{
  wdt_disable();
  serial.begin(9600);
  wdt_enable(wdto_4s);
}
 
void loop()
{
  // program alive...for now.
  wdt_reset();
 
  serial.println("hello");
 
  while (1)
    ; // nothing. program lockup here.
 
  serial.println("can't here");
}


with second bit of code, "hello" serial, onboard led flashes rapidly, , never goes main loop.

addendum: same results on nano well.


Arduino Forum > Using Arduino > Microcontrollers > WDT Reset


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts