

If the function hangs, inside the interrupt function (ISR) which will be declared as Nacked (without pushing registers) you will properly unstack the registers (pop ) pushed during the prologue of your "weird" function, then you exit from the ISR and resume your main program after the call to the "weird" function via a goto (a jump) to a C label. Timer/Counters with separate prescaler and compare mode. 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. 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. I looked on the implementation of arduino millis function and I am bit confused, why they use Timer Overflow Interrupt which is executed every 1.024 ms (freg 16MHz, 64 prescaling), when they could use Output Compare Match Interrupt which can be set up to trigger exactly every 1ms (OCR0A. 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. I am implementing a time counter on my atmega 328p.
#Arduino timer interrupt stack overflow serial#
I have both sketches working individually using the Arduino examples, but when I combine them it only writes to the serial port once and I am not sure why. To solve your problem, the best thing to do is to write a new function as stated by PaulS. I've been working on collecting flow rates using the Arduino interrupt and I want to time stamp the data using a real-time clock.
