Pages: [1]   Go Down
Author Topic: interrupts with arduino?  (Read 1277 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-wink): 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)
« Last Edit: September 19, 2006, 05:17:32 am by haesslich » Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

okay next step smiley
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?

Logged

Pages: [1]   Go Up
Jump to: