Capture/Compare/PWM (CCP)/Enhanced PWM (ECCP) Peripheral

The CCP/ECCP is a multipurpose peripheral module inside most PIC® MCU devices. The module includes four unique but related peripherals:

The Capture mode which will retrieve a timer value based on a signal event.

The Compare mode which will constantly monitor a timer counter value and compare it to a value set in the application. When they match, it will trigger an event.

The Pulse Width Modulation (PWM) will produce a variable pulse width signal based on a pulse width and period value set in the applications code.

The Enhanced Pulse Width Modulation (EPWM) will produce a variable pulse width signal based on a pulse width and period value set in the applications 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 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

The Compare Mode operates identical 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).

20th Annual
Microchip MASTERs Conference 2016
Register now - Deadline: July 29

JW Marriott Desert Ridge Resort-Phoenix, AZ

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.