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 Digital Millennium Copyright Act. If such acts
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 provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR
WARRANTIES OF ANY KIND WHETHER EXPRESS OR
IMPLIED, WRITTEN OR ORAL, STATUTORY OR
OTHERWISE, RELATED TO THE INFORMATION,
INCLUDING BUT NOT LIMITED TO ITS CONDITION,
QUALITY, PERFORMANCE, MERCHANTABILITY OR
FITNESS FOR PURPOSE. Microchip disclaims all liability
arising from this information and its use. Use of Microchip
devices in life support and/or safety applications is entirely at
the buyer’s risk, and the buyer agrees to defend, indemnify and
hold harmless Microchip from any and all damages, claims,
suits, or expenses resulting from such use. No licenses are
conveyed, implicitly or otherwise, under any Microchip
intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, K
EELOQ, KEELOQ logo, microID, MPLAB, PIC,
PICmicro, PICSTART, PRO MATE, rfPIC and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, Linear Active Thermistor, Migratable
Memory, MXDEV, MXLAB, 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, CodeGuard,
dsPICDEM, dsPICDEM.net, dsPICworks, ECAN,
ECONOMONITOR, FanSense, FlexROM, fuzzyLAB,
In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi,
MPASM, MPLAB Certified logo, MPLIB, MPLINK, PICkit,
PICDEM, PICDEM.net, PICLAB, PICtail, PowerCal,
PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB, Select
Mode, Smart Serial, SmartTel, Total Endurance, UNI/O,
WiperLock and ZENA 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 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Company’s quality system processes and procedures
are for its PIC
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.
6.0Flash Program Memory.............................................................................................................................................................. 77
17.0 Power Control PWM Module .................................................................................................................................................... 181
18.0 Synchronous Serial Port (SSP) Module ................................................................................................................................... 213
22.0 Special Features of the CPU.................................................................................................................................................... 269
23.0 Instruction Set Summary .......................................................................................................................................................... 289
24.0 Development Support............................................................................................................................................................... 331
26.0 DC and AC Characteristics Graphs and Tables ....................................................................................................................... 371
Appendix D: Migration from Baseline to Enhanced Devices.............................................................................................................. 382
Appendix E: Migration From Mid-Range to Enhanced Devices ......................................................................................................... 383
Appendix F: Migration From High-End to Enhanced Devices............................................................................................................ 383
Index .................................................................................................................................................................................................. 385
The Microchip Web Site..................................................................................................................................................................... 395
Customer Change Notification Service .............................................................................................................................................. 395
Customer Support .............................................................................................................................................................................. 395
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 comments regarding this publication, please contact the Marketing Communications Department via
E-mail at docerrors@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)
When contacting a sales office, 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 to receive the most current information on all of our products.
This document contains device specific information for
the following devices:
• PIC18F2331• PIC18F4331
• PIC18F2431• PIC18F4431
This family offers the advantages of all PIC18
microcontrollers – namely, high computational performance at an economical price, with the addition of high
endurance enhanced Flash program memory and a
high-speed 10-bit A/D Converter. On top of these
features, the PIC18F2331/2431/4331/4431 family
introduces design enhancements that make these microcontrollers a logical choice for many high-performance,
power control and motor control applications. These
special peripherals include:
• 14-Bit Resolution Power Control PWM module
(PCPWM) with Programmable Dead-time Insertion
• Motion Feedback Module (MFM), including a
3-Channel Input Capture (IC) module and
Quadrature Encoder Interface (QEI)
• High-Speed 10-Bit A/D Converter (HSADC)
The PCPWM can generate up to eight complementary
PWM outputs with dead-band time insertion. Overdrive
current is detected by off-chip analog comparators or
the digital Fault inputs (FLTA
The MFM Quadrature Encoder Interface provides
precise rotor position feedback and/or velocity
measurement. The MFM 3x input capture or external
interrupts can be used to detect the rotor state for
electrically commutated motor applications using Hall
sensor feedback, such as BLDC motor drives.
PIC18F2331/2431/4331/4431 devices also feature
Flash program memory and an internal RC oscillator
with built-in LP modes.
1.1New Core Features
1.1.1nanoWatt Technology
All of the devices in the PIC18F2331/2431/4331/4431
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 are
still active. In these states, power consumption
can be reduced even further, to as little as 4% of
normal operation requirements.
, FLTB).
• On-the-Fly Mode Switching: The power-
managed modes are invoked by user code
during operation, allowing the user to incorporate
power-saving ideas into their application’s
software design.
• Lower Consumption in Key Modules: The
power requirements for both Timer1 and the
Watchdog Timer have been reduced by up to
80%, with typical values of 1.1 and 2.1 μA,
respectively.
1.1.2MULTIPLE OSCILLATOR OPTIONS
AND FEATURES
All of the devices in the PIC18F2331/2431/4331/4431
family offer nine 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, stable over temperature and V
as well as a range of 6 user-selectable clock
frequencies (from 125 kHz to 4 MHz) for a total of
8 clock frequencies.
Besides its availability as a clock source, the internal
oscillator block provides a stable reference 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 is
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.
This allows for code execution during what would
otherwise be the clock start-up interval, and can
even allow an application to perform routine
background activities and return to Sleep without
returning to full power operation.
• Memory Endurance: The enhanced Flash cells
for both program memory and data EEPROM are
rated to last for many thousands of erase/write
cycles – up to 100,000 for program memory and
1,000,000 for EEPROM. Data retention without
refresh is conservatively estimated to be greater
than 100 years.
• Self-Programmability: These devices can write
to their own program memory spaces under internal software control. By using a bootloader routine
located in the protected Boot Block at the top of
program memory, it becomes possible to create
an application that can update itself in the field.
• Power Control PWM 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-shutdown on Fault
detection and auto-restart to reactivate outputs
once the condition has cleared.
• Enhanced USART: This serial communication
module is capable of standard RS-232 operation
using the internal oscillator block, removing the
need for an external crystal (and its
accompanying power requirement) in applications
that talk to the outside world. This module also
includes Auto-Baud Detect and LIN capability.
• High-Speed 10-Bit A/D Converter: This module
incorporates programmable acquisition time,
allowing for a channel to be selected and a
conversion to be initiated without waiting for a
sampling period and thus, reducing code
overhead.
• Motion Feedback Module (MFM): This module
features a Quadrature Encoder Interface (QEI)
and an Input Capture (IC) module. The QEI
accepts two phase inputs (QEA, QEB) and one
index input (INDX) from an incremental encoder.
The QEI supports high and low precision position
tracking, direction status and change of direction
interrupt and velocity measurement. The input
capture features 3 channels of independent input
capture with Timer5 as the time base, a Special
Event Trigger to other modules and an adjustable
noise filter on each IC input.
• Extended Watchdog Timer (WDT): This
enhanced version incorporates a 16-bit prescaler,
allowing a time-out range from 4 ms to over
2 minutes, that is stable across operating voltage
and temperature.
Devices in the PIC18F2331/2431/4331/4431 family are
available in 28-pin (PIC18F2331/2431) and 40/44-pin
(PIC18F4331/4431) packages. The block diagram for
the two groups is shown in Figure 1-1.
The devices are differentiated from each other in three
ways:
1.Flash program memory (8 Kbytes for
PIC18F2331/4331 devices, 16 Kbytes for
PIC18F2431/4431).
2.A/D channels (5 for PIC18F2331/2431 devices,
9 for PIC18F4331/4431 devices).
3.I/O ports (3 bidirectional ports on PIC18F2331/
2431 devices, 5 bidirectional ports on
PIC18F4331/4431 devices).
All other features for devices in this family are identical.
These are summarized in Table 1-1.
The pinouts for all devices are listed in Table 1-2 and
Table 1-3.
ST = Schmitt Trigger input with CMOS levels I= Input
O= Output P= Power
OD = Open-Drain (no diode to V
126
96
107
227
328
41
52
63
I
P
I
I
I
CMOS
I/O
TTL
O
O
I/O
TTL
I/OITTL
Analog
I/OITTL
Analog
I/O
TTL
I
Analog
I
Analog
I
I
I/O
TTL
I
Analog
I
Analog
I
I
I/O
TTL
I
Analog
I
I
DD)
Master Clear (input) or programming voltage (input).
ST
ST
ST
—
—
ST
ST
ST
ST
ST
ST
Master Clear (Reset) input. This pin is an active-low
Reset to the device.
High-voltage ICSP™ programming enable pin.
Digital input. Available only when MCLR
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.
PORTA is a bidirectional I/O port.
Digital I/O.
Analog input 0.
Digital I/O.
Analog input 1.
Digital I/O.
Analog input 2.
A/D reference voltage (low) input.
Input capture pin 1.
Quadrature Encoder Interface index input pin.
Digital I/O.
Analog input 3.
A/D reference voltage (high) input.
Input capture pin 2.
Quadrature Encoder Interface channel A input pin.
Digital I/O.
Analog input 4.
Input capture pin 3.
Quadrature Encoder Interface channel B input pin.
ST= Schmitt Trigger input with CMOS levels I= Input
O= Output P= Power
OD = Open-Drain (no diode to V
Note 1: RC3 is the alternate pin for T0CKI/T5CKI; RC4 is the alternate pin for SDI/SDA; RC5 is the alternate pin
for SCK/SCL.
2: RD4 is the alternate pin for FLTA
3: RD5 is the alternate pin for PWM4.
Pin Number
PDIP TQFP QFN
11818
133032
143133
Pin
Type
I/O
I/O
DD)
.
Buffer
Type
Master Clear (input) or programming voltage (input).
I
ST
P
I
ST
I
ST
I
CMOS
TTL
—
O
—
O
TTL
Master Clear (Reset) input. This pin is an active-low
Reset to the device.
Programming voltage input.
Digital input. Available only when MCLR
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.
The PIC18F2331/2431/4331/4431 devices can be
operated in 10 different oscillator modes. The user can
program the Configuration bits FOSC3:FOSC0 in
Configuration Register 1H to select one of these 10
modes:
1.LPLow-Power Crystal
2.XTCrystal/Resonator
3.HSHigh-Speed Crystal/Resonator
4.HSPLLHigh-Speed Crystal/Resonator
with PLL Enabled
5.RCExternal Resistor/Capacitor with
OSC/4 Output on RA6
F
6.RCIOExternal Resistor/Capacitor with
I/O on RA6
7.INTIO1Internal Oscillator with F
Output on RA6 and I/O on RA7
8.INTIO2Internal Oscillator with I/O on RA6
and RA7
9.ECExternal Clock with F
10. ECIOExternal Clock with I/O on RA6
2.2Crystal Oscillator/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
manufacturers’ specifications.
OSC/4
OSC/4 Output
FIGURE 2-1:CRYSTAL/CERAMIC
RESONATOR OPERATION
(XT, LP, HS OR HSPLL
CONFIGURATION)
(1)
C1
(1)
C2
Note 1: See Table 2-1 and Table 2-2 for initial values of
C1 and C2.
2: A series resistor (R
strip cut crystals.
3: R
OSC1
To
Internal
XTAL
(2)
RS
OSC2
F varies with the oscillator mode chosen.
(3)
RF
PIC18FXXXX
S) may be required for AT
Logic
Sleep
TABLE 2-1:CAPACITOR SELECTION FOR
CERAMIC RESONATORS
Typical Capacitor Values Used:
ModeFreqOSC1OSC2
XT455 kHz
2.0 MHz
4.0 MHz
HS8.0 MHz
16.0 MHz
Capacitor values are for design guidance only.
These capacitors were tested with the resonators
listed below for basic start-up and operation. Thesevalues are not optimized.
Different capacitor values may be required to produce
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.
These capacitors were tested with the crystals listed
below for basic start-up and operation. These values
are not optimized.
Different capacitor values may be required to produce
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.
Crystals Used:
32 kHz4 MHz
200 kHz8 MHz
1 MHz20 MHz
Note 1: Higher capacitance increases the
stability of 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 required to avoid overdriving
crystals with low drive level specification.
5: Always verify oscillator performance over
DD and temperature range that is
the V
expected for the application.
Typical Capacitor Values
Tested:
C1C2
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 OSC
CONFIGURATION)
Clock from
Ext. System
Open
OSC1
OSC2
PIC18FXXXX
(HS Mode)
2.3HSPLL
A Phase Locked Loop (PLL) circuit is provided as an
option for users who wish to use a lower frequency
crystal 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.
The HSPLL mode makes use of the HS Oscillator
mode for frequencies up to 10 MHz. A PLL then multiplies the oscillator output frequency by 4 to produce an
internal clock frequency up to 40 MHz.
The PLL is enabled only when the oscillator Configuration bits are programmed for HSPLL mode. If
programmed for any other mode, the PLL is not
enabled.
The EC and ECIO Oscillator modes require an external
clock source to be connected to the OSC1 pin. 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 for test purposes or to synchronize other
logic. Figure 2-4 shows the pin connections for the EC
Oscillator mode.
FIGURE 2-4:EXTERNAL CLOCK INPUT
OPERATION
(EC CONFIGURATION)
Clock from
Ext. System
OSC/4
F
The ECIO Oscillator mode functions like the EC 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-5 shows the pin connections
for the ECIO Oscillator mode.
FIGURE 2-5:EXTERNAL CLOCK INPUT
Clock from
Ext. System
RA6
OSC1/CLKI
PIC18FXXXX
OSC2/CLKO
OPERATION
(ECIO CONFIGURATION)
OSC1/CLKI
PIC18FXXXX
I/O (OSC2)
2.5RC Oscillator
For timing insensitive applications, the RC and RCIO
device options offer additional cost savings. The RC
oscillator frequency is a function of the supply voltage,
the resistor (R
operating temperature. In addition to this, the oscillator
frequency will vary from unit-to-unit due to normal
manufacturing variation. Furthermore, the difference in
lead frame capacitance between package types will
also affect the oscillation frequency, especially for low
EXT values. The user also needs to take into account
C
variation due to tolerance of external R and C
components used. Figure 2-6 shows how the R/C
combination is connected.
In the RC Oscillator mode, the oscillator frequency
divided by 4 is available on the OSC2 pin. This signal
may be used for test purposes or to synchronize other
logic.
FIGURE 2-6:RC OSCILLATOR MODE
REXT
CEXT
VSS
Recommended values: 3 kΩ ≤ REXT ≤ 100 kΩ
The RCIO Oscillator mode (Figure 2-7) 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).
The PIC18F2331/2431/4331/4431 devices include an
internal oscillator block, which generates two different
clock signals; either can be used as the system’s clock
source. This can eliminate the need for external
oscillator circuits on the OSC1 and/or OSC2 pins.
The main output (INTOSC) is an 8 MHz clock source,
which can be used to directly drive the system clock. It
also drives a postscaler, which can provide a range of
clock frequencies from 125 kHz to 4 MHz. The
INTOSC output is enabled when a system clock
frequency from 125 kHz to 8 MHz is selected.
The other clock source is the internal RC oscillator
(INTRC), which provides a 31 kHz output. The INTRC
oscillator is enabled by selecting the internal oscillator
block as the system clock source, or when any of the
following are enabled:
• Power-up Timer
• Fail-Safe Clock Monitor
• Watchdog Timer
• Two-Speed 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 (Register 2-2).
2.6.2INTRC OUTPUT FREQUENCY
The internal oscillator block is calibrated at the factory
to produce an INTOSC output frequency of 8.0 MHz.
This changes the frequency of the INTRC source from
its nominal 31.25 kHz. Peripherals and features that
depend on the INTRC source will be affected by this
shift in frequency.
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 done by writing to the OSCTUNE register
(Register 2-1). The tuning sensitivity is constant
throughout the tuning range.
When the OSCTUNE register is modified, the INTOSC
and INTRC frequencies will begin shifting to the new
frequency. The INTRC clock will reach the new
frequency within 8 clock cycles (approximately
8*32μs = 256 μs). The INTOSC clock will stabilize
within 1 ms. Code execution continues during this shift.
There is no indication that the shift has occurred. Operation of features that depend on the INTRC clock
source frequency, such as the WDT, Fail-Safe Clock
Monitor and peripherals, will also be affected by the
change in frequency.
2.6.1INTIO MODES
Using the internal oscillator as the clock source can
eliminate 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 RA7 for digital input and
output.
• In INTIO2 mode, OSC1 functions as RA7 and
OSC2 functions as RA6, both for digital input and
output.
Like previous PIC18 devices, the PIC18F2331/2431/
4331/4431 devices include a feature that allows the system clock source to be switched from the main oscillator
to an alternate low-frequency clock source. PIC18F2331/
2431/4331/4431 devices offer two alternate clock
sources. When enabled, these give additional options for
switching to the various power-managed operating
modes.
Essentially, there are three clock sources for these
devices:
• Primary oscillators
• Secondary oscillators
• Internal oscillator block
The primary oscillators include the External Crystal
and Resonator modes, the External RC modes, the
External Clock modes and the internal oscillator block.
The particular mode is defined on POR by the contents
of Configuration Register 1H. The details of these
modes are covered earlier in this chapter.
The secondary 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.
PIC18F2331/2431/4331/4431 devices offer only 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
(RTC).
Most often, a 32.768 kHz watch crystal is connected
between the RC0/T1OSO 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 12.2 “Timer1 Oscillator”.
In addition to being a primary clock source, the internaloscillator block is available as a power-managed
mode clock source. The INTRC source 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 PIC18F2331/2431/4331/4431
devices are shown in Figure 2-8. See Section 12.0“Timer1 Module” for further details of the Timer1
oscillator. See Section 22.1 “Configuration Bits” for
Configuration register details.
2.7.1OSCILLATOR CONTROL REGISTER
The OSCCON register (Register 2-2) controls several
aspects of the system clock’s operation, both in full
power operation and in power-managed modes.
The System Clock Select bits, SCS1:SCS0, select the
clock source that is used when the device is operating
in power-managed modes. The available clock sources
are the primary clock (defined in Configuration Register
1H), the secondary clock (Timer1 oscillator) and the
internal oscillator block. The clock selection has no
effect until a SLEEP instruction is executed and the
device enters a power-managed mode of operation.
The SCS bits are cleared on all forms of Reset.
The Internal Oscillator Select bits, IRCF2:IRCF0, select
the frequency output of the internal oscillator block that
is used to drive the system clock. The choices are the
INTRC source, the INTOSC source (8 MHz) or one of
the six frequencies derived from the INTOSC
postscaler (125 kHz to 4 MHz). If the internal oscillator
block is supplying the system clock, changing the
states of these bits will have an immediate change on
the internal oscillator’s output.
The OSTS, IOFS and T1RUN bits indicate which clock
source is currently providing the system clock. The OSTS
indicates that the Oscillator Start-up Timer has timed out,
and the primary clock is providing the system clock in
primary clock modes. The IOFS bit indicates when the
internal oscillator block has stabilized, and is providing
the system clock in RC Clock modes. The T1RUN bit
(T1CON<6>) indicates when the Timer1 oscillator is
providing the system clock in secondary clock modes. In
power-managed modes, only one of these three bits will
be set at any time. If none of these bits are set, the INTRC
is providing the system clock, or the internal oscillator
block has just started and is not yet stable.
The IDLEN bit controls the selective shutdown of the
controller’s CPU in power-managed modes. The use of
these bits is discussed in more detail in Section 3.0
“Power-Managed Modes”
Note 1: The Timer1 oscillator must be enabled to
select the secondary clock source. The
Timer1 oscillator is enabled by setting the
T1OSCEN bit in the Timer1 Control
register (T1CON<3>). If the Timer1
oscillator is not enabled, then any attempt
to select a secondary clock source when
executing a SLEEP instruction will be
ignored.
2: It is recommended that the Timer1
oscillator be operating and stable before
executing the SLEEP instruction, or a very
long delay may occur while the Timer1
oscillator starts.