New LPCOpen releases provide the sct_pwm driver. Using this driver application can configure and use the SCT as a standard PWM with multiple channels. An application can do this by following the steps given below
Initialize the SCT using Chip_SCTPWM_Init()
Set up the frequency/rate of SCT using Chip_SCTPWM_SetRate()
Configure PinMUX for the pin (SCT_OUTx) [x is the SCT_OUT pin number, see Chip User Manual SCT section for more information]
Assign a PWM output pin to a channel using Chip_SCTPWM_SetOutPin()
Set the duty-cycle for the PWM output generated on this channel using Chip_SCTPWM_SetDutyCycle()
Repeat step 3, 4 and 5 for desired number of PWM channels [Optional]
Start the PWM channel using Chip_SCTPWM_Start()
Change the duty-cycle as required using Chip_SCTPWM_SetDutyCycle()
SCT/PWM can be stopped when required, using Chip_SCTPWM_Stop() [Optional]
Standard PWM using a timer
A standard PWM could be implemented by using a timer which counts up from zero to a Max value and once the count reaches the max value the counter resets to zero and starts counting to max again repeatedly. If the count is plotted it will appear as a saw tooth wave as shown in the figure. A PWM capable timer outputs the PWM wave on an output pin. The output pin is set to High whenever the counter resets to zero and will be set Low when the counter reaches a specific value which is less than or equal to the max counter value (usually programmed in a MATCH register). Hence by varying the value in MATCH register from zero to max counter value, the timer could generate a waveform with duty cycle varying from zero to 100% respectively.
Using SCT the application can generate waveform of same frequency but with independently varying duty cycles. Each such output is called as a PWM channel. In an LPC15xx chip there are 4 SCTs available, SCT0 and SCT1 has 16 Match registers and 10 Output pins, SCT2 and SCT3 has 8 match registers and 6 output pins. The number of PWM channels that can be used is minimum of "number of match registers available minus one", "number of outputs available". Hence SC0 can be configured as a PWM with 10 channels (10 outputs) [index 1 to 10], and likewise SCT3 can be configured as PWM with 6 channels (6 outputs). Channel (index=0) is always reserved and applications should never use it.
Associate Output Pin to Channel (index)
Applications can associate any Output pin to any channel in a given SCT/PWM. For example an API call "Chip_SCTPWM_SetOutPin(LPC_SCT1, 2, 4);" will associate SCT1_OUT4 pin to channel (index=2), now the duty cycle of this channel (index=2) could be set using "Chip_SCTPWM_SetDutyCycle(LPC_SCT1, 2, Chip_SCTPWM_PercentageToTicks(SCT_PWM1, 50));". Once the APIChip_SCTPWM_Start(LPC_SCT1) is called, the SCT will generate a PWM wave with 50% duty cycle on pin to which SCT1_OUT4 is connected [use PinMux registers to do this].