Embedded_Geek
Full Member level 6
Code:
// 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
}
According to the calculation there must be an interrupt at each 10us, but unfortunately the interrupt is getting fired at each 21us.
*** My fuse setting are perfect since I am able to print debug message via uart at a desired baudrate.
Can anyone help me fix this issue?
Thanks in advance,