Other Parts Discussed in Thread: MSP430FR2311, MSP430WARE
Tool/software: Code Composer Studio
Following is the program designed to generate a PWM pattern using MSP430FR2000. I am operating the processor at 16 MHz. The timer 0 sourced by SMCLK, working in continuous mode outputs PWM at P2.0. The TBxCCR1 bits are continuously varied to generate different frequencies, starting from 8 KHz. However at the beginning for a time period of 660ms , the frequency produced is very low which begins at 100 Hz . The same code tested on MSP430FR2311 launch pad does not show this unusual behaviour. Please let me know what could be the reason for this.
void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR = BIT0 ; //Set 1.0 to output P1SEL1 = BIT0 ; // Select the function required for 1.0 .Secondary function is selected here. P2DIR = BIT0; P2SEL0 = BIT0 ; CSCTL1 = DCORSEL_5; // DCO frequency select CSCTL2 = FLLD_0; // FLL loop divider PM5CTL0 &= ~LOCKLPM5; TB0CCTL1 = OUTMOD_4 | CCIE; // TACCR1 toggle, interrupt enabled TB0CTL = TBSSEL_2 | MC_2| CNTL_0| TBIE | ID_0 |TBCLR ; // SMCLK, Cont mode, int enabled __bis_SR_register(GIE); } #pragma vector=TIMER0_B1_VECTOR __interrupt void Timer_B1(void) { volatile unsigned int x=0; volatile unsigned int y=0; volatile unsigned int m=0; x=BAKMEM0; y=BAKMEM1; m=BAKMEM2; switch( TB0IV ) { case 2: y++; // P1OUT ^= 0x04; if((m%2)==0) { if((y%2)==0) { x=x+0x40; } TB0CCR1 += 1000+x; // reload period if(x>1200) { m++; //P1OUT ^= 0x02; } } if((m%2)!=0) { if((y%2)==0) { x=x-0x40; } TB0CCR1 += 1000+x; // reload period if(x<80 ) { m++; x=0; //P1OUT ^= 0x02; } } BAKMEM0=x; BAKMEM1=y; BAKMEM2=m; break; case 10: P2OUT ^= 0x01; // Timer overflow break; default: break; } }