Libreria freq counter per arduino leonardo

Ciao a tutti! ho provato a modificare questa libreria http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/ per adattarla ad arduino leonardo,.

#if defined (__AVR_ATmega32U4__)//(__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__)


    TIMSK0 &=~(1<<TOIE0);       // disable Timer0  //disable  millis and delay
    delayMicroseconds(50);      // wait if any ints are pending
    
    f_period=ms;
  
  
    if (f_comp ==0) f_comp=1;  // 0 is not allowed in del us
	
    // hardware counter setup ( refer atmega32u4)
    TCCR1A=0;                  // reset timer/counter1 control register A
    TCCR1B=0;              	   // reset timer/counter1 control register A
    TCNT1=0;           		   // counter value = 0
	TCNT3=0;
    // set timer/counter1 hardware as counter , counts events on pin T1 ( arduino pin 12)
    // normal mode, wgm10 .. wgm13 = 0
    
    TCCR1B |=  (1<<CS10) ;//CLOCK ESTERNO su fronte di salita
    TCCR1B |=  (1<<CS11) ;
    TCCR1B |=  (1<<CS12) ;
    
    // timer3 setup / usato per la generazione del tempo di lettura
    TCCR3A=0;
    TCCR3B=0;
    
    // timer3 presaler set to 128 / timer3 clock = 16Mhz / 256 = 62500 Hz
    TCCR3B |=  (1<<CS30) ;
    TCCR3B &= ~(1<<CS31) ;
    TCCR3B |=  (1<<CS32) ;

    //setta il timer3 to CTC(Clear Timer on Compare)  Mode with OCR3A is top counter value (arrivato a OCR3A si resetta)
    TCCR3A &= ~(1<<WGM30) ;
    TCCR3A &= ~(1<<WGM31) ;
    TCCR3A |=  (1<<WGM32) ;
	TCCR3A &= ~(1<<WGM32) ;
    OCR3A = 124;                // CTC divider by 125
   
    f_ready=0;                  // reset period measure flag
    f_tics=0;                   // reset interrupt counter
    GTCCR = (1<<PSRASY);        // reset presacler counting (perchè resettarlo?)
    TCNT3=0;                    // timer3=0
    TCNT1=0;                    // Counter1 = 0
    
    TIMSK3 |=(1<<OCIE3A);       // enable Timer3 Interrupt (interrupt di Timer/Counter3 Compare Match A)
    
                                // External clock source on T1 pin. Clock on rising edge.
    TCCR1B |= (1<<CS12) | (1<<CS11) | (1<<CS10);        //   start counting now     
    #endif
}
//******************************************************************
//  Timer3 Interrupt Service is invoked by hardware Timer3 every 1ms = 1000 Hz
//  16Mhz/128/125 = 1000 Hz
//  here the gatetime generation for freq. measurement takes place: 
//

ISR(TIMER3_COMPA_vect) {
										// multiple 2ms = gate time = 100 ms
if (FreqCounter::f_tics >= FreqCounter::f_period) {         	
                            			// end of gate time, measurement ready

   										// GateCalibration Value, set to zero error with reference frequency counter
    //  delayMicroseconds(FreqCounter::f_comp); // 0.01=1/ 0.1=12 / 1=120 sec 
    delayMicroseconds(FreqCounter::f_comp);
    TCCR1B = TCCR1B & ~7;   			// Gate Off  / Counter T1 stopped 
    TIMSK2 &= ~(1<<OCIE3A);    			// disable Timer3 Interrupt(timer del gate)
    TIMSK0 |=(1<<TOIE0);     			// enable Timer0 again // millis and delay
    FreqCounter::f_ready=1;             // set global flag for end count period
    
                                        // calculate now frequeny value
    FreqCounter::f_freq=0x10000 * FreqCounter::f_mlt;  // mult #overflows by 65636
    FreqCounter::f_freq += TCNT1;      	// add counter1 value
    FreqCounter::f_mlt=0;
    
    }
    FreqCounter::f_tics++;            	// count number of interrupt events
    if (TIFR1 & 1) {          			// if Timer/Counter 1 overflow flag
    FreqCounter::f_mlt++;               // count number of Counter1 overflows
    TIFR1 =(1<<TOV1);        			// clear Timer/Counter 1 overflow flag
    }
    // PORTB = PORTB ^ 32;  				// int activity test
}

L’ho scritta con atmel studio poi ho cambiato il file della originale con questo ma sembra non andare, qualcuno me la può provare o darmi qualche dritta?

Si vede solo una piccola porzione della lib. Il resto?

PS:
cos'è che fa, esattamente? Calcola sbagliato, è tutto piantato? "non sembra andare" è un pò generico :wink:

Ho provato a caricare un programma su arduino che accensesse un led se la frequenza fosse superiore a 1Khz ma non si accende.
In realtà non ho idea se giri o meno, per veder queste cose dovrei avere un debugger credo...