Go Down

Topic: interrupts with arduino? (Read 1 time) previous topic - next topic

haesslich

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: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1158573939 )

mellis

It is possible to use the ATmega8 interrupts in Arduino.  You should be able to use the standard syntax documented at: http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html

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.

haesslich

#2
Sep 19, 2006, 12:15 pm Last Edit: Sep 19, 2006, 12:17 pm by haesslich Reason: 1
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)

mellis

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 build.target in your preferences file to be the new directory name (see http://www.arduino.cc/en/Main/Preferences).

haesslich

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
Code: [Select]
SIGNAL(SIG_OVERFLOW0)
{
     timer0_overflow_count++;
}


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)?

Go Up