Go Down

Topic: Interupts and other functions (Read 1 time) previous topic - next topic


I'm new to this but having great fun with a megaboard. I don't seem to be able to find a list of 'what functions work with what interupts' on the forum and I am concerned this might lead to unpredictable behavious of my project,

I've writen an ISR on Timer2 that works just fine, but I noticed I'm getting odd results from the micros() funtion. My theory - it is also using timer2. Can anyone confirm or deny this? Not a problem for me since I was only using micros() to check ISR performance, so I've gone back to using a stopwatch instead.

Anyway I am also using analogueread and Serial.print outside my ISR. I understand these are slow functions, so I am hoping that my ISR will just interupt these functions if called. Can anyone comment if there is a risk that
a) analogueread or Serial.Print will disable or slow my ISR?
b) my changes to Timer2 will cause analogueread or Serial.Print  to misfunction?

Thanks in advance,



I've writen an ISR on Timer2 that works just fine, but I noticed I'm getting odd results from the micros() funtion

The Arduino core functions use timer0 for micros and millis, so using timer2 (if that is the AtMega hardware timer2 you refer to) should have no impact on micros().

As for your questions (a and b), the answer is No on both accounts - there is no conflict either way.


Jun 01, 2010, 02:17 pm Last Edit: Jun 01, 2010, 02:18 pm by Spinlock Reason: 1
Make sure that in your ISR, you aren't using Serial.print or anything causing a significant delay.  ISR's should execute as fast as possible because interrupts are disabled.

Probably what is happening is that in your ISR you end up calling Serial.print.  Because interrupts are disabled, the timer ISR doesn't get a chance to update.


Thanks Spinlock,

Using Serial.print inside a fast ISR would indeed be a grave error. I write to a circular buffer then use Serial.print outside of my ISR.

Thank's to BenF's reassurance, it doesn't look like this will be a problem for my project. But I should go back to those micros() diagnostics and figure out what's wrong (probably a just sumb math error)

I'll post the code if I ever reproduce the problem


Go Up