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.

MSP430F2132: 如何控制对外发送的PWM脉冲的数量?

Part Number: MSP430F2132


想通过MCU,的定时器发送PWM。 目前发送pwm、设置占空比都比较正常。但有些业务需要控制发送PWM脉冲数量。 

volatile unsigned int counter=0;
void init_triggerin_pwm(){

      P1DIR |= BIT3;                            
      P1SEL |= BIT3;

      TACCTL0 = OUTMOD_2|CCIE ;                     // TACCR0 toggle mode
      TACCR0 = 11000;                        // TA1CCR1 PWM duty cycle

      TACCTL2 = OUTMOD_2 ;                      // TA1CCR1 reset/set
      TACCR2 = 50;                            // TA1CCR1 PWM duty cycle
      TACTL = TASSEL_2 + MC_1+TACLR  ;                 // SMCLK, up mode

      counter=0;

}

#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer1_A0 (void)
{
    counter++;
    if(counter>15){
        TACCR0 = 0;
        counter=0;
    }

}

以上代码控制,可以实现发送PWM,有时候也能控制发送PWM数量,但无法精准控制,有时候发了很多,有时候就发这么多。

关闭了其他中断的代码,main程序也进入低功耗。按理应该不至于有其他影响。请问能精准设置脉冲的总数吗?