Hi, I think I may have a problem with getting an interrupt running in the background of a programme I am working with. I have assumed that the AVR includes (shown below) were Arduino core functions, but I am beginning to wonder if need to upload an AVR interrupt library, and if I do, where might I get it?
#include <avr/io.h> #include <avr/interrupt.h>
I should say that I am working well beyond my level of competence!
I'm using Arduino 1.0.5 on Windows, I've worked with avr interrupts and those includes are not neccesary, they already are on Arduino core.
Here's a lil' example of a led blinking each second with timer 1 interrupt.
// Created by David Alvarez Medina aka 0xDA_bit for tallerarduino.wordpress.com
// Under cc licence
// Funcionalidad del programa:
// - Uso de interrupciones internas
// - Timer interno cada 1 segundo
//#include <avr/io.h>
//#include <avr/interrupt.h> //not neccesary on 1.0.5
int LedPin=13;
void setup(){
pinMode(LedPin, OUTPUT);
cli();
TCCR1A=0;
TCCR1B=0;
OCR1A=15624; //contador CTC, tiene un tamaño de 2^16-1=65535, pero en este
//caso se usa en 15624 para que calce con un segundo
TCCR1B |= (1<<WGM12);
TCCR1B |= (1<<CS10);//
TCCR1B |= (1<<CS12);// CS10=1, CS11=0, CS12=1 ==> prescaler=1024
// then T=1/(f/prescaler)==> 1024/16MHz = 64us
//64us*CTC=64us*15624= 1 second!
TIMSK1=(1<<OCIE1A); //Output Compare A Match (vector interrupcion)
sei();
}
void loop(){
}
ISR(TIMER1_COMPA_vect){
digitalWrite(LedPin, !digitalRead(LedPin));
}