Capture/Compare/PWM (CCP)/Enhanced PWM (ECCP) Peripheral
Contents
The CCP/ECCP is a multipurpose peripheral module inside most of the PIC® MCU devices. The module includes four unique but related peripherals:
- Capture mode - retrieves a timer value based on a signal event.
- Compare mode - constantly monitors a timer counter value and compares it to a value set in the application. Compare mode will trigger an event when the values match.
- Pulse Width Modulation (PWM) - produces a variable pulse width signal based on a pulse width and period value set in the application's code.
- Enhanced Pulse Width Modulation (EPWM) - produces a variable pulse width signal based on a pulse width and period value set in the application's code along with auto-shutdown, auto-restart, dead-band delay, and PWM steering modes. In addition, the EPWM can drive various PWM arrangements:
- Single PWM
- Half-Bridge PWM
- Full-Bridge PWM, Forward Mode
- Full-Bridge PWM, Reverse Mode
- Single PWM with PWM Steering Mode
Capture/Compare/PWM Control Register (CCPCON)
The four modes of operation are selected and controlled by the Capture/Compare/PWM Control Register CCPCON.
CCPxCON: CCPx Control Register
R/W-0 | R/W-0 | R/W-0 | R/W-0 | R/W-0 | R/W-0 | R/W-0 | R/W-0 |
PxM1 | PxM0 | DCxB1 | DCxB0 | CCPxM3 | CCPxM2 | CCPxM1 | CCPxM0 |
bit 7 | bit 0 |
bit 3-0
CCPxM<3:0>: CCP/ECCP Mode Select bits
All Modes Off
0000 = Capture/Compare/PWM off (resets ECCPx module)
Capture Settings
0100 = Capture mode: every falling edge
0101 = Capture mode: every rising edge
0110 = Capture mode: every 4th rising edge
0111 = Capture mode: every 16th rising edge
Compare Settings
0010 = Compare mode: toggle output on match
1000 = Compare mode: initialize ECCPx pin low; set output on compare match (set CCPxIF)
1001 = Compare mode: initialize ECCPx pin high; clear output on compare match (set CCPxIF)
1010 = Compare mode: generate software interrupt only; ECCPx pin reverts to I/O state
1011 = Compare mode: Special Event Trigger
CCP Modules Only
11xx = PWM mode
ECCP Modules only
1100 = PWM mode: PxA, PxC active-high; PxB, PxD active-high
1101 = PWM mode: PxA, PxC active-high; PxB, PxD active-low
1110 = PWM mode: PxA, PxC active-low; PxB, PxD active-high
1111 = PWM mode: PxA, PxC active-low; PxB, PxD active-low
CCPxCON: CCPx Control Register
R/W-0 | R/W-0 | R/W-0 | R/W-0 | R/W-0 | R/W-0 | R/W-0 | R/W-0 |
PxM1 | PxM0 | DCxB1 | DCxB0 | CCPxM3 | CCPxM2 | CCPxM1 | CCPxM0 |
bit 7 | bit 0 |
bit 5-4
DCxB<1:0>: PWM Duty Cycle Least Significant bits
PWM Mode Only
These bits are the two LSbs of the PWM duty cycle. The eight MSbs are found in the CCPRxL register.
CCPxCON: CCPx Control Register
R/W-0 | R/W-0 | R/W-0 | R/W-0 | R/W-0 | R/W-0 | R/W-0 | R/W-0 |
PxM1 | PxM0 | DCxB1 | DCxB0 | CCPxM3 | CCPxM2 | CCPxM1 | CCPxM0 |
bit 7 | bit 0 |
bit 7-6
PxM<1:0>: Enhanced PWM Output Configuration bits
If CCPxM<3:2> = 00, 01, 10
xx = PxA assigned as Capture/Compare input; PxB, PxC, PxD assigned as port pins
If CCPxM<3:2> = 11
00 = Single output; PxA modulated; PxB, PxC, PxD assigned as port pins
01 = Full-Bridge output forward; PxD modulated; PxA active; PxB, PxC inactive
10 = Half-Bridge output; PxA, PxB modulated with dead-band control; PxC, PxD assigned as port pins
11 = Full-Bridge output reverse; PxB modulated; PxC active; PxA, PxD inactive
Compare mode operates identically for both CCPx and ECCPx peripherals. Compare mode makes use of the 16-bit Timer1 peripheral. The 16-bit value of the combined 8-bit Compare register pair; CCPRxH:CCPRxL is constantly compared against the 16-bit value of the Timer1 register pair; TMR1H:TMR1L. When a match occurs, one of the following events can occur:
- Toggle the CCPx output pin
- Set the CCPx output pin
- Clear the CCPx output pin
- Generate a Special Event Trigger
- Generate a Software Interrupt
The event action is based on the value of the CCPxM<3:0> control bits of the CCPxCON register. At the same time, the interrupt flag CCPxIF bit is set. All Compare modes can generate an interrupt (except for the Special Event Mode).