I am new to the TI MSP430G2553. I would like to send a PWM signal like in this picture:

(Image source: Adafruit - Understanding Infrared Signals)

However I can't do that, because I don't know how to stop (finish) the PWM signal. Here is my PWM signal code:

void configTimer(void)  // this function sends infinite pwm signal when button is pressed  
TA1CCR0 = 26-1;                          // Period 
  TA1CCR1 = 13;                            // 50% dutycycle
  TA1CCTL1 |= OUTMOD_6;                    //  Reset/Set
  TA1CTL = TASSEL_1 + MC_1 + TACLR; 

I tried:

  1. TA1CTL1=0;
  2. TA1CTL = MC_0;
  3. set default value of TA1CCR1 = 0, when button pressed set TA1CCR1 = 13; and later __delay_cycles(any number);

However they didn't work.

Thanks in advance.

Edit: My last try Edit2: Edit: I think can't use my timer interrupt my counter is always 0.


define TIMER0_A1_VECTOR (8u * 2u) /* 0xFFF0 Timer0)A CC1, TA0 */

define TIMER0_A0_VECTOR (9u * 2u) /* 0xFFF2 Timer0_A CC0 */

This is definiton of timer0 vector. How should i write it in my code?

#include <msp430.h>

void startTimer(void);

unsigned char counter=0;

void start2Timer(void);

int main(void)
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_1MHZ; // Set range

P2DIR |= BIT2;
P2SEL |= BIT2;// Select pwm  pin (transmitter)


if((P1IN & BIT4)!=BIT4) //button is pressed


void startTimer(void) // pwm signal
TA1CCR0 = 26-1;                          // Period Register
  TA1CCR1 = 13;                            // TA1.1 25% dutycycle
  TA1CCTL1 |= OUTMOD_6;                    // TA1CCR1, Reset/Set

void start2Timer(void) // trying to stop after 50 ms
CCR0 = 5000; // CCR0 5 ms 
TACTL = TASSEL_2 + MC_2; // 

#pragma vector=TIMER0_A0_VECTOR // Timer0_A0 
__interrupt void Timer_A (void)
if(++counter==10){ // is counter 10 (5*10=ms)
 TA1CCR1 = 0;   ; // Stop pwm 
counter = 0;
  • \$\begingroup\$ TA1CTL = MC_0 should work. What actually happened when you tried that? \$\endgroup\$
    – The Photon
    Commented Apr 29, 2019 at 23:17
  • \$\begingroup\$ Maybe I don't understand. In the question, you said the problem is you can't stop the timer. Setting TA1CTL=MC_0 should stop the timer. If you have a different issue, you should edit the question to explain what the issue is. \$\endgroup\$
    – The Photon
    Commented Apr 29, 2019 at 23:28
  • \$\begingroup\$ If you're using delay_cycles() to produce delay between output changes, you don't need to use the timer. You can use the timer when you want to change the output without your code writing to P2OUT. Also, if you have the pin configured as a timer pin, writing to P2OUT won't change the state of the pin. If you have the pin configured as a GPIO pin, then the timer can't control it. \$\endgroup\$
    – The Photon
    Commented Apr 29, 2019 at 23:34
  • \$\begingroup\$ Basically, it looks like you're trying to control the output with two different and conflicting mechanisms at the same time. You need to choose whether to let the timer control the pin, or control it using the P2OUT register. You can't do both at the same time. What do you have in the P2MAP registers? \$\endgroup\$
    – The Photon
    Commented Apr 29, 2019 at 23:38
  • \$\begingroup\$ Thanks i tried something new. And edited my question. Can you look at it please? \$\endgroup\$
    – Mustafa
    Commented Apr 30, 2019 at 9:04

1 Answer 1


You could do this to turn off the timer:

TA1CTL &= ~(MC_1) ;//or whatever mode the timer is running at

  • 1
    \$\begingroup\$ TA1CTL &= ~MC is better, because it will stop the timer regardless of what mode it was in. \$\endgroup\$
    – Alex
    Commented May 20, 2021 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.