


Also, for the sake of system reliability, it might be better to actually keep the watchdog timer running (not disabling it), and add periodic calls to wdtreset. Maybe you would want to store in EEPROM some data before calling the "weird" function.ī/ I don't see the interest of using a "weird" function which will not give you (sometimes) the expected results….but if you want to stop only the process of a function called inside your program and resume your main program, then :ġ/ start a timer which will trigger an interrupt (ISR) on overflow after an estimated time lapse.ģ/ stop your timer after the exit of your function for the case you exit properly from this function. Rather than directly accessing the controller's registers from your code, use wdtenable () and wdtdisable () from the avr/wdt.h library to start and stop the watchdog timer. After a watchdog trigger, there will be a reset and you will lose what was previously in RAM and start at the beginning of your main program. But, if it's not possible for you, I see 2 possibilities:Ī/ As already mentioned, if you want to stop your main program if a function hangs, use the watchdog timer. And this discussion is about using them for timing purposes. The compare channel A/B interrupts are unused. The overflow interrupt is already being used by the timing functions millis () and micros (), as shown earlier. To solve your problem, the best thing to do is to write a new function as stated by PaulS. Timer0 has three interrupts associated with it: overflow and compare channel A and channel B.
