CCP and Eccp Pic PDF
CCP and Eccp Pic PDF
CCP and Eccp Pic PDF
HIGHLIGHTS
This section of the manual contains the following major topics:
60
CCP and ECCP
60.1 INTRODUCTION
Select PIC24 family devices incorporate one or more combined Capture/Compare/PWM (CCP)
modules. In addition, devices that use the CCP module may also include one or more Enhanced
CCP (ECCP) modules. These modules are identical to their counterparts found in PIC18 micro-
controllers, and provide many of the same features of the Input Capture and Output Compare
modules used in other PIC24F devices.
CCP and ECCP modules are differentiated by their PWM features. The standard CCP module
provides a single PWM output, while the ECCP module can drive up to four PWM outputs. The
enhanced PWM features make the ECCP module suitable for a variety of power and motor con-
trol applications. Because the CCP and ECCP modules otherwise share identical features, both
are described in this section.
Key features of all CCP modules include:
16-bit Input Capture for a range of edge events
16-bit Output Compare with multiple output options
Single output Pulse-Width Modulation with up to 10 bits of resolution
User-selectable time base from any available timer
Special Event Trigger on Capture and Compare events to automatically trigger a range of
peripherals
ECCP modules also include these features:
Operation in Half-Bridge and Full-Bridge (Forward and Reverse) modes
Pulse Steering Control across any or all Enhanced PWM pins, with user-configurable
steering synchronization
User-configurable External Fault Detect with Auto-Shutdown and Auto-Restart
As with other peripherals, CCP modules are numbered sequentially when more than one is
included in a particular device. When CCP and ECCP modules occur together, the ECCP
modules are assigned the lowest sequence numbers.
Note: Throughout this section, generic references are used for register and bit names that are
the same, except for an x variable that indicates the items association to a specific
CCP module. For the sake of clarity, all module operations are described generically,
and are equally applicable to all CCP modules. Similarly, all generic descriptions of
Enhanced PWM operations are equally applicable to all ECCP modules.
60.2 REGISTERS
Each CCP module contains at least three registers, one control register and two data registers
that combine to form a single, 16-bit virtual register. ECCP modules contain three additional reg-
isters to control Enhanced PWM features. Additional control registers are used to allocate timer
resources to the CCP and ECCP modules.
All registers are readable and writable.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
-n = Value at POR 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
Note 1: CCPxM<3:0> = 1011 will only reset the timer and not start the A/D conversion on CCPx match.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
-n = Value at POR 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
Note 1: CCPxM<3:0> = 1011 will only reset the timer and not start the A/D conversion on CCPx match.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
-n = Value at POR 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
Note 1: The auto-shutdown condition is a level-based signal, not an edge-based signal. As long as the level is
present, the auto-shutdown will persist.
2: Writing to the ECCPxASE bit is disabled while an auto-shutdown condition persists.
3: Once the auto-shutdown condition has been removed and the PWM restarted (either through firmware or
auto-restart), the PWM signal will always restart at the beginning of the next PWM period.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
-n = Value at POR 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
60
CCP and ECCP
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
-n = Value at POR 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
Note 1: The PWM Steering mode is available only when CCPxM<3:2> = 11 and PxM<1:0> = 00.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
-n = Value at POR 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
Note 1: This hypothetical configuration is based on a device with three CCP modules (one of which is an ECCP)
and three 8/16-bit timers. Actual devices may vary substantially. Refer to the device data sheet for a
specific family for the actual number of registers and their bit configuration.
60
CCP and ECCP
Set CCPxIF
CCPRxH CCPRxL
(E)CCPx Pin
Prescaler and TMR
1, 4, 16 Edge Detect Capture
TMRaH TMRaL
CCPxCON<3:0> 4
4
Q1:Q4
Note: TMRa and TMRb are generic references. The timers available to a specific CCP module are device-specific.
See Section 60.3.1 Timer Resources and Selection for more information.
60
CCP and ECCP
Compare Output S Q
Comparator
Match Logic
R
Output Enable
4
CCPxCON<3:0>
TMRaH TMRaL 0
1
TMRbH TMRbL 60
CCPTMRS
Timer Select
CCP and ECCP
Bits
Note: TMRa and TMRb are generic references; the timers available to a specific CCP module are device-specific.
See Section 60.3.1 Timer Resources and Selection for more information.
CCPRxL
CCPRxH (Slave)
Comparator R Q
CCPx
TMRc(2) (1) S
Output Enable
Comparator
Clear Timer,
CCP1 Pin and
Latch D.C.
PRc(2)
Note 1: The 8-bit TMRc value is concatenated with the 2-bit internal Q clock, or 2 bits of the prescaler, to create the 10-bit time base.
2: TMRc and PRc are generic timer references. See Section 60.3.1 Timer Resources and Selection for more information.
Period
Duty Cycle
Equation 60-1:
PWM Period = [(PR2) + 1] 2 TOSC (TMR2 Prescale Value)
The PWM frequency is defined as 1/[PWM period]. When TMR2 is equal to PR2, the following
three events occur on the next increment cycle:
TMR2 is cleared
The CCP4 pin is set (Exception: If the PWM Duty Cycle = 0%, the CCPx pin will not be set)
The PWM duty cycle is latched from CCPRxL into CCPRxH
Note: The Timer2 postscalers are not used in the determination of the PWM frequency.
The postscaler could be used to have a servo update rate at a different frequency
than the PWM output.
Equation 60-2:
PWM Duty Cycle (%) = (CCPRXL:CCPXCON<5:4>)/(4 PR2)
PWM Duty Cycle (time in s) = (CCPRXL:CCPXCON<5:4>) TOSC/2 (TMR2 Prescale Value)
CCPR4L and CCP4CON<5:4> can be written to at any time, but the duty cycle value is not
latched into CCPR4H until after a match between PR2 and TMR2 occurs (that is, the period is
complete). In PWM mode, CCPR4H is a read-only register.
The CCPR4H register and a two-bit internal latch are used to double-buffer the PWM duty cycle.
This double-buffering is essential for glitchless PWM operation.
When the CCPR4H and two-bit latch match TMR2, concatenated with an internal two-bit Q clock
or two bits of the TMR2 prescaler, the CCP4 pin is cleared.
The maximum PWM resolution (bits) for a given PWM frequency is shown in the following equation:
Equation 60-3:
2 Fosc
log --------------------
F PWM
PWM Resolution (max) = ---------------------------------- bits
log 2
Note: If the PWM duty cycle value is longer than the PWM period, the CCP4 pin will not
be cleared.
Note 1: The 8-bit TMR2 value is concatenated with the 2-bit internal Q clock, or 2 bits of the prescaler, to create the 10-bit time base.
2: TMRc and PRc are generic timer references. See Section 60.3.1 Timer Resources and Selection for more information.
Note 1: The STR<D:A> bits in the PSTRxCON register, for each PWM output, must be
configured appropriately.
2: Any pin not used by an Enhanced PWM mode is available for alternate pin functions.
PxA Active
PxD Modulated
PxA Inactive
PxD Inactive
Relationships:
Period = 2 * TOSC * (PR2 + 1) * (TMR2 Prescale Value)
Pulse Width = TOSC/2 * (CCPRxL<7:0>:ECCPxCON<5:4>) * (TMR2 Prescale Value)
Delay = 2 * TOSC * (ECCPxDEL<6:0>)
Note 1: Dead-band delay is programmed using the ECCPxDEL register (see Section 60.7.6 Programmable Dead-Band Delay Mode).
Pulse PR2 + 1
PxM<1:0> Signal 0
Width
Period
PxA Modulated
Delay(1) Delay(1)
10 (Half-Bridge) PxB Modulated
PxA Active
PxD Modulated
PxA Inactive
PxD Inactive
Relationships:
Period = 2 * TOSC * (PR2 + 1) * (TMR2 Prescale Value)
Pulse Width = TOSC/2 * (CCPRxL<7:0>:ECCPxCON<5:4>) * (TMR2 Prescale Value)
Delay = 2 * TOSC * (ECCPxDEL<6:0>)
Note 1: Dead-band delay is programmed using the ECCPxDEL register (see Section 60.7.6 Programmable Dead-Band Delay Mode).
Period Period
Pulse Width
PxA(2)
td
td
PxB(2)
(1) (1) (1)
td = Dead-Band Delay
Note 1: At this time, the TMR2 register is equal to the PR2 register.
2: Output signals are shown as active-high.
V+
Standard Half-Bridge Circuit (Push-Pull)
FET
Driver +
PxA V
-
Load
FET
Driver
+
PxB V
-
V-
Half-Bridge Output Driving a Full-Bridge Circuit
V+
FET FET
Driver Driver
PxA
Load
FET FET
Driver Driver
PxB
FET QA QC FET
Driver Driver
PxA
Load
PxB
FET FET
Driver Driver
PxC QD
QB
V-
PxD
PxA(2)
Pulse Width
(2)
PxB
PxC(2)
PxD(2)
(1) (1)
PxB(2)
60
PxC(2)
CCP and ECCP
PxD(2)
(1) (1)
Note 1: At this time, the TMR2 register is equal to the PR2 register.
2: The output signal is shown as active-high.
PxA (Active-High)
PxB (Active-High)
Pulse Width
PxC (Active-High)
(2)
PxD (Active-High)
Pulse Width
Note 1: The direction bit, PxM1 of the ECCPxCON register, is written any time during the PWM cycle.
2: When changing directions, the PxA and PxC signals switch before the end of the current PWM cycle. The
modulated PxB and PxD signals are inactive at this time. The length of this time is:
(1/FOSC) TMR2 Prescale Value.
Figure 60-13: Example of PWM Direction Change at Near 100% Duty Cycle
PxA
PxB
PW
PxC
PxD PW
TON
External Switch C
TOFF
External Switch D
60
CCP and ECCP
PWM Period
Shutdown Event
ECCPxASE bit
PWM Activity
Normal PWM
ECCPxASE
Cleared by
Start of Shutdown Shutdown Firmware PWM
PWM Period Event Occurs Event Clears Resumes
PWM Period
Shutdown Event
ECCPxASE bit
PWM Activity
Normal PWM
60
CCP and ECCP
STRA(2)
PxA Signal PxA Output
CCPxM1 1
PORT Data(1)
0
Output Enable
(2)
STRB
PORT Data(1) 0
Output Enable
STRC(2)
PORT Data(1) 0
Output Enable
STRD(2)
PORT Data(1)
0
Output Enable
Note 1: Port outputs are configured as displayed when the ECCPxCON register bits, PxM<1:0> = 00 and CCPxM<3:2> = 11.
2: Single PWM output requires setting at least one of the STR<D:A> bits.
PWM
STRn
P1n = PWM
PWM
STRn
P1n = PWM
60
CCP and ECCP
Reset
File Name Bit 15 Bit 14 Bit 13 Bit 12 Bit 11 Bit 10 Bit 9 Bit 8 Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
State
ECCPxCON PxM1 PxM0 DCxB1 DCxB0 CCPxM3 CCPxM2 CCPxM1 CCPxM0 0000
ECCPRxL Capture/Compare/PWM Register Low Byte 0000
ECCPRxH Capture/Compare/PWM Register High Byte 0000
ECCPxDEL PxRSEN PxDC6 PxDC5 PxDC4 PxDC3 PxDC2 PxDC1 PxDC0 0000
ECCPxAS ECCPxASE ECCPxAS2 ECCPxAS1 ECCPxAS0 PSSxAC1 PSSxAC0 PSSxBD1 PSSxBD0 0000
PSTRxCON CMPL1 CMPL0 STRSYNC STRD STRC STRB STRA 0001
Legend: = unimplemented, read as 0. Reset values are shown in hexadecimal.
DS30673A-page 60-27
60
Note: Please visit the Microchip web site (www.microchip.com) for additional Application
Notes and code examples for the PIC24F family of devices.
60
CCP and ECCP
NOTES:
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchips Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
Microchip is willing to work with the customer who is concerned about the integrity of their code.
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as unbreakable.
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchips code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
ISBN: 978-1-61341-762-1