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.

CCS/MSP430FR2000: MSP430FR2000 frequency pattern generation

Part Number: MSP430FR2000
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;
    }

}

  • Hello,
    Your question is best answered by the experts in the MSP430 forum. I will move this thread there.

    Thanks
    ki
  • Hello Riya,

    For future reference, when posting code to the forum, please use the Insert Code, Attach Files and more... just below the text window. Once in this menu use the </> button to insert code. This formats the code to a readable form, and may help you get answers to your questions faster. I've edited your post to to do this for now.

    From looking at your code, by changing CCR1, you are not changing the frequency of the PWM. Just the Pulse Width. Typically PWMs are done in UP mode or sometimes UP/Down mode. This way CCR0 will control the frequency of the PWM, and the output CCR (CCR1 in your case) will change the pulse width of the. Please see PWM examples for both the MSP430FR2311 and the MSP430FR2000 within MSP430Ware. MSP430Ware can be found in TI Resource Explorer, which is found in CCS or at http://dev.ti.com .
  • Hi Jace,

    Thanks for the reply. In the Multiple Time Base Method mentioned under "slaa513a" app note,it  describes continuous mode operation for multiple frequencies. Also the section  "Table 6-12. Timer0_B3 Signal Connections" in the datasheet for MSP430FR2000 , mentions CCR1 module block for TB1 output signals.  If I have used CCR0 for frequency variation, how will this be linked to the TB1 output? 

    Thanks in advance.

    Regards,

    Riya

  • Hello Riya,

    When using the Timer in UP mode, CCR0 sets the period of the signal. It does this by limiting what the timer can count to. So instead of counting to 0xFFFF, the timer counts to the value set in CCR0, then starts again at 0. You can then set CCR1 values that are less than CCR0. At this point CCR1 controls the pulse width of the signal via auto-output depending on output settings. As long as all the frequencies you need are the same time base ( read, multiples of you input Timer frequency), then all you have to do is change the CCR0 values to change frequency. This does mean you will have to scale CCR1 appropriately with your CCR0 change if you want to keep the same duty cycle output.

**Attention** This is a public forum