Lilypad: Are Timer1 and Timer3 equivalent

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! ^^

Your very best and most reliable source of information is the ATMega32u4 data sheet.

A casual glance at the timer sections shows that Timer1 and Timer3 are treated equivalently and appear to be identical except for register names, which change as you guessed.

For me it seems logical that the code will work

It may seem so, but always check the data sheet.

Ok!
Thank you!

Just if someone had the same problem:

I just found out that my comparison between the ATmega32u4 in the Lilypad USB and the Atmega32u4 in Arduino Leonardo is wrong.

Atmega32u4 in Lilypad = 8mHz
Atmega32u4 in Leonardo = 16mHz

So the right code for the Pulse Sensor interrupt in Timer3 for Lilypad USB would be taken from the part regarding to Arduino Flora (also Atmega32u4 8mHz) and modifying Timer1 for Timer3:

  void interruptSetup(){
          TCCR3A = 0x00;
          TCCR3B = 0x0C; // prescaler = 256
          OCR3A = 0x3E;  // count to 62
          TIMSK3 = 0x02;
          sei();
      }
ISR(TIMER3_COMPA_vect)