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.

MSP430G2553: G2553 Capture Example

Part Number: MSP430G2553

Hi all,

Can someone show me a simple example of using TimerA0_3 in CAP mode? As described in x2xx Family User Guide 12.2.4, I want to do speed computation. I'm not quite sure how to handle the interrupt. 

This is the code I have so far. I want to trigger an interrupt upon CCIS.

//   Use P1.6 output into Capture CCIS TimerA0_3
//            MSP430G2xx3
//         -----------------
//        |                 |-
//        |                 |
//      ->|P1.1/CCI0A       |-
//     |  |                 |
//     |  |             P1.6|--
//     |                       |
//     |_______________________|
//

//******************************************************************************

#include <msp430.h>
volatile int count;
int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  TA0CTL = TASSEL_2 + MC_2 + TACLR;			// SMCLK, Up mode
  TACCTL0 = CAP + CM_1 + CCIE;				// CAP, Int. Enabled
  P1SEL |= BIT1;              				// TA0.CCI0A
  P1DIR |= BIT6;							// pulse gen. into CCIS
  __bis_SR_register(GIE);

  while(1){
		  P1OUT ^= BIT6;					// see how many cycles TAR incremented
  }
}


// Timer_A3 Interrupt Vector (TA0IV) handler
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A1_VECTOR))) Timer_A (void)
#else
#error Compiler not supported!
#endif
{
 switch( TA0IV )
 {
   case  2:
	   count++;
	   break;                          // 
   case  4: break;                         // CCR2 not used
   case 10:                                // not used
            break;
 }
}

thank you,

Scott

  • CCR0 has its own ISR with vector=TIMER0_A0_VECTOR. TA0CCTL0:CCIE is reset on entry to the ISR, so don't read TA0IV.

    I recommend also setting TA0CCTL0:SCS, though I've forgotten why (old habit).

    The TI capture example is msp430g2xx3_ta_21.c (in SLAC485D, via the Software and Tools tab on the product page).

**Attention** This is a public forum