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/MSP430G2553: PWM Guidance needed

Part Number: MSP430G2553

Tool/software: Code Composer Studio

Hi,

I would like to have PWM output on three pins P2.2, P2.3 and P2.4. I have tried following code but it is working for P2.2 only and not for P2.3 and P2.4.

Code:

P2DIR |= BIT2|BIT3|BIT4; // P2.2,P2.3,P2.4 output
P2SEL |= BIT2|BIT3|BIT4; 
TA1CCR0 = 512-1; // PWM Period
TA1CCTL1 = OUTMOD_7; // CCR1 reset/set
TA1CCR1 = 384; //CCR1 PWM duty cycle
TA1CTL = TASSEL_2 + MC_1; // SMCLK, up mode


Please help me to understand mistake in above code. Is it possibe to have same PWM duty cycles on three different pins as mentioned above?

Is it possible to generate different PWM duty cycles on three different pins using single timer?

Thanks,

Krunal

  • Is it possibe to have same PWM duty cycles on three different pins as mentioned above?
    Yes, it is possible.

    Is it possible to generate different PWM duty cycles on three different pins using single timer?
    Yes, but you have to be advice, that you must use TA1.0 (Pin2.2), TA1.1 (Pin2.3) and TA1.2 (Pin2.3).

    Try this.

    P2DIR |= BIT2|BIT3|BIT4; // P2.2,P2.3,P2.4 output
    P2SEL |= BIT2|BIT3|BIT4;
    TA1CCR0 = 512-1; // PWM Period
    TA1CCR1 = 384; //CCR1 PWM duty cycle
    TA1CCTL1 = OUTMOD_7; // CCR1 reset/set
    TA1CCTL2 = OUTMOD_7; // CCR2 reset/set
    TA1CTL = TASSEL_2 + MC_1; // SMCLK, up mode
  • What Daniel Warner said, plus:
    In Up mode you can only get 50% duty out of TA1.0 (P2.3).
  • Thanks for reply,

    I tried your suggestion, now P2.2 and p2.4 are giving PWM output.
    P2.3 is not working. (FYI: I am checking output on CRO directly on that pin.)

    Any suggestion?

    In your suggestion you mentioned pin2.3 twice, Also TA1.0 (pin2.2) is not matching with datasheet, can you please provide updated pin names.
  • To get PWM on a channel, you (1) set CCTLx:OUTMOD as appropriate, and (2) CCRx=duty (in ticks).

    You can do this with CCR0, but most people don't bother since you can only get 50% duty out of it. (Ref SLAU144J sec. 12.2.5.1)

  • Just wanted to confirm here, if I want to use PWM on three different pins without limitations, then I should avoid using TAx.0. Instead, I can use TA0.1, right?
  • Yes. (There's also TA0.2, but that isn't available as a pin on the Launchpad DIP-20 package.)

    To get TA0.1, you will need to set up TA0 (TA0CTL and all them) in addition to TA1. You can use the same values, though if you need them to be synchronized (start at Exactly the same time) that can be difficult (depending on your definition of "Exactly").

**Attention** This is a public forum