Hi everyone, I am having a problem in restarting the timer after stopping it. As you can see in the ISR, when i=12, I clear it and stop the timer by this line of code : TA0CTL &= MC_0; delay 100ms and then restart the timer by this line :TA0CTL |= MC_1. But I could only stop the timer and I couldn't restart it again. someone please help me. thank you very much.
#include <msp430g2553.h>
#include "uart.h"
unsigned int i=0;
/*
* main.c
*/
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
//config clock
BCSCTL1 = CALBC1_16MHZ;
DCOCTL = CALDCO_16MHZ;
// config ngo ra ouput
P1SEL |= BIT6; // connect P1.6 to TA0.1
P1DIR |= BIT6; // P1.6 output
//config timer mode pwm
TA0CTL |= TASSEL_2 | MC_1; // SMCLK + up mode (count to TA0CCR0)
TA0CCTL0 |= CCIE; // enable interrupt when count to TA0CCR0
TA0CCTL1 |= OUTMOD_7; // output mode 7 (reset/set)
TA0CCR0 = 400; // TA0CCR0 = period of time
TA0CCR1 = 200; // TA0CCR1 = ON time (duty cycle)
_BIS_SR(GIE);
while(1);
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void){
i++;
if (i == 12) { // generate 12 burst 40Khz
i=0;
TA0CTL &= MC_0;
TAR=0;
__delay_cycles(1600000); // delay 100ms before send another 12 burst 40Khz
TA0CTL |=MC_1;
}
}