problems with interrupt routine

hi,

I’m trying to learn more about the interrupt routines with arduino. I’ve made a little sketch. In the void loop routine i’m reading analog input and sending it to the serial monitor and in my interrupt routine i’m blinking a led every second.
I’m using Timer1 (16bit) bc my compare match register for 1Hz is higher then 256.

My promblem is that the interrupt routine and the loop routine work individually but when i put them together it doesn’t work.

Does somebody know why?

gtrz

#include <avr/io.h>
#include <avr/interrupt.h>

int led =13;

void setup()
{
  Serial.begin(9600);
  cli();//stop interrupts
  
  //set timer1 interrupt at 1Hz
  TCCR1A = 0;// set entire TCCR1A register to 0
  TCCR1B = 0;// same for TCCR1B
  TCNT1  = 0;//initialize counter value to 0
  // set compare match register for 1hz increments
  OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536)
  // turn on CTC mode
  TCCR1B |= (1 << WGM12);
  // Set CS12 and CS10 bits for 1024 prescaler
  TCCR1B |= (1 << CS12) | (1 << CS10);  
  // enable timer compare interrupt
  TIMSK1 |= (1 << OCIE1A);
  
  sei();//allow interrupts
  
  pinMode(led,OUTPUT);
  
}

  ISR(TIMER1_COMPA_vect)//interruptroutine
  {
    digitalWrite(led,!digitalRead(led));
  }

void loop()
{
  // read the input on analog pin 0:
  int sensorValue = analogRead(A5);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);
}

My promblem is that the interrupt routine and the loop routine work individually but when i put them together it doesn't work.

Define what "doesn't work" mean.

the led on pin 13 does not blink.
When I look to the serial monitor the potentiometer shows 20 values but then it freezes

It works for me on a UNO.

In your code

  // read the input on analog pin 0:
  int sensorValue = analogRead(A5);

Which is right, the comment or the code ?

the comment must be pin A5, my mistake

after uploading it again on the UNO it worked. Strange…