PIC18F2331/2431/4331/4431
The maximum resolution (in bits) for a given device
oscillator and PWM frequency can be determined from
the following formula:
18.5 PWM Period
The PWM period is defined by the PTPER register pair
(PTPERL and PTPERH). The PWM period has 12-bit
resolution by combining 4 LSBs of PTPERH and 8 bits
of PTPERL. PTPER is a double-buffered register used
to set the counting period for the PWM time base.
EQUATION 18-4: PWM RESOLUTION
FOSC
FPWM
log
The PTPER register contents are loaded into the
PTPER register at the following times:
Resolution =
log(2)
• Free-Running and Single-Shot modes: When the
PTMR register is reset to zero after a match with
the PTPER register.
The PWM resolutions and frequencies are shown for a
selection of execution speeds and PTPER values in
Table 18-2. The PWM frequencies in Table 18-2 are
calculated for Edge-Aligned PWM mode. For
Center-Aligned mode, the PWM frequencies will be
approximately one-half the values indicated in this
table.
• Continuous Up/Down Count modes: When the
PTMR register is zero. The value held in the
PTPER register is automatically loaded into the
PTPER register when the PWM time base is
disabled (PTEN = 0). Figure 18-9 and
Figure 18-10 indicate the times when the contents
of the PTPER register are loaded into the actual
PTPER register.
TABLE 18-2: EXAMPLE PWMFREQUENCIES
AND RESOLUTIONS
PWM Frequency = 1/TPWM
The PWM period can be calculated from the following
formulas:
PTPER
PWM
PWM
FOSC
MIPS
Value Resolution Frequency
EQUATION 18-1: PWM PERIOD FOR
FREE-RUNNING MODE
40 MHz
40 MHz
40 MHz
40 MHz
40 MHz
40 MHz
40 MHz
40 MHz
40 MHz
10
10
10
10
10
10
10
10
10
0FFFh
07FFh
03FFh
01FFh
FFh
14 bits
13 bits
12 bits
11 bits
10 bits
9 bits
2.4 kHz
4.9 kHz
9.8 kHz
19.5 kHz
39.0 kHz
78.1 kHz
156.2 kHz
312.5 kHz
625 kHz
1.5 kHz
6.1 kHz
24.4 kHz
610 Hz
(PTPER + 1) x PTMRPS
TPWM =
FOSC/4
EQUATION 18-2: PWM PERIOD FOR
UP/DOWN COUNT MODE
7Fh
3Fh
8 bits
1Fh
7 bits
(2 x PTPER) x PTMRPS
TPWM =
0Fh
6 bits
FOSC
4
25 MHz 6.25 0FFFh
25 MHz 6.25 03FFh
14 bits
12 bits
10 bits
14 bits
12 bits
10 bits
14 bits
12 bits
10 bits
14 bits
12 bits
10 bits
The PWM frequency is the inverse of period; or:
25 MHz 6.25
FFh
10 MHz
10 MHz
10 MHz
5 MHz
5 MHz
5 MHz
4 MHz
4 MHz
4 MHz
2.5 0FFFh
EQUATION 18-3: PWM FREQUENCY
2.5
2.5
03FFh
FFh
2.4 kHz
9.8 kHz
305 Hz
1
PWM Frequency =
PWM Period
1.25 0FFFh
1.25 03FFh
1.2 kHz
4.9 kHz
244 Hz
1.25
FFh
0FFFh
03FFh
FFh
1
1
1
976 Hz
3.9 kHz
Note: For center-aligned operation, PWM frequencies
will be approximately 1/2 the value indicated in
the table.
2010 Microchip Technology Inc.
DS39616D-page 185