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.

Two PWM outputs on MSP430G2211 (Launchpad provided chip)

Other Parts Discussed in Thread: MSP430G2211

I just received my Launchpad and have a learning project in progress. The project calls for 2 PWM outputs. Using sample code and help from others, I have been able to setup one PWM output using Timer_A2. My question is how would one get 2 PWM outputs with different duty cycles when there are only 2 capture/compares on the chip?

 I really want to limit the project to the MSP430G2211 which came with the Launchpad, so that I can share the results to other Launchpad hobbyists.

I'm interested in alternate algorithms to achieving PWM outputs.

Any help would be greatly appreciated - more detail is better ;), since I'm a beginner.

Thanks

  • If you want to generate two PWM (with same frequency) output without CPU, you're right, you'll need three CCR. (two timers, if two frequencies).

    It is possible to make a sort of PWM with software, but as we have no other information on your project it's difficult to say if it's a good idea (power consumption, frequency, duty resolution, cpu occupation,...).

    For example your PWM frequency corresponds to 1000 clock "tic", and an 30% duty is required, set an I/O to 1, if the timers starts from 0, set the next interruption (CCR) to 300 (300 tics with output on) then manage the interruption to set IO to 0 and next interruption 700 ticks later (70% off), so CCR is 1000. It is possible to configure the timer in continuous count, so you have to read the timer value add the "software PWM value" to set next interruption, and handle it by software in interruption routine (xor).... If you have 2 CCR you can make 2 PWM output.

     

  • See this thread http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/t/57487.aspx

    which was aimed at the same goal, and more-or-less gets there with some software-assist.  To get two unassisted PWMs would require three CCR, though.

     

  • Hi,

    you can work with virtual timers. One hardware timer is used to feed some software timers (data in RAM). TI has an application note for Cortex-M3 stellaris parts which makes use of virtual timers. You can have a look at it (it is WELL DOCUMENTED, so no need to worry) and make a port to MSP430.

    You can find the app note here: http://focus.ti.com/mcu/docs/litabsmultiplefilelist.tsp?sectionId=96&tabId=1502&literatureNumber=spma027&docCategoryId=1&familyId=1755.

    Look at the 'Stellaris CNC Machine Software Reference Manual' pdf for a description of the function (only chapter 15 should be of interest for you) and then examine the source code porvided (virtualtimer.c and tirualtimer.h).

    The principle is easy to understand.

    Using virtual timers give you one drawback though: The resolution will drop since you need do deal with your PWMs in software only! The faster you clock your MCU the better the resolution you can achive (because of faster inctruction cycle time).
    Rgds
    aBUGSworstnightmare

  • f the PWM you want to generate is much slower than your MCLK, you can get two independent PWM with Timer_A2.

    For example, use the ~12kHz clock form the VLO or the 32.768kHz from the watch crystal to drive the Timer and use DCO at 1MHz or above to drive MCLK.

    (a) Set up TACTL to count in continuous mode. (And let TAR count by itself, do not change TAR with your code.)

    (b) Set up P1.1 or P1.5 as your TAO.0 output. Set up P1.2 or P1.6 as your TAO.1 output pin.

    (c) Set up both TACCTL0 and TACCTL1 to use OUTMOD=“Toggle” and enable CCE.

    (d) In the CC0 ISR, add its “number of counts for next Toggle” to TACCR0.

    (e) In the CC1 ISR, add its “number of counts for next Toggle” to TACCR1.

    Note that “number of counts for next Toggle” for CC0 is independent of that for CC1. Note also that they can be different from consecutive interrupts.

    For example, you may use 49,51, 49,51, (repeat) as “number of counts for next Toggle” for CC0. This will produce a 49 clocks low, 51 clocks high PWM, which has a period 100 clocks and a duty cycle of 51%.

    For CC1, you may use 9,1, 8,2, 7,3, 6,4, 5,5, 4,6, 3,7, 2,8, 1,9, 2,8, 3,7, 4,6, 5,5, 6,4, 7,3, 8,2, (repeat). This will produce a PWM with a period of 10 cycles and duty cycles that increases from 10% to 90% and decreases back to 10% and repeat.

  • All,

    I want to thank you for your replies. It took me a while to get back to this. Here is a link to my instructable that used some of the ideas you suggested. It is a MSP430G2211 based chronulator and has 2 independent PWM outputs.

                      http://www.instructables.com/id/MSP430-Based-Chronulator-using-Launchpad-chip/

     

  • I need to do this exactly... I already tried to follow the steps. Let's recap, 

    -My timer is working in continous mode

    -P1.5 is working as TA0.0 and P1.6 as TA0.1

    -Toggle is selected and also interruptions

    -In the interruptions I add the complement for the period or next toggle.

    But it doesn't work.. any other comment?

  • In the Instructable clock application above, I had to set the  output modes like this:

      TACCTL0 = OUTMOD_4 + CCIE;                       // output mode = toggle, interrupt enabled
      TACCTL1 = OUTMOD_1 + CCIE;                       // output mode = set, interrupt enabled

    The code for the clock is at:

    http://www.instructables.com/id/MSP430-Based-Chronulator-using-Launchpad-chip/step4/The-Code/

    The clock has kept excellent time.

  • Armando Lara said:
    -Toggle is selected and also interruptions

    Make sure you
    1) don't set TAIE, as it is for the timer overflow interrupt, which you don't need here.
    2) have an ISR for CCR0 and another one for CCR1/2/3 (TIMER0_A0_VECTOR for CCR0 and TIMER0_A1_VECTOR for all others)

**Attention** This is a public forum