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/MSP430FR6989: Configuring a PWM in Timer B

Part Number: MSP430FR6989


Tool/software: Code Composer Studio

Hello everyone.

I'm trying to configure a PWM signal in MSP430FR6989. I'm new programming with this uC, so I don't know if I'm doing it right. I use the pin 12 of the chip for making the output signal of the PWM, which corresponds with TimerB0.1. The thing is that I tried to follow the Manual's guide to configure the PWM, but I measure this pin and I don't get a PWM signal. I selected random values for making the PWM_Duty value. If someone knows what is wrong with my code, please help!

//Libraries used

#include <msp430.h>
#include <stdint.h>
#include <stdbool.h>

//Variables
float PWM_Duty = 0;

//Timer to PWM signal
void TIMER_B0_Init()
{
    TB0CCTL3 &= ~(CCIE); //Interrupt disabled in order to configure the PWM

    TB0CCR0 = 100;                            // PWM Period

    TB0CTL = TBSSEL__SMCLK | MC__UP | TBCLR; // SMCLK, up mode, clear TBR
    TB0CCTL3 = OUTMOD_7;                        // CCR3 reset/set

    TB0CCTL3 |= CCIE; //Configuration done, interrupt enabled

}

//Configuration of the PWM
void ControlPWMDuty()
{
    float D1= 50;
    float D2= 70;
    PWM_Duty = (D1+D2)/2;
    TB0CCR3 = PWM_Duty;                       // CCR3 PWM duty cycle
}

//Initial configuration of the pins
void Set_Up_GPIO()
{
    //PWM pin as output
    P6DIR |= BIT5;
    //Set the pin as LOW
    P6OUT &= ~(BIT5);
}

//Set the pins for ADC, PWM and motor driver
void InitGPIO()
{
    //For timer B it has to be 01
    P6SEL0 |= BIT5;
    P6SEL1 &= ~(BIT5);
}

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer
    Set_Up_GPIO();
    InitGPIO();
    PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode to activate previously configured port settings
    TIMER_B0_Init();
    __bis_SR_register(GIE); // Allow general interrupts

    while(1)
    {
        ControlPWMDuty();
        __delay_cycles( 4000000 );
    }
}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = TIMER1_B0_VECTOR
__interrupt void Timer1_B0_ISR (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER1_B0_VECTOR))) Timer1_B0_ISR (void)
#else
#error Compiler not supported!
#endif
{

    TB0CTL|= TBCLR;         //Clear Timer B0

}

  • Hi,

    we recommend to start off from our code examples. You can find them either on the device home page as a zip file, which can be downloaded, or e.g. within our Code Composer Studio, which is downloadable for free. Within CCS, you can find the TI Resource Explorer, which contains the same code examples, and as such for all available MSP430 derivatives.

    You can find there also multiple code examples for Timer based PWM generation. Please checkout one of those.

    Best regards

    Peter

  • 1) P6.5 is TB0.1, not TB0.3 [Ref Data Sheet (SLAS789C) Table 6-31]. You can use this via TB0CCR1/TB0CCTL1.

    2) If you use TB0CCTL1:CCIE, you need vector=TIMER0_B1_VECTOR. Be sure to explicitly clear TB0CCTL1:CCIFG in the ISR.

    3) I recommend Not using TBCLR in the ISR. Up mode will clear the counter when appropriate, and doing it explicitly will interfere with the output signal.

  • Hi,

    could you please give us a status update? Do you still need help on this one?

    Best regards

    Peter

**Attention** This is a public forum