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.

MSP430F5529: Timer "Up" Counting Questions

Part Number: MSP430F5529

Assuming the following timer settings....

TA1CCTL0 = CCIE; // CCR0 interrupt enabled
TA1CCR0 = 10000; // Set the count value
TA1CTL = TASSEL_1 + MC_1 + TACLR; // ACLK, upmode, clear TAR

*TAIE is not enabled, so TAIFG never triggers an ISR
*We are using CCIFG to trigger the ISR

I know the CCR0 ISR Vector for Timer1 will run after 10,000 counts given the above setting.
Looking at Figure 17-3 from the Technical Manual, it seems CCIFG Flag would happen just as TAxR is updated to CCR0 = 10,000.

But my question is this.
If the ISR is triggered, and code is run while TAxR = CCR0, then what would happen if we updated CCR0 value in the ISR?

1) Would changing CCR0 from 10,000 to 50,000 in the ISR mean the next CCIFG would trigger after only 40,000 clock edges?
*Would this depend on the Timer Clock Source and MCLK speed differences?

2) If you want to update the Timer Count in the ISR to a different period, would it be better to :
- Halt the Timer
- Set TACLR to clear TAxR count value back to "0"
- Set a new CCR0 value
- Restart the Timer

??

Regards,
Darren

  • Hi Darren,

    To address question 1), yes, changing CCR0 from 10000 to 50000 in the ISR would result in the next CCIFG triggering in only 40000 clock edges. This should not depend on which clock source you choose, as the CCIFG logic is simply to trigger when the counter value equals the CCR value.

    To address question 2), it depends on what exactly you are trying to do, and how time sensitive the application is. If your goal was to change the period in the ISR, you don't necessarily have to stop the timer to do so. If the timer is still running while you change the CCR value, you will have to take considerations, like the one addressed above, about how the continuously changing timer value will impact the first period after the CCR value is updated, as well as subsequent ones. If you wanted to be sure that you were starting from zero and counting up to the new CCR value, then the steps you mentioned could be a good way to do so.

    You may find it helpful to look at section "17.2.3.1.1 Changing Period Register TAxCCR0" in the MSP430x5xx and MSP430x6xx user guide, which I will link below. I will also paste that short comment here:

    When changing TAxCCR0 while the timer is running, if the new period is greater than or equal to the old period or greater than the current count value, the timer counts up to the new period. If the new period is less than the current count value, the timer rolls to zero. However, one additional count may occur before the counter rolls to zero.

    MSP430x5xx and MSP430x6xx Family User's Guide (Rev. Q) (ti.com)

**Attention** This is a public forum