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.

MSP430G2452: capture mode in timer a

Part Number: MSP430G2452

I am using the msp430g2452 and I use IAR

As I have tried the program to capture input in the port 1.1.  I am trying to use the CCI0A as the capture input to the timer.

But the program does not get into the ISR what so ever.

I can read the CCI and CCIE bit as 1 of the register TACCTL0

The TAR register is continuously running.

TACCR0 is continuously showing some value of 0x188

 

 

#include <msp430g2452.h>
#include <stdio.h>

void initTimer_A(void);

unsigned int buffer[20];
unsigned char i=0;

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; //Stop watchdog timer
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;
P1SEL |= BIT1;
initTimer_A();
_BIS_SR(LPM0_bits + GIE);
while(1);
}

void initTimer_A(void)
{
//Timer Configuration
TACTL = TACLR;
TACTL = TASSEL_2 + ID_0 + MC_2 + TAIE;
TACCTL0 = CM_1 + CCIS_0 + SCS + CAP + CCIE;
}
//Timer ISR
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A0_CCR1_ISR(void)
{
buffer[i++] = TACCR0;
if (i>10)
{
for(int j=0;j<10;j++)
printf("time= %d",buffer[j]);
}
}

  • > TACTL = TASSEL_2 + ID_0 + MC_2 + TAIE;

    Don't set TAIE here. You don't have an ISR for it (A1) and you don't appear to have a use for it. Try:

    > TACTL = TASSEL_2 + ID_0 + MC_2;

    ------------

    If you're using a Launchpad, be sure to remove the RXD/TXD jumpers from the "bridge" header block (J101).

    ------------

    To use printf you may need to increase your stack size.

  • 1. I removed TAIE.

    ---------------------

    2. I use MSP430G2 launchpad. When and where should I remove the TX/RX jumpers.

    --------------------

    3. The stack size is set as default 80. What value can I set to the stack size.

    I give the CCI0A input through a switch connected to the port 1.1.

    When I press down the switch, there is a notification sound prompting data transfer, as the TX is connected to port 1.1.


    I cannot use the ports capture inputs like CCI1A and CCI2A as capture inputs as the format for specifying the particular vector in IAR is not clear.

  • The RXD/TXD jumpers are on J101, that double row of headers between the USB area and the MCU area. You should remove them if you're using P1.1 or P1.2 for something other than the USB-UART ("backchannel").

    Last time I tried printf I needed about 120 bytes of stack.

    [Edit: I just noticed your final sentence. For all TimerA0 interrupts other than CCR0, you should be able to use:

    > #pragma vector = TIMER0_A1_VECTOR

    For those interrupts, you need to explicitly the IFG (CCIFG or TAIFG).]

  • I have used CCI2A as the capture input. It solved my problem.

    "For those interrupts, you need to explicitly the IFG (CCIFG or TAIFG).]" should I clear the flag manually.

  • Yes, that was supposed to say "explicitly clear the IFG" [Ref UG (SLAU144J) Sec 12.2.6] This isn't required for CCR0.

**Attention** This is a public forum