Search code examples
cinterruptavr

ATTiny1606 Timer TCA0 interrupt not triggering


Rather i can´t see the mistake or there is a bug in the compiler ;-). I´m trying to use TCA0 on an ATTiny1606 to generate a PWM to dim some leds. The problem is that the interrupts are never getting called. The System runs at the interal osciallator @ 20MHz and is configured correctly.

TCA0 configuration

int main(void)
{
    // ...

    TCA0.SINGLE.PER = 0xFFFF;
    TCA0.SINGLE.CMP0 = 0x1FFF;
    TCA0.SINGLE.INTCTRL = TCA_SINGLE_OVF_bm | TCA_SINGLE_CMP0_bm;
    TCA0.SINGLE.CTRLB = TCA_SINGLE_WGMODE_SINGLESLOPE_gc;
    TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV2_gc | TCA_SINGLE_ENABLE_bm;
    
    sei();
    
    // ...
    
    while (1)
    {
        // ...
    }
}

Interrupt routines

ISR(TCA0_OVF_vect)
{
    PORTA.OUTCLR = PIN6_bm;
    TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm;
}

ISR(TCA0_CMP0_vect)
{
    PORTA.OUTSET = PIN6_bm;
    TCA0.SINGLE.INTFLAGS = TCA_SINGLE_CMP0_bm;
}

The interrupts are never called. Even if i put a delay inside (I know this never should be done) for testing purpose the program is still running. So maybe i forget to set some bit in the control registers or what am I missing?


Solution

  • Sorry to bother you, but due to a configuration error the interrupts were not set correctly at compile time. The problem was not the preprocessor, compiler or any other thing. The problem was the user in front of the screen. After lots of time debugging the code and the assembly i found a mistake in my configuration:

    Microchip Studio configuration

    When I created the project, I selected the wrong microcontroller (ATTiny406 instead of ATTiny1606). What a mess! Now everything is working fine and the interrups are called correctly.

    I won't delete the question. Maybe it will help someone with the same error!

    Thanks a lot for helping @hcheung