Hello,
I am trying to generate a triangular waveform using PWM of MSP430G2553 capture/compare unit on MSP430 launchpad. PWM duty ratio is going up and down and filtered. Basically it works, but periodically something turns the output back on right after it goes low. I can't figure out why this happens. Seems when it happens, SCCI and CCI bit in TA0CCTL1 register goes high, but I think I disabled the capture.
P1.2 is shown in the figure.
The code is listed below. Any suggestion will be appreciated. Thank you.
#include <msp430.h> #pragma CODE_SECTION(timer_a0, ".ram_func") int x = 1; int pulsecounter = 0; int dur = 54; int intv = 255; void main(void) { unsigned char *flash_start_ptr; // Initialize pointers unsigned char *RAM_start_ptr; unsigned char flash_code_size = 0xE0; WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer 0.5 V step BCSCTL1 = CALBC1_1MHZ; // DCO at 1 MHz DCOCTL = CALDCO_1MHZ; // DCO at 1 MHz flash_start_ptr = (unsigned char *)0xC000; RAM_start_ptr = (unsigned char *)0x200; // Copy flash function to RAM memcpy(RAM_start_ptr,flash_start_ptr,flash_code_size); pulsecounter=1; P1DIR|=BIT2; P1SEL|=BIT2; P1DIR|=BIT6; P1SEL|=BIT6; P1DIR |= 0x01; // Set P1.0 to output direction TA0CTL=TASSEL_2 + MC_1 ; TA0CCR0=intv; TA0CCTL0=CCIE; // initiate interrupt TA0CCTL1=OUTMOD_6; TA0CCR1=0; TA0CCR2=0; _BIS_SR(LPM0_bits + GIE); // go to sleep mode and initiate interrupts } long ccc = 0; int ddd = 0; #pragma vector=TIMER0_A0_VECTOR __interrupt void timer_a0(void) { P1OUT = 0x01; // LED on if (pulsecounter < dur) { ccc = ccc + x; } else if (pulsecounter >= dur && pulsecounter < dur<<1 ) { ccc = ccc - x; if(ccc < 0) ccc = 0; } else { pulsecounter = 0; ccc=0; } pulsecounter++; TA0CCR1 = ccc; TA0CCR2 = ccc; if(pulsecounter == dur) P1OUT = 0x00; // LED off }