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.

MSP430 PWM Channels

Other Parts Discussed in Thread: MSP430G2231

Im new to MCU and MSP430 Programming and was confused about PWM Channels. I have a MSP430g2231 Chip thats included in the launchpad and was wondering How many PWM channels it has and how to determine how much PWM other microcontrollers have is it based on Timers compare channels? in this chip there seem to only be two channels CCR0 and CCR1 so can it only drive two in continuous mode?

  • The number of PWM channels depends on the number of capture/compare units a device has.
    There are many MSPs with a TImerB that has 7 CC units.
    One of these is usually required to set the PWM frequency (unless a full 16bit timer overflow will give an acceptable frequency, which it usually don't). Then the 'PWM' signal available from the CC unit 0 will have half the frequency and 50% duty cycle.
    All other CC usints will run with the same frequency but a programmable duty cycle.

    For each timer (there are some MSPs with 3 timers and 15 CC units) the pwm frequency can be different.

    If the MSP runs with >6.5MHz and a PWM frequency of 100Hz is okay (6.5536MHz/65536 = 100Hz), you can use all CC units of a timer for a PWM signal. And in this particular case you can control the duty cycle in 65535 steps of 0.0015% :)

  • Tell me if I get it right?

    The MSP430G2231 that comes with LaunchPad has 1 timer (TimerA) and two CCR registers. So it can deliver only 1 PWM signal? If it would have 3 CCRs than it could deliver 2 PWM signals?

    I also set both TA0.0 and TA0.1 as outputs, configured TimerA to run in continous mode and set OUTMOD_4 (Toggle). Clock was sourced by SMCLK at 16 Mhz giving me PWM frequency of around 120Hz but with NO ADJUSTABLE duty ratio.

    Are my toughts correct?

     

     

  • It depends :)

    If you use CCR0 for setting the pwm frequency, then you have only one 'real' PWM signal (CCR1). With 3 CCRs, you'd have 2. And there are MSPs with timers with up to 7 CCRs. And up to 4 timers (yet not all with 7 CCRs).
    If CCR0 is setting the PWM frequency, you can additionally output a signal with a) the same frequency but only a pulse of one clock cycle (by selecting CCR0 set/reset outmode) Or half the frequency and 50% duty cycle (toggle mode)

    Primoz Fiser said:
    I also set both TA0.0 and TA0.1 as outputs, configured TimerA to run in continous mode and set OUTMOD_4 (Toggle). Clock was sourced by SMCLK at 16 Mhz giving me PWM frequency of around 120Hz but with NO ADJUSTABLE duty ratio.


    Toggle just toggles when TAR counts to CCRx. THis leads to 50% duty cycle and half frequency (one toggle per TA cycle). This can be used for multi-phased clock signals where different outputs have the same frequency and duty cycle but are a defined time apart.

    To have an adjustable duty cycle, you'll need to use one of the set/reset or reset/set modes. Here the output will be set when TAR counts to CCRx and is reset when TAR counts to 0. SO the duty cycle is the ratio between CCRx and the TAR overflow (and if CCR0 is used for the PWM frequency, then TAR 'overflows' after CCRx).

    Using these modes (which one just selects which phase is high and which is low), you should get a PWM frequency of 244Hz and an adjustable duty cycle.

    Due to the nature of the settings, you cannot get 0% or 100%. If you set CCRx to 0, you don't know for sure what takes precedence (set or reset, as both are happening at the same time) and if you set it to max, you'll still have a pulse of one timer tick. In these cases, the function settign the duty cycle should switch to OUTBIT out mode and manually set the low or high state of the output pin.

  • If your looking for some basic info on PWM and timers, I tried to simplify it a bit on a post I made in my blog. The downside though is that I do skim over some topics that are important just for the sake of keeping posts small enough to digest.

    Hope you figure out all you need to with PWM.

    -NJC

    ______________________________

    http://msp430launchpad.blogspot.com

  • There's another recent thread about PWM on the launchpad, including some code ("Resetting Timer A"). Search the forum for it (I think I answered to it just an hour ago, so it is really recent).

    It even offers a way to have two PWM signals (with some frequency jitter) with some software support.

  • I think you are right.

    I am playing the board with MSP430G2231 and I am not sure if TimerA output port is fixed. 

**Attention** This is a public forum