0

thanks for reading in advance. Please have a look at the code below and note that TCCR0's interrupt is being triggered every now and then, which means what's inside ISR(TIMER0_OVF_vect) is run. However, I have set up TCCR2 the same way, but ISR(TIMER2_OVF_vect) will not be called. Also, what's inside ISRs are just temporary codes for testing purposes.

void init_timer0(void)
{
    TCCR0 = 0x07;// 32 prescaler 
    // 0000 0111b
    // clkI/O/1024 (From prescaler)
    TCNT0 = 10;

    TCCR2 = 0x07;
    //TCCR2 = 0x0E;
    TCNT2 = 20;
    
    TIMSK |= 0x01;
    TIMSK |= 0x40;
}



volatile int i = 0;

ISR(TIMER2_OVF_vect)
{
    TCNT2 = 20;
    
    i = 1;
    i = 2;
    
}


ISR(TIMER0_OVF_vect)
{
    TCNT0 = 10;
}

1 Answer 1

3

Table 68 of the data sheet says for TCCR2 (excerpt):

CS22 CS21 CS20 Description
1 0 1 clkI/O/1024 (From prescaler)
1 1 1 External clock source on T2 pin. Clock on rising edge.

You tell the AVR to use an external clock (TCCR2 = 0x07;) but you want to use the system clock.

Use TCCR2 = 0x05; instead.

Sign up to request clarification or add additional context in comments.

1 Comment

works like magic. thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.