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.

Initialization of PWM

Other Parts Discussed in Thread: MSP430F67641

Hello sir,

I am working on the PWM based project. I use

1> MSP430F67641

2> PWM pin 

        --> PM_TA2.0

       --> PM_TA2.1

so how i initialize of both as PWM pin.

My code is:-

void touch_led1(void) // pin50 TA2_1
{
TA2CCR0 = 512 - 1; // PWM Period
TA2CCTL1 = OUTMOD_7; // CCR1 reset/set
TA2CCR1 = 0; // CCR1 PWM duty cycle
TA2CTL = TASSEL_1 | MC_1 | TACLR; // ACLK, up mode, clear TAR
}

void touch_led2(void) // pin49 TA2_0
{
TA2CCR0 = 512 - 1; // PWM Period
TA2CCTL0 = OUTMOD_7; // CCR0 reset/set
TA2CCR0 = 0; // CCR0 PWM duty cycle
TA2CTL = TASSEL_1 | MC_1 | TACLR; // ACLK, up mode, clear TAR
}

i have confusion in the initialization of touch_led2(). 

Is it correct initialization , iget problem in led PWM operation...

give me solution...

  • Hi Chintan!

    Maybe you could describe what signals you want to have.

    For PWM you normally take CCR0 as frequency and then use CCR1, CCR2, CCR3, ... for the duty cycles based on the CCR0 timebase. If you set CCR1 to 0, there won't be a PWM, of course. In your second function you use OUTMOD_7 for CCR0 - is that what you want? Furthermore you are first setting CCR0 to 511 and then two lines later you set CCR0 to 0. So what did you want to do?

    Dennis

  • Hello sir,

    I use PM_TA2.1 adn PM_TA2.0 for PWM generation.

    I use TA2.1 without problem with OUTMOD_7 but how we configuration TA2.0 for PWM generation with various duty cycle.

    I am struct here, waiting for reply

  • I don't believe you can use TA2.0 for PWM. PWM requires two timer capture/compare blocks.

    TA2.0 - sets the frequency. You don't want to set OUTMOD_7 for this. Its not a valid selection as documented in the reference manual:

    Output modes 2, 3, 6, and 7 are not useful for output unit 0, because EQUx = EQU0.

    TA2.x - sets the duty cycle. You can set OUTMOD_7 for these which means, when TA2.0 expires, your output connected to TA2.x will go high, and when TA2.x expires, the output will go low. As documented in the reference manual:

    The output is reset when the timer counts to the TACCRx value. It is set when the timer counts to the TACCR0 value.

    To have two PWM outputs you should be using TA2.1 and TA2.2. They will both have the same frequency (defined by TA2.0), but can have a different duty cycle.

  • Hello sir,
    Right , i am not use Output modes 2, 3, 6, and 7 are not useful for output unit 0.
    so how we config for other Output mode. I set the Toggle mode but it is blinking not performing the PWM operation.
    So how i configure for outmode 0 for PWM generation ?
  • Exactly! And if you want two independent hardware PWMs, then you will need another timer module because there is one CCR0 for each module's base frequency and the module's other CCRx (>0) registers set the duty cycle in the range of this base frequency. Means with one timer module you cannot generate one hardware PWM that has a frequency of 10kHz with 20% duty cycle and another hardware PWM with 25kHz and 70%. You can do one with 10kHz and 20% and another with 10kHz and 70% or one with 25kHz and 20% plus one with 25kHz and 70%. For two independent ones you would also need TA1, for example.

    So what kind of signals do you need?

    Dennis
  • chintan patel83 said:

    Right , i am not use Output modes 2, 3, 6, and 7 are not useful for output unit 0.
    so how we config for other Output mode. I set the Toggle mode but it is blinking not performing the PWM operation.
    So how i configure for outmode 0 for PWM generation ?

    You are setting OUTMOD_7 for timer TA2.0. 

    chintan patel83 said:

    void touch_led2(void) // pin49 TA2_0
    {
    TA2CCR0 = 512 - 1; // PWM Period
    TA2CCTL0 = OUTMOD_7; // CCR0 reset/set <<<< Right here
    TA2CCR0 = 0; // CCR0 PWM duty cycle
    TA2CTL = TASSEL_1 | MC_1 | TACLR; // ACLK, up mode, clear TAR

    }

    This is what you need to do:

    Set up your timer

    TA2CTL = TASSEL_1 | MC_1 | TACLR; // ACLK, up mode, clear TAR


    Set the PWM frequency using TA2CCR0 as you have done

    TA2CCR0 = 512 - 1; // PWM Period

    Set the up your first PWM on TA2.1

    TA2CCTL1 = OUTMOD_7; // CCR1 reset/set

    TA2CCR1 = [DUTY CYCLE]

    Where 0 < [DUTY CYCLE] < TA2CCR0.

    And then do the same for TA2.2

    TA2CCTL2 = OUTMOD_7; // CCR1 reset/set

    TA2CCR2 = [DUTY CYCLE]


    Now you have two PWM outputs that can have different duty cycle. Just set up the pin configuration for your board and your done.

  • Hi Chris Karaplis,

    Thanks for your valuable suggestion.

    I understand it. I got an idea about PWM. 

    'once againnthank you very much

**Attention** This is a public forum