Microchip Technology MA160014 Data Sheet
PIC18(L)F2X/4XK22
DS41412F-page 202
2010-2012 Microchip Technology Inc.
14.4.8
SETUP FOR ECCP PWM
OPERATION USING ECCP1 AND
TIMER2
OPERATION USING ECCP1 AND
TIMER2
The following steps should be taken when configuring
the ECCP1 module for PWM operation using Timer2:
the ECCP1 module for PWM operation using Timer2:
1.
Configure the PWM pins to be used (P1A, P1B,
P1C, and P1D):
P1C, and P1D):
• Configure PWM outputs to be used as inputs
by setting the corresponding TRIS bits. This
prevents spurious outputs during setup.
prevents spurious outputs during setup.
• Set the PSTR1CON bits for each PWM
output to be used.
2.
Select Timer2 as the period timer by configuring
CCPTMR0 register bits C1TSEL<1:0> = ‘00’.
CCPTMR0 register bits C1TSEL<1:0> = ‘00’.
3.
Set the PWM period by loading the PR2 register.
4.
Configure auto-shutdown as OFF or select the
source with the CCP1AS<2:0> bits of the
ECCP1AS register.
source with the CCP1AS<2:0> bits of the
ECCP1AS register.
5.
Configure the auto-shutdown sources as
needed:
needed:
• Configure each comparator used.
• Configure the comparator inputs as analog.
• Configure the FLT0 input pin and clear
ANSB0.
6.
Force a shutdown condition (OFF included):
• Configure safe starting output levels by
setting the default shutdown drive states with
the PSS1AC<1:0> and PSS1BD<1:0> bits of
the ECCP1AS register.
the PSS1AC<1:0> and PSS1BD<1:0> bits of
the ECCP1AS register.
• Clear the P1RSEN bit of the PWM1CON
register.
• Set the CCP1AS bit of the ECCP1AS
register.
7.
Configure the ECCP1 module for the desired
PWM mode and configuration by loading the
CCP1CON register with the appropriate values:
PWM mode and configuration by loading the
CCP1CON register with the appropriate values:
• Select one of the available output configura-
tions and direction with the P1M<1:0> bits.
• Select the polarities of the PWM output
signals with the CCP1M<3:0> bits.
8.
Set the 10-bit PWM duty cycle:
• Load the eight MSbs into the CCPR1L
register.
• Load the two LSbs into the DC<1:0> bits of
the CCP1CON register.
9.
For Half-Bridge Output mode, set the dead-
band delay by loading P1DC<6:0> bits of the
PWM1CON register with the appropriate value.
band delay by loading P1DC<6:0> bits of the
PWM1CON register with the appropriate value.
10. Configure and start TMR2:
• Set the TMR2 prescale value by loading the
T2CKPS bits of the T2CON register.
• Start Timer2 by setting the TMR2ON bit.
11. Enable the ECCP1/P1A, P1B, P1C and/or P1D
pin outputs by clearing the respective TRIS bits.
12. Start the PWM:
• If shutdown auto-restart is used, then set the
P1RSEN bit of the PWM1CON register.
• If shutdown auto-restart is not used, then
clear the CCP1ASE bit of the ECCP1AS
register.
register.