Microchip Technology DV164136 Data Sheet

Page of 466
PIC18F87J11 FAMILY
DS39778E-page 224
 
 2007-2012 Microchip Technology Inc.
19.4
Enhanced PWM Mode
The Enhanced PWM mode provides additional PWM
output options for a broader range of control applications.
The module is a backward compatible version of the
standard CCP module and offers up to four outputs,
designated PxA through PxD. Users are also able to
select the polarity of the signal (either active-high or
active-low). The module’s output mode and polarity are
configured by setting the PxM<1:0> and CCPxM<3:0>
bits of the CCPxCON register (CCPxCON<7:6> and
CCPxCON<3:0>, respectively).
For the sake of clarity, Enhanced PWM mode operation
is described generically throughout this section with
respect to the ECCP1 and TMR2 modules. Control reg-
ister names are presented in terms of ECCP1. All three
Enhanced modules, as well as the two timer resources,
can be used interchangeably and function identically.
TMR2 or TMR4 can be selected for PWM operation by
selecting the proper bits in T3CON.
 shows a simplified block diagram of PWM
operation. All control registers are double-buffered and
are loaded at the beginning of a new PWM cycle (the
period boundary when Timer2 resets) in order to
prevent glitches on any of the outputs. The exception is
the ECCPx PWM Delay register, ECCPxDEL, which is
loaded at either the duty cycle boundary or the bound-
ary period (whichever comes first). Because of the
buffering, the module waits until the assigned timer
resets instead of starting immediately. This means that
Enhanced PWM waveforms do not exactly match the
standard PWM waveforms, but are instead offset by
one full instruction cycle (4 T
OSC
).
As before, the user must manually configure the
appropriate TRIS bits for output.
19.4.1
PWM PERIOD
The PWM period is specified by writing to the PR2
register. The PWM period can be calculated using the
equation:
EQUATION 19-1:
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 ECCP1 pin is set (if PWM Duty Cycle = 0%, 
the ECCP1 pin will not be set)
• The PWM duty cycle is copied from CCPR1L into 
CCPR1H
FIGURE 19-1:
SIMPLIFIED BLOCK DIAGRAM OF THE ENHANCED PWM MODULE     
Note:
The Timer2 postscaler (see 
) is 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.
PWM Period = [(PR2) + 1] • 4 • T
OSC
 •
(TMR2 Prescale Value) 
CCPR1L
CCPR1H (Slave)
Comparator
TMR2
PR2
(Note 1)
R
Q
S
Duty Cycle Registers
CCP1CON<5:4>
Clear Timer,
set ECCP1 Pin and 
Latch D.C.
Note:
The 8-bit TMR2 register is concatenated with the 2-bit internal Q clock, or 2 bits of the prescaler, to create the 10-bit time base.
TRISx<x>
ECCP1/P1A
TRISx<x>
P1B
TRISx<x>
TRISx<x>
P1D
Output
Controller
P1M1<1:0>
2
CCP1M<3:0>
4
ECCP1DEL
ECCP1/P1A
P1B
P1C
P1D
P1C
Comparator