I wanted a way to do a hardware reset on a periodic schedule. So far, this is the best I came up with:
int resetpin=11;
void setup(){
pinMode(resetpin,INPUT);
digitalWrite(resetpin,HIGH);
}
void loop(){
if (millis() >= 3600000) {
pinMode(resetpin,OUTPUT);
digitalWrite(resetpin,LOW);
delayMicroseconds(100);
}
}
Jumper digital pin 11 to the RESET pin, which is near the analog input ports (at least, it is on the Diecimila.
I played games with the direction of the pin, otherwise it was was constantly resetting. The final delay is probably overkill, the datasheet says that RESET needs to be pulled low for 2.5uS.
But for some reason, things went from bad to worse. I'm not entirely sure what happened, but basically it wedged the bootloader, to the point where I actually had to re-burn the bootloader on my STK500. I couldn't load new sketches, which is why I reloaded the bootloader. I haven't tried to look too deep: either the default prescaler was too low, and the code was never executing my WDR before the timeout, or the bootloader itself uses the WDT.
I just tried a test with the appnote that mem posted.
I put an LED on pin 11, because the Diecimila's LED on pin 13 starts acting funny. Pin 11 pulses the expected number of times, and then the board resets. When the WDT resets the device, the built-in LED on pin 13 blinks in very rapid sequence, and just keeps blinking. But it never appears to start re-executing the sketch.
Pressing the hardware reset button has no affect, I need to disconnect the USB cable and reconnect it, then the device will execute the sketch as above.
Good thing I gave it a 10 second delay, because during this event, I can't upload a new sketch. I've disconnected anything I've attached, other than the LED.
I hope someone else will read this and test it, and let me know the results. Maybe I can't use millis in this manner?
WDTON is a fuse, I can't set it this way. I programmed WDTON=1 with my STK500, but that doesn't allow me to upload sketches anymore. I even erased the device, reflashed the bootloader, and programmed WDTON=1. Then when I connected the USB and tried to upload a sketch, it times out. When I unprogram the WDTON fuse, the bootloader is fine.
Well, I give up, since if it works for you, there's obviously something I'm missing or doing wrong.