English
Language : 

PIC18F2331 Datasheet, PDF (195/396 Pages) Microchip Technology – 28/40/44-Pin Enhanced Flash Microcontrollers with nanoWatt Technology, High Performance PWM and A/D
PIC18F2331/2431/4331/4431
17.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.
The PTPER buffer contents are loaded into the PTPER
register at the following times:
• Free Running and Single-shot modes: when the
PTMR register is reset to zero after a match with
the PTPER register.
• Up/Down Counting modes: When the PTMR
register is zero. The value held in the PTPER
buffer is automatically loaded into the PTPER
register when the PWM time base is disabled
(PTEN = 0). Figure 17-9 and Figure 17-10
indicate the times when the contents of the
PTPER buffer are loaded into the actual PTPER
register.
The PWM period can be calculated from the following
formulas:
EQUATION 17-1: PWM PERIOD FOR FREE
RUNNING MODE
(PTPER + 1)
TPWM =
Fosc/(PTMRPS/4)
or
(PTPER + 1) x PTMRPS
TPWM =
Fosc/4
EQUATION 17-2: PWM PERIOD FOR
UP/DOWN COUNTING
MODE
(2 x PTPER)
TPWM =
Fosc/(PTMRPS/4)
The PWM frequency is the inverse of period; or
PWM frequency = ---------------1---------------
PWM period
The maximum resolution (in bits) for a given device
oscillator and PWM frequency can be determined from
the following formula:
EQUATION 17-3: PWM RESOLUTION
Fosc/4
log Fpwm
Resolution = log(2)
The PWM resolutions and frequencies are shown for a
selection of execution speeds and PTPER values in
Table 17-2. The PWM frequencies in Table 17-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.
TABLE 17-2: EXAMPLE PWM
FREQUENCIES AND
RESOLUTIONS
PWM Frequency = 1/TPWM
Fosc
MIPS
PTPER
Value
PWM
Resolution
PWM
Frequency
40 MHz 10 0FFFh
40 MHz 10 07FFh
40 MHz 10 03FFh
14 bits
13 bits
12 bits
2.4 kHz
4.9 kHz
9.8 kHz
40 MHz 10 01FFh
40 MHz 10 FFh
40 MHz 10 7Fh
40 MHz 10 3Fh
40 MHz 10 1Fh
40 MHz 10 0Fh
11 bits
10 bits
9 bits
8 bits
7 bits
6 bits
19.5 kHz
39.0 kHz
78.1 kHz
156.2 kHz
312.5 kHz
625 kHz
25 MHz
25 MHz
25 MHz
10 MHz
10 MHz
10 MHz
6.25 0FFFh
6.25 03FFh
6.25 FFh
2.5 0FFFh
2.5 03FFh
2.5 FFh
14 bits
12 bits
10 bits
14 bits
12 bits
10 bits
1.5 kHz
6.1 kHz
24.4 kHz
610 Hz
2.4 kHz
9.8 kHz
5 MHz
5 MHz
5 MHz
4 MHz
4 MHz
4 MHz
1.25 0FFFh
1.25 03FFh
1.25 FFh
1 0FFFh
1 03FFh
1 FFh
14 bits
12 bits
10 bits
14 bits
12 bits
10 bits
305 Hz
1.2 kHz
4.9 kHz
244 Hz
976 Hz
3.9 kHz
Note: For center-aligned operation, PWM frequencies will
be approximately 1/2 the value indicated in the table.
 2003 Microchip Technology Inc.
Preliminary
DS39616B-page 193