Zero crossing detection

I'm not using any libraries.
Following code compiles ok.
Binary sketch size: 3188 bytes (of a 126976 byte maximum)

volatile int counterValue;
int requestValue;

void setup() {
  attachInterrupt(0, resetCounter, CHANGE); 
  cli();                      //Disable global interrupts
  TCCR3A = 0;                 //Set register to 0
  TCCR3B = 0;                 //Set register to 0
  OCR3A = 640;                //Compare match register to get desired timer count (50Hz mains)
  TCCR3B |= (1 << WGM12);     //Turn on CTC mode
  TIMSK3 |= (1 << OCIE3A);    //Enable timer compare interrupt
  TCCR3B |= (1 << CS10);      //Start timer
  sei();                      //Enable global interrupts
  pinMode(7, OUTPUT);
}

ISR(TIMER3_COMPA_vect) {
  counterValue++;
  counterValue &= 0xff;
  if (counterValue==requestValue) {
    digitalWrite(7, HIGH);
  } else {
    digitalWrite(7, LOW);
  }
}

void resetCounter()
{
  counterValue=0;
}

void loop(){
  requestValue=map(analogRead(0), 0, 1023, 0, 255);
}