Hello!
I am working on a project using Lilypad USB (Atmega32u4), a Pulse Sensor and a Servo. The ServoLibrary is taking care of the Servo.
The Pulse Sensor sample on GitHub requires interrupts in the Timer1 to calculate the BPM, but the ServoLibrary already uses Timer 1 to control the Servo.
I found out, that the Atmega32u4 has a Timer3 and as far as I have read, both timers 1 & 3 are 16bits:
https://provideyourown.com/2012/arduino-leonardo-versus-uno-whats-new/
I took from the Pulse Sensor Amped sample, the part where they setup Timer1 as the one assigned to the Pulse Sensor:
void interruptSetup(){
TCCR1A = 0x00;
TCCR1B = 0x0C; // prescaler = 256
OCR1A = 0x7C; // count to 124
TIMSK1 = 0x02;
sei();
}
// The only other thing you will need is the correct ISR vector in the next step.
ISR(TIMER1_COMPA_vect)
Then, would it be right, just changing the 1 by the 3, in order to use Timer3?:
void interruptSetup(){
TCCR3A = 0x00;
TCCR3B = 0x0C; // prescaler = 256
OCR3A = 0x7C; // count to 124
TIMSK3 = 0x02;
sei();
}
// The only other thing you will need is the correct ISR vector in the next step.
ISR(TIMER3_COMPA_vect)
For me it seems logical that the code will work, but I am absolute newbie with timers....
Any help would be really appreciated! ^^