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.

MSP430F5419A: MSP430 DriverLib: How to Output PWM on multiple channels?

Part Number: MSP430F5419A
Other Parts Discussed in Thread: MSP430WARE

Hello,

I have an RGB LED connected to P4.1/TB0.1 for Red, P4.2/TB0.2 for Green, and P4.3/TB0.3 for Green. I've successfully used Timer_B_outputPWM to output PWM on one output, but how do I configure Timer B to output PWM on all three channels. Initialization code:

void halTimerInitRgbLedPwm()
{
rgbLedPwmParam.clockSource = TIMER_B_CLOCKSOURCE_SMCLK; //4Mhz
rgbLedPwmParam.clockSourceDivider = TIMER_B_CLOCKSOURCE_DIVIDER_1; //TACLK = 4MHz
rgbLedPwmParam.timerPeriod = RGB_LED_PWM_TIMER_PERIOD;
rgbLedPwmParam.compareRegister = TIMER_B_CAPTURECOMPARE_REGISTER_1;
rgbLedPwmParam.compareOutputMode = TIMER_B_OUTPUTMODE_RESET_SET;
rgbLedPwmParam.dutyCycle = 0;
Timer_B_outputPWM(TIMER_B0_BASE, &rgbLedPwmParam);
}

Once configured I realize I can use Timer_B_setCompareValue() to set the duty cycle for a given capture/compare register, but how do I configure all three outputs to be PWM?

Thanks,

Derek

  • Hi Derek,

    Timer_B has 7 capture/compare registers. Each of them can be used to generate PWM outputs similar to how are you generating it using REGISTER_1.

    You can see the code example "timer_b_ex3_pwm" in MSP430WARE (https://www.ti.com/tool/MSPWARE) or MSP430 Driver Lib (https://www.ti.com/tool/MSPDRIVERLIB).

    I am including the relevant portion here:

    -------------------------------------------------------------------------------

    //Initialize compare mode to generate PWM1
    Timer_B_initCompareModeParam initComp1Param = {0};
    initComp1Param.compareRegister = TIMER_B_CAPTURECOMPARE_REGISTER_1;
    initComp1Param.compareInterruptEnable = TIMER_B_CAPTURECOMPARE_INTERRUPT_DISABLE;
    initComp1Param.compareOutputMode = TIMER_B_OUTPUTMODE_RESET_SET;
    initComp1Param.compareValue = 383;
    Timer_B_initCompareMode(TIMER_B0_BASE, &initComp1Param);

    //Initialize compare mode to generate PWM2
    Timer_B_initCompareModeParam initComp2Param = {0};
    initComp2Param.compareRegister = TIMER_B_CAPTURECOMPARE_REGISTER_2;
    initComp2Param.compareInterruptEnable = TIMER_B_CAPTURECOMPARE_INTERRUPT_DISABLE;
    initComp2Param.compareOutputMode = TIMER_B_OUTPUTMODE_RESET_SET;
    initComp2Param.compareValue = 128;
    Timer_B_initCompareMode(TIMER_B0_BASE, &initComp2Param);

    -------------------------------------------------------------------------------

    Srinivas

**Attention** This is a public forum