Datasheet
PICkit™ 3 Debug Express Lessons
© 2009 Microchip Technology Inc. DS41370C-page 71
FIGURE 3-61: CCPXCON: CCPX CONTROL REGISTER
For more information on Timer2 see Section 13.0 “Timer2 Module” of the
PIC18F45K20 Data Sheet (DS41303). More info on the CCP module PWM
functionality can be found in Section 15.0 “Capture/Compare/PWM (CCP) Module”,
and Section 15.4 “PWM Mode”.
3.12.3 Exploring the Lesson 12 Source Code
The PWM signal from the CCP1 module is normally output on the CCP1/RC2 pin.
However, this pin is not connected to any demo board LEDs. To output a signal on an
LED pin, the Enhanced CCP module (ECCP) on the PIC18F45K20 is utilized. This
functionality is selected in the upper 2 bits of CCP1CON (P1Mx), which are set to 0b01
so the modulated PWM signal appears on the P1D/RD7 which drives LED 7. No other
aspect of the enhanced PWM functionality is used; for more information see Section
16.0 “Enhanced Capture/Compare/Pwm (ECCP) Module”.
The first thing done in the lesson source code is to set PWM pin RD7 to an output.
TRISDbits.TRISD7 = 0;
Timer2 is then configured to generate the PWM period of 16 ms as discussed
previously in this lesson.
T2CON = 0b00000111;// Prescale = 1:16, timer on
PR2 = 249;// Timer 2 Period Register = 250 counts