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, dsPIC,
K
logo, rfPIC and UNI/O are registered trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
FilterLab, Hampshire, HI-TECH C, Linear Active Thermistor,
MXDEV, MXLAB, SEEVAL 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, dsSPEAK, ECAN,
ECONOMONITOR, FanSense, HI-TIDE, In-Circuit Serial
Programming, ICSP, Mindi, MiWi, MPASM, MPLAB Certified
logo, MPLIB, MPLINK, mTouch, Omniscient Code
Generation, PICC, PICC-18, PICDEM, PICDEM.net, PICkit,
PICtail, REAL ICE, rfLAB, Select Mode, Total Endurance,
TSHARC, UniWinDriver, 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.
®
MCUs and dsPIC® DSCs, KEELOQ
®
code hopping
DS39957C-page 2 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
64/80-Pin, High-Performance Microcontrollers with
LCD Driver and nanoWatt XLP Technology
Low-Power Features:
• Power-Managed modes:
- Run: CPU on, peripherals on
- Idle: CPU off, peripherals on
- Sleep: CPU off, peripherals off
• Two-Speed Oscillator Start-up
• Fail-Safe Clock Monitor
• Power-Saving Peripheral Module Disable (PMD)
• Ultra Low-Power Wake-up
• Fast Wake-up, 2 s Typical
• Low-Power WDT, 300 nA Typical
• Ultra Low 50 nA Input Leakage
• Run mode Currents Down to Very Low 5.5 A, Typical
• Idle mode Currents Down to Very Low 2.2 A, Typical
• Sleep mode Current Down to Very Low 20 nA, Typical
• RTCC Current Down to Very Low 700 nA, Typical
• LCD Current Down to Very Low 300 nA, Typical
LCD Driver and Keypad Features:
• Direct LCD Panel Drive Capability:
- Can drive LCD panel while in Sleep mode
• Up to 48 Segments and 192 Pixels,
Software-Selectable
• Programmable LCD Timing module:
- Multiple LCD timing sources available
- Up to four commons: static, 1/2, 1/3 or
1/4 multiplex
- Bias configuration: Static, 1/2 or 1/3
• Low-Power Resistor Bias Network for LCD
Peripheral Highlight s:
• Ten or Eight CCP/ECCP modules:
- Seven Capture/Compare/PWM (CCP) modules
- Three Enhanced Capture/Compare/PWM
(ECCP) modules
• Eleven 8/16-Bit Timer/Counter modules:
- Timer0 – 8/16-bit timer/counter with 8-bit
programmable prescaler
- Timer1,3,5,7 – 16-bit timer/counter
- Timer2,4,6,8,10,12 – 8-bit timer/counter
• Three Analog Comparators
• Configurable Reference Clock Output
• Hardware Real-Time Clock and Calendar (RTCC)
module with Clock, Calendar and Alarm Functions
- Time-out from 0.5s to 1 year
• Charge Time Measurement Unit (CTMU):
- Capacitance measurement for mTouch™
Sensing
- Time measurement with 1 ns typical resolution
• High-Current Sink/Source 25 mA/25 mA (PORTB
and PORTC)
• Up to Four External Interrupts
• Two Master Synchronous Serial Port (MSSP)
modules:
- 3/4-wire SPI (supports all four SPI modes)
2
C™ Master and Slave mode
-I
Flash
Device
PIC18F65K9032K2K1K531324/45/3YesYes2163YY
PIC18F66K9064K4K1K53132 6/5 7/3 YesYes2163YY
PIC18F67K90128K4K1K53132 6/5 7/3 YesYes2163YY
PIC18F85K9032K2K1K69192 4/4 5/3 YesYes2243YY
PIC18F86K9064K4K1K69192 6/5 7/3 YesYes2243YY
PIC18F87K90128K4K1K69192 6/5 7/3 YesYes2243YY
2011 Microchip Technology Inc.DS39957C-page 3
Program
Memory
(Bytes)
SRAM
Data
Memory
(Bytes)
EEPROM
(Bytes)
I/O
LCD
Pixels
Timers
8/16-Bit
CCP/
ECCP
SPII
2
C™
EUSART
12-Bit A/D
(Channels)
RTCC
CTMU
Comparators
PIC18F87K90 FAMILY
Special Microcontroller Features:
• Operating Voltage Range: 1.8V to 5.5V
• On-Chip 3.3V Regulator
• Operating Speed up to 64 MHz
• Up to 128 Kbytes On-Chip Flash Program
Memory
• Data EEPROM of 1,024 Bytes
• 4K x 8 General Purpose Registers (SRAM)
• 10,000 Erase/Write Cycle Flash Program
Memory, Typical
• 1,000,000 Erase/write Cycle Data EEPROM
Memory, Typical
• Flash Retention 40 Years, Minimum
• Three Internal Oscillators: LF-INTRC (31 kHz),
MF-INTOSC (500 kHz) and HF-INTOSC
(16 MHz)
• Self-Programmable under Software Control
• Priority Levels for Interrupts
• 8 x 8 Single-Cycle Hardware Multiplier
• Extended Watchdog Timer (WDT):
- Programmable period from 4 ms to 4,194s
(about 70 minutes)
• In-Circuit Serial Programming™ (ICSP™) via
Two Pins
• In-Circuit Debug via Two Pins
• Programmable:
-BOR
-LVD
• Two Enhanced Addressable USART modules:
- LIN/J2602 support
- Auto-Baud Detect (ABD)
• 12-Bit A/D Converter with up to 24 Channels:
- Auto-acquisition and Sleep operation
- Differential Input mode of operation
DS39957C-page 4 2011 Microchip Technology Inc.
Pin Diagrams – PIC18F6XK90
64-Pin QFN, TQFP
50 49
RE2/LCDBIAS3/P2B/CCP10
(2)
RE3/COM0/P3C/CCP9
(2)
/REFO
RE4/COM1/P3B/CCP8
RE5/COM2/P1C/CCP7
RE6/COM3/P1B/CCP6
RE7/ECCP2
(1)
/SEG31/P2A
RD0/SEG0/CTPLS
V
DD
VSS
RD1/SEG1/T5CKI/T7G
RD2/SEG2
RD3/SEG3
RD4/SEG4/SDO2
RD5/SEG5/SDI2/SDA2
RD6/SEG6/SCK2/SCL2
RD7/SEG7/SS2
RE1/LCDBIAS2/P2C
RE0/LCDBIAS1/P2D
RG0/ECCP3/P3A
RG1/TX2/CK2/AN19/C3OUT
RG2/RX2/DT2/AN18/C3INA
RG3/CCP4/AN17/P3D/C3INB
MCLR
/RG5
V
SS
VDDCORE/VCAP
RF7/AN5/SS1/SEG25
RF6/AN11/SEG24/C1INA
RF5/AN10/CV
REF/SEG23/C1INB
RF4/AN9/SEG22/C2INA
RF3/AN8/SEG21/C2INB/CTMUI
RF2/AN7/C1OUT/SEG20
RB0/INT0/SEG30/FLTO
RB1/INT1/SEG8
RB2/INT2/SEG9/CTED1
RB3/INT3/SEG10/CTED2/P2A
RB4/KBI0/SEG11
RB5/KBI1/SEG29/T3CKI/T1G
RB6/KBI2/PGC
V
SS
OSC2/CLKO/RA6
OSC1/CLKI/RA7
V
DD
RB7/KBI3/PGD
RC4/SDI1/SDA1/SEG16
RC3/SCK1/SCL1/SEG17
RC2/ECCP1/P1A/SEG13
ENVREG
RF1/AN6/C2OUT/SEG19/CTDIN
AV
DD
AVSS
RA3/AN3/VREF+
RA2/AN2/V
REF-
RA1/AN1/SEG18
RA0/AN0/ULPWU
V
SS
VDD
RA4/T0CKI/SEG14
RA5/AN4/T1CKI/SEG15/T3G/HLVDIN
RC1/SOSCI/ECCP2
(1)
/P2A/SEG32
RC0/SOSCO/SCLKI
RC7/RX1/DT1/SEG28
RC6/TX1/CK1/SEG27
RC5/SDO1/SEG12
5453 52 5158 57 56 5560 59
64
63 62 61
Note 1: The ECCP2 pin placement depends on the CCP2MX Configuration bit setting.
2: Not available on the PIC18F65K90 and PIC18F85K90.
2.0Guidelines for Getting Started with PIC18FXXKXX Microcontrollers ......................................................................................... 35
7.0Flash Program Memory............................................................................................................................................................ 111
21.0 Master Synchronous Serial Port (MSSP) Module .................................................................................................................... 303
27.0 Charge Time Measurement Unit (CTMU) ................................................................................................................................ 407
28.0 Special Features of the CPU.................................................................................................................................................... 425
29.0 Instruction Set Summary.......................................................................................................................................................... 451
30.0 Development Support............................................................................................................................................................... 501
Appendix B: Migration From PIC18F85J90 and PIC18F87J90 to PIC18F87K90 .............................................................................. 551
Index ................................................................................................................................................................................................. 553
The Microchip Web Site..................................................................................................................................................................... 565
Customer Change Notification Service .............................................................................................................................................. 565
Customer Support .............................................................................................................................................................................. 565
Product Identification System ............................................................................................................................................................ 567
2011 Microchip Technology Inc.DS39957C-page 7
PIC18F87K90 FAMILY
NOTES:
DS39957C-page 8 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
1.0DEVICE OVERVIEW
This document contains device-specific information for
the following devices:
• PIC18F65K90• PIC18F85K90
• PIC18F66K90• PIC18F86K90
• PIC18F67K90• PIC18F87K90
This family combines the traditional advantages of all
PIC18 microcontrollers – namely, high computational
performance and a rich feature set – with a versatile
on-chip LCD driver, while maintaining an extremely
competitive price point. These features make the
PIC18F87K90 family a logical choice for many
high-performance applications where price is a primary
consideration.
1.1Core Features
1.1.1nanoWatt TECHNOLOGY
All of the devices in the PIC18F87K90 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 RC
oscillator, power consumption during code
execution can be reduced.
• Multiple Idle Modes: The controller can also run
with its CPU core disabled but the peripherals still
active. In these states, power consumption can be
reduced even further.
• On-the-Fly Mode Swit ching: 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.
• nanoWatt XL P: An extra low-power BOR, RTCC
and low-power Watchdog Timer. Also, an ultra
low-power regulator for Sleep mode is provided in
regulator-enabled modes.
1.1.2OSCILLATOR OPTIONS AND
FEATURES
All of the devices in the PIC18F87K90 family offer
different oscillator options, allowing users a range of
choices in developing application hardware. These
include:
• External Resistor/Capacitor (RC); RA6 available
• External Resistor/Capacitor with Clock Out (RCIO)
• Three External Clock modes:
- External Clock (EC); RA6 available
- External Clock with Clock Out (ECIO)
- External Crystal (XT, HS, LP)
• A Phase Lock Loop (PLL) frequency multiplier,
available to the External Oscillator modes which
allows clock speeds of up to 64 MHz. PLL can
also be used with the internal oscillator.
• An internal oscillator block that provides a 16 MHz
clock (±2% accuracy) and an INTRC source
(approximately 31 kHz, stable over temperature
DD)
and V
- Operates as HF-INTOSC or MF-INTOSC
when block selected for 16 MHz or 500 kHz
- Frees the two oscillator pins for use as
additional general purpose I/O
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, allowing for continued low-speed
operation or a safe application shutdown.
• T wo-S pe ed 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.
1.1.3MEMORY OPTIONS
The PIC18F87K90 family provides ample room for
application code, from 32 Kbytes to 128 Kbytes of code
space. The Flash cells for program memory are rated
to last up to 10,000 erase/write cycles. Data retention
without refresh is conservatively estimated to be
greater than 40 years.
The Flash program memory is readable and writable.
During normal operation, the PIC18F87K90 family also
provides plenty of room for dynamic application data
with up to 3,828 bytes of data RAM.
1.1.4EXTENDED INSTRUCTION SET
The PIC18F87K90 family implements the optional
extension to the PIC18 instruction set, adding 8 new
instructions and an Indexed Addressing mode.
Enabled as a device configuration option, the extension
has been specifically designed to optimize re-entrant
application code originally developed in high-level
languages, such as ‘C’.
1.1.5EASY MIGRATION
Regardless of the memory size, all devices share the
same rich set of peripherals (except the 32-Kbyte parts,
which have two less CCPs and three less Timers),
allowing for a smooth migration path as applications
grow and evolve.
The consistent pinout scheme, used throughout the
entire family, also aids in migrating to the next larger
device. This is true when moving between the 64-pin
members, between the 80-pin members, or even
jumping from 64-pin to 80-pin devices.
2011 Microchip Technology Inc.DS39957C-page 9
PIC18F87K90 FAMILY
The PIC18F87K90 family is also largely
pin-compatible with other PIC18 families, such as the
PIC18F8720, PIC18F8722, PIC18F85J11, PIC18F8490,
PIC18F85J90, PIC18F87J90 and PIC18F87J93 families
of microcontrollers with LCD drivers. This allows a new
dimension to the evolution of applications, allowing
developers to select different price points within
Microchip’s PIC18 portfolio, while maintaining a similar
feature set.
1.2LCD Driver
The on-chip LCD driver includes many features that
ease the integration of displays in low-power
applications. These include an integrated internal
resistor ladder, so bias voltages can be generated
internally. This enables software-controlled contrast
control and eliminates the need for external bias
voltage resistors.
1.3Other Special Features
• Communications: The PIC18F87K90 family
incorporates a range of serial communication
peripherals including two Enhanced USART, that
support LIN/J2602, and two Master SSP modules
capable of both SPI and I
modes of operation.
• CCP Modules: PIC18F87K90 family devices
incorporate up to seven or five Capture/
Compare/PWM (CCP) modules. Up to six different time bases can be used to perform several different operations at once.
• ECCP Modules: The PIC18F87K90 family has
three Enhanced CCP (ECCP) modules to
maximize flexibility in control applications:
- Up to eight different time bases for performing several different operations at once
- Up to four PWM outputs for each module, for
a total of 12 PWMs
- Other beneficial features, such as polarity
selection, programmable dead time,
auto-shutdown and restart, and Half-Bridge
and Full-Bridge Output modes
• 12-Bit A/D Converter: The PIC18F87K90 family
has differential ADC. It 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.
• Charge Time Me as ure ment Unit (CTMU): The
CTMU is a flexible analog module that provides accurate differential time measurement between pulse
sources, as well as asynchronous pulse generation.
Together with other on-chip analog modules, the
CTMU can precisely measure time, measure
capacitance or relative changes in capacitance, or
generate output pulses that are independent of the
system clock.
2
C™ (Master and Slave)
• LP Watchdog Timer (WDT): This enhanced
version incorporates a 22-bit prescaler, allowing
an extended time-out range that is stable across
operating voltage and temperature. See
Section 31.0 “Electrical Characteristics” for
time-out periods.
• Real-Time Clock and Calendar Module (RTCC):
The RTCC module is intended for applications
requiring that accurate time be maintained for
extended periods of time with minimum to no
intervention from the CPU.
The module is a 100-year clock and calendar with
automatic leap year detection. The range of the
clock is from 00:00:00 (midnight) on January 1, 2000
to 23:59:59 on December 31, 2099.
1.4Details on Individual Family
Members
Devices in the PIC18F87K90 family are available in
64-pin and 80-pin packages. Block diagrams for the
two groups are shown in Figure 1-1 and Figure 1-2.
The devices are differentiated from each other in these ways:
• Flash Program Memory:
- PIC18FX5K90 (PIC18F65K90 and
PIC18F85K90) – 32 Kbytes
- PIC18FX6K90 (PIC18F66K90 and
PIC18F86K90) – 64 Kbytes
- PIC18FX7K90 (PIC18F67K90 and
PIC18F87K90) – 128 Kbytes
ST= Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2
C™ = I2C/SMBus
I
Note 1:Default assignment for ECCP2 when the CCP2MX Configuration bit is set.
2:Alternate assignment for ECCP2 when the CCP2MX Configuration bit is cleared.
3:Not available on PIC18F65K90 and PIC18F85K90 devices.
7
39
40
I/O
O
O
I/O
I
STSTMaster Clear (input) or programming voltage (input).
This pin is an active-low Reset to the device.
I
I
CMOS
I
CMOS
TTL
—
—
TTL
General purpose, input only pin.
Oscillator crystal or external clock input.
Oscillator crystal input.
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 certain oscillator modes, OSC2 pin outputs CLKO,
which has 1/4 the frequency of OSC1 and denotes the
instruction cycle rate.
General purpose I/O pin.
ST= Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2
C™ = I2C/SMBus
I
Note 1:Default assignment for ECCP2 when the CCP2MX Configuration bit is set.
2:Alternate assignment for ECCP2 when the CCP2MX Configuration bit is cleared.
3:Not available on PIC18F65K90 and PIC18F85K90 devices.
4:The CCP6, CCP7, CCP8 and CCP9 pin placement depends on the ECCPMX Configuration bit setting.
Pin Number
TQFP
9
49
50
Pin
Type
I
I
I
I
I/O
O
O
I/O
Buffer
Type
STSTMaster Clear (input) or programming voltage (input).
This pin is an active-low Reset to the device.
General purpose, input only pin.
Oscillator crystal or external clock input.
CMOS
CMOS
TTL
—
—
TTL
Oscillator crystal input.
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 certain oscillator modes, OSC2 pin outputs CLKO,
which has 1/4 the frequency of OSC1 and denotes the
instruction cycle rate.
General purpose I/O pin.
Note 1:Default assignment for ECCP2 when the CCP2MX Configuration bit is set.
REF-
REF-
REF+
REF+
ST= Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2
I
C™ = I2C/SMBus
2:Alternate assignment for ECCP2 when the CCP2MX Configuration bit is cleared.
3:Not available on PIC18F65K90 and PIC18F85K90 devices.
4:The CCP6, CCP7, CCP8 and CCP9 pin placement depends on the ECCPMX Configuration bit setting.
Pin Number
TQFP
30
29
28
27
34
33
Pin
Type
I/O
I
I
I/O
I
O
I/O
I
I
I/O
I
I
I/O
I
O
I/O
I
O
I
I
I
Buffer
Type
TTL
Analog
Analog
TTL
Analog
Analog
TTL
Analog
Analog
TTL
Analog
Analog
ST
ST
Analog
TTL
Analog
Analog
ST
ST
Analog
Description
PORTA is a bidirectional I/O port.
Digital I/O.
Analog Input 0.
Ultra low-power wake-up input.
Digital I/O.
Analog Input 1.
SEG18 output for LCD.
Digital I/O.
Analog Input 2.
A/D reference voltage (low) input.
Digital I/O.
Analog Input 3.
A/D reference voltage (high) input.
Digital I/O.
Timer0 external clock input.
SEG14 output for LCD.
Digital I/O.
Analog Input 4.
SEG15 output for LCD.
Timer1 clock input.
Timer3 external clock gate input.
High/Low-Voltage Detect (HLVD) input.
ST= Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2
C™ = I2C/SMBus
I
Note 1:Default assignment for ECCP2 when the CCP2MX Configuration bit is set.
2:Alternate assignment for ECCP2 when the CCP2MX Configuration bit is cleared.
3:Not available on PIC18F65K90 and PIC18F85K90 devices.
4:The CCP6, CCP7, CCP8 and CCP9 pin placement depends on the ECCPMX Configuration bit setting.
Pin Number
TQFP
58
57
56
55
54
53
Pin
Type
I/O
I
O
I
I/O
I
O
I/O
I
O
I
I/O
I
O
I
I/O
O
I/O
I
O
I/O
I
O
I
I
Buffer
Type
TTL
ST
Analog
ST
TTL
ST
Analog
TTL
ST
Analog
ST
TTL
ST
Analog
ST
ST
ST
TTL
TTL
Analog
TTL
TTL
Analog
ST
ST
Description
PORTB is a bidirectional I/O port. PORTB can be software
programmed for internal weak pull-ups on all inputs.
Digital I/O.
External Interrupt 0.
SEG30 output for LCD.
Enhanced PWM Fault input for ECCP1/2/3.
Digital I/O.
External Interrupt 1.
SEG8 output for LCD.
Digital I/O.
External Interrupt 2.
SEG9 output for LCD.
CTMU Edge 1 input.
Digital I/O.
External Interrupt 3.
SEG10 output for LCD.
CTMU Edge 2 input.
Capture 2 input/Compare 2 output/PWM2 output.
Enhanced PWM 2 Output A.
Digital I/O.
Interrupt-on-change pin.
SEG11 output for LCD.
Digital I/O.
Interrupt-on-change pin.
SEG29 output for LCD.
Timer3 clock input.
Timer1 external clock gate input.
ST= Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2
I
C™ = I2C/SMBus
Note 1:Default assignment for ECCP2 when the CCP2MX Configuration bit is set.
2:Alternate assignment for ECCP2 when the CCP2MX Configuration bit is cleared.
3:Not available on PIC18F65K90 and PIC18F85K90 devices.
4:The CCP6, CCP7, CCP8 and CCP9 pin placement depends on the ECCPMX Configuration bit setting.
Pin Number
TQFP
52
47
Pin
Type
I/O
I
I/O
I/O
I
I/O
Buffer
Type
TTL
TTL
ST
TTL
TTL
ST
Description
Digital I/O.
Interrupt-on-change pin.
In-Circuit Debugger and ICSP™ programming clock pin.
Digital I/O.
Interrupt-on-change pin.
In-Circuit Debugger and ICSP programming data pin.
ST= Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2
C™ = I2C/SMBus
I
Note 1:Default assignment for ECCP2 when the CCP2MX Configuration bit is set.
2:Alternate assignment for ECCP2 when the CCP2MX Configuration bit is cleared.
3:Not available on PIC18F65K90 and PIC18F85K90 devices.
4:The CCP6, CCP7, CCP8 and CCP9 pin placement depends on the ECCPMX Configuration bit setting.
Pin Number
TQFP
36
35
43
44
45
46
37
38
Pin
Type
I/O
O
I
I/O
I
I/O
O
O
I/O
I/O
O
O
I/O
I/O
I/O
O
I/O
I
I/O
O
I/O
O
O
I/O
O
I/O
O
I/O
I
I/O
O
Buffer
Type
ST
—
ST
ST
CMOS
ST
Analog
—
ST
ST
—
Analog
ST
ST
ST
Analog
ST
ST
ST
Analog
ST
—
Analog
ST
—
ST
Analog
ST
ST
ST
Analog
Description
PORTC is a bidirectional I/O port.
Digital I/O.
SOSC oscillator output.
Digital SOSC input.
Digital I/O.
SOSC oscillator input.
Capture 2 input/Compare 2 output/PWM2 output.
SEG32 output for LCD.
Enhanced PWM 2 Output A.
Digital I/O.
Capture 1 input/Compare 1 output/PWM1 output.
Enhanced PWM 1 Output A.
SEG13 output for LCD.
Digital I/O.
Synchronous serial clock input/output for SPI mode.
Synchronous serial clock input/output for I
SEG17 output for LCD.
Digital I/O.
SPI data in.
2
C data I/O.
I
SEG16 output for LCD.
Digital I/O.
SPI data out.
SEG12 output for LCD.
Digital I/O.
EUSART asynchronous transmit.
EUSART synchronous clock (see related RX1/DT1).
SEG27 output for LCD.
Digital I/O.
EUSART asynchronous receive.
EUSART synchronous data (see related TX1/CK1).
SEG28 output for LCD.
Note 1:Default assignment for ECCP2 when the CCP2MX Configuration bit is set.
2:Alternate assignment for ECCP2 when the CCP2MX Configuration bit is cleared.
3:Not available on PIC18F65K90 and PIC18F85K90 devices.
4:The CCP6, CCP7, CCP8 and CCP9 pin placement depends on the ECCPMX Configuration bit setting.
ST= Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2
I
C™ = I2C/SMBus
Pin Number
TQFP
72
69
68
67
66
65
64
63
Pin
Buffer
Type
Type
I/O
O
Analog
O
I/O
O
Analog
I
I
I/OOST
Analog
I/OOST
Analog
I/O
O
Analog
O
I/O
O
Analog
I
I/O
I/O
O
Analog
I/O
I/O
I/O
O
Analog
I
PORTD is a bidirectional I/O port.
ST
ST
ST
ST
ST
ST
—
ST
ST
2
C
I
ST
ST
2
I
C
ST
TTL
Digital I/O.
SEG0 output for LCD.
CTMU pulse generator output.
Digital I/O.
SEG1 output for LCD.
Timer5 clock input.
Timer7 external clock gate input.
Digital I/O.
SEG2 output for LCD.
Digital I/O.
SEG3 output for LCD.
Digital I/O.
SEG4 output for LCD.
SPI data out.
Digital I/O.
SEG5 output for LCD.
SPI data in.
2
C™ data in.
I
Digital I/O.
SEG6 output for LCD.
Synchronous serial clock input/output for SPI mode.
Synchronous serial clock input/output for I2C™ mode.
Digital I/O.
SEG7 output for LCD.
SPI slave select input.
ST= Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2
C™ = I2C/SMBus
I
Note 1:Default assignment for ECCP2 when the CCP2MX Configuration bit is set.
2:Alternate assignment for ECCP2 when the CCP2MX Configuration bit is cleared.
3:Not available on PIC18F65K90 and PIC18F85K90 devices.
4:The CCP6, CCP7, CCP8 and CCP9 pin placement depends on the ECCPMX Configuration bit setting.
Pin
Type
I/O
I
O
I/O
I
O
I/O
I
O
I/O
I/O
O
O
I/O
O
I/O
O
O
I/O
I/O
O
O
I/O
I/O
O
O
I/O
I/O
I/O
O
O
Buffer
Type
ST
Analog
—
ST
Analog
—
ST
Analog
ST
ST
ST
Analog
—
S/T
—
ST
Analog
—
ST
ST
Analog
—
ST
ST
Analog
—
ST
ST
ST
—
Analog
Description
PORTE is a bidirectional I/O port.
Digital I/O.
BIAS1 input for LCD.
ECCP2 PWM Output D.
Digital I/O.
BIAS2 input for LCD.
ECCP2 PWM Output C.
Digital I/O.
BIAS3 input for LCD.
ECCP2 PWM Output B.
Capture 10 input/Compare 10 output/PWM10 output.
Digital I/O.
COM0 output for LCD.
ECCP3 PWM Output C.
Capture 9 input/Compare 9 output/PWM9 output.
Reference clock out.
Digital I/O.
COM1 output for LCD.
ECCP4 PWM Output B.
Capture 8 input/Compare 8 output/PWM8 output.
Digital I/O.
COM2 output for LCD.
ECCP1 PWM Output C.
Capture 7 input/Compare 7 output/PWM7 output.
Digital I/O.
COM3 output for LCD.
ECCP1 PWM Output B.
Capture 6 input/Compare 6 output/PWM6 output.
Digital I/O.
Capture 2 input/Compare 2 output/PWM2 output.
ECCP2 PWM Output A.
SEG31 output for LCD.
Note 1:Default assignment for ECCP2 when the CCP2MX Configuration bit is set.
2:Alternate assignment for ECCP2 when the CCP2MX Configuration bit is cleared.
3:Not available on PIC18F65K90 and PIC18F85K90 devices.
4:The CCP6, CCP7, CCP8 and CCP9 pin placement depends on the ECCPMX Configuration bit setting.
REF/
/SEG25
ST= Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2
C™ = I2C/SMBus
I
Pin Number
TQFP
23
18
17
16
15
14
13
Pin
Type
I/O
I
O
O
I
I/O
I
O
O
O
I/O
I
O
I
I/O
I
O
I
I/O
I
O
O
I
I/O
I
O
I
I/O
O
I
O
Buffer
Type
ST
Analog
—
Analog
ST
ST
Analog
—
Analog
—
ST
Analog
Analog
Analog
ST
Analog
Analog
Analog
ST
Analog
Analog
Analog
Analog
ST
Analog
Analog
Analog
ST
Analog
TTL
Analog
Description
PORTF is a bidirectional I/O port.
Digital I/O.
Analog Input 6.
Comparator 2 output.
SEG19 output for LCD.
CTMU pulse delay input.
Digital I/O.
Analog Input 7.
Comparator 1 output.
SEG20 output for LCD.
CTMU pulse generator charger for the C2INB
comparator input.
Digital I/O.
Analog Input 8.
SEG21 output for LCD.
Comparator 2 Input B.
Digital I/O.
Analog Input 9.
SEG22 output for LCD.
Comparator 2 Input A.
Digital I/O.
Analog Input 10.
Comparator reference voltage output.
SEG23 output for LCD.
Comparator 1 Input B.
Digital I/O.
Analog Input 11.
SEG24 output for LCD.
Comparator 1 Input A.
Digital I/O.
Analog Input 5.
SPI slave select input.
SEG25 output for LCD.
Note 1:Default assignment for ECCP2 when the CCP2MX Configuration bit is set.
ST= Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2
C™ = I2C/SMBus
I
2:Alternate assignment for ECCP2 when the CCP2MX Configuration bit is cleared.
3:Not available on PIC18F65K90 and PIC18F85K90 devices.
4:The CCP6, CCP7, CCP8 and CCP9 pin placement depends on the ECCPMX Configuration bit setting.
Pin Number
TQFP
5
6
7
8
10
Pin
Type
I/O
I/O
O
I/O
O
I/O
I
O
I/O
I
I/O
I
I
I/O
I/O
I
O
I
I/O
O
O
I
I
I/O
I
O
I
Buffer
Type
ST
ST
—
ST
—
ST
Analog
—
ST
ST
ST
Analog
Analog
ST
ST
Analog
—
Analog
ST
Analog
—
ST
ST
ST
Analog
—
Analog
Description
PORTG is a bidirectional I/O port.
Digital I/O.
Capture 3 input/Compare 3 output/PWM3 output.
ECCP3 PWM Output A.
Digital I/O.
EUSART asynchronous transmit.
EUSART synchronous clock (see related RX2/DT2).
Analog Input 19.
Comparator 3 output.
Digital I/O.
EUSART asynchronous receive.
EUSART synchronous data (see related TX2/CK2).
Analog Input 18.
Comparator 3 Input A.
Digital I/O.
Capture 4 input/Compare 4 output/PWM4 output.
Analog Input 17.
ECCP3 PWM Output D.
Comparator 3 Input B.
Digital I/O.
SEG26 output for LCD.
RTCC output.
Timer7 clock input.
Timer5 external clock gate input.
Capture 5 input/Compare 5 output/PWM5 output.
Analog Input 16.
ECCP1 PWM Output D.
Comparator 3 Input C.
ST= Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2
C™ = I2C/SMBus
I
Note 1:Default assignment for ECCP2 when the CCP2MX Configuration bit is set.
2:Alternate assignment for ECCP2 when the CCP2MX Configuration bit is cleared.
3:Not available on PIC18F65K90 and PIC18F85K90 devices.
4:The CCP6, CCP7, CCP8 and CCP9 pin placement depends on the ECCPMX Configuration bit setting.
Pin Number
TQFP
79
80
1
2
22
21
20
Pin
Type
I/O
O
I
I/O
O
I
I/O
O
I
I/O
O
I
I/O
O
I/O
O
I
I
I/O
O
I/O
O
I
I
I/O
O
I/O
O
I
I
Buffer
Type
ST
Analog
Analog
ST
Analog
Analog
ST
Analog
Analog
ST
Analog
Analog
ST
Analog
ST
—
Analog
Analog
ST
Analog
ST
—
Analog
Analog
ST
Analog
ST
—
Analog
Analog
Description
PORTH is a bidirectional I/O port.
Digital I/O.
SEG47 output for LCD.
Analog Input 23.
Digital I/O.
SEG46 output for LCD.
Analog Input 22.
Digital I/O.
SEG45 output for LCD.
Analog Input 21.
Digital I/O.
SEG44 output for LCD.
Analog Input 20.
Digital I/O.
SEG40 output for LCD.
Capture 9 input/Compare 9 output/PWM9 output.
ECCP3 PWM Output C.
Analog Input 12.
Comparator 2 Input C.
Digital I/O.
SEG41 output for LCD.
Capture 8 input/Compare 8 output/PWM8 output.
ECCP3 PWM Output B.
Analog Input 13.
Comparator 1 Input D.
Digital I/O.
SEG42 output for LCD.
Capture 7 input/Compare 7 output/PWM7 output.
ECCP1 PWM Output C.
Analog Input 14.
Comparator 1 Input C.
ST= Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2
I
C™ = I2C/SMBus
Note 1:Default assignment for ECCP2 when the CCP2MX Configuration bit is set.
2:Alternate assignment for ECCP2 when the CCP2MX Configuration bit is cleared.
3:Not available on PIC18F65K90 and PIC18F85K90 devices.
4:The CCP6, CCP7, CCP8 and CCP9 pin placement depends on the ECCPMX Configuration bit setting.
Pin Number
TQFP
19
Pin
Type
I/O
O
I/O
O
I
Buffer
Type
ST
Analog
ST
—
Analog
Description
Digital I/O.
SEG43 output for LCD.
Capture 6 input/Compare 6 output/PWM6 output.
ECCP1 PWM Output B.
Analog Input 15.
ST= Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2
C™ = I2C/SMBus
I
Note 1:Default assignment for ECCP2 when the CCP2MX Configuration bit is set.
2:Alternate assignment for ECCP2 when the CCP2MX Configuration bit is cleared.
3:Not available on PIC18F65K90 and PIC18F85K90 devices.
4:The CCP6, CCP7, CCP8 and CCP9 pin placement depends on the ECCPMX Configuration bit setting.
Pin Number
TQFP
61
60
59
39
40
41
42
12
Pin
Buffer
Type
Type
I/OOST
Analog
I/OOST
Analog
I/OOST
Analog
I/OOST
Analog
I/OOST
Analog
I/OOST
Analog
I/OOST
Analog
P—
Description
PORTJ is a bidirectional I/O port.
Digital I/O.
SEG33 output for LCD.
Digital I/O.
SEG34 output for LCD.
Digital I/O.
SEG35 output for LCD.
Digital I/O.
SEG39 output for LCD.
Digital I/O
SEG38 output for LCD.
Digital I/O.
SEG37 output for LCD.
Digital I/O.
SEG36 output for LCD.
Core logic power or external filter capacitor connection.
Other devices may have more or less pairs;
adjust the number of decoupling capacitors
appropriately.
(1)
2.0GUIDELINES FOR GETTING
STARTED WITH PIC18FXXKXX
FIGURE 2-1:RECOMMENDED
MINIMUM CONNECTIONS
MICROCONTROLLERS
2.1Basic Connection Requirements
Getting started with the PIC18F87K90 family family of
8-bit microcontrollers requires attention to a minimal
set of device pin connections before proceeding with
development.
The following pins must always be connected:
DD and VSS pins
•All V
(see Section 2.2 “Power Supply Pins”)
•All AV
•MCLR
• ENVREG (if implemented) and V
These pins must also be connected if they are being
used in the end application:
• PGC/PGD pins used for In-Circuit Serial
• OSCI and OSCO pins when an external oscillator
Additionally, the following pins may be required:
•V
The minimum mandatory connections are shown in
Figure 2-1.
DD and AVSS pins, regardless of whether or
not the analog device features are used
(see Section 2.2 “Power Supply Pins”)
pin
(see Section 2.3 “Master Clear (MCLR) Pin”)
CAP/VDDCORE pins
(see Section 2.4 “Voltage Regulator Pins
(ENVREG and VCAP/VDDCORE)”)
Programming™ (ICSP™) and debugging purposes
(see Section 2.5 “ICSP Pins”)
source is used
(see Section 2.6 “External Oscillator Pins”)
REF+/VREF- pins are used when external voltage
reference for analog modules is implemented
Note:The AVDD and AVSS pins must always be
connected, regardless of whether any of
the analog modules are being used.
2011 Microchip Technology Inc.DS39957C-page 35
PIC18F87K90 FAMILY
Note 1: R1 10 k is recommended. A suggested
starting value is 10 k. Ensure that the
MCLR
pin VIH and VIL specifications are met.
2: R2 470 will limit any current flowing into
MCLR
from the external capacitor, C, in the
event of MCLR
pin breakdown, due to
Electrostatic Discharge (ESD) or Electrical
Overstress (EOS). Ensure that the MCLR
pin
V
IH and VIL specifications are met.
C1
R2
R1
V
DD
MCLR
PIC18FXXKXX
JP
2.2Power Supply Pins
2.2.1DECOUPLING CAPACITORS
The use of decoupling capacitors on every pair of
power supply pins, such as V
SS, is required.
AV
Consider the following criteria when using decoupling
capacitors:
• Value and type of capacitor: A 0.1 F (100 nF),
10-20V capacitor is recommended. The capacitor
should be a low-ESR device, with a resonance
frequency in the range of 200 MHz and higher.
Ceramic capacitors are recommended.
• Placement on the printed circuit board: The
decoupling capacitors should be placed as close
to the pins as possible. It is recommended to
place the capacitors on the same side of the
board as the device. If space is constricted, the
capacitor can be placed on another layer on the
PCB using a via; however, ensure that the trace
length from the pin to the capacitor is no greater
than 0.25 inch (6 mm).
• Handling high-frequency noise: If the board is
experiencing high-frequency noise (upward of
tens of MHz), add a second ceramic type capacitor in parallel to the above described decoupling
capacitor. The value of the second capacitor can
be in the range of 0.01 F to 0.001 F. Place this
second capacitor next to each primary decoupling
capacitor. In high-speed circuit designs, consider
implementing a decade pair of capacitances as
close to the power and ground pins as possible
(e.g., 0.1 F in parallel with 0.001 F).
• Maximizing performance: On the board layout
from the power supply circuit, run the power and
return traces to the decoupling capacitors first,
and then to the device pins. This ensures that the
decoupling capacitors are first in the power chain.
Equally important is to keep the trace length
between the capacitor and the power pins to a
minimum, thereby reducing PCB trace
inductance.
DD, VSS, AVDD and
2.3Master Clear (MCLR) Pin
The MCLR pin provides two specific device
functions: Device Reset, and Device Programming
and Debugging. If programming and debugging are
not required in the end application, a direct
connection to V
addition of other components, to help increase the
application’s resistance to spurious Resets from
voltage sags, may be beneficial. A typical
configuration is shown in Figure 2-1. Other circuit
designs may be implemented, depending on the
application’s requirements.
During programming and debugging, the resistance
and capacitance that can be added to the pin must
be considered. Device programmers and debuggers
drive the MCLR
levels (V
not be adversely affected. Therefore, specific values
of R1 and C1 will need to be adjusted based on the
application and PCB requirements. For example, it is
recommended that the capacitor, C1, be isolated
from the MCLR
debugging operations by using a jumper (Figure 2-2).
The jumper is replaced for normal run-time
operations.
Any components associated with the MCLR
should be placed within 0.25 inch (6 mm) of the pin.
FIGURE 2-2:EXAMPLE OF MCLR PIN
DD may be all that is required. The
pin. Consequently, specific voltage
IH and VIL) and fast signal transitions must
pin during programming and
pin
CONNECTIONS
2.2.2TANK CAPACITORS
On boards with power traces running longer than
six inches in length, it is suggested to use a tank capacitor for integrated circuits, including microcontrollers, to
supply a local power source. The value of the tank
capacitor should be determined based on the trace
resistance that connects the power supply source to
the device, and the maximum current drawn by the
device in the application. In other words, select the tank
capacitor so that it meets the acceptable voltage sag at
the device. Typical values range from 4.7 F to 47 F.
DS39957C-page 36 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
10
1
0.1
0.01
0.001
0.010.11101001000 10,000
Frequency (MHz)
ESR ()
Note:Typical data measurement at 25°C, 0V DC bias.
2.4Voltage Regulator Pins (ENVREG
and V
CAP/VDDCORE)
The on-chip voltage regulator enable pin, ENVREG,
must always be connected directly to either a supply
voltage or to ground. Tying ENVREG to VDD enables
the regulator, while tying it to ground disables the
regulator. Refer to Section 28.3 “On-Chip Voltage
Regulator” for details on connecting and using the
on-chip regulator.
When the regulator is enabled, a low-ESR (< 5Ω)
capacitor is required on the V
stabilize the voltage regulator output voltage. The
CAP/VDDCORE pin must not be connected to VDD and
V
must use a capacitor of 10 µF connected to ground. The
type can be ceramic or tantalum. Suitable examples of
capacitors are shown in Ta bl e 2 - 1. Capacitors with
equivalent specifications can be used.
Designers may use Figure 2-3 to evaluate ESR
equivalence of candidate devices.
It is recommended that the trace length not exceed
0.25 inch (6 mm). Refer to Section 31.0 “Electrical
Characteristics” for additional information.
When the regulator is disabled, the V
must be tied to a voltage supply at the V
Refer toSe ction 31.0 “Electrical Cha racteristics” for
information on VDD and VDDCORE.
CAP/VDDCORE pin to
CAP/VDDCORE pin
DDCORE level.
Some PIC18FXXKXX families, or some devices within
a family, do not provide the option of enabling or
disabling the on-chip voltage regulator:
• Some devices (with the name, PIC18LFXXKXX)
permanently disable the voltage regulator.
These devices do not have the ENVREG pin and
require a 0.1 F capacitor on the V
pin. The V
DD level of these devices must comply
CAP/VDDCORE
with the “voltage regulator disabled” specification
for Parameter D001, in Section 31.0 “Electrical
Characteristics”.
• Some devices permanently enable the voltage
regulator.
These devices also do not have the ENVREG pin.
The 10 F capacitor is still required on the
CAP/VDDCORE pin.
V
FIGURE 2-3:FREQUENCY vs. ESR
PERFORMANCE FOR
SUGGESTED V
CAP
TABLE 2-1:SUITABLE CAPACITOR EQUIVALENTS
MakePart #
TDKC3216X7R1C106K10 µF±10%16V-55 to 125ºC
TDKC3216X5R1C106K10 µF±10%16V-55 to 85ºC
PanasonicECJ-3YX1C106K10 µF±10%16V-55 to 125ºC
PanasonicECJ-4YB1C106K10 µF±10%16V-55 to 85ºC
MurataGRM32DR71C106KA01L10 µF±10%16V-55 to 125ºC
MurataGRM31CR61C106KC31L10 µF±10%16V-55 to 85ºC
2011 Microchip Technology Inc.DS39957C-page 37
Nominal
Capacitance
.
Base Tolerance Rated Voltage Temp. Range
PIC18F87K90 FAMILY
-80
-70
-60
-50
-40
-30
-20
-10
0
10
51011121314151617
DC Bias Voltage (VDC)
Capacitance Change (%)
012346789
16V Capacitor
10V Capacitor
6.3V Capacitor
2.4.1CONSIDERATIONS FOR CERAMIC
CAPACITORS
In recent years, large value, low-voltage, surface-mount
ceramic capacitors have become very cost effective in
sizes up to a few tens of microfarad. The low-ESR, small
physical size and other properties make ceramic
capacitors very attractive in many types of applications.
Ceramic capacitors are suitable for use with the internal voltage regulator of this microcontroller. However,
some care is needed in selecting the capacitor to
ensure that it maintains sufficient capacitance over the
intended operating range of the application.
Typical low-cost, 10 F ceramic capacitors are available
in X5R, X7R and Y5V dielectric ratings (other types are
also available, but are less common). The initial tolerance specifications for these types of capacitors are
often specified as ±10% to ±20% (X5R and X7R), or
-20%/+80% (Y5V). However, the effective capacitance
that these capacitors provide in an application circuit will
also vary based on additional factors, such as the
applied DC bias voltage and the temperature. The total
in-circuit tolerance is, therefore, much wider than the
initial tolerance specification.
The X5R and X7R capacitors typically exhibit satisfactory temperature stability (ex: ±15% over a wide
temperature range, but consult the manufacturer's data
sheets for exact specifications). However, Y5V capacitors typically have extreme temperature tolerance
specifications of +22%/-82%. Due to the extreme
temperature tolerance, a 10 F nominal rated Y5V type
capacitor may not deliver enough total capacitance to
meet minimum internal voltage regulator stability and
transient response requirements. Therefore, Y5V
capacitors are not recommended for use with the
internal regulator if the application must operate over a
wide temperature range.
In addition to temperature tolerance, the effective
capacitance of large value ceramic capacitors can vary
substantially, based on the amount of DC voltage
applied to the capacitor. This effect can be very significant, but is often overlooked or is not always
documented.
A typical DC bias voltage vs. capacitance graph for
X7R type and Y5V type capacitors is shown in
Figure 2-4.
FIGURE 2-4:DC BIAS VOLTAGE vs.
CAPACITANCE
CHARACTERISTICS
When selecting a ceramic capacitor to be used with the
internal voltage regulator, it is suggested to select a
high-voltage rating, so that the operating voltage is a
small percentage of the maximum rated capacitor voltage. For example, choose a ceramic capacitor rated at
16V for the 2.5V core voltage. Suggested capacitors
are shown in Table 2-1.
2.5ICSP Pins
The PGC and PGD pins are used for In-Circuit Serial
Programming™ (ICSP™) and debugging purposes. It
is recommended to keep the trace length between the
ICSP connector and the ICSP pins on the device as
short as possible. If the ICSP connector is expected to
experience an ESD event, a series resistor is recommended, with the value in the range of a few tens of
ohms, not to exceed 100Ω.
Pull-up resistors, series diodes and capacitors on the
PGC and PGD pins are not recommended as they will
interfere with the programmer/debugger communications to the device. If such discrete components are an
application requirement, they should be removed from
the circuit during programming and debugging. Alternatively, refer to the AC/DC characteristics and timing
requirements information in the respective device
Flash programming specification for information on
capacitive loading limits, and pin input voltage high
IH) and input low (VIL) requirements.
(V
For device emulation, ensure that the “Communication
Channel Select” (i.e., PGCx/PGDx pins), programmed
into the device, matches the physical connections for
the ICSP to the Microchip debugger/emulator tool.
For more information on available Microchip
development tools connection requirements, refer to
Section 30.0 “Development Support”.
DS39957C-page 38 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
GND
`
`
`
OSC1
OSC2
T1OSO
T1OS I
Copper Pour
Primary Oscillator
Crystal
Timer1 Oscillator
Crystal
DEVICE PINS
Primary
Oscillator
C1
C2
T1 Oscillator: C1
T1 Oscillator: C2
(tied to ground)
Single-Sided and In-Line Layouts:
Fine-Pitch (Dual-Sided) Layouts:
GND
OSCO
OSCI
Bottom Layer
Copper Pour
Oscillator
Crystal
Top Layer Copper Pour
C2
C1
DEVICE PINS
(tied to ground)
(tied to ground)
2.6External Oscillator Pins
Many microcontrollers have options for at least two
oscillators: a high-frequency primary oscillator and a
low-frequency secondary oscillator (refer to
Section 3.0 “Oscillator Configurations” for details).
The oscillator circuit should be placed on the same
side of the board as the device. Place the oscillator
circuit close to the respective oscillator pins with no
more than 0.5 inch (12 mm) between the circuit
components and the pins. The load capacitors should
be placed next to the oscillator itself, on the same side
of the board.
Use a grounded copper pour around the oscillator circuit to isolate it from surrounding circuits. The
grounded copper pour should be routed directly to the
MCU ground. Do not run any signal traces or power
traces inside the ground pour. Also, if using a two-sided
board, avoid any traces on the other side of the board
where the crystal is placed.
Layout suggestions are shown in Figure 2-4. In-line
packages may be handled with a single-sided layout
that completely encompasses the oscillator pins. With
fine-pitch packages, it is not always possible to completely surround the pins and components. A suitable
solution is to tie the broken guard sections to a mirrored
ground layer. In all cases, the guard trace(s) must be
returned to ground.
In planning the application’s routing and I/O assignments, ensure that adjacent port pins, and other
signals in close proximity to the oscillator, are benign
(i.e., free of high frequencies, short rise and fall times,
and other similar noise).
For additional information and design guidance on
oscillator circuits, please refer to these Microchip
Application Notes, available at the corporate web site
(www.microchip.com):
• AN826, “Crystal Oscillator Basics and Crystal
Selection for rfPIC™ and PICmicro
• AN849, “Basic PICmicro
• AN943, “Practical PICmicro
and Design”
• AN949, “Making Your Oscillator Work”
2.7Unused I/Os
Unused I/O pins should be configured as outputs and
driven to a logic low state. Alternatively, connect a 1 kΩ
to 10 kΩ resistor to VSS on unused pins and drive the
output to logic low.
®
®
Oscillator Design”
®
Devices”
Oscillator Analysis
FIGURE 2-5:SUGGESTED
PLACEMENT OF THE
OSCILLATOR CIRCUIT
2011 Microchip Technology Inc.DS39957C-page 39
PIC18F87K90 FAMILY
NOTES:
DS39957C-page 40 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
3.0OSCILLATOR
CONFIGURATIONS
3.1Oscillator Types
The PIC18F87K90 family of devices can be operated in
the following oscillator modes:
• ECExternal Clock, RA6 available
• ECIOExternal Clock, Clock Out RA6
(F
OSC/4 on RA6)
• HSHigh-Speed Crystal/Resonator
• XTCrystal/Resonator
• LPLow-Power Crystal
• RCExternal Resistor/Capacitor, RA6
available
• RCIOExternal Resistor/Capacitor, Clock
Out RA6 (F
• INTIO2Internal Oscillator with I/O on RA6
and RA7
• INTIO1Internal Oscillator with F
on RA6 and I/O on RA7
There is also an option for running the 4xPLL on any of
the clock sources in the input frequency range of 4 to
16 MHz.
The PLL is enabled by setting the PLLCFG bit
(CONFIG1H<4>) or the PLLEN bit (OSCTUNE<6>).
For the EC and HS mode, the PLLEN (software) or
PLLCFG (CONFIG) bit can be used to enable the PLL.
For the INTIOx modes (HF-INTOSC):
• Only the PLLEN can enable the PLL (PLLCFG is
ignored).
• When the oscillator is configured for the internal
oscillator (OSC<3:0> = 100x), the PLL can be
enabled only when the HF-INTOSC frequency is
8or 16MHz.
When the RA6 and RA7 pins are not used for an oscillator function or CLKOUT function, they are available
as general purpose I/Os.
OSC/4 on RA6)
OSC/4 Output
To optimize power consumption when using EC/HS/
XT/LP/RC as the primary oscillator, the frequency input
range can be configured to yield an optimized power
bias:
• Low-Power Bias – External frequency less than
160 kHz
• Medium Power Bias – External frequency
between 160 kHz and 16 MHz
• High-Power Bias – External frequency greater
than 16 MHz
All of these modes are selected by the user by
programming the OSC<3:0> Configuration bits
(CONFIG1H<3:0>). In addition, PIC18F87K90 family
devices can switch between different clock sources,
either under software control or under certain conditions, automatically. This allows for additional power
savings by managing device clock speed in real time
without resetting the application. The clock sources for
the PIC18F87K90 family of devices are shown in
Figure 3-1.
For the HS and EC mode, there are additional power
modes of operation – depending on the frequency of
operation.
HS1 is the Medium Power mode with a frequency
range of 4 MHz to 16 MHz. HS2 is the High-Power
mode where the oscillator frequency can go from
16 MHz to 25 MHz. HS1 and HS2 are achieved by
setting the CONFIG1H<3:0> correctly. (For details, see
Register 28-2 on page 428.)
EC mode has these modes of operation:
• EC1 – For low power with a frequency range up to
160 kHz
• EC2 – Medium power with a frequency range of
160 kHz to 16 MHz
• EC3 – High power with a frequency range of
16 MHz to 64 MHz
EC1, EC2 and EC3 are achieved by setting the
CONFIG1H<3:0> correctly. (For details, see
Register 28-2 on page 428.)
Table 3-1 shows the HS and EC modes’ frequency
range and OSC<3:0> settings.
2011 Microchip Technology Inc.DS39957C-page 41
PIC18F87K90 FAMILY
OSC2
OSC1
SOSCO
SOSCI
HF INTOSC
16 MHz to
31 kHz
MF INTOSC
500 kHz to
31 kHz
LF INTOSC
31 kHz
PostscalerPostscaler
16 MHz
8 MHz
4 MHz
2 MHz
1 MHz
500 kHz
250 kHz
31 kHz
500 kHz
250 kHz
31 kHz
31 kHz
16 MHz
8 MHz
4 MHz
2 MHz
1 MHz
500 kHz
250 kHz
31 kHz
4x PLL
FOSC<3:0>
INTSRC
MUX
MUX
MUX
MUX
MFIOSEL
MUX
Peripheral s
CPU
IDLEN
Clock Control
FOSC<3:0>
SCS<1:0>
111
110
101
100
011
010
001
000
IRCF<2:0>
MUX
PLLEN
and PLLCFG
TABLE 3-1:HS, EC, XT, LP AND RC MODES: RANGES AND SETTINGS
The OSCCON register (Register 3-1) controls the main
aspects of the device clock’s operation. It selects the
oscillator type to be used, which of the power-managed
modes to invoke and the output frequency of the
The OSCTUNE register (Register 3-3) controls the
tuning and operation of the internal oscillator block. It also
implements the PLLEN bit which controls the operation of
the Phase Locked Loop (PLL) (see
Frequency Multiplier”
).
Section 3.5.2 “PLL
INTOSC source. It also provides status on the oscillators.
REGISTER 3-1:OSCCON: OSCILLATOR CONTROL REGISTER
R/W-0R/W-1R/W-1R/W-0R
IDLENIRCF2
(2)
IRCF1
(2)
IRCF0
(2)
(1)
OSTSHFIOFSSCS1
(1)
R-0R/W-0R/W-0
(4)
SCS0
(4)
bit 7bit 0
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
bit 7IDLEN: Idle Enable bit
1 = Device enters an Idle mode when a SLEEP instruction is executed
0 = Device enters Sleep mode when a SLEEP instruction is executed
bit 6-4IRCF<2:0>: Internal Oscillator Frequency Select bits
(2)
111 = HF-INTOSC output frequency used (16 MHz)
110 = HF-INTOSC/2 output frequency used (8 MHz, default)
101 = HF-INTOSC/4 output frequency used (4 MHz)
100 = HF-INTOSC/8 output frequency used (2 MHz)
011 = HF-INTOSC/16 output frequency used (1 MHz)
If INTSRC =
0 and MFIOSEL = 0:
(3,5)
010 = HF-INTOSC/32 output frequency used (500 kHz)
001 = HF-INTOSC/64 output frequency used (250 kHz)
000 = LF-INTOSC output frequency used (31.25 kHz)
If INTSRC = 1 and MFIOSEL = 0:
(3,5)
010 = HF-INTOSC/32 output frequency used (500 kHz)
001 = HF-INTOSC/64 output frequency used (250 kHz)
000 = HF-INTOSC/512 output frequency used (31.25 kHz)
If INTSRC =
0 and MFIOSEL = 1:
(3,5)
010 = MF-INTOSC output frequency used (500 kHz)
001 = MF-INTOSC/2 output frequency used (250 kHz)
000 = LF-INTOSC output frequency used (31.25 kHz)
If INTSRC =
1 and MFIOSEL = 1:
(3,5)
010 = MF-INTOSC output frequency used (500 kHz)
001 = MF-INTOSC/2 output frequency used (250 kHz)
000 = MF-INTOSC/16 output frequency used (31.25 kHz)
bit 3OSTS: Oscillator Start-up Timer Time-out Status bit
(1)
1 = Oscillator Start-up Timer (OST) time-out has expired: primary oscillator is running, as defined by
OSC<3:0>
0 = Oscillator Start-up Timer (OST) time-out is running: primary oscillator is not ready, device is running
from an internal oscillator (HF-INTOSC, MF-INTOSC or LF-INTOSC)
Note 1:Reset state depends on the state of the IESO Configuration bit (CONFIG1H<7>).
2:Modifying these bits will cause an immediate clock frequency switch if the internal oscillator is providing
the device clocks.
3:Source selected by the INTSRC bit (OSCTUNE<7>).
4:Modifying these bits will cause an immediate clock source switch.
5:INTSRC = OSCTUNE<7> and MFIOSEL = OSCCON2<0>.
2011 Microchip Technology Inc.DS39957C-page 43
PIC18F87K90 FAMILY
REGISTER 3-1:OSCCON: OSCILLATOR CONTROL REGISTER
bit 2HFIOFS: INTOSC Frequency Stable bit
1 = HF-INTOSC oscillator frequency is stable
0 = HF-INTOSC oscillator frequency is not stable
bit 1-0SCS<1:0>: System Clock Select bits
1x = Internal oscillator block (LF-INTOSC, MF-INTOSC or HF-INTOSC)
01 = SOSC oscillator
00 = Default primary oscillator (OSC1/OSC2 or HF-INTOSC with or without PLL. Defined by the
OSC<3:0> Configuration bits, CONFIG1H<3:0>.)
Note 1:Reset state depends on the state of the IESO Configuration bit (CONFIG1H<7>).
2:Modifying these bits will cause an immediate clock frequency switch if the internal oscillator is providing
the device clocks.
3:Source selected by the INTSRC bit (OSCTUNE<7>).
4:Modifying these bits will cause an immediate clock source switch.
5:INTSRC = OSCTUNE<7> and MFIOSEL = OSCCON2<0>.
(4)
(1)
(CONTINUED)
REGISTER 3-2:OSCCON2: OSCILLATOR CONTROL REGISTER 2
U-0R-0U-0U-0R/W-0U-0R-xR/W-0
—SOSCRUN——SOSCGO—MFIOFSMFIOSEL
bit 7bit 0
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
bit 7Unimplemented: Read as ‘0’
bit 6SOSCRUN: SOSC Run Status bit
1 = System clock comes from a secondary SOSC
0 = System clock comes from an oscillator other than SOSC
bit 5-4Unimplemented: Read as ‘0’
bit 3SOSCGO: Oscillator Start Control bit
1 = Oscillator is running, even if no other sources are requesting it
0 = Oscillator is shut off if no other sources are requesting it (When the SOSC is selected to run from
a digital clock input, rather than an external crystal, this bit has no effect.)
bit 2Unimplemented: Read as ‘0’
bit 1MFIOFS: MF-INTOSC Frequency Stable bit
1 = MF-INTOSC is stable
0 = MF-INTOSC is not stable
bit 0MFIOSEL: MF-INTOSC Select bit
1 = MF-INTOSC is used in place of HF-INTOSC frequencies of 500 kHz, 250 kHz and 31.25 kHz
0 = MF-INTOSC is not used
DS39957C-page 44 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
REGISTER 3-3:OSCTUNE: OSCILLATOR TUNING REGISTER
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
INTSRCPLLENTUN5TUN4TUN3TUN2TUN1TUN0
bit 7bit 0
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
bit 7INTSRC: Internal Oscillator Low-Frequency Source Select bit
1 = 31.25 kHz device clock is derived from 16 MHz INTOSC source (divide-by-512 enabled, HF-INTOSC)
0 = 31 kHz device clock is derived from INTRC 31 kHz oscillator (LF-INTOSC)
bit 6PLLEN: Frequency Multiplier PLL Enable bit
1 = PLL is enabled
0 = PLL is disabled
bit 5-0TUN<5:0>: Fast RC Oscillator (INTOSC) Frequency Tuning bits
011111 = Maximum frequency
•
•
000001
000000 = Center frequency. Fast RC oscillator is running at the calibrated frequency.
111111
•
•
100000 = Minimum frequency
3.3Clock Sources and
Oscillator Switching
Essentially, PIC18F87K90 family devices have these
independent clock sources:
• Primary oscillators
• Secondary oscillators
• Internal oscillator
The primary oscillators can be thought of as the main
device oscillators. These are any external oscillators
connected to the OSC1 and OSC2 pins, and include
the External Crystal and Resonator modes and the
External Clock modes. If selected by the OSC<3:0>
Configuration bits (CONFIG1H<3:0>), the internal
oscillator block may be considered a primary oscillator.
The internal oscillator block can be one of the following:
• 31 kHz LF-INTRC source
• 31 kHz to 500 kHz MF-INTOSC source
• 31 kHz to 16 MHz HF-INTOSC source
The particular mode is defined by the OSC
Configuration bits. The details of these modes are
covered in Section 3.4 “External Oscillator Modes”.
The secondary oscillators are external clock
sources that are not connected to the OSC1 or OSC2
pin. These sources may continue to operate, even
after the controller is placed in a power-managed
mode. PIC18F87K90 family devices offer the SOSC
(Timer1/3/5/7) oscillator as a secondary oscillator
source. This oscillator, in all power-managed modes, is
often the time base for functions, such as a Real-Time
Clock (RTC).
The SOSCEN bit in the corresponding timer should be
set correctly for the enabled SOSC. The
SOSCEL<1:0> bits (CONFIG1L<4:3>) decide the
SOSC mode of operation:
• 11 = High-power SOSC circuit
• 10 = Digital (SCLKI) mode
• 01 = Low-power SOSC circuit
In addition to being a primary clock source in some
circumstances, the internal oscillator is available as a
power-managed mode clock source. The LF-INTOSC
source is also used as the clock source for several
special features, such as the WDT and Fail-Safe Clock
Monitor. The internal oscillator block is discussed in
more detail in Section 3.6 “Internal Oscillator
Block”.
The PIC18F87K90 family includes features that allow
the device clock source to be switched from the main
oscillator, chosen by device configuration, to one of the
alternate clock sources. When an alternate clock
source is enabled, various power-managed operating
modes are available.
2011 Microchip Technology Inc.DS39957C-page 45
PIC18F87K90 FAMILY
3.3.1OSC1/OSC2 OSCILLATOR
The OSC1/OSC2 oscillator block is used to provide the
oscillator modes and frequency ranges:
Mode Design Operating Frequency
LP31.25-100 kHz
XT100 kHz to 4 MHz
HS 4 MHz to 25 MHz
EC0 to 64 MHz (external clock)
EXTRC0 to 4 MHz (external RC)
The crystal-based oscillators (XT, HS and LP) have a
built-in start-up time. The operation of the EC and
EXTRC clocks is immediate.
3.3.2CLOCK SOURCE SELECTION
The System Clock Select bits, SCS<1:>0
(OSCCON2<1:0>), select the clock source. The available clock sources are the primary clock defined by the
OSC<3:0> Configuration bits, the secondary clock
(SOSC oscillator) and the internal oscillator. The clock
source changes after one or more of the bits is written
to, following a brief clock transition interval.
The OSTS (OSCCON<3>) and SOSCRUN
(OSCCON2<6>) bits indicate which clock source is
currently providing the device clock. The OSTS bit
indicates that the Oscillator Start-up Timer (OST) has
timed out and the primary clock is providing the device
clock in primary clock modes. The SOSCRUN bit
indicates when the SOSC oscillator (from Timer1/3/5/7)
is providing the device clock in secondary clock modes.
In power-managed modes, only one of these bits will
be set at any time. If neither of these bits is set, the
INTRC is providing the clock, or the internal oscillator
has just started and is not yet stable.
The IDLEN bit (OSCCON<7>) determines if the device
goes into Sleep mode or one of the Idle modes when
the SLEEP instruction is executed.
The use of the flag and control bits in the OSCCON
register is discussed in more detail in Section 4.0
“Power-Managed Modes”.
Note 1: The secondary oscillator must be enabled
to select the secondary clock source. The
SOSC oscillator is enabled by setting the
SOSCGO bit in the OSCCON2 register
(OSCCON<3>). If the SOSC 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 secondary
oscillator be operating and stable before
executing the SLEEP instruction or a very
long delay may occur while the SOSC
oscillator starts.
3.3.2.1System Clock Selection and Device
Resets
Since the SCS bits are cleared on all forms of Reset,
this means the primary oscillator, defined by the
OSC<3:0> Configuration bits, is used as the primary
clock source on device Resets. This could either be the
internal oscillator block by itself, or one of the other
primary clock source (HS, EC, XT, LP, External RC and
PLL-enabled modes).
In those cases when the internal oscillator block, without PLL, is the default clock on Reset, the Fast RC
oscillator (INTOSC) will be used as the device clock
source. It will initially start at 8 MHz; the postscaler
selection that corresponds to the Reset value of the
IRCF<2:0> bits (‘110’).
Regardless of which primary oscillator is selected,
INTRC will always be enabled on device power-up. It
serves as the clock source until the device has loaded
its configuration values from memory. It is at this point
that the OSC Configuration bits are read and the
oscillator selection of the operational mode is made.
Note that either the primary clock source or the internal
oscillator will have two bit setting options for the possible
values of the SCS<1:0> bits, at any given time.
3.3.3OSCILLATOR TRANSITIONS
PIC18F87K90 family devices contain circuitry to
prevent clock “glitches” when switching between clock
sources. A short pause in the device clock occurs during the clock switch. The length of this pause is the sum
of two cycles of the old clock source and three to four
cycles of the new clock source. This formula assumes
that the new clock source is stable.
Clock transitions are discussed in greater detail in
Section 4.1.2 “Entering Power-Managed Modes”.
3.4External Oscillator Modes
3.4.1CRYSTAL OSCILLATOR/CERAMIC
RESONATORS (HS MODES)
In HS or HSPLL Oscillator modes, a crystal or ceramic
resonator is connected to the OSC1 and OSC2 pins to
establish oscillation. Figure 3-2 shows the pin
connections.
The oscillator design requires the use of a crystal rated
for parallel resonant operation.
Note:Use of a crystal rated for series resonant
operation may give a frequency out of the
crystal manufacturer’s specifications.
DS39957C-page 46 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
Note 1: See Table 3-2 and Table 3-3 for initial values of
C1 and C2.
2: A series resistor (R
S) may be required for AT
strip cut crystals.
3: R
F varies with the oscillator mode chosen.
C1
(1)
C2
(1)
XTAL
OSC2
OSC1
RF
(3)
Sleep
To
Logic
RS
(2)
Internal
PIC18F87K90
TABLE 3-2:CAPACITOR SELECTION FOR
CERAMIC RESONATORS
Typical Capacitor Values Used:
ModeFreq.OSC1OSC2
HS8.0 MHz
16.0 MHz
Capacitor values are for design guidance only.
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. Refer
V
to the following application notes for oscillator-specific
information:
®
• AN588, “PIC
Microcont roller Oscillator Design
Guide”
• AN826, “Crystal Oscillator Basics and Crystal
Selection for rfPIC
®
and PIC® Devices”
• AN849, “Basic PIC® Oscillator Design”
• AN943, “Practical PIC® Oscillator Analysis and
Design”
• AN949, “Making Your Oscillator Work”
See the notes following Tab le 3 -3 for additional
information.
27 pF
22 pF
27 pF
22 pF
Note 1: Higher capacitance increases the stability
of oscillator but also increases the start-up
time.
2: Since each resonator/crystal has its
own characteristics, the user should
consult the resonator/crystal manufacturer for appropriate values of external
components.
3: Rs may be required to avoid overdriving
crystals with low drive level specification.
4: Always verify oscillator performance over
DD and temperature range that is
the V
expected for the application.
FIGURE 3-2:CRYSTAL/CERAMIC
RESONATOR OPERATION
(HS OR HSPLL
CONFIGURATION)
TABLE 3-3:CAPACITOR SELECTION FOR
CRYSTAL OSCILLATOR
Osc T y pe
Crystal
Freq.
HS4 MHz27 pF27 pF
8 MHz22 pF22 pF
20 MHz15 pF15 pF
Capacitor values are for design guidance only.
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
Refer to the Microchip application notes cited in
Table 3-2 for oscillator-specific information. Also see
the notes following this table for additional
information.
T ypical Cap acitor V alues
Tested:
C1C2
3.5RC Oscillator
For timing-insensitive applications, the RC and RCIO
Oscillator modes 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
EXT values)
- Variations within the tolerance of limits of
R
EXT and CEXT
EXT) and
2011 Microchip Technology Inc.DS39957C-page 47
PIC18F87K90 FAMILY
OSC2/CLKO
CEXT
REXT
PIC18FXXXX
OSC1
F
OSC/4
Internal
Clock
VDD
VSS
Recommended values: 3 k REXT 100 k
20 pF C
EXT 300 pF
CEXT
REXT
PIC18FXXXX
OSC1
Internal
Clock
VDD
VSS
Recommended values: 3 k REXT 100 k
20 pF C
EXT 300 pF
I/O (OSC2)
RA6
OSC1/CLKI
OSC2/CLKO
F
OSC/4
Clock from
Ext. System
PIC18F87K90
OSC1
OSC2
Open
Clock from
Ext. System
(HS Mode)
PIC18F87K90
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 3-3 shows how the R/C combination is
connected.
FIGURE 3-3:RC OSCILLATOR MODE
The RCIO Oscillator mode (Figure 3-4) 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 3-4:RCIO OSCILLATOR MODE
FIGURE 3-5:EXTERNAL CLOCK
INPUT OPERATION
(EC CONFIGURATION)
An external clock source may also be connected to the
OSC1 pin in the HS mode, as shown in Figure 3-6. In
this configuration, the divide-by-4 output on OSC2 is
not available. Current consumption in this configuration
will be somewhat higher than EC mode, as the internal
oscillator’s feedback circuitry will be enabled (in EC
mode, the feedback circuit is disabled).
FIGURE 3-6:EXTERNAL CLOCK INPUT
OPERATION (HS OSC
CONFIGURATION)
3.5.1EXTERNAL CLOCK INPUT
(EC MODES)
The EC and ECPLL 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 3-5 shows the pin connections for the EC
Oscillator mode.
DS39957C-page 48 2011 Microchip Technology Inc.
3.5.2PLL FREQUENCY MULTIPLIER
A Phase Lock Loop (PLL) circuit is provided as an
option for users who want 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.
3.5.2.1HSPLL and ECPLL Modes
The HSPLL and ECPLL modes provide the ability to
selectively run the device at four times the external
oscillating source to produce frequencies up to 64 MHz.
The PLL is enabled by setting the PLLEN bit
(OSCTUNE<6>) or the PLLCFG bit (CONFIG1H<4>).
For the HF-INTOSC as primary, the PLL must be
enabled with the PLLEN. This provides software control for the PLL, enabling even if PLLCFG is set to ‘1’,
so that the PLL is enabled only when the HF-INTOSC
frequency is within the 4 MHz to 16 MHz input range.
This also enables additional flexibility for controlling the
application’s clock speed in software. The PLLEN
should be enabled in HF-INTOSC mode only if the
input frequency is in the range of 4 MHz-16 MHz.
PIC18F87K90 FAMILY
MUX
VCO
Loop
Filter
OSC2
OSC1
PLL Enable (OSCTUNE)
F
IN
FOUT
SYSCLK
Phase
Comparator
PLLCFG (CONFIG1H<4>)
4
HS or EC
Mode
OSC2
F
OSC/4
I/O (OSC1)
RA7
PIC18F87K90
I/O (OSC2)
RA6
I/O (OSC1)
RA7
PIC18F87K90
FIGURE 3-7:PLL BLOCK DIAGRAM
3.5.2.2PLL and HF-INTOSC
The PLL is available to the internal oscillator block
when the internal oscillator block is configured as the
primary clock source. In this configuration, the PLL is
enabled in software and generates a clock output of up
to 64 MHz.
The operation of INTOSC with the PLL is described in
Section 3.6.2 “INTPLL Modes” . Care should be taken
that the PLL is enabled only if the HF-INTOSC
postscaler is configured for 4 MHz, 8 MHz or 16 MHz
3.6Internal Oscillator Block
The PIC18F87K90 family of devices includes an
internal oscillator block which generates two different
clock signals. Either clock can be used as the microcontroller’s clock source, which may eliminate the need
for an external oscillator circuit on the OSC1 and/or
OSC2 pins.
The internal oscillator consists of three blocks, depending on the frequency of operation. They are
HF-INTOSC, MF-INTOSC and LF-INTRC.
In HF-INTOSC mode, the internal oscillator can provide
a frequency, ranging from 31 kHz to 16 MHz, with the
postscaler deciding the selected frequency
(IRCF<2:0>).
The INTSRC bit (OSCTUNE<7>) and MFIOSEL bit
(OSCCON2<0>) also decide which INTOSC provides
the lower frequency (500 kHz to 31 kHz). For the
HF-INTOSC to provide these frequencies, INTSRC = 1
and MFI0SEL = 0.
In HF-INTOSC, the postscaler (IRCF<2:0>) provides the
frequency range of 31 kHz to 16 MHz. If HF-INTOSC is
used with the PLL, the input frequency to the PLL should
be 4 MHz to 16 MHz (IRCF<2:0> = 111, 110 or 101).
For MF-INTOSC mode to provide a frequency range of
500 kHz to 31 kHz, INTSRC = 1 and MFIOSEL = 1.
The postscaler (IRCF<2:0>), in this mode, provides the
frequency range of 31 kHz to 500 kHz.
The LF-INTRC can provide only 31 kHz if INTSRC = 0.
The LF-INTRC provides 31 kHz and is enabled if it is
selected as the device clock source. The mode is
enabled automatically when any of the following is
enabled:
• Power-up Timer
• Fail-Safe Clock Monitor
• Watchdog Timer
• Two-Speed Start-up
These features are discussed in greater detail in
Section 28.0 “Special Features of the CPU”.
The clock source frequency (HF-INTOSC, MF-INTOSC
or LF-INTRC direct) is selected by configuring the IRCF
bits of the OSCCON register, as well the INTSRC and
MFIOSEL bits. The default frequency on device Resets
is 8 MHz.
3.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
oscillator configurations, which are determined by the
OSC Configuration bits, are available:
• In INTIO1 mode, the OSC2 pin (RA6) outputs
.
FOSC/4, while OSC1 functions as RA7 (see
Figure 3-8) for digital input and output.
• In INTIO2 mode, OSC1 functions as RA7 and
OSC2 functions as RA6 (see Figure 3-9). Both
are available as digital input and output ports.
FIGURE 3-8:INTIO1 OSCILLATOR MODE
FIGURE 3-9:INTIO2 OSCILLATOR MODE
2011 Microchip Technology Inc.DS39957C-page 49
PIC18F87K90 FAMILY
3.6.2INTPLL MODES
The 4x Phase Locked Loop (PLL) can be used with the
HF-INTOSC to produce faster device clock speeds
than are normally possible with the internal oscillator
sources. When enabled, the PLL produces a clock
speed of 16 MHz or 64 MHz.
PLL operation is controlled through software. The control bits, PLLEN (OSCTUNE<6>) and PLLCFG
(CONFIG1H<4>), are used to enable or disable its
operation. The PLL is available only to HF-INTOSC
and the other oscillator is set with HS and EC modes.
Additionally, the PLL will only function when the
selected output frequency is either 4 MHz or 16 MHz
(OSCCON<6:4> = 111, 110 or 101).
Like the INTIO modes, there are two distinct INTPLL
modes available:
• In INTPLL1 mode, the OSC2 pin outputs F
while OSC1 functions as RA7 for digital input and
output. Externally, this is identical in appearance
to INTIO1 (Figure 3-8).
• In INTPLL2 mode, OSC1 functions as RA7 and
OSC2 functions as RA6, both for digital input and
output. Externally, this is identical to INTIO2
(Figure 3-9).
OSC/4,
3.6.3INTERNAL OSCILLATOR OUTPUT
FREQUENCY AND TUNING
The internal oscillator block is calibrated at the factory
to produce an INTOSC output frequency of 16 MHz. It
can be adjusted in the user’s application by writing to
TUN<5:0> (OSCTUNE<5:0>) in the OSCTUNE
register (Register 3-3).
When the OSCTUNE register is modified, the INTOSC
(HF-INTOSC and MF-INTOSC) frequency will begin
shifting to the new frequency. The oscillator will require
some time to stabilize. Code execution continues
during this shift and there is no indication that the shift
has occurred.
The LF-INTOSC oscillator operates independently of
the HF-INTOSC or the MF-INTOSC source. Any
changes in the HF-INTOSC or the MF-INTOSC source,
across voltage and temperature, are not necessarily
reflected by changes in LF-INTOSC or vice versa. The
frequency of LF-INTOSC is not affected by OSCTUNE.
3.6.4INTOSC FREQUENCY DRIFT
The INTOSC frequency may drift as VDD or temperature changes and 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. Depending on the device, this may have no
effect on the LF-INTOSC clock source frequency.
Tuning INTOSC 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 shown here.
3.6.4.1Compensating with the EUSART
An adjustment may be required when the EUSART
begins to generate framing errors or receives data 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.
3.6.4.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 SOSC
oscillator.
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 much greater than expected, then the internal
oscillator block is running too fast. To adjust for this,
decrement the OSCTUNE register.
3.6.4.3Compensating with the CCP Module
in Capture Mode
A CCP module can use free-running Timer1 (or
Timer3), clocked by the internal oscillator block and an
external event with a known period (i.e., AC power
frequency). The time of the first event is captured in the
CCPRxH:CCPRxL registers and is recorded for use
later. When the second event causes a capture, the
time of the first event is subtracted from the time of the
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
calculated time, the internal oscillator block is running
too slow. To compensate, increment the OSCTUNE
register.
DS39957C-page 50 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
3.7Reference Clock Output
In addition to the FOSC/4 clock output in certain oscillator modes, the device clock in the PIC18F87K90 family
can also be configured to provide a reference clock output signal to a port pin. This feature is available in all
oscillator configurations and allows the user to select a
greater range of clock submultiples to drive external
devices in the application.
This reference clock output is controlled by the
REFOCON register (Register 3-4). Setting the ROON
bit (REFOCON<7>) makes the clock signal available
on the REFO (RE3) pin. The RODIV<3:0> bits enable
the selection of 16 different clock divider options.
The ROSSLP and ROSEL bits (REFOCON<5:4>) control the availability of the reference output during Sleep
mode. The ROSEL bit determines if the oscillator on
OSC1 and OSC2, or the current system clock source,
is used for the reference clock output. The ROSSLP bit
determines if the reference source is available on RE3
when the device is in Sleep mode.
To use the reference clock output in Sleep mode, both
the ROSSLP and ROSEL bits must be set. The device
clock must also be configured for an EC or HS mode;
otherwise, the oscillator on OSC1 and OSC2 will be
powered down when the device enters Sleep mode.
Clearing the ROSEL bit allows the reference output
frequency to change as the system clock changes
during any clock switches.
REGISTER 3-4:REFOCON: REFERENCE OSCILLAT OR CONTROL REGISTER
R/W-0 U-0R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
ROON
bit 7bit 0
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
—ROSSLPROSEL
(1)
RODIV3RODIV2RODIV1RODIV0
bit 7ROON: Reference Oscillator Output Enable bit
1 = Reference oscillator output is available on REFO pin
0 = Reference oscillator output is disabled
bit 6Unimplemented: Read as ‘0’
bit 5ROSSLP: Reference Oscillator Output Stop in Sleep bit
1 = Reference oscillator continues to run in Sleep
0 = Reference oscillator is disabled in Sleep
bit 4ROSEL: Reference Oscillator Source Select bit
1 = Primary oscillator (EC or HS) is used as the base clock
0 = System clock is used as the base clock; base clock reflects any clock switching of the device
bit 3-0RODIV<3:0>: Reference Oscillator Divisor Select bits
1111 = Base clock value divided by 32,768
1110 = Base clock value divided by 16,384
1101 = Base clock value divided by 8,192
1100 = Base clock value divided by 4,096
1011 = Base clock value divided by 2,048
1010 = Base clock value divided by 1,024
1001 = Base clock value divided by 512
1000 = Base clock value divided by 256
0111 = Base clock value divided by 128
0110 = Base clock value divided by 64
0101 = Base clock value divided by 32
0100 = Base clock value divided by 16
0011 = Base clock value divided by 8
0010 = Base clock value divided by 4
0001 = Base clock value divided by 2
0000 = Base clock value
(1)
Note 1:For ROSEL (REFOCON<4>), the primary oscillator is only available when configured as a default via the
FOSC settings (regardless of whether the device is in Sleep mode).
2011 Microchip Technology Inc.DS39957C-page 51
PIC18F87K90 FAMILY
3.8Effects of Power-Managed Modes
on the Various Clock Sources
When PRI_IDLE mode is selected, the designated primary oscillator continues to run without interruption.
For all other power-managed modes, the oscillator
using the OSC1 pin is disabled. The OSC1 pin (and
OSC2 pin if used by the oscillator) will stop oscillating.
In secondary clock modes (SEC_RUN and
SEC_IDLE), the SOSC oscillator is operating and
providing the device clock. The SOSC oscillator may
also run in all power-managed modes if required to
clock SOSC.
In RC_RUN and RC_IDLE modes, the internal
oscillator provides the device clock source. The 31 kHz
LF-INTOSC output can be used directly to provide the
clock and may be enabled to support various special
features, regardless of the power-managed mode (see
Section 28.2 “Watchdog Timer (WDT)” through
Section 28.5 “Fail-Safe Clock Monitor” for more
information on WDT, Fail-Safe Clock Monitor and
Two-Speed Start-up).
If the Sleep mode is selected, all clock sources are
stopped. Since all the transistor switching currents
have been stopped, Sleep mode achieves the lowest
current consumption of the device (only leakage
currents).
Enabling any on-chip feature that will operate during
Sleep will increase the current consumed during Sleep.
The INTOSC is required to support WDT operation.
The SOSC oscillator may be operating to support a
Real-Time Clock (RTC). Other features may be operating that do not require a device clock source (i.e.,
MSSP slave, INTx pins and others). Peripherals that
may add significant current consumption are listed in
Section 31.2 “DC Characteristics: Power-Down and
Supply Current PIC18F87K90 Family (Industrial)”.
3.9Power-up Delays
Power-up delays are controlled by two timers, so that
no external Reset circuitry is required for most applications. The delays ensure that the device is kept in
Reset until the device power supply is stable under normal circumstances and the primary clock is operating
and stable. For additional information on power-up
delays, see Section 5.6 “Power-up Timer (PWRT)”.
The first timer is the Power-up Timer (PWRT), which
provides a fixed delay on power-up time of about 64 ms
(Parameter 33, Table 31-10); it is always enabled.
The second timer is the Oscillator Start-up Timer
(OST), intended to keep the chip in Reset until the
crystal oscillator is stable (HS, XT or LP modes). The
OST does this by counting 1,024 oscillator cycles
before allowing the oscillator to clock the device.
There is a delay of interval, T
Table 31-10), following POR, while the controller
becomes ready to execute instructions.
CSD (Parameter 38,
TABLE 3-4:OSC1 AND OSC2 PIN STATES IN SLEEP MODE
Oscillator ModeOSC1 PinOSC2 Pin
EC, ECPLLFloating, pulled by external clockAt logic low (clock/4 output)
HS, HSPLLFeedback inverter is disabled at quiescent
voltage level
INTOSC, INTPLL1/2I/O pin, RA6, direction controlled by
TRISA<6>
Note:See Section 5.0 “Reset” for time-outs due to Sleep and MCLR
Feedback inverter disabled at quiescent
voltage level
I/O pin, RA6, direction controlled by
TRISA<7>
Reset.
DS39957C-page 52 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
4.0POWER-MANAGED MODES
The PIC18F87K90 family of devices offers a total of
seven operating modes for more efficient power management. These modes provide a variety of options for
selective power conservation in applications where
resources may be limited (such as battery-powered
devices).
There are three categories of power-managed modes:
• Run modes
• Idle modes
• Sleep mode
There is an Ultra Low-Power Wake-up (ULPWU) for
waking from the Sleep mode.
These categories define which portions of the device
are clocked, and sometimes, at what speed. The Run
and Idle modes may use any of the three available
clock sources (primary, secondary or internal oscillator
block). The Sleep mode does not use a clock source.
The ULPWU mode, on the RA0 pin, enables a slow falling voltage to generate a wake-up, even from Sleep,
without excess current consumption. (See Section 4.7
“Ultra Low-Power Wake-up”.)
The power-managed modes include several powersaving features offered on previous PIC
is the clock switching feature, offered in other PIC18
devices. This feature allows the controller to use the
SOSC oscillator instead of the primary one. Another
power-saving feature is Sleep mode, offered by all PIC
devices, where all device clocks are stopped.
4.1Selecting Power-Managed Modes
Selecting a power-managed mode requires two
decisions:
• Will the CPU be clocked or not
• What will be the clock source
®
devices. One
The IDLEN bit (OSCCON<7>) controls CPU clocking,
while the SCS<1:0> bits (OSCCON<1:0>) select the
clock source. The individual modes, bit settings, clock
sources and affected modules are summarized in
Ta bl e 4- 1 .
4.1.1CLOCK SOURCES
The SCS<1:0> bits select one of three clock sources
for power-managed modes. Those sources are:
• The primary clock, as defined by the OSC<3:0>
Configuration bits
• The secondary clock (the SOSC oscillator)
• The internal oscillator block (for LF-INTOSC
modes)
4.1.2ENTERING POWER-MANAGED
MODES
Switching from one power-managed mode to another
begins by loading the OSCCON register. The
SCS<1:0> bits select the clock source and determine
which Run or Idle mode is used. Changing these bits
causes an immediate switch to the new clock source,
assuming that it is running. The switch may also be
subject to clock transition delays. These considerations
are discussed in Section 4.1.3 “Clock Transitions
and Status Indicators” and subsequent sections.
Entering the power-managed Idle or Sleep modes is
triggered by the execution of a SLEE P instruction. The
actual mode that results depends on the status of the
IDLEN bit.
Depending on the current and impending mode, a
change to a power-managed mode does not always
require setting all of the previously discussed bits. Many
transitions can be done by changing the oscillator select
bits, or changing the IDLEN bit, prior to issuing a SLEEP
instruction. If the IDLEN bit is already configured as
desired, it may only be necessary to perform a SLEEP
instruction to switch to the desired mode.
Note 1:IDLEN reflects its value when the SLEEP instruction is executed.
2:Includes INTOSC (HF-INTOSC and MG-INTOSC) and INTOSC postscaler, as well as the LF-INTISC source.
2011 Microchip Technology Inc.DS39957C-page 53
OSCCON BitsModule Clocking
IDLEN<7>
(1)
SCS<1:0>CPUPeripherals
Available Clock and Oscillator Source
Primary – XT, LP, HS, EC, RC and PLL modes.
This is the normal, full-power execution mode.
(2)
(2)
PIC18F87K90 FAMILY
4.1.3CLOCK TRANSITIONS AND STATUS
INDICATORS
The length of the transition between clock sources is
the sum of two cycles of the old clock source and
three to four cycles of the new clock source. This formula assumes that the new clock source is stable.
The HF-INTOSC and MF-INTOSC are termed as
INTOSC in this chapter.
Three bits indicate the current clock source and its
status, as shown in Tab le 4 -2 . The three bits are:
• OSTS (OSCCON<3>)
• HFIOFS (OSCCON<2>)
• SOSCRUN (OSCCON2<6>)
TABLE 4-2:SYSTEM CLOCK INDICATOR
Main Clock SourceOSTS
Primary Oscillator100
INTOSC (HF-INTOSC or
MF-INTOSC)
Secondary Oscillator001
MF-INTOSC or
HF-INTOSC as Primary
Clock Source
LF-INTOSC is Running or
INTOSC is Not Yet Stable
When the OSTS bit is set, the primary clock is providing
the device clock. When the HFIOFS or MFIOFS bit is
set, the INTOSC output is providing a stable clock
source to a divider that actually drives the device clock.
When the SOSCRUN bit is set, the SOSC oscillator is
providing the clock. If none of these bits are set, either
the LF-INTOSC clock source is clocking the device or
the INTOSC source is not yet stable.
If the internal oscillator block is configured as the
primary clock source by the OSC<3:0> Configuration
bits (CONFIG1H<3:0>), then the OSTS and HFIOFS or
MFIOFS bits can be set when in PRI_RUN or
PRI_IDLE modes. This indicates that the primary clock
(INTOSC output) is generating a stable output.
Entering another INTOSC power-managed mode at
the same frequency would clear the OSTS bit.
Note 1: Caution should be used when modifying
a single IRCF bit. At a lower V
possible to select a higher clock speed
than is supportable by that V
device operation may result if the V
OSC specifications are violated.
F
2: Executing a SLEEP instruction does not
necessarily place the device into Sleep
mode. It acts as the trigger to place the
controller into either the Sleep mode or
one of the Idle modes, depending on the
setting of the IDLEN bit.
HFIOFS or
MFIOFS
010
110
000
SOSCRUN
DD, it is
DD. Improper
DD/
4.1.4MULTIPLE SLEEP COMMANDS
The power-managed mode that is invoked with the
SLEEP instruction is determined by the setting of the
IDLEN bit at the time the instruction is executed. If
another SLEEP instruction is executed, the device will
enter the power-managed mode specified by IDLEN at
that time. If IDLEN has changed, the device will enter
the new power-managed mode specified by the new
setting.
4.2Run Modes
In the Run modes, clocks to both the core and
peripherals are active. The difference between these
modes is the clock source.
4.2.1PRI_RUN MODE
The PRI_RUN mode is the normal, full-power execution mode of the microcontroller. This is also the default
mode upon a device Reset, unless Two-Speed Start-up
is enabled. (For details, see Section 28.4 “Two-Speed
Start-up”.) In this mode, the OSTS bit is set. The
HFIOFS or MFIOFS bit may be set if the internal
oscillator block is the primary clock source. (See
Section 3.2 “Control Registers”.)
4.2.2SEC_RUN MODE
The SEC_RUN mode is the compatible mode to the
“clock-switching” feature offered in other PIC18
devices. In this mode, the CPU and peripherals are
clocked from the SOSC oscillator. This enables lower
power consumption while retaining a high-accuracy
clock source.
SEC_RUN mode is entered by setting the SCS<1:0>
bits to ‘01’. The device clock source is switched to the
SOSC oscillator (see Figure 4-1), the primary oscillator
is shut down, the SOSCRUN bit (OSCCON2<6>) is set
and the OSTS bit is cleared.
Note:The SOSC oscillator can be enabled by
setting the SOSCGO bit (OSCCON2<3>).
If this bit is set, the clock switch to the
SEC_RUN mode can switch immediately
once SCS<1:0> are set to ‘01’.
On transitions from SEC_RUN mode to PRI_RUN
mode, the peripherals and CPU continue to be clocked
from the SOSC oscillator while the primary clock is
started. When the primary clock becomes ready, a
clock switch back to the primary clock occurs (see
Figure 4-2). When the clock switch is complete, the
SOSCRUN bit is cleared, the OSTS bit is set and the
primary clock is providing the clock. The IDLEN and
SCS bits are not affected by the wake-up and the
SOSC oscillator continues to run.
DS39957C-page 54 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
Q4Q3Q2
OSC1
Peripheral
Program
Q1
SOSCI
Q1
Counter
Clock
CPU
Clock
PC + 2PC
123n-1n
Clock Transition
(1)
Q4Q3Q2Q1Q3Q2
PC + 4
Note 1: Clock transition typically occurs within 2-4 T
OSC.
Q1Q3 Q4
OSC1
Peripheral
Program
PC
SOSC
PLL Clock
Q1
PC + 4
Q2
Output
Q3Q4Q1
CPU Clock
PC + 2
Clock
Counter
Q2Q2Q3
Note 1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
2: Clock transition typically occurs within 2-4 T
OSC.
SCS<1:0> bits Changed
TPLL
(1)
12 n-1n
Clock
OSTS bit Set
Transition
(2)
TOST
(1)
FIGURE 4-1:TRANSITION TIMING FOR ENTRY TO SEC_RUN MODE
FIGURE 4-2:TRANSITION TIMING FROM SEC_RUN MODE TO PRI_RUN MODE (HSPLL)
4.2.3RC_RUN MODE
In RC_RUN mode, the CPU and peripherals are
clocked from the internal oscillator block using the
INTOSC multiplexer. In this mode, the primary clock is
shut down. When using the LF-INTOSC source, this
mode provides the best power conservation of all the
Run modes, while still executing code. It works well for
user applications which are not highly timing-sensitive
or do not require high-speed clocks at all times.
If the primary clock source is the internal oscillator
block – either LF-INTOSC or INTOSC (MF-INTOSC or
HF-INTOSC) – there are no distinguishable differences
between the PRI_RUN and RC_RUN modes during
execution. Entering or exiting RC_RUN mode,
however, causes a clock switch delay. Therefore, if the
primary clock source is the internal oscillator block,
using RC_RUN mode is not recommended.
2011 Microchip Technology Inc.DS39957C-page 55
This mode is entered by setting the SCS1 bit to ‘1’. To
maintain software compatibility with future devices, it is
recommended that the SCS0 bit also be cleared, even
though the bit is ignored. When the clock source is
switched to the INTOSC multiplexer (see Figure 4-3),
the primary oscillator is shut down and the OSTS bit is
cleared. The IRCF bits may be modified at any time to
immediately change the clock speed.
Note:Caution should be used when modifying a
single IRCF bit. At a lower V
DD, it is
possible to select a higher clock speed
than is supportable by that V
device operation may result if the V
OSC specifications are violated.
F
DD. Improper
DD/
PIC18F87K90 FAMILY
If the IRCF bits and the INTSRC bit are all clear, the
INTOSC output (HF-INTOSC/MF-INTOSC) is not
enabled and the HFIOFS and MFIOFS bits will remain
clear. There will be no indication of the current clock
source. The LF-INTOSC source is providing the device
clocks.
If the IRCF bits are changed from all clear (thus,
enabling the INTOSC output) or if INTSRC or
MFIOSEL is set, the HFIOFS or MFIOFS bit is set after
the INTOSC output becomes stable. For details, see
Table 4-3.
TABLE 4-3:INTERNAL OSCILLATOR FREQUENCY STABILITY BITS
IRCF<2:0>INTSRCMFIOSELStatus of MFIOFS or HFIOFS when INTOSC is Stable
000 0xMFIOFS = 0, HFIOFS = 0 and clock source is LF-INTOSC
00010MFIOFS = 0, HFIOFS = 1 and clock source is HF-INTOSC
00011MFIOFS = 1, HFIOFS = 0 and clock source is MF-INTOSC
Non-Zerox0MFIOFS = 0, HFIOFS = 1 and clock source is HF-INTOSC
Non-Zerox1MFIOFS = 1, HFIOFS = 0 and clock source is MF-INTOSC
Clocks to the device continue while the INTOSC source
stabilizes after an interval of T
Table 31-10).
If the IRCF bits were previously at a non-zero value, or
if INTSRC was set before setting SCS1, and the
INTOSC source was already stable, the HFIOFS or
MFIOFS bit will remain set.
IOBST (Parameter 39,
On transitions from RC_RUN mode to PRI_RUN mode,
the device continues to be clocked from the INTOSC
multiplexer while the primary clock is started. When the
primary clock becomes ready, a clock switch to the
primary clock occurs (see Figure 4-4). When the clock
switch is complete, the HFIOFS or MFIOFS bit is
cleared, the OSTS bit is set and the primary clock is
providing the device clock. The IDLEN and SCS bits
are not affected by the switch. The LF-INTOSC source
will continue to run if either the WDT or the Fail-Safe
Clock Monitor is enabled.
DS39957C-page 56 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
Q4Q3Q2
OSC1
Peripheral
Program
Q1
LF-INTOSC
Q1
Counter
Clock
CPU
Clock
PC + 2PC
123n-1n
Clock Transition
(1)
Q4Q3Q2Q1Q3Q2
PC + 4
Note 1: Clock transition typically occurs within 2-4 T
OSC.
Q1
Q3 Q4
OSC1
Peripheral
Program
PC
INTOSC
PLL Clock
Q1
PC + 4
Q2
Output
Q3
Q4
Q1
CPU Clock
PC + 2
Clock
Counter
Q2
Q2
Q3
Note 1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
2: Clock transition typically occurs within 2-4 T
OSC.
SCS<1:0> bits Changed
TPLL
(1)
12 n-1n
Clock
OSTS bit Set
Transition
(2)
Multiplexer
TOST
(1)
FIGURE 4-3:TRANSITION TIMING TO RC_RUN MODE
FIGURE 4-4:TRANSITION TIMING FROM RC_RUN MODE TO PRI_RUN MODE
2011 Microchip Technology Inc.DS39957C-page 57
PIC18F87K90 FAMILY
Q4Q3Q2
OSC1
Peripheral
Sleep
Program
Q1Q1
Counter
Clock
CPU
Clock
PC + 2PC
Q3 Q4 Q1 Q2
OSC1
Peripheral
Program
PC
PLL Clock
Q3 Q4
Output
CPU Clock
Q1Q2 Q3 Q4 Q1 Q2
Clock
Counter
PC + 6
PC + 4
Q1 Q2 Q3 Q4
Wake Event
Note 1: T
OST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
TOST
(1)
TPLL
(1)
OSTS bit Set
PC + 2
4.3Sleep Mode
The power-managed Sleep mode in the PIC18F87K90
family of devices is identical to the legacy Sleep mode
offered in all other PIC devices. It is entered by clearing
the IDLEN bit (the default state on device Reset) and
executing the SLEEP instruction. This shuts down the
selected oscillator (Figure 4-5). All clock source status
bits are cleared.
Entering Sleep mode from any other mode does not
require a clock switch. This is because no clocks are
needed once the controller has entered Sleep. If the
WDT is selected, the LF-INTOSC source will continue
to operate. If the SOSC oscillator is enabled, it will also
continue to run.
When a wake event occurs in Sleep mode (by interrupt,
Reset or WDT time-out), the device will not be clocked
until the clock source selected by the SCS<1:0> bits
becomes ready (see Figure 4-6). Alternately, the device
will be clocked from the internal oscillator block if either
the Two-Speed Start-up or the Fail-Safe Clock Monitor is
enabled (see Section 28.0 “Special Features of the
CPU”). In either case, the OSTS bit is set when the
primary clock is providing the device clocks. The IDLEN
and SCS bits are not affected by the wake-up.
4.4Idle Modes
The Idle modes allow the controller’s CPU to be
selectively shut down while the peripherals continue to
operate. Selecting a particular Idle mode allows users
to further manage power consumption.
If the IDLEN bit is set to a ‘1’ when a SLEEP instruction is
executed, the peripherals will be clocked from the clock
source selected using the SCS<1:0> bits. The CPU,
however, will not be clocked. The clock source status bits
are not affected. This approach is a quick method to
switch from a given Run mode to its corresponding Idle
mode.
If the WDT is selected, the LF-INTOSC source will
continue to operate. If the SOSC oscillator is enabled,
it will also continue to run.
Since the CPU is not executing instructions, the only
exits from any of the Idle modes are by interrupt, WDT
time-out or a Reset. When a wake event occurs, CPU
execution is delayed by an interval of T
(Parameter 38, Table 31-10) while it becomes ready to
execute code. When the CPU begins executing code,
it resumes with the same clock source for the current
Idle mode. For example, when waking from RC_IDLE
mode, the internal oscillator block will clock the CPU
and peripherals (in other words, RC_RUN mode). The
IDLEN and SCS bits are not affected by the wake-up.
While in any Idle mode or Sleep mode, a WDT timeout will result in a WDT wake-up to the Run mode
currently specified by the SCS<1:0> bits.
CSD
FIGURE 4-5:TRANSITION TIMING FOR ENTRY TO SLEEP MODE
FIGURE 4-6:TRANSITION TIMING FOR WAKE FROM SLEEP (HSPLL)
DS39957C-page 58 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
Q1
Peripheral
Program
PCPC + 2
OSC1
Q3
Q4
Q1
CPU Clock
Clock
Counter
Q2
OSC1
Peripheral
Program
PC
CPU Clock
Q1Q3Q4
Clock
Counter
Q2
Wake Even t
TCSD
4.4.1PRI_IDLE MODE
This mode is unique among the three low-power Idle
modes, in that it does not disable the primary device
clock. For timing-sensitive applications, this allows for
the fastest resumption of device operation with its more
accurate, primary clock source, since the clock source
does not have to “warm-up” or transition from another
oscillator.
PRI_IDLE mode is entered from PRI_RUN mode by
setting the IDLEN bit and executing a SLEEP instruction. If the device is in another Run mode, set IDLEN
first, then clear the SCS bits and execute SLEEP.
Although the CPU is disabled, the peripherals continue
to be clocked from the primary clock source specified
by the OSC<3:0> Configuration bits. The OSTS bit
remains set (see Figure 4-7).
When a wake event occurs, the CPU is clocked from the
primary clock source. A delay of interval, T
(Parameter 39, Table 31-10), is required between the
wake event and the start of code execution. This is
required to allow the CPU to become ready to execute
instructions. After the wake-up, the OSTS bit remains
set. The IDLEN and SCS bits are not affected by the
wake-up (see Figure 4-8).
CSD
4.4.2SEC_IDLE MODE
In SEC_IDLE mode, the CPU is disabled but the
peripherals continue to be clocked from the SOSC
oscillator. This mode is entered from SEC_RUN by setting the IDLEN bit and executing a SLEEP instruction. If
the device is in another Run mode, set the IDLEN bit
first, then set the SCS<1:0> bits to ‘01’ and execute
SLEEP . When the clock source is switched to the SOSC
oscillator, the primary oscillator is shut down, the OSTS
bit is cleared and the SOSCRUN bit is set.
When a wake event occurs, the peripherals continue to
be clocked from the SOSC oscillator. After an interval of
CSD following the wake event, the CPU begins execut-
T
ing code being clocked by the SOSC oscillator. The
IDLEN and SCS bits are not affected by the wake-up and
the SOSC oscillator continues to run (see Figure 4-8).
FIGURE 4-7:TRANSITION TIMING FOR ENTRY TO IDLE MODE
FIGURE 4-8:TRANSITION TIMING FOR WAKE FROM IDLE TO RUN MODE
2011 Microchip Technology Inc.DS39957C-page 59
PIC18F87K90 FAMILY
4.4.3RC_IDLE MODE
In RC_IDLE mode, the CPU is disabled but the peripherals continue to be clocked from the internal oscillator
block using the INTOSC multiplexer. This mode
provides controllable power conservation during Idle
periods.
From RC_RUN, this mode is entered by setting the
IDLEN bit and executing a SLEEP instruction. If the
device is in another Run mode, first set IDLEN, then set
the SCS1 bit and execute SLEEP. To maintain software
compatibility with future devices, it is recommended
that SCS0 also be cleared, though its value is ignored.
The INTOSC multiplexer may be used to select a
higher clock frequency by modifying the IRCF bits
before executing the SLEEP instruction. When the
clock source is switched to the INTOSC multiplexer, the
primary oscillator is shut down and the OSTS bit is
cleared.
If the IRCF bits are set to any non-zero value, or the
INTSRC/MFIOSEL bit is set, the INTOSC output is
enabled. The HFIOFS/MFIOFS bits become set, after
the INTOSC output becomes stable after an interval of
IOBST (Parameter 38, Table 31-10). (For information
T
on the HFIOFS/MFIOFS bits, see Table 4-3.)
Clocks to the peripherals continue while the INTOSC
source stabilizes. The HFIOFS/MFIOFS bits will
remain set if the IRCF bits were previously at a nonzero value or if INTSRC was set before the SLEEP
instruction was executed and the INTOSC source was
already stable. If the IRCF bits and INTSRC are all
clear, the INTOSC output will not be enabled, the
HFIOFS/MFIOFS bits will remain clear and there will be
no indication of the current clock source.
When a wake event occurs, the peripherals continue to
be clocked from the INTOSC multiplexer. After a delay
CSD (Parameter 38, Table 31-10), following the
of T
wake event, the CPU begins executing code clocked
by the INTOSC multiplexer. The IDLEN and SCS bits
are not affected by the wake-up. The INTRC source will
continue to run if either the WDT or the Fail-Safe Clock
Monitor is enabled.
4.5Selective Peripheral Module
Control
Idle mode allows users to substantially reduce power
consumption by stopping the CPU clock. Even so,
peripheral modules still remain clocked, and thus,
consume power. There may be cases where the
application needs what this mode does not provide: the
allocation of power resources to the CPU, processing
with minimal power consumption from the peripherals.
PIC18F87K90 family devices address this requirement
by allowing peripheral modules to be selectively
disabled, reducing or eliminating their power
consumption. This can be done with two control bits:
• Peripheral Enable bit, generically named XXXEN –
Located in the respective module’s main control
register
named XXXMD – Located in one of the PMDx
Control registers (PMD0, PMD1, PMD2 or PMD3)
Disabling a module by clearing its XXXEN bit disables
the module’s functionality, but leaves its registers
available to be read and written to. This reduces power
consumption, but not by as much as the second
approach.
Most peripheral modules have an enable bit.
In contrast, setting the PMD bit for a module disables all
clock sources to that module, reducing its power
consumption to an absolute minimum. In this state, the
control and status registers associated with the
peripheral are also disabled, so writes to those registers
have no effect and read values are invalid. Many
peripheral modules have a corresponding PMD bit.
There are four PMD registers in the PIC18F87K90 family
devices: PMD0, PMD1, PMD2 and PMD3. These
registers have bits associated with each module for
disabling or enabling a particular peripheral.
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
bit 7CCP3MD: PMD ECCP3 Enable/Disable bit
1 = Peripheral Module Disable (PMD) is enabled for ECCP3, disabling all of its clock sources
0 = PMD is disabled for ECCP3
bit 6CCP2MD: PMD ECCP2 Enable/Disable bit
1 = PMD is enabled for ECCP2, disabling all of its clock sources
0 = PMD is disabled for ECCP2
bit 5CCP1MD: PMD ECCP1 Enable/Disable bit
1 = PMD is enabled for ECCP1, disabling all of its clock sources
0 = PMD is disabled for ECCP1
bit 4UART2MD: PMD UART2 Enable/Disable bit
1 = PMD is enabled for UART2, disabling all of its clock sources
0 = PMD is disabled for UART2
bit 3UART1MD: PMD UART1 Enable/Disable bit
1 = PMD is enabled for UART1, disabling all of its clock sources
0 = PMD is disabled for UART1
bit 2SSP2MD: PMD MSSP2 Enable/Disable bit
1 = PMD is enabled for MSSP2, disabling all of its clock sources
0 = PMD is disabled for MSSP2
bit 1SSP1MD: PMD MSSP1 Enable/Disable bit
1 = PMD is enabled for MSSP1, disabling all of its clock sources
0 = PMD is disabled for MSSP1
bit 0ADCMD: PMD Analog/Digital Converter PMD Enable/Disable bit
1 = PMD is enabled for Analog/Digital Converter, disabling all of its clock sources
0 = PMD is disabled for Analog/Digital Converter
DS39957C-page 64 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
4.6Exiting Idle and Sleep Modes
An exit from Sleep mode or any of the Idle modes is
triggered by an interrupt, a Reset or a WDT time-out.
This section discusses the triggers that cause exits
from power-managed modes. The clocking subsystem
actions are discussed in each of the power-managed
modes (see Section 4.2 “Run Modes”, Section 4.3
“Sleep Mode” and Section 4.4 “Idle Modes”).
4.6.1EXIT BY INTERRUPT
Any of the available interrupt sources can cause the
device to exit from an Idle or Sleep mode to a Run
mode. To enable this functionality, an interrupt source
must be enabled by setting its enable bit in one of the
INTCONx or PIEx registers. The exit sequence is
initiated when the corresponding interrupt flag bit is set.
On all exits from Idle or Sleep modes by interrupt, code
execution branches to the interrupt vector if the GIE/
GIEH bit (INTCON<7>) is set. Otherwise, code execution continues or resumes without branching (see
Section 10.0 “Interrupts”).
4.6.2EXIT BY WDT TIME-OUT
A WDT time-out will cause different actions depending
on which power-managed mode the device is in when
the time-out occurs.
If the device is not executing code (all Idle modes and
Sleep mode), the time-out will result in an exit from the
power-managed mode (see Section 4.2 “Run
Modes” and Section 4.3 “Sleep Mode”). If the device
is executing code (all Run modes), the time-out will
result in a WDT Reset (see Section 28.2 “Watchdog
Timer (WDT)”).
Executing a SLEEP or CLRWDT instruction clears the
WDT timer and postscaler, loses the currently selected
clock source (if the Fail-Safe Clock Monitor is enabled)
and modifies the IRCF bits in the OSCCON register (if
the internal oscillator block is the device clock source).
4.6.3EXIT BY RESET
Normally, the device is held in Reset by the Oscillator
Start-up Timer (OST) until the primary clock becomes
ready. At that time, the OSTS bit is set and the device
begins executing code. If the internal oscillator block is
the new clock source, the HFIOFS/MFIOFS bits are set
instead.
The exit delay time from Reset to the start of code
execution depends on both the clock sources before
and after the wake-up, and the type of oscillator if the
new clock source is the primary clock. Exit delays are
summarized in Tab l e 4- 4.
Code execution can begin before the primary clock
becomes ready. If either the Two-Speed Start-up (see
Section 28.4 “Two-Speed Start-up”) or Fail-Safe
Clock Monitor (see Section 28.5 “Fail-Safe Clock
Monitor”) is enabled, the device may begin execution
as soon as the Reset source has cleared. Execution is
clocked by the INTOSC multiplexer, driven by the internal oscillator block. Execution is clocked by the internal
oscillator block until either the primary clock becomes
ready or a power-managed mode is entered before the
primary clock becomes ready; the primary clock is then
shut down.
4.6.4EXIT WITHOUT AN OSCILLATOR
START-UP DE LAY
Certain exits from power-managed modes do not
invoke the OST at all. The two cases are:
• When in PRI_IDLE mode, where the primary
clock source is not stopped
• When the primary clock source is not any of the
LP, XT, HS or HSPLL modes
In these instances, the primary clock source either
does not require an oscillator start-up delay, since it is
already running (PRI_IDLE), or normally does not
require an oscillator start-up delay (RC, EC and INTIO
Oscillator modes). However, a fixed delay of interval,
CSD, following the wake event, is still required when
T
leaving Sleep and Idle modes to allow the CPU to
prepare for execution. Instruction execution resumes
on the first clock cycle following this delay.
2011 Microchip Technology Inc.DS39957C-page 65
PIC18F87K90 FAMILY
RA0/AN0/ULPWU
4.7Ultra Low-Power Wake-up
The Ultra Low-Power Wake-up (ULPWU) on pin, RA0,
allows a slow falling voltage to generate an interrupt
without excess current consumption.
To use this feature:
1.Charge the capacitor on RA0 by configuring the
2.Stop charging the capacitor by configuring RA0
3.Discharge the capacitor by setting the ULPEN
4.Configure Sleep mode.
5.Enter Sleep mode.
When the voltage on RA0 drops below V
wakes up and executes the next instruction.
This feature provides a low-power technique for
periodically waking up the device from Sleep mode.
The time-out is dependent on the discharge time of the
RC circuit on RA0.
When the ULPWU module wakes the device from
Sleep mode, the ULPLVL bit (WDTCON<5>) is set.
Software can check this bit upon wake-up to determine
the wake-up source.
See Example 4-1 for initializing the ULPWU module.
EXAMPLE 4-1:ULTRA LOW-POWER
RA0 pin to an output and setting it to ‘1’.
as an input.
and ULPSINK bits in the WDTCON register.
WAKE-UP INITIALIZATION
//***************************
//Charge the capacitor on RA0
A series resistor, between RA0 and the external capacitor, provides overcurrent protection for the RA0/AN0/
ULPWU pin and enables software calibration of the
time-out (see Figure 4-9).
FIGURE 4-9:ULTRA LOW-POWER
WAKE-UP INITIALIZATION
IL, the device
A timer can be used to measure the charge time and
discharge time of the capacitor. The charge time can
then be adjusted to provide the desired delay in Sleep.
This technique compensates for the affects of
temperature, voltage and component accuracy. The
peripheral can also be configured as a simple
programmable Low-Voltage Detect (LVD) or
temperature sensor.
Note:For more information, see AN 879, “Using
the Microchip Ultra Low-Power Wake-up
Module” (DS00879).
DS39957C-page 66 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
TABLE 4-4:EXIT DELAY ON WAKE-UP BY RESET FROM SLEEP MODE OR ANY IDLE MODE
(BY CLOCK SOURCES)
Power-Managed
Mode
PRI_IDLE mode
SEC_IDLE modeSOSCT
RC_IDLE mode
Sleep mode
Note 1:TCSD (Parameter 38, Table 31-10) is a required delay when waking from Sleep and all Idle modes, and
runs concurrently with any other required delays (see Section 4.4 “Idle Modes”).
2:Includes postscaler derived frequencies. On Reset, INTOSC defaults to HF-INTOSC at 8 MHz.
3:T
OST is the Oscillator Start-up Timer (Parameter 32, Table 31-10). TRC is the PLL Lock-out Timer
(Parameter F12, Table 31-7); it is also designated as T
4:Execution continues during TIOBST (Parameter 39, Table 31-10), the INTOSC stabilization period.
5:The clock source is dependent upon the settings of the SCS (OSCCON<1:0>), IRCF (OSCCON<6:4>)
and FOSC (CONFIG1H<3:0>) bits.
Clock Source
(5)
Exit Delay
Clock Ready
Status Bits
LP, XT, HS
EC, RC
HF-INTOSC
MF-INTOSC
(2)
(2)
TCSD
(1)
HFIOFS
MFIOFS
LF-INTOSCNone
(1)
HF-INTOSC
MF-INTOSC
(2)
(2)
CSD
TCSD
(1)
SOSCRUN
HFIOFS
MFIOFS
LF-INTOSCNone
TIOBST
(3)
(1)
rc
(4)
(3)
HFIOFS
MFIOFS
LP, XT, HSTOST
EC, RCTCSD
HF-INTOSC
MF-INTOSC
(2)
(2)
LF-INTOSCNone
PLL.
OSTSHSPLL
OSTSHSPLLTOST + t
2011 Microchip Technology Inc.DS39957C-page 67
PIC18F87K90 FAMILY
NOTES:
DS39957C-page 68 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
External Reset
MCLR
VDD
WDT
Time-out
V
DD Rise
Detect
PWRT
LF-INTOSC
POR Pulse
Chip_Reset
Brown-out
Reset
RESET Instruction
Stack
Pointer
Stack Full/Underflow Reset
Sleep
( )_IDLE
32 s
PWRT
11-Bit Ripple Counter
66 ms
S
R
Q
Configuration Word Mismatch
5.0RESET
A simplified block diagram of the on-chip Reset circuit
is shown in Figure 5-1.
The PIC18F87K90 family of devices differentiates
between various kinds of Reset:
a)Power-on Reset (POR)
b)MCLR
Reset during normal operation
c)MCLR Reset during power-managed modes
d)Watchdog Timer (WDT) Reset (during
This section discusses Resets generated by MCLR,
POR and BOR, and covers the operation of the various
start-up timers. Stack Reset events are covered in
5.1RCON Register
Device Reset events are tracked through the RCON
register (Register 5-1). The lower five bits of the
register indicate that a specific Reset event has
occurred. In most cases, these bits can only be set by
the event and must be cleared by the application after
the event.
The state of these flag bits, taken together, can be read
to indicate the type of Reset that just occurred. This is
described in more detail in Section 5. 7 “Reset State
of Registers”.
The RCON register also has a control bit for setting
interrupt priority (IPEN). Interrupt priority is discussed
in Section 10.0 “Interrupts”.
Section 6.1.3.4 “Stack Full and Underflow Resets”.
WDT Resets are covered in Section 28.2 “Watchdog
Timer (WDT)”.
FIGURE 5-1:SIMPLIFIED BLOCK DIAGRAM OF ON-CHIP RESET CIRCUIT
2011 Microchip Technology Inc.DS39957C-page 69
PIC18F87K90 FAMILY
REGISTER 5-1:RCON: RESET CONTROL REGISTER
R/W-0R/W-1R/W-1R/W-1R-1R-1R/W-0R/W-0
IPENSBORENCM
bit 7bit 0
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
bit 7IPEN: Interrupt Priority Enable bit
1 = Enable priority levels on interrupts
0 = Disable priority levels on interrupts (PIC16CXXX Compatibility mode)
bit 6SBOREN: BOR Software Enable bit
If BOREN<1:0> =
1 = BOR is enabled
0 = BOR is disabled
If BOREN<1:0> =
Bit is disabled and read as ‘0’.
bit 5CM: Configuration Mismatch Flag bit
1 = A Configuration Mismatch Reset has not occurred
0 = A Configuration Mismatch Reset has occurred (must be set in software after a Configuration
Mismatch Reset occurs)
bit 4RI: RESET Instruction Flag bit
1 = The RESET instruction was not executed (set by firmware only)
0 = The RESET instruction was executed, causing a device Reset (must be set in software after a
Brown-out Reset occurs)
bit 3TO
bit 2PD
bit 1POR
bit 0BOR
: Watchdog Time-out Flag bit
1 = Set by power-up, CLRWDT instruction or SLEEP instruction
0 = A WDT time-out has occurred
: Power-Down Detection Flag bit
1 = Set by power-up or by the CLRWDT instruction
0 = Set by execution of the SLEEP instruction
: Power-on Reset Status bit
1 = A Power-on Reset has not occurred (set by firmware only)
0 = A Power-on Reset has occurred (must be set in software after a Power-on Reset occurs)
: Brown-out Reset Status bit
1 = A Brown-out Reset has not occurred (set by firmware only)
0 = A Brown-out Reset has occurred (must be set in software after a Brown-out Reset occurs)
01:
00, 10 or 11:
RITOPDPORBOR
Note 1: It is recommended that the POR
Power-on Resets may be detected.
2: Brown-out Reset is said to have occurred when BOR
‘1’ by software immediately after a Power-on Reset).
DS39957C-page 70 2011 Microchip Technology Inc.
bit be set after a Power-on Reset has been detected, so that subsequent
is ‘0’ and POR is ‘1’ (assuming that POR was set to
PIC18F87K90 FAMILY
Note 1: External Power-on Reset circuit is required
only if the V
DD power-up slope is too slow.
The diode, D, helps discharge the capacitor
quickly when V
DD powers down.
2: R < 40 k is recommended to make sure that
the voltage drop across R does not violate
the device’s electrical specification.
3: R1 1 k will limit any current flowing into
MCLR
from external capacitor, C, in the event
of MCLR
/VPP pin breakdown, due to
Electrostatic Discharge (ESD) or Electrical
Overstress (EOS).
C
R1
R
D
V
DD
MCLR
VDD
PIC18F87K90
5.2Master Clear (MCLR)
The MCLR pin provides a method for triggering a hard
external Reset of the device. A Reset is generated by
holding the pin low. PIC18 extended microcontroller
devices have a noise filter in the MCLR
Reset path
which detects and ignores small pulses.
The MCLR
pin is not driven low by any internal Resets,
including the WDT.
5.3Power-on Reset (POR)
A Power-on Reset condition is generated on-chip
whenever V
allows the device to start in the initialized state when
DD is adequate for operation.
V
To take advantage of the POR circuitry, tie the MCLR
pin through a resistor (1 k to 10 k) to VDD. This will
eliminate external RC components usually needed to
create a Power-on Reset delay. A minimum rise rate for
DD is specified (Parameter D004). For a slow rise
V
time, see Figure 5-2.
When the device starts normal operation (exiting the
Reset condition), device operating parameters (such
as voltage, frequency and temperature) must be met to
ensure operation. If these conditions are not met, the
device must be held in Reset until the operating
conditions are met.
Power-on Reset events are captured by the POR
(RCON<1>). The state of the bit is set to ‘0’ whenever
a Power-on Reset occurs and does not change for any
other Reset event. POR
hardware event. To capture multiple events, the user
manually resets the bit to ‘1’ in software following any
Power-on Reset.
DD rises above a certain threshold. This
bit
is not reset to ‘1’ by any
In Zero-Power BOR (ZPBORMV), the module monitors
DD voltage and re-arms the POR at about 2V.
the V
ZPBORMV does not cause a Reset, but re-arms the
POR.
The BOR accuracy varies with its power level. The
lower the power setting, the less accurate the BOR trip
levels are. So, the high-power BOR has the highest
accuracy and the low-power BOR has the lowest accuracy. The trip levels (B
VDD, Parameter D005), current
consumption (Section 31.2 “DC Characteristics:
Power-Down and Supply Current PIC18F87K90
Family (Industrial)”) and time required below B
VDD
(TBOR, Parameter 35) can all be found in Section 31.0
“Electrical Characteristics”
FIGURE 5-2:EXTERNAL POWER-ON
RESET CIRCUIT (FOR
SLOW V
DD POWER-UP)
5.4Brown-out Reset (BOR)
The PIC18F87K90 family has four BOR modes:
• High-Power BOR
• Medium Power BOR
• Low-Power BOR
• Zero-Power BOR
Each power mode is selected by the BORPWR<1:0>
setting (CONFIG2L<6:5>). For low, medium and highpower BOR, the module monitors the V
on the BORV<1:0> setting (CONFIG1L<3:2>). A BOR
event re-arms the Power-on Reset. It also causes a
Reset depending on which of the trip levels has been
set: 1.8V, 2V, 2.7V or 3V. The typical (IB
for the Low and Medium Power BOR will be 0.75 A
and 3 A.
2011 Microchip Technology Inc.DS39957C-page 71
DD depending
OR) trip level
5.4.1DETECTING BOR
The BOR bit always resets to ‘0’ on any Brown-out
Reset or Power-on Reset event. This makes it difficult
to determine if a Brown-out Reset event has occurred
just by reading the state of BOR
method is to simultaneously check the state of both
POR
and BOR. This assumes that the POR bit is reset
to ‘1’ in software immediately after any Power-on Reset
event. If BOR
is ‘0’ while POR is ‘1’, it can be reliably
assumed that a Brown-out Reset event has occurred.
LP-BOR cannot be detected with the BOR
RCON register. LP-BOR can rearm the POR
cause a Power-on Reset.
alone. A more reliable
bit in the
and can
PIC18F87K90 FAMILY
TPWRT
VDD
MCLR
INTERNAL POR
PWRT TIME-OUT
INTERNAL RESET
5.5Configuration Mismatch (CM)
The Configuration Mismatch (CM) Reset is designed to
detect, and attempt to recover from, random, memory
corrupting events. These include Electrostatic Discharge
(ESD) events that can cause widespread, single bit
changes throughout the device and result in catastrophic
failure.
In PIC18F87K90 family Flash devices, the device
Configuration registers (located in the configuration
memory space) are continuously monitored during
operation by comparing their values to complimentary
shadow registers. If a mismatch is detected between
the two sets of registers, a CM Reset automatically
occurs. These events are captured by the CM
(RCON<5>). The state of the bit is set to ‘0’ whenever
a CM event occurs and does not change for any other
Reset event.
A CM Reset behaves similarly to a Master Clear Reset,
RESET instruction, WDT time-out or Stack Event Reset.
As with all hard and power Reset events, the device
Configuration Words are reloaded from the Flash
Configuration Words, in program memory, as the
device restarts.
bit
5.6Power-up Timer (PWRT)
PIC18F87K90 family devices incorporate an on-chip
Power-up Timer (PWRT) to help regulate the Power-on
Reset process. The PWRT is enabled by setting the
PWRTEN bit (CONFIG2L<0>). The main function is to
ensure that the device voltage is stable before code is
executed.
The Power-up Timer (PWRT) of the PIC18F87K90
family devices is a 13-bit counter that uses the
LF-INTOSC source as the clock input. This yields an
approximate time interval of 2,048 x 32 s=66ms.
While the PWRT is counting, the device is held in
Reset.
The power-up time delay depends on the LF-INTOSC
clock and will vary from chip-to-chip due to temperature
and process variation. See DC Parameter 33 for
details.
5.6.1TIME-OUT SEQUENCE
If enabled, the PWRT time-out is invoked after the POR
pulse has cleared. The total time-out will vary based on
the status of the PWRT. Figure 5-3, Figure 5-4,
Figure 5-5 and Figure 5-6 all depict time-out
sequences on power-up with the Power-up Timer
enabled.
Since the time-outs occur from the POR pulse, if
is kept low long enough, the PWRT will expire.
MCLR
Bringing MCLR
(Figure 5-5). This is useful for testing purposes, or for
synchronizing more than one PIC18 device operating
in parallel.
high will begin execution immediately
FIGURE 5-3:TIME-OUT SEQUENCE ON POWER-UP (MCLR TIED TO VDD, VDD RISE < TPWRT)
DS39957C-page 72 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
TPWRT
VDD
MCLR
INTERNAL POR
PWRT TIME-OUT
INTERNAL RESET
VDD
MCLR
INTERNAL POR
PWRT TIME-OUT
INTERNAL RESET
TPWRT
VDD
MCLR
INTERNAL POR
PWRT TIME-OUT
INTERNAL RESET
0V
1V
3.3V
T
PWRT
FIGURE 5-4:TIME-OUT SEQUENCE ON POWER-UP (MCLR NOT TIED TO VDD): CASE 1
FIGURE 5-5:TIME-OUT SEQUENCE ON POWER-UP (MCLR
FIGURE 5-6:SLOW RISE TIME (MCLR
TIED TO VDD, VDD RISE > TPWRT)
NOT TIED TO VDD): CASE 2
2011 Microchip Technology Inc.DS39957C-page 73
PIC18F87K90 FAMILY
5.7Reset State of Registers
Most registers are unaffected by a Reset. Their status
is unknown on POR and unchanged by all other
Resets. The other registers are forced to a “Reset
state” depending on the type of Reset that occurred.
Most registers are not affected by a WDT wake-up,
since this is viewed as the resumption of normal
operation. Status bits from the RCON register (CM
TO
, PD, POR and BOR) are set or cleared differently in
, RI,
different Reset situations, as indicated in Tab le 5 -1 .
These bits are used in software to determine the nature
of the Reset.
Table 5-2 describes the Reset states for all of the
Special Function Registers. These are categorized by
Power-on and Brown-out Resets, Master Clear and
WDT Resets, and WDT wake-ups.
TABLE 5-1:STATUS BITS, THEIR SIGNIFICANCE AND THE INITIALIZATION CONDITION FOR
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Shaded cells indicate conditions do not apply for the designated device.
Note 1:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
2:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the interrupt
vector (0008h or 0018h).
3:One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
4:See Ta bl e 5 -1 for the Reset value for a specific condition.
WDT Reset,
RESET Instruction,
Stack Rese ts,
CM Resets
Wake-up via WDT
or Interrupt
(1)
(1)
(1)
(1)
(2)
(3)
(3)
(3)
2011 Microchip Technology Inc.DS39957C-page 75
PIC18F87K90 FAMILY
TABLE 5-2:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Shaded cells indicate conditions do not apply for the designated device.
Note 1:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
2:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the interrupt
vector (0008h or 0018h).
3:One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
4:See Ta bl e 5 -1 for the Reset value for a specific condition.
Power-on Reset,
Brown-out Reset
WDT Reset,
RESET Instruction,
Stack Rese ts,
CM Resets
Wake-up via WDT
or Interrupt
DS39957C-page 76 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
TABLE 5-2:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Shaded cells indicate conditions do not apply for the designated device.
Note 1:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
2:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the interrupt
vector (0008h or 0018h).
3:One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
4:See Ta bl e 5 -1 for the Reset value for a specific condition.
Power-on Reset,
Brown-out Reset
WDT Reset,
RESET Instruction,
Stack Rese ts,
CM Resets
Wake-up via WDT
or Interrupt
(1)
(1)
2011 Microchip Technology Inc.DS39957C-page 77
PIC18F87K90 FAMILY
TABLE 5-2:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Note 1:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
2:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the interrupt
3:One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
4:See Ta bl e 5 -1 for the Reset value for a specific condition.
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Note 1:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
2:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the interrupt
3:One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
4:See Ta bl e 5 -1 for the Reset value for a specific condition.
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Note 1:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
2:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the interrupt
3:One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
4:See Ta bl e 5 -1 for the Reset value for a specific condition.
Shaded cells indicate conditions do not apply for the designated device.
Note 1:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
2:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the interrupt
vector (0008h or 0018h).
3:One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
4:See Ta bl e 5 -1 for the Reset value for a specific condition.
Power-on Reset,
Brown-out Reset
WDT Reset,
RESET Instruction,
Stack Rese ts,
CM Resets
Wake-up via WDT
or Interrupt
2011 Microchip Technology Inc.DS39957C-page 81
PIC18F87K90 FAMILY
TABLE 5-2:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Shaded cells indicate conditions do not apply for the designated device.
Note 1:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
2:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the interrupt
vector (0008h or 0018h).
3:One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
4:See Ta bl e 5 -1 for the Reset value for a specific condition.
Power-on Reset,
Brown-out Reset
WDT Reset,
RESET Instruction,
Stack Rese ts,
CM Resets
Wake-up via WDT
or Interrupt
DS39957C-page 82 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
TABLE 5-2:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Note 1:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
2:When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the interrupt
3:One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
4:See Ta bl e 5 -1 for the Reset value for a specific condition.
Shaded cells indicate conditions do not apply for the designated device.
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
vector (0008h or 0018h).
Power-on Reset,
Brown-out Reset
WDT Reset,
RESET Instruction,
Stack Rese ts,
CM Resets
Wake-up via WDT
or Interrupt
2011 Microchip Technology Inc.DS39957C-page 83
PIC18F87K90 FAMILY
NOTES:
DS39957C-page 84 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
Note:Sizes of memory areas are not to scale. The sizes of program memory areas are enhanced to show detail.
Unimplemented
Read as ‘0’
Unimplemented
Read as ‘0’
000000h
1FFFFFh
01FFFFh
00FFFFh
PC<20:0>
Stack Level 1
Stack Level 31
CALL, CALLW, RC ALL,
RETURN, RETFIE, RETLW,
21
User Memory Space
On-Chip
Memory
On-Chip
Memory
ADDULNK, SUBULN K
PIC18FX6K90
PIC18FX7K90
Unimplemented
Read as ‘0’
On-Chip
Memory
PIC18FX5K90
007FFFh
6.0MEMORY ORGANIZATION
PIC18F87K90 family devices have these types of
memory:
• Program Memory
• Data RAM
• Data EEPROM
As Harvard architecture devices, the data and program
memories use separate busses. This enables
concurrent access of the two memory spaces.
FIGURE 6-1:MEMORY MAPS FOR PIC18F87K90 FAMILY DEVICES
The data EEPROM, for practical purposes, can be
regarded as a peripheral device because it is
addressed and accessed through a set of control
registers.
Additional detailed information on the operation of the
Flash program memory is provided in Section 7.0
“Flash Program Memory”. The data EEPROM is
discussed separately in Section 8.0 “Data EEPROM
Memory”.
2011 Microchip Technology Inc.DS39957C-page 85
PIC18F87K90 FAMILY
Reset Vector
Low-Priority Interrupt Vector
0000h
0018h
On-Chip
Program Memory
High-Priority Interrupt Vector
0008h
1FFFFFh
Read ‘0’
Legend:(Top of Memory) represents upper boundary
of on-chip program memory space (see
Figure 6-1 for device-specific values).
Shaded area represents unimplemented
memory. Areas are not shown to scale.
6.1Program Memory Organization
PIC18 microcontrollers implement a 21-bit program
counter that is capable of addressing a 2-Mbyte
program memory space. Accessing a location between
the upper boundary of the physically implemented
memory and the 2-Mbyte address will return all ‘0’s (a
NOP instruction).
The entire PIC18F87K90 family offers a range of
on-chip Flash program memory sizes, from 32 Kbytes
(up to 16,384 single-word instructions) to 128 Kbytes
(65,536 single-word instructions).
• PIC18F65K90 and PIC18F85K90 – 32 Kbytes of
Flash memory, storing up to 16,384 single-word
instructions
• PIC18F66K90 and PIC18F86K90 – 64 Kbytes of
Flash memory, storing up to 32,768 single-word
instructions
• PIC18F67K90 and PIC18F87K90 – 128 Kbytes of
Flash memory, storing up to 65,536 single-word
instructions
The program memory maps for individual family
members are shown in Figure 6-1.
6.1.1HARD MEMORY VECTORS
All PIC18 devices have a total of three hard-coded
return vectors in their program memory space. The
Reset vector address is the default value to which the
program counter returns on all device Resets; it is
located at 0000h.
PIC18 devices also have two interrupt vector
addresses for handling high-priority and low-priority
interrupts. The high-priority interrupt vector is located at
0008h and the low-priority interrupt vector is at 0018h.
The locations of these vectors are shown, in relation to
the program memory map, in Figure 6-2.
FIGURE 6-2:HARD VECTOR FOR
PIC18F87K90 FAMILY
DEVICES
DS39957C-page 86 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
00011
001A34h
11111
11110
11101
00010
00001
00000
00010
Return Address Stack <20:0>
Top-of-Stack
000D58h
TOSLTOSHTOSU
34h1Ah00h
STKPTR<4:0>
Top-of-Stack Registers
Stack Pointer
6.1.2PROGRAM COUNTER
The Program Counter (PC) specifies the address of the
instruction to fetch for execution. The PC is 21 bits wide
and contained in three separate 8-bit registers.
The low byte, known as the PCL register, is both
readable and writable. The high byte, or PCH register,
contains the PC<15:8> bits and is not directly readable
or writable. Updates to the PCH register are performed
through the PCLATH register. The upper byte is called
PCU. This register contains the PC<20:16> bits; it is also
not directly readable or writable. Updates to the PCU
register are performed through the PCLATU register.
The contents of PCLATH and PCLATU are transferred to
the program counter by any operation that writes PCL.
Similarly, the upper two bytes of the program counter are
transferred to PCLATH and PCLATU by an operation
that reads PCL. This is useful for computed offsets to the
PC (see Section 6.1.5.1 “Computed GOTO”).
The PC addresses bytes in the program memory. To
prevent the PC from becoming misaligned with word
instructions, the Least Significant bit (LSb) of PCL is
fixed to a value of ‘0’. The PC increments by two to
address sequential instructions in the program
memory.
The CALL, RCALL, GOTO and program branch
instructions write to the program counter directly. For
these instructions, the contents of PCLATH and
PCLATU are not transferred to the program counter.
6.1.3RETURN ADDRESS STACK
The return address stack enables execution of any
combination of up to 31 program calls and interrupts.
The PC is pushed onto the stack when a CALL or
RCALL instruction is executed, or an interrupt is
Acknowledged. The PC value is pulled off the stack on
a RETURN, RETLW or a RETFIE instruction. The value
also is pulled off the stack on ADDULNK and SUBULNK
instructions, if the extended instruction set is enabled.
PCLATU and PCLATH are not affected by any of the
RETURN or CALL instructions.
The stack operates as a 31-word by 21-bit RAM and a
5-bit Stack Pointer, STKPTR. The stack space is not
part of either program or data space. The Stack Pointer
is readable and writable and the address on the top of
the stack is readable and writable through the
Top-of-Stack Special Function Registers. Data can also
be pushed to, or popped from the stack, using these
registers.
A CALL type instruction causes a push onto the stack.
The Stack Pointer is first incremented and the location
pointed to by the Stack Pointer is written with the
contents of the PC (already pointing to the instruction
following the CALL). A RETURN type instruction causes
a pop from the stack. The contents of the location
pointed to by the STKPTR are transferred to the PC
and then the Stack Pointer is decremented.
The Stack Pointer is initialized to ‘00000’ after all
Resets. There is no RAM associated with the location
corresponding to a Stack Pointer value of ‘00000’; this
is only a Reset value. Status bits indicate if the stack is
full, has overflowed or has underflowed.
6.1.3.1Top-of-Stack Access
Only the top of the return address stack (TOS) is
readable and writable. A set of three registers,
TOSU:TOSH:TOSL, holds the contents of the stack
location pointed to by the STKPTR register
(Figure 6-3). This allows users to implement a software
stack, if necessary. After a CALL, RCALL or interrupt (orADDULNK and SUBULNK instructions, if the extended
instruction set is enabled), the software can read the
pushed value by reading the TOSU:TOSH:TOSL registers. These values can be placed on a user-defined
software stack. At return time, the software can return
these values to TOSU:TOSH:TOSL and do a return.
While accessing the stack, users must disable the
Global Interrupt Enable bits to prevent inadvertent
stack corruption.
FIGURE 6-3:RETURN ADDRESS ST AC K A ND AS SOC IAT ED RE GIS T ERS
2011 Microchip Technology Inc.DS39957C-page 87
PIC18F87K90 FAMILY
6.1.3.2Return Stack Pointer (STKPTR)
The STKPTR register (Register 6-1) contains the Stack
Pointer value, the STKFUL (Stack Full) status bit and
the STKUNF (Stack Underflow) status bits. The value
of the Stack Pointer can be 0 through 31. The Stack
Pointer increments before values are pushed onto the
stack and decrements after values are popped off the
stack. On Reset, the Stack Pointer value will be zero.
The user may read and write the Stack Pointer value.
This feature can be used by a Real-Time Operating
System (RTOS) for return-stack maintenance.
After the PC is pushed onto the stack 31 times (without
popping any values off the stack), the STKFUL bit is
set. The STKFUL bit is cleared by software or by a
POR.
What happens when the stack becomes full depends
on the state of the STVREN (Stack Overflow Reset
Enable) Configuration bit. (For a description of the
device Configuration bits, see Section 28.1 “Configu-
ration Bits”.) If STVREN is set (default), the 31st push
will push the (PC + 2) value onto the stack, set the
STKFUL bit and reset the device. The STKFUL bit will
remain set and the Stack Pointer will be set to zero.
If STVREN is cleared, the STKFUL bit will be set on the
31st push and the Stack Pointer will increment to 31.
Any additional pushes will not overwrite the 31st push
and the STKPTR will remain at 31.
When the stack has been popped enough times to
unload the stack, the next pop will return a value of zero
to the PC and set the STKUNF bit, while the Stack
Pointer remains at zero. The STKUNF bit will remain
set until cleared by software or until a POR occurs.
Note:Returning a value of zero to the PC on an
underflow has the effect of vectoring the
program to the Reset vector, where the
stack conditions can be verified and
appropriate actions can be taken. This is
not the same as a Reset, as the contents
of the SFRs are not affected.
6.1.3.3PUSH and POP Instructions
Since the Top-of-Stack is readable and writable, the
ability to push values onto the stack and pull values off
the stack, without disturbing normal program execution, is a desirable feature. The PIC18 instruction set
includes two instructions, PUSH and POP, that permit
the TOS to be manipulated under software control.
TOSU, TOSH and TOSL can be modified to place data
or a return address on the stack.
The PUSH instruction places the current PC value onto
the stack. This increments the Stack Pointer and loads
the current PC value onto the stack.
The POP instruction discards the current TOS by
decrementing the Stack Pointer. The previous value
pushed onto the stack then becomes the TOS value.
REGISTER 6-1:STKPTR: STACK POINTER REGISTER
R/C-0R/C-0U-0R/W-0R/W-0R/W-0R/W-0R/W-0
STKFUL
bit 7bit 0
Legend:C = Clearable bit
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
bit 7STKFUL: Stack Full Flag bit
bit 6STKUNF: Stack Underflow Flag bit
bit 5Unimplemented: Read as ‘0’
bit 4-0SP<4:0>: Stack Pointer Location bits
Note 1:Bit 7 and bit 6 are cleared by user software or by a POR.
(1)
STKUNF
1 = Stack became full or overflowed
0 = Stack has not become full or overflowed
1 = Stack underflow occurred
0 = Stack underflow did not occur
(1)
—SP4SP3SP2SP1SP0
(1)
(1)
DS39957C-page 88 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
CALL SUB1, FAST;STATUS, WREG, BSR
;SAVED IN FAST REGISTER
;STACK
SUB1
RETURN FAST;RESTORE VALUES SAVED
;IN FAST REGISTER STACK
MOVFOFFSET, W
CALLTABLE
ORG nn00h
TABLEADDWFPCL
RETLWnnh
RETLWnnh
RETLWnnh
.
.
.
6.1.3.4Stack Full and Underflow Resets
Device Resets on stack overflow and stack underflow
conditions are enabled by setting the STVREN bit
(CONFIG4L<0>). When STVREN is set, a full or underflow condition will set the appropriate STKFUL or
STKUNF bit and then cause a device Reset. When
STVREN is cleared, a full or underflow condition will set
the appropriate STKFUL or STKUNF bit, but not cause
a device Reset. The STKFUL or STKUNF bits are
cleared by the user software or a Power-on Reset.
6.1.4FAST REGISTER STACK
A Fast Register Stack is provided for the STATUS,
WREG and BSR registers to provide a “fast return”
option for interrupts. This stack is only one level deep
and is neither readable nor writable. It is loaded with the
current value of the corresponding register when the
processor vectors for an interrupt. All interrupt sources
will push values into the Stack registers. The values in
the registers are then loaded back into the working
registers if the RETFIE, FAST instruction is used to
return from the interrupt.
If both low and high-priority interrupts are enabled, the
Stack registers cannot be used reliably to return from
low-priority interrupts. If a high-priority interrupt occurs
while servicing a low-priority interrupt, the Stack
register values stored by the low-priority interrupt will
be overwritten. In these cases, users must save the key
registers in software during a low-priority interrupt.
If interrupt priority is not used, all interrupts may use the
Fast Register Stack for returns from interrupt. If no
interrupts are used, the Fast Register Stack can be
used to restore the STATUS, WREG and BSR registers
at the end of a subroutine call. To use the Fast Register
Stack for a subroutine call, a CALL label, FAST
instruction must be executed to save the STATUS,
WREG and BSR registers to the Fast Register Stack. A
RETURN, FAST instruction is then executed to restore
these registers from the Fast Register Stack.
Example 6-1 shows a source code example that uses
the Fast Register Stack during a subroutine call and
return.
EXAMPLE 6-1:FAST REGISTER STACK
CODE EXAMPLE
2011 Microchip Technology Inc.DS39957C-page 89
6.1.5LOOK-UP TABLES IN PROGRAM
MEMORY
There may be programming situations that require the
creation of data structures, or look-up tables, in
program memory. For PIC18 devices, look-up tables
can be implemented in two ways:
• Computed GOTO
• Table Reads
6.1.5.1Computed GOTO
A computed GOTO is accomplished by adding an offset
to the program counter. An example is shown in
Example 6-2.
A look-up table can be formed with an ADDWF PCL
instruction and a group of RETLW nn instructions. The
W register is loaded with an offset into the table before
executing a call to that table. The first instruction of the
called routine is the ADDWF PCL instruction. The next
instruction executed will be one of the RETLW nn
instructions that returns the value, ‘nn’, to the calling
function.
The offset value (in WREG) specifies the number of
bytes that the program counter should advance and
should be multiples of two (LSb = 0).
In this method, only one data byte may be stored in
each instruction location and room on the return
address stack is required.
EXAMPLE 6-2:COMPUTED GOTO USING
AN OFFSET VALUE
6.1.5.2Table Reads
A better method of storing data in program memory
allows two bytes of data to be stored in each instruction
location.
Look-up table data may be stored two bytes per
program word while programming. The Table Pointer
(TBLPTR) specifies the byte address and the Table
Latch (TABLAT) contains the data that is read from the
program memory. Data is transferred from program
memory one byte at a time.
The table read operation is discussed further in
Section 7.1 “Table Reads and Table Writes”.
PIC18F87K90 FAMILY
Q1
Q2Q3Q4
Q1
Q2Q3Q4
Q1
Q2Q3Q4
OSC1
Q1
Q2
Q3
Q4
PC
OSC2/CLKO
(RC mode)
PCPC + 2PC + 4
Fetch INST (PC)
Execute INST (PC – 2)
Fetch INST (PC + 2)
Execute INST (PC)
Fetch INST (PC + 4)
Execute INST (PC + 2)
Internal
Phase
Clock
All instructions are single cycle, except for any program branches. These take two cycles since the fetch instruction
is “flushed” from the pipeline while the new instruction is being fetched and then executed.
TCY0TCY1TCY2TCY3TCY4TCY5
1. MOVLW 55h
Fetch 1Execute 1
2. MOVWF PORTB
Fetch 2Execute 2
3. BRA SUB_1
Fetch 3Execute 3
4. BSF PORTA, BIT3 (Forced NOP)
Fetch 4Flush (NOP)
5. Instruction @ address SUB_1
Fetch SUB_1 Execute SUB_1
6.2PIC18 Instruction Cycle
6.2.1CLOCKING SCHEME
The microcontroller clock input, whether from an
internal or external source, is internally divided by four
to generate four non-overlapping quadrature clocks
(Q1, Q2, Q3 and Q4). Internally, the program counter is
incremented on every Q1, with the instruction fetched
from the program memory and latched into the
Instruction Register (IR) during Q4.
The instruction is decoded and executed during the
following Q1 through Q4. The clocks and instruction
execution flow are shown in Figure 6-4.
FIGURE 6-4:CLOCK/INSTRUCTION CYCLE
6.2.2INSTRUCTION FLOW/PIPELINING
An “Instruction Cycle” consists of four Q cycles, Q1
through Q4. The instruction fetch and execute are pipelined in such a manner that a fetch takes one instruction
cycle, while the decode and execute take another
instruction cycle. However, due to the pipelining, each
instruction effectively executes in one cycle. If an
instruction (such as GOTO) causes the program counter
to change, two cycles are required to complete the
instruction. (See Example 6-3.)
A fetch cycle begins with the Program Counter (PC)
incrementing in Q1.
In the execution cycle, the fetched instruction is latched
into the Instruction Register (IR) in cycle Q1. This
instruction is then decoded and executed during the
Q2, Q3 and Q4 cycles. Data memory is read during Q2
(operand read) and written during Q4 (destination
write).
The program memory is addressed in bytes. Instructions
are stored as two or four bytes in program memory. The
Least Significant Byte (LSB) of an instruction word is
always stored in a program memory location with an
even address (LSB = 0). To maintain alignment with
instruction boundaries, the PC increments in steps of
two and the LSB will always read ‘0’ (see Section 6.1.2
“Program Counter”).
Figure 6-5 shows an example of how instruction words
are stored in the program memory.
The CALL and GOTO instructions have the absolute
program memory address embedded into the instruction. Since instructions are always stored on word
boundaries, the data contained in the instruction is a
word address. The word address is written to PC<20:1>
which accesses the desired byte address in program
memory. Instruction #2 in Figure 6-5 shows how the
instruction, GOTO 0006h, is encoded in the program
memory. Program branch instructions, which encode a
relative address offset, operate in the same manner. The
offset value stored in a branch instruction represents the
number of single-word instructions that the PC will be
offset by. For more details on the instruction set, see
Section 29.0 “Instruction Set Summary”.
FIGURE 6-5:INSTRUCTIONS IN PROGRAM MEMORY
6.2.4TWO-WORD INSTRUCTIONS
The standard PIC18 instruction set has four two-word
instructions: CALL, MOVFF, GOTO and LSFR. In all
cases, the second word of the instructions always has
‘1111’ as its four Most Significant bits. The other 12 bits
are literal data, usually a data memory address.
The use of ‘1111’ in the 4 MSbs of an instruction
specifies a special form of NOP. If the instruction is
executed in proper sequence, immediately after the
first word, the data in the second word is accessed and
used by the instruction sequence. If the first word is
skipped for some reason, and the second word is
executed by itself, a NOP is executed instead. This is
necessary for cases when the two-word instruction is
preceded by a conditional instruction that changes the
PC. Example 6-4 shows how this works.
Note:For information on two-word instructions
in the extended instruction set, see
Section 6.5 “Program Memory and the
Extended Instruction Set”.
EXAMPLE 6-4:TWO-WORD INSTRUCTIONS
CASE 1:
Object CodeSource Code
0110 0110 0000 0000TSTFSZREG1; is RAM location 0?
1100 0001 0010 0011MOVFFREG1, REG2 ; No, skip this word
1111 0100 0101 0110; Execute this word as a NOP
0010 0100 0000 0000ADDWFREG3; continue code
CASE 2:
Object CodeSource Code
0110 0110 0000 0000TSTFSZREG1; is RAM location 0?
1100 0001 0010 0011MOVFFREG1, REG2 ; Yes, execute this word
1111 0100 0101 0110; 2nd word of instruction
0010 0100 0000 0000ADDWFREG3; continue code
2011 Microchip Technology Inc.DS39957C-page 91
PIC18F87K90 FAMILY
6.3Data Memory Organization
Note:The operation of some aspects of data
memory are changed when the PIC18
extended instruction set is enabled. See
Section 6.6 “Data Memory and the
Extended Instruction Set” for more
information.
The data memory in PIC18 devices is implemented as
static RAM. Each register in the data memory has a
12-bit address, allowing up to 4,096 bytes of data
memory. The memory space is divided into as many as
16 banks that contain 256 bytes each. PIC18FX6K90
and PIC18FX7K90 devices implement all 16 complete
banks, for a total of 4 Kbytes. PIC18FX5K90 devices
implement only the first eight complete banks, for a
total of 2 Kbytes.
Figure 6-6 and Figure 6-7 show the data memory
organization for the devices.
The data memory contains Special Function Registers
(SFRs) and General Purpose Registers (GPRs). The
SFRs are used for control and status of the controller
and peripheral functions, while GPRs are used for data
storage and scratchpad operations in the user’s
application. Any read of an unimplemented location will
read as ‘0’s.
The instruction set and architecture allow operations
across all banks. The entire data memory may be
accessed by Direct, Indirect or Indexed Addressing
modes. Addressing modes are discussed later in this
section.
To ensure that commonly used registers (select SFRs
and select GPRs) can be accessed in a single cycle,
PIC18 devices implement an Access Bank. This is a
256-byte memory space that provides fast access to
select SFRs and the lower portion of GPR Bank 0 without using the Bank Select Register. For details on the
Access RAM, see Section 6.3.2 “Acces s Bank”.
6.3.1BANK SELECT REGISTER
Large areas of data memory require an efficient
addressing scheme to make possible rapid access to
any address. Ideally, this means that an entire address
does not need to be provided for each read or write
operation. For PIC18 devices, this is accomplished with
a RAM banking scheme. This divides the memory
space into 16 contiguous banks of 256 bytes. Depending on the instruction, each location can be addressed
directly by its full 12-bit address, or an 8-bit, low-order
address and a four-bit Bank Pointer.
Most instructions in the PIC18 instruction set make use
of the Bank Pointer, known as the Bank Select Register
(BSR). This SFR holds the four Most Significant bits of
a location’s address. The instruction itself includes the
eight Least Significant bits. Only the four lower bits of
the BSR are implemented (BSR<3:0>). The upper four
bits are unused, always read as ‘0’ and cannot be
written to. The BSR can be loaded directly by using the
MOVLB instruction.
The value of the BSR indicates the bank in data
memory. The eight bits in the instruction show the location in the bank and can be thought of as an offset from
the bank’s lower boundary. The relationship between
the BSR’s value and the bank division in data memory
is shown in Figure 6-7.
Since up to 16 registers may share the same low-order
address, the user must always be careful to ensure that
the proper bank is selected before performing a data
read or write. For example, writing what should be
program data to an 8-bit address of F9h while the BSR
is 0Fh, will end up resetting the program counter.
While any bank can be selected, only those banks that
are actually implemented can be read or written to.
Writes to unimplemented banks are ignored, while
reads from unimplemented banks will return ‘0’s. Even
so, the STATUS register will still be affected as if the
operation was successful. The data memory map in
Figure 6-6 indicates which banks are implemented.
In the core PIC18 instruction set, only the MOVFF
instruction fully specifies the 12-bit address of the
source and target registers. When this instruction
executes, it ignores the BSR completely. All other
instructions include only the low-order address as an
operand and must use either the BSR or the Access
Bank to locate their target registers.
DS39957C-page 92 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
00h
5Fh
60h
FFh
Access Bank
When a = 0:
The BSR is ignored and the
Access Bank is used.
The first 96 bytes are general
purpose RAM (from Bank 0).
The second 160 bytes are
Special Function Registers
(from Bank 15).
When a = 1:
The BSR specifies the bank
used by the instruction.
Access RAM High
Access RAM Low
(SFRs)
Bank 0
Bank 1
Bank 14
Bank 15
Data Memory Map
BSR<3:0>
= 0000
= 0001
= 1111
060h
05Fh
F60h
FFFh
F5Fh
F00h
EFFh
1FFh
100h
0FFh
000h
Access RAM
FFh
00h
FFh
00h
FFh
00h
GPR
GPR
SFR
Bank 2
= 0010
2FFh
200h
Bank 3
FFh
00h
GPR
FFh
= 0011
GPR
(1,2)
GPR
GPR
GPR
GPR
GPR
4FFh
400h
5FFh
500h
3FFh
300h
FFh
00h
FFh
00h
FFh
00h
FFh
00h
FFh
00h
00h
= 0110
= 0111
= 0101
= 0100
Bank 4
Bank 5
Bank 6
Bank 7
Bank 8
= 1110
6FFh
600h
7FFh
700h
800h
Bank 9
Bank 10
Bank 11
Bank 12
Bank 13
8FFh
900h
9FFh
A00h
AFFh
B00h
BFFh
C00h
CFFh
D00h
DFFh
E00h
FFh
00h
FFh
00h
FFh
00h
FFh
00h
FFh
00h
FFh
00h
GPR
(1,2)
GPR
(2)
GPR
(2)
GPR
(2)
GPR
(2)
GPR
(2)
GPR
(2)
Note 1: Addresses, EF4h through F5Fh, are also used by SFRs, but are not part of the Access RAM. Users must
always use the complete address, or load the proper BSR value, to access these registers.
2: These addresses are unused for devices with 32 Kbytes of program memory (PIC18FX5K90). For those
devices, read these addresses at 00h.
= 1000
= 1001
= 1010
= 1011
= 1100
= 1101
FIGURE 6-6:DATA MEMORY MAP FOR PIC18FX5K90 AND PIC18FX7K90 DEVICES
2011 Microchip Technology Inc.DS39957C-page 93
PIC18F87K90 FAMILY
Note 1:The Access RAM bit of the instruction can be used to force an override of the selected bank (BSR<3:0>)
to the registers of the Access Bank.
2:The MOVFF instruction embeds the entire 12-bit address in the instruction.
Data Memory
Bank Select
(2)
7
0
From Opcode
(2)
0000
000h
100h
200h
300h
F00h
E00h
FFFh
Bank 0
Bank 1
Bank 2
Bank 14
Bank 15
00h
FFh
00h
FFh
00h
FFh
00h
FFh
00h
FFh
00h
FFh
Bank 3
through
Bank 13
0010
11111111
7
0
BSR
(1)
11111111
FIGURE 6-7:USE OF THE BANK SELECT REGISTER (DIRECT ADDRESSING)
6.3.2ACCESS BANK
While the use of the BSR, with an embedded 8-bit
address, allows users to address the entire range of data
memory, it also means that the user must ensure that the
correct bank is selected. If not, data may be read from,
or written to, the wrong location. This can be disastrous
if a GPR is the intended target of an operation, but an
SFR is written to instead. But verifying and/or changing
the BSR for each read or write to data memory can
become very inefficient.
To streamline access for the most commonly used data
memory locations, the data memory is configured with
an Access Bank, which allows users to access a
mapped block of memory without specifying a BSR.
The Access Bank consists of the first 96 bytes of
memory (00h-5Fh) in Bank 0 and the last 160 bytes of
memory (60h-FFh) in Bank 15. The lower half is known
as the “Access RAM” and is composed of GPRs. The
upper half is where the device’s SFRs are mapped.
These two areas are mapped contiguously in the
Access Bank and can be addressed in a linear fashion
by an 8-bit address (Figure 6-6).
The Access Bank is used by core PIC18 instructions
that include the Access RAM bit (the ‘a’ parameter in
the instruction). When ‘a’ is equal to ‘1’, the instruction
uses the BSR and the 8-bit address included in the
opcode for the data memory address. When ‘a’ is ‘0’,
however, the instruction is forced to use the Access
Bank address map. In that case, the current value of
the BSR is ignored entirely.
Using this “forced” addressing allows the instruction to
operate on a data address in a single cycle without
updating the BSR first. For 8-bit addresses of 60h and
above, this means that users can evaluate and operate
on SFRs more efficiently. The Access RAM below 60h
is a good place for data values that the user might need
to access rapidly, such as immediate computational
results or common program variables.
Access RAM also allows for faster and more code
efficient context saving and switching of variables.
The mapping of the Access Bank is slightly different
when the extended instruction set is enabled (XINST
Configuration bit = 1). This is discussed in more detail
in Section 6.6.3 “Mapping the Access Bank in
Indexed Literal Offset Mode”.
6.3.3GENERAL PURPOSE
REGISTER FILE
PIC18 devices may have banked memory in the GPR
area. This is data RAM which is available for use by all
instructions. GPRs start at the bottom of Bank 0
(address 000h) and grow upwards towards the bottom of
the SFR area. GPRs are not initialized by a Power-on
Reset and are unchanged on all other Resets.
DS39957C-page 94 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
6.3.4SPECIAL FUNCTION REGISTERS
The Special Function Registers (SFRs) are registers
used by the CPU and peripheral modules for controlling
the desired operation of the device. These registers are
implemented as static RAM. SFRs start at the top of
data memory (FFFh) and extend downward to occupy
all of Bank 15 (F00h to FFFh) and the top part of
Bank 14 (EF4h to EFFh).
A list of these registers is given in Tab le 6 -1 and
Table 6-2.
TABLE 6-1:PIC18F87K90 FAMILY SPECIAL FUNCTION REGISTER MAP
The SFRs can be classified into two sets: those
associated with the “core” device functionality (ALU,
Resets and interrupts) and those related to the
peripheral functions. The Reset and Interrupt registers
are described in their respective chapters, while the
ALU’s STATUS register is described later in this section.
Registers related to the operation of the peripheral
features are described in the chapter for that peripheral.
The SFRs are typically distributed among the
peripherals whose functions they control. Unused SFR
locations are unimplemented and read as ‘0’s.
2:Unimplemented registers are read as ‘0’.
3:This register is not available in 64-pin devices (PIC18F6XK90).
4:This register is not available in devices with a program memory of 32 Kbytes (PIC18FX5K90).
5:Addresses, EF4h through F5Fh, are also used by SFRs, but are not part of the Access RAM. Users must always load
the proper BSR value to access these registers.
2011 Microchip Technology Inc.DS39957C-page 95
PIC18F87K90 FAMILY
TABLE 6-1:PIC18F87K90 FAMILY SPECIAL FUNCTION REGISTER MAP
2:Unimplemented registers are read as ‘0’.
3:This register is not available in 64-pin devices (PIC18F6XK90).
4:This register is not available in devices with a program memory of 32 Kbytes (PIC18FX5K90).
5:Addresses, EF4h through F5Fh, are also used by SFRs, but are not part of the Access RAM. Users must always load
the proper BSR value to access these registers.
(3)
DS39957C-page 96 2011 Microchip Technology Inc.
PIC18F87K90 FAMILY
TABLE 6-2:PIC18F87K90 FAMILY REGISTER FILE SUMMARY
—CTMUSIDLTGENEDGENEDGSEQEN IDISSENCTTRIG0-00 0000
F58hALRMVALLAlarm Value High Register Window based on APTR<1:0>0000 0000
F59hALRMVALHAlarm Value High Register Window based on APTR<1:0>xxxx xxxx
F5AhALRMRPTARPT7ARPT6ARPT5ARPT4ARPT3ARPT2ARPT1ARPT00000 0000
F5BhALRMCFGALRMENCHIMEAMASK3AMASK2AMASK1AMASK0 ALRMPTR1 ALRMPTR0 0000 0000
F5ChRTCVALLRTCC Value Low Register Window based on RTCPTR<1:0>0000 0000
F5DhRTCVALHRTCC Value High Register Window based on RTCPTR<1:0>xxxx xxxx
F5EhRTCCALCAL7CAL6CAL5CAL4CAL3CAL2CAL1CAL0xxxx xxxx