Datasheet

Table Of Contents
2010 Microchip Technology Inc. Preliminary DS39979A-page 165
PIC18F87J72 FAMILY
16.4.3 SETUP FOR PWM OPERATION
The following steps should be taken when configuring
the CCP module for PWM operation:
1. Set the PWM period by writing to the PR2
register.
2. Set the PWM duty cycle by writing to the
CCPR2L register and CCP2CON<5:4> bits.
3. Make the CCP2 pin an output by clearing the
appropriate TRIS bit.
4. Set the TMR2 prescale value, then enable
Timer2 by writing to T2CON.
5. Configure the CCP2 module for PWM operation.
TABLE 16-5: REGISTERS ASSOCIATED WITH PWM AND TIMER2
Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Reset
Values
on Page
INTCON GIE/GIEH PEIE/GIEL
TMR0IE INT0IE RBIE TMR0IF INT0IF RBIF 49
RCON IPEN
CM RI TO PD POR BOR 50
PIR1 ADIF RC1IF TX1IF SSPIF —TMR2IFTMR1IF 52
PIE1 ADIE RC1IE TX1IE SSPIE —TMR2IETMR1IE 52
IPR1
ADIP RC1IP TX1IP SSPIP —TMR2IPTMR1IP 52
TRISC TRISC7 TRISC6 TRISC5 TRISC4 TRISC3 TRISC2 TRISC1 TRISC0 52
TRISE TRISE7 TRISE6 TRISE5 TRISE4 TRISE3 TRISE1 TRISE0 52
TRISG
SPIOD CCP2OD CCP1OD TRISG4 TRISG3 TRISG2 TRISG1 TRISG0 52
TMR2 Timer2 Register 50
PR2 Timer2 Period Register 50
T2CON
T2OUTPS3 T2OUTPS2 T2OUTPS1 T2OUTPS0 TMR2ON T2CKPS1 T2CKPS0 50
CCPR1L Capture/Compare/PWM Register 1 Low Byte 53
CCPR1H Capture/Compare/PWM Register 1 High Byte 53
CCP1CON
DC1B1 DC1B0 CCP1M3 CCP1M2 CCP1M1 CCP1M0 53
CCPR2L Capture/Compare/PWM Register 2 Low Byte 53
CCPR2H Capture/Compare/PWM Register 2 High Byte 53
CCP2CON
DC2B1 DC2B0 CCP2M3 CCP2M2 CCP2M1 CCP2M0 53
Legend: — = unimplemented, read as0. Shaded cells are not used by PWM or Timer2.