To generate edge-aligned PWMs, TIMx can be configured for up- or down-counting mode and the PWM period in TIMCLK cycles is TIMx.LOAD + 1. The waveform uses load, zero, and compare events to
drive the CCPx output high or low depending on the configuration settings of the compare/capture block and counter.
Edge-Aligned PWM Configuration
To generate edge-aligned PWMs using compare match events from the counter:
- In the TIMx.CTRCTL register, set the desired counter control settings for:
- Up-counting (CM = 2) or down-counting mode (CM = 0) and counter value after enable (CVAE) (see as described in Section 25.2.2)
- Zero (CZC), advance (CAC), and load control (CLC) to specify what condition controls zeroing, advancing, or loading the counter
- Repeat or one-shot mode (REPEAT)
- Set the TIMx.LOAD value to configure the PWM period.
- Set the TIMx.CC_xy[0/1] value to configure the duty cycle.
- Set TIMx.CCCTL_xy[0/1].COC = 1 for compare mode.
- Configure CCP as an output for the CC block by setting respective bit in the CCPD registers. For instance, if TIMx Channel 0 is an output, set CCPD.C0CCP0 = 1.
- In TIMx.CCACT_xy[0/1], set the CCP output action settings for compare events, zero events, load events, software force action, or fault events (TIMA only).
- In TIMx.OCTL_xy[0/1], set CCPO = 0 to select the signal generator output.
- Enable the corresponding CCP output by setting ODIS.C0CCPn to 1 for the corresponding counter n.
- Configure polarity of the signal using the CCPOINV bit, and configure CCPIV to specify the CCP output state while disabled.
- Enable the counter by setting TIMx.CTRCTL.EN = 1.
Example using edge-aligned PWM in down-counting mode
A typical 2-channel edge-aligned PWM generation for down-counting mode is shown in Figure 25-28 with the following edge-aligned PWM output waveforms:
-
CCP0 output generates:
- High pulse-width from TIMx.LOAD to TIMx.CC0 value (LACT = 1h)
- Low pulse-width from TIMx.CC0 value to zero (CDACT = 2h)
-
CCP1 output generates:
- High pulse-width from TIMx.LOAD to TIMx.CC1 value (LACT = 1h)
- Low pulse-width from TIMx.CC1 value to zero (CDACT = 2h)
Example using edge-aligned PWM in up-counting mode
A typical 2-channel edge-aligned PWM generation for up-counting mode is shown in Figure 25-28 with the following edge-aligned PWM output waveforms:
- CCP0 output generates:
- High pulse-width from zero to TIMx.CC0 value (ZACT = 1h)
- Low pulse-width from TIMx.CC0 value to TIMx.LOAD (CUACT = 2h)
- CCP1 output generates:
- High pulse-width from zero to TIMx.CC1 value (ZACT = 1h)
- Low pulse-width from TIMx.CC1 value to TIMx.LOAD (CUACT = 2h)