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.

Confusion regarding interrupts enable for TimerA module - TAIE vs CCIE

Part Number: MSP430G2553

CCIE Bit 4 Capture/compare interrupt enable. This bit enables the interrupt request of the corresponding CCIFG flag.
0 Interrupt disabled
1 Interrupt enabled

TAIE Bit 1 Timer_A interrupt enable. This bit enables the TAIFG interrupt request.
0 Interrupt disabled
1 Interrupt enabled

From SLAU144J.

I'm having a hard time telling those two apart. How do I know which one to use? I don't have any code to post, since I haven't gotten that far with my project just yet, but here I am thinking just general.

For example, let's just say I wan't the timer to count up to 500 and trigger an interrupt, which one do I use and why?

Could I get an example with both registers?

  • In Compare mode (which sounds like what you're interested in) TAIFG tells you about the state of the counter, and CCIFG tells you about the state of the counter with respect to that CCR.

    For the particular case you asked about -- counting repeatedly to 500 -- you want Up mode. In this mode, TAIFG and CCTL0:CCIFG are (almost) equivalent, since each triggers at around the "start over" time. [The difference -- one tick -- can be seen in SLAU144J Figure 12-3,] In the Examples suite (SLAC485D), msp430g2xx3_ta02/03 show pretty much the same program, one using CCTL0:CCIFG and the other TAIFG. (ta03 uses Continuous mode, so the cycle is 65536, not 50000.)

    For the particular case of Up mode, one usually uses CCTL0:CCIFG, since it has a specific vector dedicated to it (TIMERn_A0_VECTOR). For this vector, CCTL0:CCIFG is automatically cleared. [Ref SLAU144J Sec 12.2.2.6] That means (a) you don't have to check what condition got you there and (b) you don't have to explicitly clear the condition, which makes it rather convenient.

  • Thanks for helping, Bruce, as always ;-)

    Ok, I can see the TIMERn_A0_VECTOR in the table, so I guess that makes sense to use it, then. So when I program interrupts, I always have to check if a certain bit has a vector attached to it? This vector business is still very confusing to me.

    Is it then correct to say, that I would use TAIFG for other purposes than interrupt routines? Say just "regular" programming, where I check/poll if the flag is set? IF(TAIFG == 1) then do this and this?

  • Thanks for the link! This is great!

  • Every IE/IFG bit has a vector associated with it, even if it's not always obvious which one (it usually is).

    An IFG bit indicates that an event happened. The IE bit allows the IFG to cause an actual interrupt (ISR call). It's routine to see IFG bits set for events you're not interested in. If you aren't interested in TAIFG, ignore it (and don't set TAIE).

    You can also poll an IFG bit (without setting the IE), e.g. in a spin loop. You might do this if you expect the event to happen "very soon" and don't want to slow things down with a trip through an ISR.

    >  IF(TAIFG == 1)

    Be careful with this notation: TAIFG is a C symbol whose value is defined to be 0x0001, so this condition (as written) is always true. To test TA0CTL:TAIFG, use something like:

    >  if (TA0CTL & TAIFG)

  • This helped clear things with regards to the IE/IFG connection.

    But I still have trouble finding the associated vector. I usually look up in the G2553 chip datasheet, under the vector table, but that does not name the correct vector name, which CCS recognizes. I can see in the header file for the mentioned chip "msp430.h", that the vectors are defined there. Is this the most simple way to find the correct vector?

  • The User Guide and Data Sheet generally don't tell you the CCS names (_VECTOR) to use. There is information in the data sheet [Table 5] from which you can compute (somewhat arcane) the number you need, then find it by number in the _VECTOR list in the .h file.

    But yeah, by the time you've done all that you might as well just browse the _VECTOR names in the .h and pick the one that looks right (that's what I do). Or copy it from some suitable Example code.

  • Ok, I will stick to the .h searching method from now on. All the other sheets and tables just confuse me. Thanks for the tip.

  • Hi Stong,

    We haven’t heard from you for more than a week, so I’m assuming you were able to resolve your issue. If this isn’t the case, please click the "This did NOT resolve my issue" button and reply to this thread with more information. If this thread locks, please click the "Ask a related question" button and in the new thread describe the current status of your issue and any additional details you may have to assist us in helping to solve your issues.

**Attention** This is a public forum