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/MSP430FR5994: How does Software PWM work?

Part Number: MSP430FR5994

Tool/software: Code Composer Studio

Hi everyone,

I am VERY new to embedded programming. Now I am working on a project which I need 12 PWM signals with different duty cycles. The MCU (MSP430FR5994) I'm using has 2 timers which can generate total 11 PWM signals with desired duty cycle but due to hardware limitation I will probably have to use software to make the last PWM signal? These signals will drive 12 loads and form a feedback loop through 12 ADCs. I have no idea how to implement software PWM. Any suggestions will be appreciated. 

  • PWM uses 2 triggers, normally from timer matches: one causes the pin to go high, and the other causes the pin to go low. The spacings between these two triggers determines the duty cycle and frequency.

    In Timer A or B, one trigger is a timer (hardware) match with CCR0 and the other a match with some other CCRn. (OUTMOD says which one does what). The timer itself sets the pin high or low. This is hardware PWM.

    In software PWM, the software sets the pin high or low. The triggers are also to some extent generated by software (usually by "watching" a timer in some way). This is not as accurate or simple as hardware PWM, but you can (in theory) have an arbitrarily large number of such channels.

    In your case, I suggest you look to timer TA2 or TA3 for your 12th channel. These aren't connected to an external pin, but they have all the other mechanics. Consider setting (e.g.) the TA2CCR0/1 just as you do the other timers for the other channels, but have the CCR0 and CCR1 matches generate interrupts (CCIE); in the ISRs (there will be two of them) explicitly set your chosen output pin high or low (PxOUT). This will allow you to treat the 12th channel mostly like the other channels, i.e. minimal extra work.

**Attention** This is a public forum