Electrical – How to disable timer on MSP430

msp430pwmtimer

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
DCOCTL = CALDCO_1MHZ; 
CCTL0 = CCIE; 

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


while(1){

if((P1IN & BIT4)!=BIT4) //button is pressed
  {
 startTimer(); 
 start2Timer();
  }
  
}

}

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


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;
} 
}

Best Answer

You could do this to turn off the timer:

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