Other Parts Discussed in Thread: ENERGIA
Tool/software:
Hi,
I am getting fluctuations of the PWM Voltage when I try to use a print function or any other function. The voltage goes high or low randomly then continues with the set duty cycle after the function is complete. The same operation works easily in Energia IDE, However not working in CCS.
Ideally, I want it to stay constant at the set duty cycle without interference.
Here's my code:
#include <msp430.h>
#include <stdio.h>
void initClock()
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
PM5CTL0 &= ~LOCKLPM5; // Disable GPIO high-impedance mode
// Configure DCO to 1 MHz
CSCTL0_H = CSKEY >> 8; // Unlock CS registers
CSCTL1 = DCOFSEL_0 | DCORSEL; // Set DCO to 1 MHz
CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK; // Set ACLK = VLO; SMCLK = DCO; MCLK = DCO
CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers to 1
CSCTL0_H = 0; // Lock CS registers
}
void initPWM()
{
// Configure P1.0 as PWM output
P1DIR |= BIT0; // Set P1.0 as output
P1SEL0 |= BIT0; // Select Timer_A function for P1.0
// Configure Timer_A
TA0CCR0 = 1000 - 1; // PWM period
TA0CCTL1 = OUTMOD_7; // CCR1 reset/set
TA0CCR1 = 0; // CCR1 PWM duty cycle
TA0CTL = TASSEL_2 + MC_1 + TACLR; // SMCLK, up mode, clear TAR
}
void setPWMDutyCycle(unsigned int dutyCycle)
{
TA0CCR1 = dutyCycle; // Set PWM duty cycle
}
void main(void)
{
initClock();
initPWM();
setPWMDutyCycle(100);
while(1)
{
printf("hello\n");
__delay_cycles(1000000); // Adjust delay for fade speed
}
}