I am using an ATMEGA4809 but have a problem with the watchdog. I enable the watchdog with a 1 second timeout and then put the code into a permanent loop to force the wdt to fire. The wdt fires and the device resets to address 0x0000 but the stops execution I can restart execution if I am attached by pressing F5 but normally I wouldn't want to be attached obviously so the system is hanging.
The basic code is
#include <avr/wdt.h> #include <xc.h>
volatile long cnt = 0;
RSTCTRL.RSTFR |= RSTCTRL_WDRF_bm ;
// Turn on watchdog timer
cnt++; //TODO:: Please write your application code
@jremington I had a quick look at the 4809 datasheet and I might have looked in the wrong place, but it seemed that you don't get the option of raising an interrupt (like you do on the 328P). It looks like the only outcome of a WDT timeout is a system reset.
yes the wdt on the 4809 has reset only the only good part is that it has a windowed function as well as standard watchdog. I seem to have got to the bottom of the problem I was having in thatbit appears that if I detach the debugger in microchip studio the wdt works fine and I can see it is resetting via some debug LEDs
You could make your own hardware wdt by having a digital output feeding a diode pump with a square wave generated in your program loop . If the processor stops , the square wave stops and the pump voltage falls to zero- use that to reset the processor .
Worth a look at data sheets , does debugger affect the watch dog ?