Chapter 7: Microcontroller Interrupts and Timers
r
timer2 counter
ag
F2A)) );
sei(); // __enable_interrupt(); // enable global interrupt
if ( (TIFR1 && (1<<TOV1)) )
verflows, set the temp to 0xFFFF
the timer1 counter value
tempL = TCNT1L;
temp = TCNT1H;
increase OSCCAL
}
else
calibrate = TRUE; // the interRC is correct
TCCR1B = (1<<CS10); // start timer1
}
}
OSCCAL_calibration() function – detailed explanation
he ‘System Clock and Clock Options’ section of the ATmega169 data book tells
TCNT1H = 0; // clear timer1 counte
TCNT1L = 0;
TCNT2 = 0; // clear
// wait for timer2 comparefl
while ( !(TIFR2 && (1<<OC
TCCR1B = 0; // stop timer1
{
temp = 0xFFFF; // if timer1 o
}
else
{ // read out
temp = (temp << 8);
temp += tempL;
}
if (temp > 6250)
{
OSCCAL--; //RC oscillator runs to fast, decrease OSCCAL
}
else if (temp < 6120)
{
OSCCAL++;//RC oscillator runs to slow,
T
more than you’ll ever want to know about the ATmega169's clock. Let’s focus on
only what we need for our system.