Note the following details of the code protection feature on Microchip devices:
•Microchip products meet the specification contained in their particular Microchip Data Sheet.
•Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•Microchip is willing to work with the customer who is concerned about the integrity of their code.
•Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digit al Millennium Copyright Act. If suc h a c t s
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is intended through suggestion only
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
No representation or warranty is given and no liability is
assumed by Microchip Technology Incorporated with respect
to the accuracy or use of such information, or infringement of
patents or other intellectual property rights arising from such
use or otherwise. Use of Microchip’s products as critical
components in life support systems is not authorized except
with express written approval by Microchip. No licenses are
conveyed, implicitly or otherwise, under any intellectual
property rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, K
EELOQ, microID, MPLAB, PIC, PICmicro, PICSTART,
PRO MATE, PowerSmart, rfPIC, and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, MXDEV, MXLAB, PICMASTER, SEEVAL,
SmartSensor and The Embedded Control Solutions Company
are registered trademarks of Microchip Technology
Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, dsPICDEM,
dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR,
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial
Programming, ICSP, ICEPIC, Migratable Memory, MPASM,
MPLIB, MPLINK, MPSIM, PICkit, PICDEM, PICDEM.net,
PICLAB, PICtail, PowerCal, PowerInfo, PowerMate,
PowerTool, rfLAB, rfPICDEM, Select Mode, Smart Serial,
SmartTel and Total Endurance are trademarks of Microchip
Technology Incorporated in the U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
Microchip received ISO/TS-16949:2002 quality system certification for
its worldwide headquarters, design and wafer fabrication facilities in
Chandler and Tempe, Arizona and Mountain View, California in
October 2003. The Company’s quality system processes and
procedures are for its PICmicro
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
®
8-bit MCUs, KEELOQ
®
code hopping
DS39636A-page iiPreliminary 2004 Microchip Technology Inc.
PIC18F2X1X/4X1X
28/40/44-Pin Flash Microcontrollers with
10-bit A/D and nanoWatt Technology
Power Managed Modes:
• Run: CPU on, peripheral s on
• Idle: CPU off, peripheral s on
• Sleep: CPU off, peripherals off
• Idle mode currents down to 3.0 µA typical
• Sleep mode currents down to 20 nA typical
• Timer1 Oscillator: 1.8 µA, 32 kHz, 2V
• Watchdog Timer: 2.1 µA
• T wo -Spe ed Os ci ll ator Start-up
Peripheral Highlights:
• High-current sink/source 25 mA/25 mA
• Up to 2 Capture/Compare/PWM (CCP) modules,
one with Auto-Shutdown (28-pin devices)
• Enhanced Capture/Compare/PWM (ECCP)
module (40/44-pin devices only):
- One, two or four PWM outputs
- Selectable polarity
- Programmable dead time
- Auto-Shutdown and Auto-Restart
• Master Synchronous Serial Port (MSSP) module
supporting 3-wire SPI™ (all 4 modes) and I
Master and Slave Modes
• Enhanced Addressable USART module:
- Supports RS-485, RS-232 and LIN 1.2
- RS-232 operation using internal oscillator
block (no external cryst a l requi red)
- Auto-Wake-up on Start bit
- Auto-Baud Detect
• 10-bit, up to 13-channel Analog-to-Digital
Converter module (A/D):
16.0 Master Synchronous Serial Port (MSSP) Module ............................................................................... .....................................151
22.0 Special Features of the CPU.......... ................. ................ ................. ................. ....................................................................... 237
23.0 Instruction Set Summary.......................................................................................................................................................... 257
24.0 Development Support............................................................................................................................................................... 307
26.0 DC and AC Characteristics Graphs And Tables ......................................................................................................................351
27.0 Packaging Informa tio n. ................................................ ................. ............................................................................................ 353
Appendix D: Migration From Baseline to Enhanced Devices ............................................................................................................ 362
Appendix E: Migration From Mid-Range to Enhanced Devices.........................................................................................................363
Appendix F: Migration From High-End to Enhanced Devices............................................................................................................363
Index ................................................................................................................................................................................................. 365
Systems Information and Upgrade Hot Line...................................................................................................................................... 375
It is our intention to provide our valued customers with the best documentation possible to ensure successful use of your Microchip
products. To this end, we will continue to improve our publications to better suit your needs. Our publications will be refined and
enhanced as new volumes and updates are introduced.
If you have any questions or c omm ents regarding t his publication, p lease c ontact the M arket ing Co mmunications Department via
E-mail at docerrors@mail.microchip.com or fax the Reader Response Form in the back of this data sheet to (480) 792-4150.
We welcome your feedback.
Most Current Data Sheet
To obtain the most up-to-date version of this data sheet, please register at our Worldwide Web site at:
http://www.microchip.com
You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page.
The last character of the literature number is the version number, (e.g., DS30000A is version A of document DS30000).
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current
devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision
of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Microchip’s Worldwide Web site; http://www.microchip.com
• Your local Microchip sales office (see last page)
• The Microchip Corporate Literature Center; U.S. FAX: (480) 792-7277
When contacting a sales office or the literature center, please specify which device, revision of silicon and data sheet (include
literature number) you are using.
Customer Notification System
Register on our Web site at www.microchip.com/cn to receive the most current information on all of our products.
DS39636A-page 6Preliminary 2004 Microchip Technology Inc.
PIC18F2X1X/4X1X
1.0DEVICE OVERVIEW
This documen t conta i ns dev ic e spec if i c in for m at i on fo r
the following devices:
• PIC18F2410• PIC18LF2410
• PIC18F2510• PIC18LF2510
• PIC18F2515• PIC18LF2515
• PIC18F2610• PIC18LF2610
• PIC18F4410• PIC18LF4410
• PIC18F4510• PIC18LF4510
• PIC18F4515• PIC18LF4515
• PIC18F4610• PIC18LF4610
This family offers the advantages of all PIC18
microcontrollers – namely, high computational
performance at an economical price – with the addition
of high-endurance, Flash program memory. On top of
these features, the PIC18F2X1X/4X1X family introduces
design enhancements that make these microcontrollers
a logical choice for many high-performance, power
sensitive applications.
1.1New Core Features
1.1.1nanoWatt TECHNOLOGY
All of the devices in the PIC18F2X1X/4X1X family
incorporate a range of features that can significantly
reduce power consumption during operation. Key
items include:
• Alternate Run Modes: By clocking the controller
from the Timer1 source or the internal oscillator
block, power consumption during code execution
can be reduced by as much as 90%.
• Multiple Idle Modes: The controller can also run
with its CPU core disabled but the peripherals still
active. In these st ates, powe r consumpt ion can be
reduced even further, to as little as 4% of normal
operation requirements.
• On-the-fly Mode Switching: The power
managed modes a re invo ked b y user code durin g
operation, allowing the user to incorporate powersaving ideas into their application’s software
design.
• Lower Consumption in Key Modules: The
power requirements for both Timer1 and the
Watchdog Timer have been minimized. See
Section 25.0 “Electrical Characteristics” for
values.
1.1.2MULTIPLE OSCILLATOR OPTIONS
AND FEATURES
All of the devices in th e PIC 18F2X1X/ 4X1X fam ily of f er
ten different oscillator options, allowing users a wide
range of choices in developing application hardware.
These include:
• Four Crystal modes, using crystals or ceramic
resonators
• Two External Clock modes, offering the option of
using two pins (oscillator input and a divide-by-4
clock output) or one pin (oscillator input, with the
second pin reassigned as general I/O)
• Two External RC Oscillator modes with the same
pin options as the External Clock modes
• An internal oscillator block which provides an
8 MHz clock and an INTRC source (approximately 31 kHz), as well as a range of 6 user
selectable cl ock fre quenc ies, be tween 125 kHz to
4 MHz, for a total of 8 clock frequencies. This
option frees the two oscillator pins for use as
additional general purpose I/O.
• A Phase Lock Loop (PLL) frequency multiplier,
available to both the high-speed crystal and
internal oscillator modes, which allows clock
speeds of up to 40 MHz. Used with the internal
oscillator, the PLL gi ves users a complete sele ction
of clock speeds, from 31 kHz to 32 MHz – all
without using an external crystal or clock circuit.
Besides its ava ilability as a cloc k source, the intern al
oscillator block pro vid es a s t ab le re fere nce source that
gives the family additional features for robust
operation:
• Fail-Safe Clock Monitor: This option constantly
monitors the main clock source against a
reference signal provided by the internal
oscillator. If a clock failure occurs, the controller i s
switched to the internal oscillator block, allowing
for continued low-speed operation or a safe
application shutdown.
• Two-Speed Start-up: This option allows the
internal oscillator to serve as the clock source
from Power-on Reset, or wake-up from Sleep
mode, until the primary clock source is available.
• Memory Endurance: The Flas h cells f or prog ram
memory are rated to 100,000 erase/write cycles.
Data retention without refresh is conservatively
estimated to be greater than 40 years.
• Extended Instruction Set: The PIC18F2X1X/
4X1X family introduces an optional extension to
the PIC18 instruction set, which adds 8 new
instructions and an Indexed Addressing mode.
This extension, en abled as a de vi ce conf igurati on
option, has been specifi cally des igned to opt imize
re-entrant applica tion cod e origina lly deve loped in
high-level languages, such as C.
• Enhanced CCP Module: In PWM mode, this
module provides 1, 2 or 4 modulated outputs for
controlling half-bridge and full-bridge drivers.
Other features include Auto-S hutdown, for
disabling PWM output s on interrup t or other selec t
conditions and Auto-Rest art, to re activ ate outpu ts
once the condition has cleared.
• Enhanced Addressable USART: This serial
communication module is capable of standard
RS-232 operation an d provides support for th e LIN
bus protocol. Other enhancements include automatic baud r ate detection and a 16-bit Baud Rate
Generator for improved resolution. When the
microcontroller is using the internal oscillator
block, the USART provides stable operation for
applications that talk to the outside world without
using an external crystal (or its accompanying
power requirement).
• 10-bit A/D Converter: This module incorporates
programmable acquisition time, allowing for a
channel to be selected and a conversion to be
initiated withou t wai ting for a sampling period and
thus, reduce code overhead.
• Extended Watchdog Timer (WDT): This
enhanced version in corpora tes a 1 6-bit pre scale r,
allowing an extende d time-o ut rang e that is s ta ble
across operating voltage and temperature. See
Section 25.0 “Electrical Characteristics” for
time-out periods.
1.3Details on Individual Family
Members
Devices in the PIC18F2X1X/4X1X family are available
in 28-pin and 40/44-pin packages. Block diagrams for
the two group s are shown in Figure 1-1 and Figure 1-2.
The devices are differentiated from each other in five
ways:
1.Flash program memory
• 16 Kbytes for PIC18F2410/4410 devices
• 32 Kbytes for PIC18F2510/4510 devices
• 48 Kbytes for PIC18F2515/4515 devices
• 64 Kbytes for PIC18F2610/4610 devices
2.A/D channels (10 for 28-pin devices, 13 for
40/44-pin devices).
3.I/O ports (3 bidirectio nal ports on 28-pin devices,
5 bidirectional ports on 40/44-pin devices).
4.CCP and Enhanced CCP implementation (28-pin
devices have 2 s tandard CCP modules; 40/4 4-pin
devices have one standard CCP module and one
ECCP module).
5.Parallel Slave Port (present only on 40/44-pin
devices).
All other features fo r device s in this family are identi cal.
These are summarized in Table 1-1.
The pinouts for all devices are listed in Table 1-3 and
Table 1-4.
Like all Microchip PIC18 devices, members of the
PIC18F2X1X/4X1X family are available as both
standard and low-voltage devices. Standard devices
with Flash memory, designated with an “F” in the part
number (such as PIC18F2610), accommodate an
operating V
parts, designated by “LF” (such as PIC18LF2610),
function over an extended VDD range of 2.0V to 5.5V.
DD range of 4.2V to 5.5V. Low-voltage
DS39636A-page 8Preliminary 2004 Microchip Technology Inc.
PIC18F2X1X/4X1X
T ABLE 1-1:DEVICE FEATURES (PIC18F2410/2510/2515/2610)
FeaturesPIC18F2410PIC18F2510PIC18F2515PIC18F2610
Operating FrequencyDC – 40 MHzDC – 40 MHzDC – 40 MHzDC – 40 MHz
Program Memory (Bytes)16384327684915265536
Program Memory
(Instructions)
Data Memory (Bytes)768153639683968
Interrupt Sources18181818
I/O PortsPorts A, B, C, (E)Ports A, B, C, (E)Ports A, B, C, (E)Ports A, B, C, (E)
Timers4444
Capture/Compare/PWM Modules2222
Enhanced
Capture/Compare/PWM Modules
Serial CommunicationsMSSP,
Note 1: CCP2 is multiplexed with RC1 when configuration bit CCP2MX is set, or RB3 when CCP2MX is not set.
2: RE3 is only available when MCLR
3: OSC1/CLKI and OSC2/CLKO are only available in select oscillator modes and when these pins are not being used as digital I/O.
Refer to Section 2.0 “Oscillator Configurations” for additional information.
Note 1: CCP2 is multiplexed with RC1 when configuration bit CCP2MX is set, or RB3 when CCP2MX is not set.
2: RE3 is only available when MCLR
3: OSC1/CLKI and OSC2/CLKO are only available in select oscillator modes and when these pins are not being used as digital I/O.
Refer to Section 2.0 “Oscillator Configurations ” for additional information.
CCP2
MSSP
functionality is disabled.
Timer2Timer1Timer3Timer0
EUSARTComparator
W
8
ALU<8>
8
8
ADC
10-bit
8
8
8
PORTD
PORTE
RD0/PSP0
RE0/RD/AN5
RE1/WR/AN6
RE2/CS/AN7
MCLR/VPP/RE3
:RD4/PSP4
(2)
DS39636A-page 12Preliminary 2004 Microchip Technology Inc.
PIC18F2X1X/4X1X
T ABLE 1-3:PIC18F2410/2510/2515/2610 PINOUT I/O DESCRIPTIONS
ST = Schmitt Trigger input with CMOS levels I= Input
O=Output P =Power
Note 1: Default assignment for CCP2 when configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when configuration bit CCP2MX is cleared.
126
96
107
P
I/O
O
O
I/O
I
I
I
I
ST
ST
ST
CMOS
TTL
—
—
TTL
Master Clear (input) or programming voltage (input).
Master Clear (Reset) input. This pin is an active-low
Reset to the device.
Programming voltage input.
Digital input.
Oscillator crystal or external clock input.
Oscillator crystal input or external clock source input.
ST buffer when configured in RC mode; CMOS otherwise.
External clock source input. Always associated with pin
function OSC1. (See related OSC1/CLKI, OSC2/CLKO
pins.)
General purpose I/O pin.
Oscillator crystal or clock output.
Oscillator crystal output. Connects to crystal or
resonator in Crystal Oscillator mode.
In RC mode, OSC2 pin outputs CLKO, which has 1/4 the
frequency of OSC1 and denotes the instruction cycle rate.
General purpose I/O pin.
Digital I/O.
Capture 1 input/Compare 1 output/PWM 1 output.
Digital I/O.
Synchronous serial clock input/output for SPI™ mode.
Synchronous serial clock input/output for I
Digital I/O.
SPI data in.
I2C data I/O.
Digital I/O.
SPI data out.
Digital I/O.
EUSART asynchronous transmit.
EUSART synchronous clock (see related RX/DT).
Digital I/O.
EUSART asynchronous receive.
EUSART synchronous data (see related TX/CK).
/VPP/RE3 pin.
Description
2
C™ mode.
DS39636A-page 16Preliminary 2004 Microchip Technology Inc.
PIC18F2X1X/4X1X
T ABLE 1-4:PIC18F4410/4510/4515/4610 PINOUT I/O DESCRIPTIONS
Pin Name
Pin Number
PDIPQFN TQFP
Pin
Type
Buffer
Type
Description
/VPP/RE3
MCLR
MCLR
VPP
RE3
OSC1/CLKI/RA7
OSC1
CLKI
RA7
OSC2/CLKO/RA6
OSC2
CLKO
RA6
Legend: TTL = TTL compatible input CMOS = CMOS compatib le input or output
ST = Schmitt Trigger input with CMOS levels I= Input
O=Output P=Power
Note 1: Default assignment for CCP2 when configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when configuration bit CCP2MX is cleared.
11818
133230
143331
P
I/O
O
O
I/O
Master Clear (input) or programming voltage (input).
I
ST
I
ST
I
ST
I
CMOS
TTL
—
—
TTL
Master Clear (Reset) input. This pin is an ac tive-low
Reset to the device.
Programming voltage input.
Digital input.
Oscillator crystal or external clock input.
Oscillator crystal input or external clock source input.
ST buffer when configured in RC mode;
analog otherwise.
External clock source input. Always associated with
pin function OSC1. (See related OSC1/CLKI,
OSC2/CLKO pins.)
General purpose I/O pin.
Oscillator crystal or clock output.
Oscillator crystal output. Connects to crystal
or resonator in Crystal Oscillator mode.
In RC mode, OSC2 pin outputs CLKO, which
has 1/4 the frequency of OSC1 and denotes
the instruction cycle rate.
General purpose I/O pin.
Digital I/O.
Capture1 input/Compare1 output/PWM1 output.
Enhanced CCP1 output.
Digital I/O.
Synchronous serial clock input/output for
SPI™ mode.
Synchronous serial clock input/output for I
Digital I/O.
SPI data in.
2
C data I/O.
I
Digital I/O.
SPI data out.
Digital I/O.
EUSART asynchronous transmit.
EUSART synchronous clock (see related RX/DT).
Digital I/O.
EUSART asynchronous receive.
EUSART synchronous data (see related TX/CK).
Description
2
C™ mode.
DS39636A-page 20Preliminary 2004 Microchip Technology Inc.
PIC18F2X1X/4X1X
T ABLE 1-4:PIC18F4410/4510/4515/4610 PINOUT I/O DESCRIPTIONS (CONTINUED)
Pin Name
RD0/PSP0
RD0
PSP0
RD1/PSP1
RD1
PSP1
RD2/PSP2
RD2
PSP2
RD3/PSP3
RD3
PSP3
RD4/PSP4
RD4
PSP4
RD5/PSP5/P1B
RD5
PSP5
P1B
RD6/PSP6/P1C
RD6
PSP6
P1C
RD7/PSP7/P1D
RD7
PSP7
P1D
Legend: TTL = TTL compatible input CMOS = CMOS compatib le input or output
ST = Schmitt Trigger input with CMOS levels I= Input
O=Output P=Power
Note 1: Default assignment for CCP2 when configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when configuration bit CCP2MX is cleared.
Pin Number
PDIPQFN TQFP
193838
203939
214040
224141
2722
2833
2944
3055
Pin
Buffer
Type
Type
I/O
I/OSTTTL
I/O
I/OSTTTL
I/O
I/OSTTTL
I/O
I/OSTTTL
I/O
I/OSTTTL
I/O
I/O
O
I/O
I/O
O
I/O
I/O
O
Description
PORTD is a bidirectional I/O port or a Parallel Slave
Port (PSP) for interfacing to a microprocessor port.
These pins have TTL input buffers when PSP module
is enabled.
Digital I/O.
Parallel Slave Port data.
Digital I/O.
Parallel Slave Port data.
Digital I/O.
Parallel Slave Port data.
Digital I/O.
Parallel Slave Port data.
Digital I/O.
Parallel Slave Port data.
ST
TTL
—
ST
TTL
—
ST
TTL
—
Digital I/O.
Parallel Slave Port data.
Enhanced CCP1 output.
Digital I/O.
Parallel Slave Port data.
Enhanced CCP1 output.
Digital I/O.
Parallel Slave Port data.
Enhanced CCP1 output.
ST = Schmitt Trigger input with CMOS levels I= Input
O=Output P=Power
Note 1: Default assignment for CCP2 when configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when configuration bit CCP2MX is cleared.
7, 28P—Positive supply for logic and I/O pins.
——No co nne ct.
33, 34
DS39636A-page 22Preliminary 2004 Microchip Technology Inc.
PIC18F2X1X/4X1X
2.0OSCILLATOR
CONFIGURATIONS
2.1Oscillator Types
PIC18F2X1X/4X1X devices can be operated in ten
different oscillator modes. The user can program the
configuration bits, FOSC3:FOSC0, in Configuration
Register 1H to select one of these ten modes:
1.LPLow-Power Crystal
2.XTCrystal/Resonator
3.HSHigh-Speed Crystal/Resonator
4.HSPLL High-Speed Crystal/Resonator
with PLL enabled
5.RCExternal Resistor/Capacitor with
F
OSC/4 output on RA6
6.RCIOExternal Resistor/Capacitor with I/O
on RA6
7.INTIO1 Internal Oscillator with F
on RA6 and I/O on RA7
8.INTIO2 Internal Oscillator with I/O on RA6
and RA7
9.ECExternal Clock with F
10. ECIOExternal Clock with I/O on RA6
2.2Crystal Oscilla tor/Ceramic
Resonators
In XT, LP, HS or HSPLL Oscillator modes, a crystal or
ceramic resonator is connected to the OSC1 and
OSC2 pins to establish oscillation. Figure 2-1 shows
the pin connections.
The oscillator design requires the use of a parallel cut
crystal.
Note:Use of a series cut crystal may give a
frequency out of the crystal manufacturer’s
specifications.
OSC/4 output
OSC/4 output
FIGURE 2-1:CRYSTAL/CERAMIC
RESONATOR OPERATION
(XT, LP, HS OR HSPLL
CONFIGURATION)
(1)
C1
(1)
C2
Note 1: See T able 2-1 and Table 2-2 for initial values of
2: A series resistor (R
3: R
OSC1
XTAL
(2)
RS
OSC2
C1 and C2.
strip cut crystals.
F varies with the oscillator mode chosen.
(3)
RF
Sleep
PIC18FXXXX
S) may be required for AT
To
Internal
Logic
T ABLE 2-1:CAPACITOR SELECTION FOR
CERAMIC RESONATORS
Typical Capacitor Values Used:
ModeFreqOSC1OSC2
XT3.58 MHz
4.19 MHz
4 MHz
4 MHz
Capacitor values are for design guidance only.
Different cap acitor values may be required to prod uce
acceptable oscillator operation. The user should test
the performance of the oscillator over the expected
DD and temperature range for the application.
V
See the notes following Table 2-2 for additional
information.
Note:When using resonators with frequencies
above 3.5 MHz, the use of HS mode,
rather than XT mode, is recommended.
HS mode may be used at any V
which the controller is rated. If HS is
selected, it is possible that the gain of the
oscillator will overdrive the resonator.
Therefore, a series resistor should be
placed between the OSC2 pin and the
resonator. As a good starting point, the
recommended value of R
Capacitor values are for design guidance only.
Different capa citor values may be required to produc e
acceptable oscillator operation. The user should test
the performance of the oscillator over the expected
DD and temperature range for the application.
V
See the notes following this table for additional
information.
Note 1: Higher capacitanc e increases th e stabilit y
Crystal
Freq
4 MHz
10 MHz
20 MHz
25 MHz
of the oscillator but also increases the
start-up time.
2: When operating below 3V V
using certain ceramic resonators at any
voltage, it may be necessary to use the
HS mode or switch to a crystal oscillator.
3: Since each resonator/crystal has its own
characteristics, the user should consult
the resonator/crystal manufacturer for
appropriate values of external
components.
4: Rs may be r equired to av oid overdr iving
crystals with low driv e lev e l spe ci fic ati on.
5: Always verify oscillator perform an ce over
DD and temperature range that is
the V
expected for the application.
T ypical Cap acitor V alues
Tested:
C1C2
15 pF
15 pF
15 pF
15 pF
15 pF
15 pF
15 pF
15 pF
15 pF
15 pF
15 pF
15 pF
DD, or when
An external clock source may also be connected to the
OSC1 pin in the HS mode, as shown in Figure 2-2.
FIGURE 2-2:EXTERNAL CLOCK INPUT
OPERATION
(HS OSCILLATOR
CONFIGURATION)
Clock from
Ext. System
Open
OSC1
OSC2
PIC18FXXXX
(HS Mode)
2.3External Clock Input
The EC and ECIO Oscillator mode s require an externa l
clock source to be conn ected to the OSC1 pi n. There is
no oscillator start-up time required after a Power-on
Reset or after an exit from Sleep mode.
In the EC Oscillator mode, the oscillator frequency
divided by 4 is available on the OSC2 pin. This signal
may be used f or t e st pu r pos es or t o sy nc hr o n iz e ot he r
logic. Figure 2-3 shows the pin connections for the EC
Oscillator mode.
FIGURE 2-3:EXTERNAL CLOCK
INPUT OPERATION
(EC CONFIGURATION)
Clock from
Ext. System
F
OSC/4
The ECIO Oscillator mo de func tio ns lik e t he EC mod e,
except that the OSC2 pin becomes an additional
general purpose I/O pin. The I/O pin becomes bit 6 of
PORTA (RA6). Figure 2-4 shows the pin connections
for the ECIO Oscillator mode.
OSC1/CLKI
PIC18FXXXX
OSC2/CLKO
FIGURE 2-4:EXTERNAL CLOCK
INPUT OPERATION
(ECIO CONFIGURATION)
Clock from
Ext. System
RA6
DS39636A-page 24Preliminary 2004 Microchip Technology Inc.
OSC1/CLKI
PIC18FXXXX
I/O (OSC2)
PIC18F2X1X/4X1X
2.4RC Oscillator
For timing insensitive applications, the “RC” and
“RCIO” device options offer additional cost savings.
The actual oscillator frequency is a function of several
factors:
• supply voltage
• values of the external resistor (R
capacitor (C
EXT)
• operating temperature
Given the same device, operating voltage and temperature and component values, there will also be unit-to-unit
frequency variations. These are due to factors such as:
• normal manufacturing variation
• difference in lead frame capacitance between
package types (especially for low C
• variations within the t olerance of limits of REXT
EXT
and C
In the RC Oscillator mode, the oscillator frequency
divided by 4 is available on the OSC2 pin. This signal
may be used f or t e st pu r pos es or t o sy nc hr o n iz e ot he r
logic. Figure 2-5 shows how the R/C combination is
connected.
FIGURE 2-5:RC OSCILLATOR MODE
VDD
REXT
OSC1
CEXT
VSS
F
Recommended values: 3 kΩ ≤ REXT ≤ 100 kΩ
OSC/4
OSC2/CLKO
EXT > 20 pF
C
The RCIO Oscillator mode (Figure 2-6) functions like
the RC mode, except that the OSC2 pin becomes an
additional general purpose I/O pin. The I/O pin
becomes bit 6 of PORTA (RA6).
FIGURE 2-6:RCIO OSCILLATOR MODE
VDD
REXT
OSC1
EXT) and
EXT values)
Internal
Clock
PIC18FXXXX
Internal
Clock
2.5PLL Frequency Multiplier
A Phase Locked Loop (PLL) circuit is provided as an
option for users who wish to use a lower frequency
oscillator circuit or to clock the device up to its highest
rated frequency from a crystal oscillator. This may be
useful for customers who are concerned with EMI due
to high-frequency crystals or users who require higher
clock speeds from an internal oscillator.
2.5.1HSPLL OSCILLATOR MODE
The HSPLL mode make s use of the HS mode osc illator
for frequencies up t o 10 MHz. A PLL then multipl ies the
oscillator output frequency by 4 to produce an internal
clock frequency up to 40 MHz. The PLLEN bit is not
available in this oscillator mode.
The PLL is only available to the crystal oscillator when
the FOSC3:FOSC0 configu r ati on bi t s are prog ram med
for HSPLL mode (= 0110).
FIGURE 2-7:PLL BLOCK DIAGRAM
(HS MODE)
HS Oscillator Enable
PLL Enable
(from Configuration Register 1H)
OSC2
OSC1
HS Mode
Crystal
Osc
IN
F
FOUT
÷4
2.5.2PLL AND INTOSC
The PLL is also ava ilabl e to th e inte rnal os cill ator bl ock
in selected oscillator modes. In this configuration, the
PLL is enabled in software and generates a clock
output of up to 32MHz. The operation of INTOSC with
the PLL is describ ed in Section 2.6.4 “PLL in INTOSCModes”.
The PIC18F2X1X/4X1X devices include an internal
oscillator block which generates two different clock
signals; either can be used as the microcontroller’s
clock source. This may eliminate the need for external
oscillator circuits on the OSC1 and/or OSC 2 pins.
The main output (INTOSC) is an 8 MHz clock source,
which can be used to directly drive the device clock. It
also drives a postscaler, which can provide a range of
clock frequencies from 31 kHz to 4 MHz. The INTOSC
output is enabled when a clock fre quency from 12 5 kHz
to 8 MHz is selected.
The other clock source is the internal RC oscillator
(INTRC), which provides a nominal 31 kHz output.
INTRC is enabled if it is selected as the device clock
source; it is also ena bled autom atically when an y of the
following are enabled:
• Power-up Timer
• Fail-Safe Clock Monitor
• Watchdog Timer
• T wo-Spe ed Start-up
These features are discussed in greater detail in
Section 22.0 “Special Features of the CPU”.
The clock source frequency (INTOSC direct, INTRC
direct or INTOSC postscaler) is selected by configuring
the IRCF bits of the OSCCON register (page30).
2.6.1INTIO MODES
Using the internal oscillator as the clock source eliminates the need for up to two external oscillator pins,
which can then be used for digital I/O. Two distinct
configurations are available:
• In INTIO1 mode, the OSC2 pin outputs F
while OSC1 functions as RA 7 fo r dig it a l in put a nd
output.
• In INTIO2 mode, OSC1 functions as RA7 and
OSC2 functions as RA6, both for digital input and
output.
2.6.2INTOSC OUTPUT FREQUENCY
The internal oscillator block is calibrated at the factory
to produce an INTOSC output frequency of 8.0MHz.
The INTRC oscillator operates independently of the
INTOSC source. Any changes in INTOSC across
voltage and temperature are not necessarily reflected
by changes in INTRC and vice versa.
2.6.3OSCTUNE REGISTER
The internal oscillator’s output has been calibrated at
the factory but can be adjusted in the user’s application. This is do ne by writi ng to the OSC TUNE regi ster
(Register 2-1). The tuning sensitivity is constant
throughout the tuning range.
OSC/4,
When the OSCTUNE regis ter is mo di fied , the IN T O SC
frequency will begin shifting to the new frequency. The
INTRC clock will reach the new frequency within
8 clock cy cles (approximately 8 * 32 µs=256µs). The
INTOSC clock will stabilize within 1ms. Code execution conti nues during t his shift. There is no indication
that the shift has occurred.
The OSCTUNE register also implements the INTSRC
and PLLEN bits, which control certain features of the
internal oscillator block. The INTSRC bit allows users
to select which internal oscillator provides the clock
source when the 31 kHz frequency option is selected.
This is covered in greater detail in Section 2.7.1“Oscillator Control Register”.
The PLLEN bit controls the operation of the frequency
multiplier, PLL, in internal oscillator modes.
2.6.4PLL IN INTOSC MODES
The 4x frequency multiplier can be used with the
internal oscillator block to produce faster device clock
speeds than are normally possible with an internal
oscillator. When enabled, the PLL produces a clock
speed of up to 32MHz.
Unlike HSPLL mode, the PLL is controlled through
software. The control bit, PLLEN (OSCTUNE<6>), is
used to enable or disable its operation.
The PLL is available when the device is configured to
use the internal oscillator block as its primary clock
source (FOSC3:FOSC0 = 1001 or 1000). Additionally,
the PLL will only function when the selected output frequency is either 4 MHz or 8 MHz (OSCCON<6:4> = 111
or 110). If both of these conditions are not met, the PLL
is disabled.
The PLLEN control bit is only functional in those
internal oscillator m ode s w h ere t he PL L is av ai lab le. In
all other modes, it is forced to ‘0’ and is effectively
unavailable.
2.6.5INTOSC FREQUENCY DRIFT
The factory calibrates the internal oscillator block
output (INTOSC) for 8 MHz. However, this frequency
may drift as VDD or temperature changes, which can
affect the controller operation in a variety of ways. It is
possible to adjust the INTOSC frequency by modifying
the value in the OSCTUNE register. This has no effect
on the INTRC clock source frequency.
Tuning the INTOSC source requires knowing when to
make the adjustment, in which direction it should be
made and in some cases, how large a change is
needed. Three compensation techniques are
discussed in Section 2.6.5.1 “Compensating with
the USART”, Section 2.6.5.2 “Compensating with
the Timers” and Section2.6.5.3 “Compensating
with the CCP Module in Capture Mode”, but other
techniques may be used.
DS39636A-page 26Preliminary 2004 Microchip Technology Inc.
PIC18F2X1X/4X1X
REGISTER 2-1:OSCTUNE: OSCILLATOR TUNING REGISTER
R/W-0 R/W-0
INTSRCPLLEN
bit 7bit 0
bit 7INTSRC: Internal Oscillator Low-Frequency Source Select bit
bit 6PLLEN: Frequency Multiplier PLL for INTOSC Enable bit
1 = PLL enabled for INTOSC (4 MHz and 8 MHz only)
0 = PLL disabled
Note 1: Available only in certain oscillator configurations; otherwise, this bit is unavailable
bit 5Unimplemented: Read as ‘0’
bit 4-0TUN4:TUN0: Frequency Tuning bits
01111 = Maximum frequency
• •
• •
00001
00000 = Center frequency. Oscillator module is running at the calibrated frequency.
11111
• •
• •
10000 = Minimum frequency
(1)
(1)
and reads as ‘0’. See Section 2.6.4 “PLL in INTOSC Modes” for details.
U-0R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
—TUN4TUN3TUN2TUN1TUN0
(1)
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
2.6.5.1Compensating with the USART
An adjustment may be required when the USART
begins to generate frami ng errors or rec eive s dat a with
errors while in Asynchronous mode. Framing errors
indicate that the device clock frequency is too high; to
adjust for this, decrement the value in OSCTUNE to
reduce the clock frequency. On the other hand, errors
in data may suggest that the clock speed is too low; to
compensate, increment OSCTUNE to increase the
clock frequency.
2.6.5.2Compensating with the Timers
This technique compares device clock speed to some
reference clock. Two timers may be used; one timer is
clocked by the peripheral clock, while the other is
clocked by a fixed reference source, such as the
Timer1 oscillat or.
Both timers are cleared, but the timer clocked by the
reference generates interrupts. When an interrupt
occurs, the internally clocked timer is read and both
timers are cleared. If the internally clocked timer value
is greater than expected, then the internal oscillator
block is ru nning too fast. To adjust for t his, decr ement
the OSCTUNE register.
2.6.5.3Compensating with the CCP Module
in Capture Mode
A CCP module can use free running Timer1 (or
Timer3), cl oc ked by the internal oscillator bl ock and an
external event with a known period (i.e., AC power
frequency). The time of the first event is capt ured in th e
CCPRxH:CCPRxL registers and is recorded for use
later. When the second event causes a capture, the
time of the first event is su btra cte d fro m the tim e of th e
second event. Since the period of the external event is
known, the time difference between events can be
calculated.
If the measured time is much greater than the calculated time, the internal oscillator block is running too
fast; to compensate, decrement the OSCTUNE register.
If the measured time is much less than the calculate d
time, the internal oscillator block is runn ing t oo slow; to
compensate, increment the OSCTUNE register.
Like previous PIC18 devices, the PIC18F2X1X/4X1X
family includes a feature that allows the device clock
source to be switched from the main oscillator to an alternate low-frequency clock source. PIC18F2X1X/4X1X
devices offer two alternate clock sources. When an
alternate clock source is enabled, the various power
managed operating modes are available.
Essentially, there are three clock sources for these
devices:
• Primary oscillators
• Secondary oscillators
• Internal oscillator block
The primary oscillators include the Ex ternal Crystal
and Resonator modes, the External RC modes, the
External Clock modes and the internal oscillator block.
The particular mode is defined by the FOSC3:FOSC0
configuration bits. The details of these modes are
covered earlier in this chapter.
The s econdary oscillators are those external sources
not connected to the OSC1 or OSC2 pins. These
sources may continue to operate even after the
controller is placed in a power managed mode.
PIC18F2X1X/4X1X devices offer the Timer1 oscillator
as a secondary oscillator. This oscillator, in all power
managed modes, is often the time base for functions
such as a real-time clock.
Most often, a 32.768 kHz watch crystal is connected
between the RC0/T1OSO/T13CKI and RC1/T1OSI
pins. Like the LP mode oscillator circuit, loading
capacitors are also connected from each pin to ground.
The Timer1 oscillator is discussed in greater detail in
Section 11.3 “Timer1 Oscillator”.
In addition to being a prim ary clock source, the internaloscillator block is available as a power managed
mode clock source. T he IN TR C s ource is also used as
the clock source for several special features, such as
the WDT and Fail-Safe Clock Monitor.
The clock sources for the PIC18F2X1X/4X1X devices
are shown in Figure 2-8. See Section 22.0 “Special
Features of the CPU” for Configuration register details.
FIGURE 2-8:PIC18F2X1X/4X1X CLOCK DIAGRAM
OSC2
OSC1
T1OSO
T1OSI
Primary Oscillator
Sleep
Secondary Oscillator
T1OSCEN
Enable
Oscillator
OSCCON<6:4>
Internal
Oscillator
Block
8 MHz
Source
INTRC
Source
31 kHz (INTRC)
OSCTUNE<6>
8 MHz
(INTOSC)
PIC18F2X1X/4X1X
8 MHz
4 MHz
2 MHz
1 MHz
500 kHz
Postscaler
250 kHz
125 kHz
1
31 kHz
0
4 x PLL
OSCCON<6:4>
111
110
101
100
MUX
011
010
001
000
OSCTUNE<7>
LP, XT, HS, RC, EC
HSPLL, INTOSC/PLL
T1OSC
Internal Oscillator
FOSC3:FOSC0
Peripherals
MUX
CPU
Clock
Control
Clock Source Option
for other Modules
WDT, PWRT, FSCM
and Two-Speed Start-up
IDLEN
OSCCON<1:0>
DS39636A-page 28Preliminary 2004 Microchip Technology Inc.
Loading...
+ 350 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.