// F_CLK = 4MHz
// CALCULATIONS
Timer Frequency = F_CLK = 4MHz
Time Period = 1/4Mhz = 0.25 us
Interrupt period = 0.25us * 40 = 10us
So, according to this every 10us an interrupt will be fired
#include <avr/io.h>
#include <avr/interrupt.h>
int main(void)
{
// Mode 4, CTC on OCR1A
TCCR1B |= (1 << WGM12);
// Set interrupt on compare match
TIMSK |= (1 << OCIE1A);
// Compare value
OCR1A = 40;
// Set prescaler to No Prescalar (i.e., F_CLK/1)
TCCR1B |= (1 << CS10);
sei();
// enable interrupts
while (1);
{
}
}
ISR (TIMER1_COMPA_vect)
{
// Action to be done every 10us
}