To generate center-aligned PWMs, TIMx is configured for up/down counting mode and the TIMx.LOAD value contains the half-period. The waveform uses up compare events and down compare events to drive the CCPx output high or low depending on the
configuration settings of the compare/capture block and counter.
In TIMCLK cycles, the PWM period is (2 * TIMx.LOAD) and the duty cycle is 1 - (TIMx.CC_xy[0/1] / TIMx.LOAD).
Center-Aligned PWM Configuration
To generate center-aligned PWMs using compare match events from the counter:
- In the TIMx.CTRCTL register, set the desired counter control settings for:
- Up/down counting mode (CM = 1) and counter value after enable (CVAE) (see as described in Section 23.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 center-aligned PWM in up/down counting mode
A typical 2-channel center-aligned PWM generation using up/down counting mode is shown in Figure 23-30 with the following center-aligned
PWM output waveforms:
- CCP0 output generates:
- High pulse-width from TIMx.CC0 compare up event to TIMx.CC0 compare down event (CUACT = 1h)
- Low pulse-width from TIMx.CC0 compare down event to TIMx.CC0 compare up event (CDACT = 2h)
- CCP1 output generates:
- High pulse-width from TIMx.CC0 compare up event to TIMx.CC0 compare down event (CUACT = 1h)
- Low pulse-width from TIMx.CC0 compare down event to TIMx.CC0 compare up event (CDACT = 2h)