Pulse width capture measures the high-time of a signal on CCP. The high time is the number of TIMCLK periods from rising edge to falling edge of the CCP input, and is useful for applications such as measuring the duty cycle of an PWM input
signal. The counter is loaded at the positive edge and captured at the negative edge (capture event is generated).
Pulse-Width Capture Configuration
- Set the TIMx.LOAD value.
- In the CTRCTL register, set the desired counter control settings for:
- Counting mode (CM) and counter value after enable (CVAE) (see as described in Section 31.1.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 TIMx.CCCTL_xy[0/1].COC = 1 for capture mode.
- Configure CCP as an input for the CC block by setting respective bit in the CCPD registers. For instance, if TIMx Channel 0 is an input, set CCPD.C0CCP0 = 0.
- For the corresponding CC block control register (CCCTL_01[0/1]), set CCOND to the corresponding setting to capture events based off the input signal condition (rising and/or falling edge). Additionally, set ZCOND or LCOND depending on
the counting mode used.
- Configure input capture settings in the TIMx.IFCTL_xy[0/1] register as described in Section 31.1.2.3.1.1.
- Enable the counter by setting EN = 1 or waiting for a capture event to occur from the input edge.
Example using up-counting mode for pulse width capture
In up-counting mode starting from zero (CM = 2, CVAE = 2), TIMx channel 0 can be configured to generate a zero pulse and start the counter from the configured capture event (CCOND) by setting ZCOND to 1. To start the counter, a load
condition can be triggered from the CCP rising edge input by setting LCOND = 1.
The expected internal timing for a pulse width capture in up-counting mode using a rising and falling edge is shown in Figure 31-11.