Code:
#define FOSC 16000000
// timer 1 input capture ISR (1000 hertz)
SIGNAL(SIG_INPUT_CAPTURE1)
{
counter_1k++; // 1 KHz counter
}
// Now, somewhere down in main()...
// set up input capture 1 interrupt at 1000Hz
TCNT1 = 0; // load 16 bit counter 1
ICR1 = (long)F_OSC / 1000; // timer at 1000 Hz
TCCR1A = 0; // no output action on match
// let counter 1 run at fosc, reset to 0 at ICR1
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);
TIMSK1 = (1 << ICIE1); // enable input capture 1 interrupt
Just change FOSC to whatever frequency you are running at.