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
}
