Atmega 4809 wdt

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>

int main(void)
{
volatile long cnt = 0;

RSTCTRL.RSTFR |= RSTCTRL_WDRF_bm ;

 // Turn on watchdog timer
    wdt_enable(WDT_PERIOD_1KCLK_gc);


while(1)
{
   cnt++; //TODO:: Please write your application code 
}

}

Please explain this? F5 on what?

I think you need to describe your setup in more detail.

How do you know that your code stops execution as it doesn't appear to generate any observable indication that it is/isn't running.

Do you have a debugger hooked up to your 4809? Maybe it is causing the 4809 to stop at address 0x0000 on a reset.

To "continue execution", most people would use the watchdog to wake from a sleep mode, rather than reset the processor.

Sorry should have said I am debugging via microchip studio so the F5 key on the attached pc is the run command

@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.

Looks like you are correct. On the ATmega4809 the options appear to be limited to querying the reset flag register upon startup to determine the cause of reset, and if WDT, take appropriate action.

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 ?

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