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.

MSP430F5659: PWM freq

Part Number: MSP430F5659


Hello,

I am using msp430f5659 for PWM waveform generation. I have used the code given below to generate pwm using timer.

    PWM_PINDIR;
    PWM_PINMODESELECT;                        //Select pin 1.6 as our PWM output.

    TA0CCR0 = 1000;                           //Set the period in the Timer A0 Capture/Compare 0 register to 1000 us.
    TA0CTL = TASSEL_2+ MC_1 + TACLR ;         //TASSEL_2 selects SMCLK as the clock source,
                                              //and MC_1 tells it to count up to the value in TA0CCR0 upmode, clear TAR.
    TA0CCTL1 = OUTMOD_7;
    TA0CCR1 = 500;                            //The period in microseconds that the power is ON. It's half the time,
                                              //which translates to a 50% duty cycle.
    //TA0CTL = TASSEL_2 + MC_1;                //TASSEL_2 selects SMCLK as the clock source, and
                                             //MC_1 tells it to count up to the value in TA0CCR0.
    TA0CCTL0 = CCIE;                          // CCR0 interrupt enabled
    __bis_SR_register(LPM0_bits);            //Switch to low power mode 0.

// Timer0 A0 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) TIMER0_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
    PWM_PINTOGGLE;                            // Toggle P1.6
    __bic_SR_register(LPM0_bits);
}

I am getting freq of 12kHz of the generated PWM but my SMCLK is oscillating at 12MHz.  How can i get the higher freq?

I have tried to change the output PWM freq by changing the value in the ID of TA0CTL register but it does not affect the freq.

How can I change the freq of the PWM? Which register value I have to modify to get desired freq.

  • Hi,

    thank you for posting this question!

    Please note: TA0CCR0 register value defines the PWM frequency, TA0CCR1 register value defines the duty cylce.

    In order to change the output PWM frequency, you'll thus need to adapt the TA0CCR0 register.

    You can calculate the resulting  PWM frequency by dividing the Timer clock frequency (in your case SMCLK = 12 MHz as you've informed) by Timer compare value(number in TA0CCR0, in your case 1000). In your current example it results in 12kHz, as described by you.

    If you need a higher PWM frequency, decrease the value in TA0CCR0 and adapt also the value in TA0CCR1 for the right duty cycle.

    Please take a look at the MSP430F5xx and MSP430F6xx Family User's Guide, Section 17.2.4.2 Timer_A Compare Mode.

    For examples on PWM implementation using Timer_A you can also take a look at the examples included in the MSP driver library.

    Let me know if you have additional questions.

    Best regards,

    Britta

  • Hello,
    Thanks for the information.
    I want to generate 2 PWM waveforms on diff pins (PIN P1.6, P1.5) for bridge driving application.
    I need inverting PWM waveform on the pin P1.5.
    One PWM freq has been generated on P1.6.
    How to generate the another inverting waveform at the same time from single ISR routine.
  • Hi,

    you can configure the two pins as outputs of the  OUTn signal. The OUTn signal changes when the Timer reaches the CCRn  value.

    Find the description in Section 17.2.5.1.2 of the MSP430Fxx and MSP430F6xx Family User's Guide.

    In your case you can set the CCRx registers to the same value but choose the OUTn signals to be inverting, this is explained in Table 17-2 in Section 17.2.5.1 of the linked User's Guide above (you could for example use the Reset/Set mode on Pin 1.5 and the Set/Reset mode on Pin 1.6, see all option in Table 17-2).

    Chapter 17 in the User's Guide should provide all information you need to implement the funcitonality.

    Best regards,

    Britta

  • "How can i get the higher freq?"

    you should ask yourself, as the code you wrote clearly stated how to change the PWM frequency.

**Attention** This is a public forum