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.

MSP430FR5994: PWM Output Fluctuating when using Printf or other functions

Part Number: MSP430FR5994
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

    }

}

  • Hello Shoaib,

    I want to confirm with you:

    you mean that when you add the "printf()" instruction, the PWM will occur fluctuations but when you delete "printf()" instruction, PWM won't occur fluctuations?

    And you can try to monitor the VDD voltage when "printf()" instruction is operated.

    Best Regards,

    Janz Bai

  • Hi Janz,

    These fluctuations occur when the printf() or any other function is operated. When there are no instructions only the PWM is set then there’s no fluctuations.

    I have monitored the PWM voltage and I can see the fluctuations on the built in led used in the provided code too.

    The same operation works perfectly in Energia IDE.

    Kind Regards,

    Shoaib

  • Hello Shoaib,

    Thanks for your specific information and can you help to confirm that whether the VDD of MCU have fluctuation too when the printf() is operated? not the GPIO which is used to generate PWM, just the GPIO which is used to power MCU.

    Best Regards,

    Janz Bai

  • Thank you for your response Janz,

    I have not checked the VDD of the MCU for fluctuations. How can that help me in this situation?

    In the code provided I am using Pin 1.0 for PWM, however I have tested other pins but the same issue persists. 

    Kind Regards,

    Shoaib

  • Hello Shoaib,

    Because I want to know whether the printf() affects the power up of MCU (voltage on VDD) and then the VDD fluctuations affect the PWM output.

    Best Regards,

    Janz Bai

  • If you're using the printf() into the CCS console, that uses a protocol with the Host (PC) resembling a breakpoint. When hitting a breakpoint the clocks normally stop.

    The debugger "Tools->Debugger Options->MSP43x Debugger Options->Clock Control" has checkboxes for which timers stop, and I see Timer0_A3 there. I haven't used this feature, but it might help.

    To avoid this completely, I use the backchannel (or other) UART directly. I expect this is what Energia does.

    [Edit: This is discussed in C Compiler User Guide (SLAU132Y) Sec 7.2.3]

  • Yes, removing the printf has resolved the issue.

    Thank you.

**Attention** This is a public forum