This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

In this example code, why does the TACCR register is added a value? It's is the coutinuous mode.

This is part of an example code: msp430fr69xx_ta0_01.c given at TI Explorer. I did not understand how this sum will affect the counter and interrupts since the interrupt service will be called after TAxR completes FFFFh number os countings.

  • the part of code:

    // Timer0_A0 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = TIMER0_A0_VECTOR
    __interrupt void Timer0_A0_ISR (void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer0_A0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
    P1OUT ^= BIT0;
    TA0CCR0 += 50000; // Add Offset to TA0CCR0
    }
  • The sixteen bit CCR register can hold values from 0 to 65535. If the register is currently loaded with let's say 50000 and you add another 50000 to it, you would have 100000, but the register cannot hold this number, so it rolls over. There are 15535 left to 65535, then 1 to roll over to 0 again and then your final value in the register is 34464. In this way you can always add a fixed amount of ticks. The timer running in continuous mode will count from 0 to 65535, roll over to zero and again count up to 65535 and so on. The interrupt fires when the timer hits CCR. So by adding a fixed amount to CCR you add a fixed time that will elapse until the timer again hits the value.

    Dennis

  • 1) The interrupt shouldn't fire when TAR is 65535?
    2) If it's not, and if the interrupt fires when timer hits CCR, it's like the up mode.
    3) By adding always 50000 the CCR will vary to 34464 and a second time to 18911, etc, so this interval would be changed during the program execution?
  • 1) The TAIFG (TIMER0_A1) interrupt fires when TAR rolls over. The CCR0:CCIFG (TIMER0_A0) interrupt fires when TAR==CCR0.
    2) Two separate functions: The CCR0 interrupt always fires when TAR==CCR0. If running in Up mode, it also resets TAR.
    3) but the difference between these values is always 50000 clocks, which gives a fixed span between (CCR0) interrupts.

    Doing this allows using the timer for multiple things. If you need Continuous mode for other reasons, this technique provides a semblance of the Up mode behavior.

**Attention** This is a public forum