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/MSP430F5529: Voltage swing in PWM using MSPWare

Part Number: MSP430F5529
Other Parts Discussed in Thread: MSPWARE

Tool/software: Code Composer Studio

I am using MSPware to generate a PWM waveform. The code is given below:

#define TIMER_PERIOD 13105
#define DUTY_CYCLE 825

void main (void)
{
//Stop WDT
WDT_A_hold(WDT_A_BASE);

//P2.0 as PWM output
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P2,
GPIO_PIN0
);
//Generate PWM - Timer runs in Up mode
Timer_A_outputPWMParam param = {0};
param.clockSource = TIMER_A_CLOCKSOURCE_ACLK;
param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
param.timerPeriod = TIMER_PERIOD;
param.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
param.compareOutputMode = TIMER_A_OUTPUTMODE_SET_RESET;
param.dutyCycle = DUTY_CYCLE;
Timer_A_outputPWM(TIMER_A1_BASE, &param);

//Enter LPM0
__bis_SR_register(LPM0_bits);

//For debugger
__no_operation();
}



When I connect my multimeter across P2.0, I see voltage swing from [2.63,3.26]. Can someone tell me why it is not going 0 all the way?

  • Hi,

    what are your ACLK settings looking like? Might it just change too fast for your multi meter to measure? Is there an option to use an oscilloscope and post a screenshot here?
    We can take it from there and further get down to the root cause.

    Thanks an best regards,
    Britta
  • That's my only code, so from what I know the default ACLK is set to 32.768KHz. I am not sure if it's too fast to be measured by a multimeter. I don't have an oscilloscope, so I am pasting the waveform off of a software oscillopscope[TeXas - Valvano - 32b TI launchpad]. The high pulses are supposed to go a regulator IC, which is supposed to give 5V for ON period when I gave the pulse to the regulator IC, I am not seeing any output.

  • This trace indicates 0-3.3V swing, with a very short (24ms) low period, which is too short for any multimeter I've worked with. Averaged over 400ms, a 2.5-3.3V reading sounds about right.

    Is this the waveform you intended?

  • <<< When I connect my multimeter across P2.0, I see voltage swing from [2.63,3.26]. Can someone tell me why it is not going 0 all the way?
    Multimeters do a few sampling per second and readings depend on the way the samplings overlap your wave.

    <<< The high pulses are supposed to go a regulator IC, which is supposed to give 5V for ON period when I gave the pulse to the regulator IC, I am not seeing any output.
    What is connected to P2.0?
    Could you post this part of schematic?
  • Thanks a lot for taking the scope measurement. I am in the process of ordering a scope myself. Well, I intended to produce the opposite of what is appearing on the oscilloscope. As in less ON time, more OFF time.

  • Try:
    > param.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET;

    This is OUTMOD=7, which will invert what you have now. The first (RESET) operation happens partway through the cycle (CCR1 match) and the second (SET) happens at the end/start of the cycle (CCR0 match).
  • This is what I get after that change:

  • Amazing, thanks a lot for your help. I need to just my regulator IC to check whether controller's pulse works fine for my usecase.

  • Hi Sparsh,

    as I didn't hear back from you on this thread I assume that your issue has been solved in the meantime.
    Note that I will close this thread. Please reply back in case further assistance is needed.

    Best regards,
    Britta
  • Hi Britta

    Your fix, did rectify my issue. Thanks a lot. However I have another problem. I want to know if its possible to generate the wave, such that the total period is 4s instead of 400ms. Essentailly increase the period by 10x
  • The simplest change is probably:

    >param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_10;
  • Hi Britta

    Thanks for your continuous support. As mentioned in the thread that I need to get 4s instead of 400ms. I modified the code to divide the clock by 10. I see a weird pattern now, 3 pulses are fine, but then there is a big lag. Could you please verify and provide suggestions to me?

    #include "driverlib.h"

    #define TIMER_PERIOD 13105
    #define DUTY_CYCLE 82

    void main (void)
    {
    //Stop WDT
    WDT_A_hold(WDT_A_BASE);

    //P2.0 as PWM output
    GPIO_setAsPeripheralModuleFunctionOutputPin(
    GPIO_PORT_P2,
    GPIO_PIN0
    );
    //GPIO_setOutputHighOnPin(GPIO_PORT_P2,GPIO_PIN0);
    //Generate PWM - Timer runs in Up mode
    Timer_A_outputPWMParam param = {0};
    param.clockSource = TIMER_A_CLOCKSOURCE_ACLK;
    param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_10;
    param.timerPeriod = TIMER_PERIOD;
    param.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
    param.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET;
    param.dutyCycle = DUTY_CYCLE;
    Timer_A_outputPWM(TIMER_A1_BASE, &param);

    //Enter LPM0
    __bis_SR_register(LPM0_bits);

    //For debugger
    __no_operation();
    }

  • I don't see that effect. (F5529 Launchpad, Rigol DS1102E scope).

    I'm not sure what we're doing differently.

  • I suppose something is wrong with how I take measurements on this USB scope. Although with the changes done and with my calculation, I excpected to get 25ms as ON period and not 200ms. Do you think the macro DUTY_CYCLE is correct?
  • One way to double-check your scope is to patch your output pin (P2.0) to one of the Launchpad LEDs. As it is now, your (240ms) pulse is long enough to be visible, so you should be able to actually see a pulse every 4 seconds.

    If you want your pulse width to stay at 24ms, you need to divide your DUTY_CYCLE by 10 to match the amount you slowed down the timer. 825 doesn't divide neatly by 10, but I estimate the error as 825/(10*82) or about 0.6%. Is this close enough? The alternative is to re-compute the constants and the divider so you get just what you want.
  • Hi Sparsh,

    as I didn't hear back from you I assume that the issue has been solved.
    Please note that I am going to close this thread. Please reply back to re-open it in case you need further assistance.

    Thanks and best regards,
    Britta
  • Hi Britta,

    How can I generate an output PWM pulse using interrupts, essentially from what I see in MSPWare I would need to use the up mode and use the compare an capture register. Could you guide me so that I can get a similar DUTY cycle and period as what I am getting here.

    Thanks

  • Different issue, different thread.
    Please mark this thread as resolved and create a new one.

**Attention** This is a public forum