Go Down

Topic: Tutorial: Basic Watchdog Timer Setup (Read 132045 times) previous topic - next topic

guy_c

on Mega 2650 whatshdog is a special hardware timer dedicated to it (which can operate even if interrupts are disabled) or it depends on timer0?
Thank you
The watchdog has it's own -not very precise- timer

gunaygurer

Hi, I'll also use this code as I've experienced that my code is freezing at some point unexpectedly.

In my code I'm using Time library and TimeAlarms library. What it does is there are several alarms set, when alarm time is up, it activate an output to run a water pump and starts another timer to deactivate the output and stop the pump.

My question is do I have to add the last part of the code(The one I add below) if I dont want anything other then just resetting Arduino? Should I still add below code with empty content for some reason?

Code: [Select]
ISR(WDT_vect) // Watchdog timer interrupt.
{
// Include your code here - be careful not to use functions they may cause the interrupt to hang and
// prevent a reset.
}


Another one is, what if I want to tell Arduino to deactivate output to make sure that before it is restarted, pump is off? Like the code below?

Code: [Select]
ISR(WDT_vect) // Watchdog timer interrupt.
{
  digitalWrite(alarmOut, LOW)
}



guy_c

@gunaygurer
If the wd control reg is not configured to call the wd isr then it won't be called and you dont need to put the empty body

If you set low the port before wd resets the machine, the port will still go hi z at reset so maybe you should at setup set the port as output and write a low. Under these condition, as soon as wd cicks, output will go ui z but after some boot delay, setup code will execute and set the port low.

Yet, if your code freezes, you should do your best to find the reason. I use a trace per called function and ask the the wd isr to write the trace into eeprom. If you want I'll detail

Guy

lastchancename

@OP,   could I suggest you trim/tidy your original intent with this topic, and create a standalone post in "Introductory Tutorials"

Fix your early hiccups, and credit those others that helped put it straight - but it's very useful to beginners... 
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

Go Up