Hi Im using a ATmega324P & im doing a second count. If i use a overflow or CTC i still get less 31us per second. Over the case of hours it goes out. Im am using an external 32.768khz crystal & a external 7.3728Mhz main Crystal. Any ideas about what could be wrong?
void Timer_Init (void) { //Setup for timer ASSR |= (1<<AS2); //Timer/Counter2 is clocked from a crystal Oscillator connected to the Timer Oscillator1 (TOSC1) pin. TCCR2A |= (1<<WGM21); //CTC mode (1<<CS20)|(1<<CS21)|(1<<CS22); == 1024 TCCR2B |= (1<<CS21)|(1<<CS22); //Prescaler 256 OCR2A = 128; //128 should be equal to 1 second at prescaler of 256 32.768Khz external crystal. while ((ASSR & ((1<<TCN2UB)|(1<<OCR2AUB)|(1<<TCR2AUB))) != 0);. TIMSK2 |= (1<<OCIE2A); //Timer/Counter2 Compare Match A interrupt is enabled. // TIMSK2 |= (1<<TOIE2); //Timer/Counter2 Overflow interrupt is enabled. } ISR ( TIMER2_COMPA_vect ) { Tick = 1; Seconds--; if(Seconds == -1) { Minutes--; Seconds = 59; if(Minutes == -1) { Hours--; Minutes = 59; } } } int main (void) { DDRB = 0b00001000; //Set as output Timer_Init(); sei(); //Enable global interrupts for(;;) { if (Tick == 1) { PORTB ^= (1<<3); Tick = 0; } } }