interrupts with arduino?

is it possible to use the interrupts of the atmega8 within the arduino environment? i guess it's the only way to get my midi stepsequencer running properly (look here for more details: )

It is possible to use the ATmega8 interrupts in Arduino. You should be able to use the standard syntax documented at:

Note that the timers are already used by Arduino: timer 0 increments the time count returned by millis(), timer 1 and timer 2 are used to generate the PWM outputs on pins 9, 10 and 11.

this is what i thought. i think i will need one timer for my sequencer project (as a stable clock source). is it possible to use one of the timers, when i don't need millis() or pwm output?

OR (even more tricky ;)): can i use the timer interrupts regardless to the fact, that the timers are used for other function too? (in this case i would need to know at which rate the timers are operating, so that i can adjust my needed tempo of the sequencer)

At the moment, this will require editing the Arduino core (not hard!) in ARDUINO/lib/targets/arduino/wiring.c. This is because each interrupt handler can only appear once in a program, and this file already contains handlers for the timer interrupts. You should be able to edit those functions to do what you want, or remove them and implement them within your sketch. If you want to keep the unmodified core around, you can simply copy the whole lib/targets/arduino directory, and edit in your preferences file to be the new directory name (see

okay, it's the first time for me to get along with interrupts and stuff... the only interrupt handler in the wiring.c that i recognize is in line 324


it incremets the overflow counter variable, which tells us how often timer0 had an overflow since the controller get power, right? so i could easily add my midi code here, as long as it's not too long? (and i let it operate only every X-th interrupt, dependent on the tempo i want to have)?

Yep, you should be able to just stick the code in there. It can get tricky though, as the interrupt can, as its name suggests, interrupt any other bit of your code (meaning that if it, say, changes the value of a variable, that change could happen in the middle of some other line of code).

thanks so far! as i see no other interrupt handler is used, so i could just write any interrupt handler for the timer overflow of timer 1 and 2? well, thanks so far, i will give it a try with and then report in here later :)

okay next step :) the thing is that i want to use the uart output but i cannot use the Serial.print command in the interrupt handler of timer0 because the right librarys are not present at compiling or linking time. so i used the "old" serial commands, which are defined in the wiring.c. this worked, but i was not shure, where to put the beginSerial command. seems kind of dirty method to place it in the SIGNAL function. but i cannot place the signal function into my arduino program because the timer0_overflow_count variable will not be present in the wiring.c. so i thought maybe i can use the timer1 oder timer2. but i did not find any interrupt handler for timer1 and timer2, and i wrote one into my program, but this seemed not to be executed anyway. so there seems to be an interrupt handler for these timers or the timers are not running (which i guess is not the case, because mellis said, they are running). any further hints?