English
Language : 

PIC16LF18854 Datasheet, PDF (286/668 Pages) Microchip Technology – C Compiler Optimized RISC Architecture
PIC16(L)F18856/76
19.1.7
CHANGES IN SYSTEM CLOCK
FREQUENCY
The PWM frequency is derived from the system clock
frequency. Any changes in the system clock frequency
will result in changes to the PWM frequency. See
Section 6.0 “Oscillator Module (with Fail-Safe
Clock Monitor)” for additional details.
19.1.8 EFFECTS OF RESET
Any Reset will force all ports to Input mode and the
PWMx registers to their Reset states.
TABLE 19-1: EXAMPLE PWM FREQUENCIES AND RESOLUTIONS (FOSC = 20 MHz)
PWM Frequency
1.22 kHz 4.88 kHz 19.53 kHz 78.12 kHz 156.3 kHz
Timer Prescale
16
4
1
1
1
PR2 Value
Maximum Resolution (bits)
0xFF
10
0xFF
10
0xFF
10
0x3F
8
0x1F
7
208.3 kHz
1
0x17
6.6
TABLE 19-2: EXAMPLE PWM FREQUENCIES AND RESOLUTIONS (FOSC = 8 MHz)
PWM Frequency
1.22 kHz 4.90 kHz 19.61 kHz 76.92 kHz 153.85 kHz
Timer Prescale
16
4
1
1
1
PR2 Value
0xFF
0xFF
0xFF
0x3F
0x1F
Maximum Resolution (bits)
10
10
10
8
7
200.0 kHz
1
0x17
6.6
19.1.9 SETUP FOR PWM OPERATION
The following steps should be taken when configuring
the module for using the PWMx outputs:
1. Disable the PWMx pin output driver(s) by setting
the associated TRIS bit(s).
2. Configure the PWM output polarity by
configuring the PWMxPOL bit of the PWMxCON
register.
3. Load the PR2 register with the PWM period value,
as determined by Equation 19-1.
4. Load the PWMxDCH register and bits <7:6> of
the PWMxDCL register with the PWM duty cycle
value, as determined by Equation 19-2.
5. Configure and start Timer2:
• Clear the TMR2IF interrupt flag bit of the PIR1
register.
• Select the Timer2 prescale value by configuring
the T2CKPS<1:0> bits of the T2CON
register.
• Enable Timer2 by setting the TMR2ON bit of
the T2CON register.
6. Wait until the TMR2IF is set.
7. When the TMR2IF flag bit is set:
• Clear the associated TRIS bit(s) to enable the
output driver.
• Route the signal to the desired pin by
configuring the RxyPPS register.
• Enable the PWMx module by setting the
PWMxEN bit of the PWMxCON register.
In order to send a complete duty cycle and period on
the first PWM output, the above steps must be followed
in the order given. If it is not critical to start with a com-
plete PWM signal, then the PWM module can be
enabled during Step 2 by setting the PWMxEN bit of
the PWMxCON register.
DS40001824A-page 286
Preliminary
 2016 Microchip Technology Inc.