ETC PIC16CR65

M
PICmicro™
Mid-Range MCU Family
Reference Manual
 1997 Microchip Technology Inc.
December 1997 /DS33023A
M
Internationally Recognized Quality
System Certifications
Microchip’s Quality System embodies the requirements
of ISO9001:1994. Our Microchip Chandler and Tempe
Design and Manufacturing facilities have been certified
to ISO 9001. The Microchip Kaohsiung Test facility, and
primary Assembly houses have been certified to ISO
9002. ISO certification plans are in-process for an estimated certification grant by year-end 1997. In addition,
Microchip has received numerous customer certifications, including a Delco issued certificate of compliance
to AEC-A100/QS9000.
“All rights reserved. Copyright © 1997, Microchip Technology
Incorporated, USA. Information contained in this publication
regarding device applications and the like is intended through
suggestion only and may be superseded by updates. No representation or warranty is given and no liability is assumed by
Microchip Technology Incorporated with respect to the accuracy or use of such information, or infringement of patents or
other intellectual property rights arising from such use or otherwise. Use of Microchip’s products as critical components in
life support systems is not authorized except with express
written approval by Microchip. No licenses are conveyed,
implicitly or otherwise, under any intellectual property rights.
The Microchip logo and name are registered trademarks of
Microchip Technology Inc. in the U.S.A. and other countries.
All rights reserved. All other trademarks mentioned herein are
the property of their respective companies. No licenses are
conveyed, implicitly or otherwise, under any intellectual property rights.”
December 1997 /DS33023A
Microchip received ISO 9001 Quality System certification for its worldwide headquarters, design, and wafer
fabrication facilities in January, 1997. Our field-programmable PICmicro™ 8-bit MCUs, Serial EEPROMs,
related specialty memory products and development
systems conform to the stringent quality standards of
the International Standard Organization (ISO).
Trademarks
The Microchip name, logo, PIC, KEELOQ, PICMASTER,
PICSTART, PRO MATE, and SEEVAL are registered
trademarks of Microchip Technology Incorporated in the
U.S.A.
MPLAB, PICmicro, ICSP and In-Circuit Serial Programming
are trademarks of Microchip Technology Incorporated.
Serialized Quick-Turn Production is a Service Mark of Microchip Technology Incorporated.
All other trademarks mentioned herein are property of their
respective companies.
 1997 Microchip Technology Inc.
M
Table of Contents
PAGE
SECTION 1. INTRODUCTION
1-1
Introduction .......................................................................................................................................................1-2
Manual Objective ..............................................................................................................................................1-3
Device Structure ...............................................................................................................................................1-4
Development Support .......................................................................................................................................1-6
Device Varieties ...............................................................................................................................................1-7
Style and Symbol Conventions ......................................................................................................................1-12
Related Documents ........................................................................................................................................1-14
Related Application Notes ..............................................................................................................................1-17
Revision History .............................................................................................................................................1-18
SECTION 2. OSCILLATOR
2-1
Introduction .......................................................................................................................................................2-2
Oscillator Configurations ..................................................................................................................................2-2
Crystal Oscillators / Ceramic Resonators .........................................................................................................2-4
External RC Oscillator ....................................................................................................................................2-12
Internal 4 MHz RC Oscillator ..........................................................................................................................2-13
Effects of Sleep Mode on the On-chip Oscillator ............................................................................................2-17
Effects of Device Reset on the On-chip Oscillator .........................................................................................2-17
Design Tips ....................................................................................................................................................2-18
Related Application Notes ..............................................................................................................................2-19
Revision History .............................................................................................................................................2-20
SECTION 3. RESET
3-1
Introduction .......................................................................................................................................................3-2
Power-on Reset (POR), Power-up Timer (PWRT),
Oscillator Start-up Timer (OST), Brown-out Reset (BOR), and Parity Error Reset (PER) ..............................3-4
Registers and Status Bit Values .....................................................................................................................3-10
Design Tips ....................................................................................................................................................3-16
Related Application Notes ..............................................................................................................................3-17
Revision History .............................................................................................................................................3-18
SECTION 4. ARCHITECTURE
4-1
Introduction .......................................................................................................................................................4-2
Clocking Scheme/Instruction Cycle ..................................................................................................................4-5
Instruction Flow/Pipelining ................................................................................................................................4-6
I/O Descriptions ................................................................................................................................................4-7
Design Tips ....................................................................................................................................................4-12
Related Application Notes ..............................................................................................................................4-13
Revision History .............................................................................................................................................4-14
 1997 Microchip Technology Inc.
DS00097D-page iii
M
Table of Contents
PAGE
SECTION 5. CPU AND ALU
5-1
Introduction .......................................................................................................................................................5-2
General Instruction Format ...............................................................................................................................5-4
Central Processing Unit (CPU) .........................................................................................................................5-4
Instruction Clock ...............................................................................................................................................5-4
Arithmetic Logical Unit (ALU) ...........................................................................................................................5-5
STATUS Register .............................................................................................................................................5-6
OPTION_REG Register ...................................................................................................................................5-8
PCON Register .................................................................................................................................................5-9
Design Tips ....................................................................................................................................................5-10
Related Application Notes ..............................................................................................................................5-11
Revision History .............................................................................................................................................5-12
SECTION 6. MEMORY ORGANIZATION
6-1
Introduction .......................................................................................................................................................6-2
Program Memory Organization ........................................................................................................................6-2
Data Memory Organization ..............................................................................................................................6-8
Initialization .....................................................................................................................................................6-14
Design Tips ....................................................................................................................................................6-16
Related Application Notes ..............................................................................................................................6-17
Revision History .............................................................................................................................................6-18
SECTION 7. DATA EEPROM
7-1
Introduction .......................................................................................................................................................7-2
Control Register ...............................................................................................................................................7-3
EEADR .............................................................................................................................................................7-4
EECON1 and EECON2 Registers ....................................................................................................................7-4
Reading the EEPROM Data Memory ...............................................................................................................7-5
Writing to the EEPROM Data Memory .............................................................................................................7-5
Write Verify .......................................................................................................................................................7-6
Protection Against Spurious Writes ..................................................................................................................7-7
Data EEPROM Operation During Code Protected Configuration ....................................................................7-7
Initialization .......................................................................................................................................................7-7
Design Tips ......................................................................................................................................................7-8
Related Application Notes ................................................................................................................................7-9
Revision History .............................................................................................................................................7-10
SECTION 8. INTERRUPTS
8-1
Introduction .......................................................................................................................................................8-2
Control Registers ..............................................................................................................................................8-5
Interrupt Latency ............................................................................................................................................8-10
INT and External Interrupts ............................................................................................................................8-10
Context Saving During Interrupts ...................................................................................................................8-11
Initialization .....................................................................................................................................................8-14
Design Tips ....................................................................................................................................................8-16
Related Application Notes ..............................................................................................................................8-17
Revision History .............................................................................................................................................8-18
DS00097D-page iv
 1997 Microchip Technology Inc.
M
Table of Contents
PAGE
SECTION 9. I/O PORTS
9-1
Introduction .......................................................................................................................................................9-2
PORTA and the TRISA Register ......................................................................................................................9-4
PORTB and the TRISB Register ......................................................................................................................9-6
PORTC and the TRISC Register ......................................................................................................................9-8
PORTD and the TRISD Register ......................................................................................................................9-9
PORTE and the TRISE Register ....................................................................................................................9-10
PORTF and the TRISF Register ....................................................................................................................9-11
PORTG and the TRISG Register ...................................................................................................................9-12
GPIO and the TRISGP Register .....................................................................................................................9-13
I/O Programming Considerations ...................................................................................................................9-14
Initialization .....................................................................................................................................................9-16
Design Tips ....................................................................................................................................................9-17
Related Application Notes ..............................................................................................................................9-19
Revision History .............................................................................................................................................9-20
SECTION 10. PARALLEL SLAVE PORT
10-1
Introduction .....................................................................................................................................................10-2
Control Register .............................................................................................................................................10-3
Operation ........................................................................................................................................................10-4
Operation in Sleep Mode ................................................................................................................................10-5
Effect of a Reset .............................................................................................................................................10-5
PSP Waveforms .............................................................................................................................................10-5
Design Tips ....................................................................................................................................................10-6
Related Application Notes ..............................................................................................................................10-7
Revision History .............................................................................................................................................10-8
 1997 Microchip Technology Inc.
DS00097D-page v
M
Table of Contents
PAGE
SECTION 11. TIMER0
11-1
Introduction .....................................................................................................................................................11-2
Control Register .............................................................................................................................................11-3
Operation ........................................................................................................................................................11-4
TMR0 Interrupt ...............................................................................................................................................11-5
Using Timer0 with an External Clock .............................................................................................................11-6
TMR0 Prescaler .............................................................................................................................................11-7
Design Tips ..................................................................................................................................................11-10
Related Application Notes ............................................................................................................................11-11
Revision History ...........................................................................................................................................11-12
SECTION 12. TIMER1
12-1
Introduction .....................................................................................................................................................12-2
Control Register .............................................................................................................................................12-3
Timer1 Operation in Timer Mode ...................................................................................................................12-4
Timer1 Operation in Synchronized Counter Mode .........................................................................................12-4
Timer1 Operation in Asynchronous Counter Mode ........................................................................................12-5
Timer1 Oscillator ............................................................................................................................................12-7
Sleep Operation .............................................................................................................................................12-9
Resetting Timer1 Using a CCP Trigger Output ..............................................................................................12-9
Resetting of Timer1 Register Pair (TMR1H:TMR1L) ......................................................................................12-9
Timer1 Prescaler ............................................................................................................................................12-9
Initialization ...................................................................................................................................................12-10
Design Tips ..................................................................................................................................................12-12
Related Application Notes ............................................................................................................................12-13
Revision History ...........................................................................................................................................12-14
SECTION 13. TIMER2
13-1
Introduction .....................................................................................................................................................13-2
Control Register .............................................................................................................................................13-3
Timer Clock Source ........................................................................................................................................13-4
Timer (TMR2) and Period (PR2) Registers ....................................................................................................13-4
TMR2 Match Output .......................................................................................................................................13-4
Clearing the Timer2 Prescaler and Postscaler ...............................................................................................13-4
Sleep Operation .............................................................................................................................................13-4
Initialization .....................................................................................................................................................13-5
Design Tips ....................................................................................................................................................13-6
Related Application Notes ..............................................................................................................................13-7
Revision History .............................................................................................................................................13-8
SECTION 14. COMPARE/CAPTURE/PWM (CCP)
14-1
Introduction .....................................................................................................................................................14-2
Control Register .............................................................................................................................................14-3
Capture Mode .................................................................................................................................................14-4
Compare Mode ...............................................................................................................................................14-6
PWM Mode .....................................................................................................................................................14-8
Initialization ...................................................................................................................................................14-12
Design Tips ..................................................................................................................................................14-15
Related Application Notes ............................................................................................................................14-17
Revision History ...........................................................................................................................................14-18
DS00097D-page vi
 1997 Microchip Technology Inc.
M
Table of Contents
PAGE
SECTION 15. SYNCHRONOUS SERIAL PORT (SSP)
15-1
Introduction .....................................................................................................................................................15-2
Control Registers ............................................................................................................................................15-3
SPI Mode ........................................................................................................................................................15-6
SSP I2C Operation .......................................................................................................................................15-16
Initialization ...................................................................................................................................................15-26
Design Tips ..................................................................................................................................................15-28
Related Application Notes ............................................................................................................................15-29
Revision History ...........................................................................................................................................15-30
SECTION 16. BASIC SYCHRONOUS SERIAL PORT (BSSP)
16-1
Introduction .....................................................................................................................................................16-2
Control Registers ............................................................................................................................................16-3
SPI Mode ........................................................................................................................................................16-6
SSP I2C Operation .......................................................................................................................................16-15
Initialization ...................................................................................................................................................16-23
Design Tips ..................................................................................................................................................16-24
Related Application Notes ............................................................................................................................16-25
Revision History ...........................................................................................................................................16-26
SECTION 17. MASTER SYNCHRONOUS SERIAL PORT (MSSP)
17-1
Introduction .....................................................................................................................................................17-2
Control Register .............................................................................................................................................17-4
SPI Mode ........................................................................................................................................................17-9
SSP I2C™ Operation ....................................................................................................................................17-18
Connection Considerations for I2C Bus ........................................................................................................17-56
Initialization ...................................................................................................................................................17-57
Design Tips ..................................................................................................................................................17-58
Related Application Notes ............................................................................................................................17-59
Revision History ...........................................................................................................................................17-60
SECTION 18. USART
18-1
Introduction .....................................................................................................................................................18-2
Control Registers ............................................................................................................................................18-3
USART Baud Rate Generator (BRG) .............................................................................................................18-5
USART Asynchronous Mode .........................................................................................................................18-8
USART Synchronous Master Mode .............................................................................................................18-15
USART Synchronous Slave Mode ...............................................................................................................18-19
Initialization ...................................................................................................................................................18-21
Design Tips ..................................................................................................................................................18-22
Related Application Notes ............................................................................................................................18-23
Revision History ...........................................................................................................................................18-24
 1997 Microchip Technology Inc.
DS00097D-page vii
M
Table of Contents
PAGE
SECTION 19. VOLTAGE REFERENCE
19-1
Introduction .....................................................................................................................................................19-2
Control Register .............................................................................................................................................19-3
Configuring the Voltage Reference ................................................................................................................19-4
Voltage Reference Accuracy/Error .................................................................................................................19-5
Operation During Sleep ..................................................................................................................................19-5
Effects of a Reset ...........................................................................................................................................19-5
Connection Considerations ............................................................................................................................19-6
Initialization .....................................................................................................................................................19-7
Design Tips ....................................................................................................................................................19-8
Related Application Notes ..............................................................................................................................19-9
Revision History ...........................................................................................................................................19-10
SECTION 20. COMPARATOR
20-1
Introduction .....................................................................................................................................................20-2
Control Register .............................................................................................................................................20-3
Comparator Configuration ..............................................................................................................................20-4
Comparator Operation ....................................................................................................................................20-6
Comparator Reference ...................................................................................................................................20-6
Comparator Response Time ..........................................................................................................................20-8
Comparator Outputs .......................................................................................................................................20-8
Comparator Interrupts ....................................................................................................................................20-9
Comparator Operation During SLEEP ...........................................................................................................20-9
Effects of a RESET ........................................................................................................................................20-9
Analog Input Connection Considerations .....................................................................................................20-10
Initialization ...................................................................................................................................................20-11
Design Tips ..................................................................................................................................................20-12
Related Application Notes ............................................................................................................................20-13
Revision History ...........................................................................................................................................20-14
SECTION 21. 8-BIT A/D CONVERTER
21-1
Introduction .....................................................................................................................................................21-2
Control Registers ............................................................................................................................................21-3
Operation ........................................................................................................................................................21-5
A/D Acquisition Requirements ........................................................................................................................21-6
Selecting the A/D Conversion Clock ..............................................................................................................21-8
Configuring Analog Port Pins .........................................................................................................................21-9
A/D Conversions ..........................................................................................................................................21-10
A/D Operation During Sleep .........................................................................................................................21-12
A/D Accuracy/Error .......................................................................................................................................21-13
Effects of a RESET ......................................................................................................................................21-13
Use of the CCP Trigger ................................................................................................................................21-14
Connection Considerations ..........................................................................................................................21-14
Transfer Function .........................................................................................................................................21-14
Initialization ...................................................................................................................................................21-15
Design Tips ..................................................................................................................................................21-16
Related Application Notes ............................................................................................................................21-17
Revision History ...........................................................................................................................................21-18
DS00097D-page viii
 1997 Microchip Technology Inc.
M
Table of Contents
PAGE
SECTION 22. BASIC 8-BIT A/D CONVERTER
22-1
Introduction .....................................................................................................................................................22-2
Control Registers ............................................................................................................................................22-3
A/D Acquisition Requirements ........................................................................................................................22-6
Selecting the A/D Conversion Clock ..............................................................................................................22-8
Configuring Analog Port Pins .......................................................................................................................22-10
A/D Conversions ..........................................................................................................................................22-11
A/D Operation During Sleep .........................................................................................................................22-14
A/D Accuracy/Error .......................................................................................................................................22-15
Effects of a RESET ......................................................................................................................................22-16
Connection Considerations ..........................................................................................................................22-16
Transfer Function .........................................................................................................................................22-16
Initialization ...................................................................................................................................................22-17
Design Tips ..................................................................................................................................................22-18
Related Application Notes ............................................................................................................................22-19
Revision History ...........................................................................................................................................22-20
SECTION 23. 10-BIT A/D CONVERTER
23-1
Introduction .....................................................................................................................................................23-2
Control Register .............................................................................................................................................23-3
Operation ........................................................................................................................................................23-5
A/D Acquisition Requirements ........................................................................................................................23-6
Selecting the A/D Conversion Clock ..............................................................................................................23-8
Configuring Analog Port Pins .........................................................................................................................23-9
A/D Conversions ..........................................................................................................................................23-10
Operation During Sleep ................................................................................................................................23-14
Effects of a Reset .........................................................................................................................................23-14
A/D Accuracy/Error .......................................................................................................................................23-15
Connection Considerations ..........................................................................................................................23-16
Transfer Function .........................................................................................................................................23-16
Initialization ...................................................................................................................................................23-17
Design Tips ..................................................................................................................................................23-18
Related Application Notes ............................................................................................................................23-19
Revision History ...........................................................................................................................................23-20
SECTION 24. SLOPE A/D
24-1
Introduction .....................................................................................................................................................24-2
Control Registers ............................................................................................................................................24-3
Conversion Process .......................................................................................................................................24-6
Other Analog Modules ..................................................................................................................................24-12
Calibration Parameters .................................................................................................................................24-13
Design Tips ..................................................................................................................................................24-14
Related Application Notes ............................................................................................................................24-15
Revision History ...........................................................................................................................................24-16
 1997 Microchip Technology Inc.
DS00097D-page ix
M
Table of Contents
PAGE
SECTION 25. LCD
25-1
Introduction .....................................................................................................................................................25-2
Control Register .............................................................................................................................................25-3
LCD Timing ....................................................................................................................................................25-6
LCD Interrupts ..............................................................................................................................................25-12
Pixel Control .................................................................................................................................................25-13
Voltage Generation ......................................................................................................................................25-15
Operation During Sleep ................................................................................................................................25-16
Effects of a Reset .........................................................................................................................................25-17
Configuring the LCD Module ........................................................................................................................25-17
Discrimination Ratio .....................................................................................................................................25-18
LCD Voltage Generation ..............................................................................................................................25-20
Contrast ........................................................................................................................................................25-22
LCD Glass ....................................................................................................................................................25-22
Initialization ...................................................................................................................................................25-23
Design Tips ..................................................................................................................................................25-24
Related Application Notes ............................................................................................................................25-25
Revision History ...........................................................................................................................................25-26
SECTION 26. WATCHDOG TIMER AND SLEEP MODE
26-1
Introduction .....................................................................................................................................................26-2
Control Register .............................................................................................................................................26-3
Watchdog Timer (WDT) Operation .................................................................................................................26-4
SLEEP (Power-Down) Mode ..........................................................................................................................26-7
Initialization .....................................................................................................................................................26-9
Design Tips ..................................................................................................................................................26-10
Related Application Notes ............................................................................................................................26-11
Revision History ...........................................................................................................................................26-12
SECTION 27. DEVICE CONFIGURATION BITS
27-1
Introduction .....................................................................................................................................................27-2
Configuration Word Bits .................................................................................................................................27-4
Program Verification/Code Protection ............................................................................................................27-8
ID Locations ...................................................................................................................................................27-9
Design Tips ..................................................................................................................................................27-10
Related Application Notes ............................................................................................................................27-11
Revision History ...........................................................................................................................................27-12
SECTION 28. IN-CIRCUIT SERIAL PROGRAMMING™
28-1
Introduction .....................................................................................................................................................28-2
Entering In-Circuit Serial Programming Mode ................................................................................................28-3
Application Circuit ...........................................................................................................................................28-4
Programmer ...................................................................................................................................................28-6
Programming Environment .............................................................................................................................28-6
Other Benefits ................................................................................................................................................28-7
Field Programming of PICmicro OTP MCUs ..................................................................................................28-8
Field Programming of FLASH PICmicros .....................................................................................................28-10
Design Tips ..................................................................................................................................................28-12
Related Application Notes ............................................................................................................................28-13
Revision History ...........................................................................................................................................28-14
DS00097D-page x
 1997 Microchip Technology Inc.
M
Table of Contents
PAGE
SECTION 29. INSTRUCTION SET
29-1
Introduction .....................................................................................................................................................29-2
Instruction Formats .........................................................................................................................................29-4
Special Function Registers as Source/Destination ........................................................................................29-6
Q Cycle Activity ..............................................................................................................................................29-7
Instruction Descriptions ..................................................................................................................................29-8
Design Tips ..................................................................................................................................................29-45
Related Application Notes ............................................................................................................................29-47
Revision History ...........................................................................................................................................29-48
SECTION 30. ELECTRICAL SPECIFICATIONS
30-1
Introduction .....................................................................................................................................................30-2
Absolute Maximums .......................................................................................................................................30-3
Device Selection Table ...................................................................................................................................30-4
Device Voltage Specifications ........................................................................................................................30-5
Device Current Specifications ........................................................................................................................30-6
Input Threshold Levels ...................................................................................................................................30-9
I/O Current Specifications ............................................................................................................................30-10
Output Drive Levels ......................................................................................................................................30-11
I/O Capacitive Loading .................................................................................................................................30-12
Data EEPROM / Flash .................................................................................................................................30-13
LCD ..............................................................................................................................................................30-14
Comparators and Voltage Reference ...........................................................................................................30-15
Timing Parameter Symbology ......................................................................................................................30-16
Example External Clock Timing Waveforms and Requirements ..................................................................30-17
Example Power-up and Reset Timing Waveforms and Requirements ........................................................30-19
Example Timer0 and Timer1 Timing Waveforms and Requirements ...........................................................30-20
Example CCP Timing Waveforms and Requirements .................................................................................30-21
Example Parallel Slave Port (PSP) Timing Waveforms and Requirements .................................................30-22
Example SSP and Master SSP SPI Mode Timing Waveforms and Requirements ......................................30-23
Example SSP I2C Mode Timing Waveforms and Requirements ..................................................................30-27
Example Master SSP I2C Mode Timing Waveforms and Requirements ......................................................30-30
Example USART/SCI Timing Waveforms and Requirements ......................................................................30-32
Example 8-bit A/D Timing Waveforms and Requirements ...........................................................................30-34
Example 10-bit A/D Timing Waveforms and Requirements .........................................................................30-36
Example Slope A/D Timing Waveforms and Requirements .........................................................................30-38
Example LCD Timing Waveforms and Requirements ..................................................................................30-40
Related Application Notes ............................................................................................................................30-41
Revision History ...........................................................................................................................................30-42
SECTION 31. DEVICE CHARACTERISTICS
31-1
Introduction .....................................................................................................................................................31-2
Characterization vs. Electrical Specification ...................................................................................................31-2
DC and AC Characteristics Graphs and Tables .............................................................................................31-2
Revision History ...........................................................................................................................................31-22
 1997 Microchip Technology Inc.
DS00097D-page xi
M
Table of Contents
PAGE
SECTION 32. DEVELOPMENT TOOLS
32-1
Introduction .....................................................................................................................................................32-2
The Integrated Development Environment (IDE) ...........................................................................................32-3
MPLAB Software Language Support .............................................................................................................32-6
MPLAB-SIM Simulator Software ....................................................................................................................32-8
MPLAB Emulator Hardware Support ..............................................................................................................32-9
MPLAB Programmer Support .......................................................................................................................32-10
Supplemental Tools ......................................................................................................................................32-11
Development Boards ....................................................................................................................................32-12
Development Tools for Other Microchip Products ........................................................................................32-14
Related Application Notes ............................................................................................................................32-15
Revision History ...........................................................................................................................................32-16
SECTION 33. CODE DEVELOPMENT
33-1
Revision History .............................................................................................................................................33-2
SECTION 34. APPENDIX
34-1
I2C Overview ...............................................................................................................................................34-2
List of LCD Glass Manufacturers ................................................................................................................. 34-11
Device Enhancement ...................................................................................................................................34-13
Revision History ........................................................................................................................................... 34-19
SECTION 35. GLOSSARY
35-1
Revision History ...........................................................................................................................................35-14
DS00097D-page xii
 1997 Microchip Technology Inc.
M
1
Introduction
Section 1. Introduction
HIGHLIGHTS
This section of the manual contains the following major topics:
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
Introduction ....................................................................................................................1-2
Manual Objective ...........................................................................................................1-3
Device Structure ............................................................................................................1-4
Development Support ....................................................................................................1-6
Device Varieties..............................................................................................................1-7
Style and Symbol Conventions ....................................................................................1-12
Related Documents .....................................................................................................1-14
Related Application Notes............................................................................................1-17
Revision History ...........................................................................................................1-18
 1997 Microchip Technology Inc.
DS31001A page 1-1
PICmicro MID-RANGE MCU FAMILY
1.1
Introduction
Microchip is the Embedded Control Solutions Company. The company’s focus is on products
that meet the needs of the embedded control market. We are a leading supplier of:
•
•
•
•
8-bit General Purpose Microcontrollers (PICmicro™ MCUs)
Speciality and standard non-volatile memory devices
Security devices (KEELOQ®)
Application specific standard products
Please request a Microchip Product Line Card for a listing of all the interesting products that we
have to offer. This literature can be obtained from your local sales office, or downloaded from the
Microchip web site (www.microchip.com).
In the past, 8-bit MCU users were fixed on the traditional MCU model for production, a ROM device
was required. Microchip has been the leader in changing this perception by showing that OTP
devices can give a better lifetime product cost compared to ROM versions.
Microchip has a strength is in EPROM technology. That made it the memory technology of choice
for the PICmicro MCU’s program memory. Microchip has minimized the cost difference between
EPROM and ROM memory technology, and therefore Microchip can pass these benefits onto our
customers. This is not true for other MCU vendors, and is seen in the price difference between their
EPROM and ROM versions.
The growth of Microchip’s 8-bit MCU market share is a testament to the PICmicro MCUs ability to
meet the needs of many. This growth has made the PICmicro architecture one of the top three
architectures available in the general market today. This growth was fueled by the Microchip vision
of the benefits of a low cost OTP solution. Some of the benefits for the customer include:
•
•
•
•
•
•
•
Quick time to market
Allows code changes to product, during production run
No Non-Recurring Engineering (NRE) charges for Mask Revisions
Ability to easily serialize the product
Ability to store calibration data, without additional hardware
Better able to maximize PICmicro MCU inventory
Less risk, since the same device is used for development as well as for production.
Microchip’s PICmicro 8-bit MCUs offer a price/performance ratio that allows them to be considered
for any traditional 8-bit MCU application as well as some traditional 4-bit applications (Base-Line
family), dedicated logic replacement and low-end DSP applications (High-End family). These features and price-performance mix make PICmicro MCUs an attractive solution for most applications.
DS31001A-page 1-2
 1997 Microchip Technology Inc.
Section 1. Introduction
1.2
1
Manual Objective
1.
2.
3.
Base-Line: 12-bit Instruction Word length
Mid-Range: 14-bit Instruction Word length
High-End:
16-bit Instruction Word length
This manual focuses on the Mid-Range devices, which are also referred to as the PIC16CXXX
MCU family.
The operation of the PIC16CXXX MCU family architecture and peripheral modules is explained,
but does not cover the specifics of each device. Therefore, it is not intended to replace the device
data sheets, but complement them. In other words, this guide supplies the general details and
operation of the PICmicro architecture and peripheral modules, while the data sheet s give specific details such as device memory mapping.
Initialization examples are given throughout this manual. These examples sometimes need to be
written as device specific as opposed to family generic, though they are valid for most other
devices. Some modifications may be required for devices with variations in register file mappings.
Note:
 1997 Microchip Technology Inc.
The first few Mid-Range devices have minor device variations when compared to
this general description. We have tried to describe these variations throughout this
manual. Please refer to the specific device data sheet for complete information on
the device.
DS31001A-page 1-3
Introduction
PICmicro devices are grouped by the size of their Instruction Word. The three current PICmicro
families are:
PICmicro MID-RANGE MCU FAMILY
1.3
Device Structure
Each part of a device can be placed into one of three groups:
1.
2.
3.
1.3.1
Core
Peripherals
Special Features
The Core
The core pertains to the basic features that are required to make the device operate. These
include:
1.
2.
3.
4.
5.
6.
7.
1.3.2
Device Oscillator
Reset logic
CPU (Central Processing Unit) operation
ALU (Arithmetic Logical Unit) operation
Device memory map organization
Interrupt operation
Instruction set
Revision “DS31002A”
Revision “DS31003A”
Revision “DS31005A”
Revision “DS31005A”
Revision “DS31006A”
Revision “DS31008A”
Revision “DS31029A”
Peripherals
Peripherals are the features that add a differentiation from a microprocessor. These ease in interfacing to the external world (such as general purpose I/O, LCD drivers, A/D inputs, and PWM
outputs), and internal tasks such as keeping different time bases (such as timers). The peripherals that are discussed are:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
DS31001A-page 1-4
General purpose I/O
Timer0
Timer1
Timer2
Capture, Compare, and PWM (CCP)
Synchronous Serial Port (SSP)
Basic Synchronous Serial Port (SSP)
Master Synchronous Serial Port (MSSP)
USART (SCI)
Voltage References
Comparators
8-bit Analog to Digital (A/D)
Basic 8-bit Analog to Digital (A/D)
10-bit Analog to Digital (A/D)
Slope Analog to Digital (A/D) w/ Thermister
Liquid Crystal Display (LCD) Drivers
Parallel Slave Port (PSP)
Revision “DS31009A”
Revision “DS31011A”
Revision “DS31012A”
Revision “DS31013A”
Revision “DS31014A”
Revision “DS31015A”
Revision “DS31016A”
Revision “DS31017A”
Revision “DS31018A”
Revision “DS31019A”
Revision “DS31020A”
Revision “DS31021A”
Revision “DS31022A”
Revision “DS31023A”
Revision “DS31024A”
Revision “DS31025A”
Revision “DS31010A”
 1997 Microchip Technology Inc.
Section 1. Introduction
1.3.3
1
Special Features
• Decrease system cost
• Increase system reliability
• Increase design flexibility
The Mid-Range PICmicro MCUs offer several features that help achieve these goals. The special
features discussed are:
1.
2.
3.
4.
5.
6.
7.
Device Configuration bits
On-chip Power-on Reset (POR)
Brown-out Reset (BOR) logic
Watchdog Timer
Low power mode (Sleep)
Internal RC device oscillator
In-Circuit Serial Programming™ (ICSP™)
 1997 Microchip Technology Inc.
Revision “DS31027A”
Revision “DS31003A”
Revision “DS31003A”
Revision “DS31026A”
Revision “DS31026A”
Revision “DS31002A”
Revision “DS31028A”
DS31001A-page 1-5
Introduction
Special features are the unique features that help to do one or more of the following things:
PICmicro MID-RANGE MCU FAMILY
1.4
Development Support
Microchip offers a wide range of development tools that allow users to efficiently develop and
debug application code. Microchip’s development tools can be broken down into four categories:
1.
2.
3.
4.
Code generation
Software debug
Device programmer
Product evaluation boards
All tools developed by Microchip operate under the MPLAB™ Integrated Development Environment (IDE), while some third party tools may not. The code generation tools include:
• MPASM
• MPLAB-C
• MP-DriveWay™
These software development programs include device header files. Each header file defines the
register names (as shown in the device data sheet) to the specified address or bit location. Using
the header files eases code migration, and reduces the tediousness of memorizing a register’s
address or a bit’s position in a register.
Note:
Microchip strongly recommends that the supplied header files be used in the source
code of your program. This eases code migration as well as increases the quality
and depth of the technical support that Microchip can offer.
Tools which ease in debugging software are:
• PICMASTER® In-Circuit Emulator
• ICEPIC In-Circuit Emulator
• MPLAB-SIM Software Simulator
After generating and debugging the application software, the device will need to be programmed.
Microchip offers two levels of programmers:
1.
2.
PICSTART Plus programmer
PROMATE II programmer
Demonstration boards allow the developer of software code to evaluate the capability and suitability of the device to the application. The demo boards offered are:
•
•
•
•
PICDEM-1
PICDEM-2
PICDEM-3
PICDEM-14A
A full description of each of Microchip’s development tools is discussed in the “Development
Tools” section. As new tools are developed, product briefs and user guides may be obtained
from the Microchip web site (www.microchip.com) or from your local Microchip Sales Office.
Code development recommendations and techniques are provided in the “Code Development”
section.
Microchip offers other reference tools to speed the development cycle. These include:
•
•
•
•
•
•
Application Notes
Reference Designs
Microchip web site
Microchip BBS
Local Sales Offices with Field Application Support
Corporate Support Line
Additional avenues of assistance can be found in many Web User Groups including the MIT
reflector PIClist. The Microchip web site lists other sites that may be useful references.
DS31001A-page 1-6
 1997 Microchip Technology Inc.
Section 1. Introduction
1.5
1
Device Varieties
•
•
•
•
•
Memory technology
Operating voltage
Operating temperature range
Operating frequency
Packaging
Microchip has a large number of options and option combinations, one of which should fulfill your
requirements.
1.5.1
Memory Varieties
Memory technology has no effect on the logical operation of a device. Due to the different processing steps required, some electrical characteristics may vary between devices with the same
feature set/pinout but with different memory technologies. An example is the electrical characteristic VIL (Input Low Voltage), which may have some difference between a typical EPROM device
and a typical ROM device.
Each device has a variety of frequency ranges and packaging options available. Depending on
application and production requirements, the proper device options can be identified using the
information in the Product Selection System section at the end of each data sheet. When placing
orders, please use the “Product Identification System” at the back of the data sheet to specify the
correct part number.
When discussing the functionality of the device, the memory technology and the voltage range
do not matter. Microchip offers three program memory types. The memory type is designated in
the part number by the first letter(s) after the family affiliation designators.
1.
2.
3.
1.5.1.1
C, as in PIC16CXXX. These devices have EPROM type memory.
CR, as in PIC16CRXXX. These devices have ROM type memory.
F, as in PIC16FXXX. These devices have Flash type memory.
EPROM
Microchip focuses on Erasable Programmable Read Only Memory (EPROM) technology to give
the customers flexibility throughout their entire design cycle. With this technology Microchip
offers various packaging options as well as services.
1.5.1.2
Read Only Memory (ROM) Devices
Microchip offers a masked Read Only Memory (ROM) version of several of the highest volume
parts, thus giving customers a lower cost option for high volume, mature products.
ROM devices do not allow serialization information in the program memory space.
For information on submitting ROM code, please contact your local Microchip sales office.
1.5.1.3
Flash Memory Devices
These devices are electrically erasable, and can therefore be offered in a low cost plastic package. Being electrically erasable, these devices can be both erased and reprogrammed without
removal from the circuit. A device will have the same specifications whether it is used for prototype development, pilot programs, or production.
 1997 Microchip Technology Inc.
DS31001A-page 1-7
Introduction
Once the functional requirements of the device are specified, some other decisions need to be
made. These include:
PICmicro MID-RANGE MCU FAMILY
1.5.2
Operating Voltage Range Options
All Mid-Range PICmicro™ MCUs operate over the standard voltage range. Devices are also
offered which operate over an extended voltage range (and reduced frequency range). Table 1-1
shows all possible memory types and voltage range designators for the PIC16CXXX MCU family.
The designators are in bold typeface.
Table 1-1:
Device Memory Type and Voltage Range Designators
Voltage Range
Memory Type
Standard
EPROM
ROM
Flash
Extended
PIC16CXXX
PIC16CRXXX
PIC16FXXX
PIC16LCXXX
PIC16LCRXXX
PIC16LFXXX
Note:Not all memory types may be available for a particular device.
As you can see in Table 1-2, Microchip specifications its extended range devices at a more conservative voltage range until device characterization has ensured they will be able to meet the
goal of their final design specifications.
Table 1-2:
Typical Voltage Ranges for Each Device Type
Typical Voltage Range (1)
EPROM
ROM
Flash
Standard
Extended
C
4.5 - 6.0V
CR
4.5 - 6.0V
F
4.5 - 6.0V
Before device characterization
LC
3.0 - 6.0V
LCR
3.0 - 6.0V
LF
3.0 - 6.0V
Final specification (2)
LC
2.5 - 6.0V
LCR
2.5 - 6.0V
LF
2.0 - 6.0V
Note 1: Devices fabricated in Microchip’s 120K Process Technology will have a maximum limit on VDD of 5.5V. New
device data sheets will specify Microchip’s technology designation
2: This voltage range depends on the results of device characterization.
DS31001A-page 1-8
 1997 Microchip Technology Inc.
Section 1. Introduction
1.5.3
1
Packaging Varieties
The first is a device with an erasure window. Typically these are found in packages with a ceramic
body. These devices are used for the development phase, since the device’s program memory
can be erased and reprogrammed many times.
The second package type is a low cost plastic package. This package type is used in production
where device cost is to be kept to a minimum.
Lastly, there is the DIE option. A DIE is an unpackaged device that has been tested. DIEs are
used in low cost designs and designs where board space is at a minimum. Table 1-3 shows a
quick summary of this.
Table 1-3:
Typical Package Uses
Package Type
Typical Usage
Windowed
Plastic
DIE
Development Mode
Production
Special Applications, such as those which require minimum board space
 1997 Microchip Technology Inc.
DS31001A-page 1-9
Introduction
Depending on the development phase of your project, one of three package types would be used:
PICmicro MID-RANGE MCU FAMILY
1.5.3.4
UV Erasable Devices
The UV erasable version of EPROM program memory devices is optimal for prototype development and pilot programs.
These devices can be erased and reprogrammed to any of the configuration modes. Third party
programmers are also available; refer to Microchip’s Third Party Guide (DS00104) for a list of
sources.
The amount of time required to completely erase a UV erasable device depends on: the wavelength of the light, its intensity, distance from UV source, the process technology of the device
(how small are the memory cells).
Note:
1.5.3.5
Fluorescent lights and sunlight both emit ultraviolet light at the erasure wavelength.
Leaving a UV erasable device’s window uncovered could cause, over time, the
devices memory cells to become erased. The erasure time for a fluorescent light is
about three years, while sunlight requires only about one week. To prevent the memory cells from losing data, an opaque label should be placed over the erasure window.
One-Time-Programmable (OTP) Devices
The availability of OTP devices is especially useful for customers expecting code changes and
updates.
OTP devices, packaged in plastic packages, permit the user to program them once. In addition
to the program and data EPROM memories, the configuration bits must be programmed.
1.5.3.6
Flash Devices
A Flash device allows its memory to be changed by an electric charge. This means that the system can be designed so that programming may be performed in-circuit. Since no window is
required, the lower cost plastic packages can used for these devices.
1.5.3.7
EEPROM Devices
An EEPROM device allows its memory to be erased by an electric charge. This means that the
system can be designed so that erasure and reprogramming may be performed in-circuit. Since
no window is required, the lower cost plastic packages can used for these devices.
DS31001A-page 1-10
 1997 Microchip Technology Inc.
Section 1. Introduction
1.5.3.8
1
ROM Devices
1.5.3.9
DIE
The DIE option allows the board size to become as small as physically possible. The DIE Support
document (DS30258) explains general information about using and designing with DIE. There
are also individual specification sheets that detail DIE specific information. Manufacturing with
DIE requires special knowledge and equipment. This means that the number of manufacturing
houses that support DIE will be limited. If you decide to use the DIE option, please research your
manufacturing sites to ensure that they will be able to meet the specialized requirements of DIE
use.
1.5.3.10
Specialized Services
For OTP customers with established code, Microchip offers two specialized services. These two
services, Quick Turn Production Programming and Serialized Quick Turn Production Programming, that allow customers to shorten their manufacturing cycle time.
1.5.3.11
Quick Turn Production (QTP) Programming
Microchip offers this programming service for factory production orders. This service is made
available for users who choose not to program a medium to high quantity of units and whose code
patterns have stabilized. The devices are identical to the OTP devices but with all EPROM locations and configuration options already programmed by the factory. Certain code and prototype
verification procedures apply before production shipments are available. Please contact your
local Microchip sales office for more details.
1.5.3.12
Serialized Quick Turn Production (SQTPSM) Programming
Microchip offers a this unique programming service where a few user-defined locations in each
device are programmed with different serial numbers. The serial numbers may be random,
pseudo-random or sequential.
Serial programming allows each device to have a unique number which can serve as an
entry-code, password or ID number.
 1997 Microchip Technology Inc.
DS31001A-page 1-11
Introduction
ROM devices have their program memory fixed at the time of the silicon manufacture. Since the
program memory cannot be changed, the device can be housed in the lower cost plastic package.
PICmicro MID-RANGE MCU FAMILY
1.6
Style and Symbol Conventions
Throughout this document, certain style and font format changes are used. Most format changes
imply a distinction should be made for the emphasized text. The MCU industry has many symbols
and non-conventional word definitions/abbreviations. Table 1-4 provides a description for many
of the conventions contained in this document. A glossary is provided in the “Glossary” section,
which contains more word and abbreviation definitions that are used throughout this manual.
1.6.1
Document Conventions
Table 1-4 defines some of the symbols and terms used throughout this manual.
Table 1-4:
Document Conventions
Symbol or Term
Description
set
clear
reset
To force a bit/register to a value of logic ‘1’.
To force a bit/register to a value of logic ‘0’.
1) To force a register/bit to its default state.
2) A condition in which the device places itself after a device reset
occurs. Some bits will be forced to ‘0’ (such as interrupt enable bits),
while others will be forced to ‘1’ (such as the I/O data direction bits).
0xnn or nnh
Designates the number ‘nn’ in the hexadecimal number system. These
conventions are used in the code examples.
B’bbbbbbbb’
Designates the number ‘bbbbbbbb’ in the binary number system. This
convention is used in the text and in figures and tables.
R-M-W
Read - Modify - Write. This is when a register or port is read, then the
value is modified, and that value is then written back to the register or
port. This action can occur from a single instruction (such as bit set file,
BSF) or a sequence of instructions.
: (colon)
Used to specify a range, or the concatenation of registers / bits / pins.
An example is TMR1H:TMR1L is the concatenation of two 8-bit registers
to form a 16-bit timer value, while SSPM3:SSPM0 are 4-bits used to
specify the mode of the SSP module. Concatenation order (left-right)
usually specifies a positional relationship (MSb to LSb, higher to lower).
<>
Specifies bit(s) locations in a particular register.
An example is SSPCON<SSPM3:SSPM0> (or SSPCON<3:0>) specifies
the register and associated bits or bit positions.
Courier Font
Used for code examples, binary numbers, and for Instruction Mnemonics
in the text.
Times Font
Used for equations and variables.
Times, Bold Font,
Used in explanatory text for items called out from a graphic/equaItalics
tion/example.
Note
Notes present information that we wish to reemphasize, either to help
you avoid a common pitfall, or make you aware of operating differences
between some device family members. A Note is always in a shaded box
(as below), unless used in a table, where it is at the bottom of the table
(as in this table).
Note: This is a note in a note box.
Caution(1)
A caution statement describes a situation that could potentially damage
software or equipment.
Warning(1)
A warning statement describes a situation that could potentially cause
personnel harm.
Note 1: The information in a caution or a warning is provided for your protection. Please read
each caution and warning carefully.
DS31001A-page 1-12
 1997 Microchip Technology Inc.
Section 1. Introduction
1.6.2
1
Electrical Specifications
The “Electrical Specifications” section shows all the specifications that are documented for all
devices. No one device has all these specifications. This section is intended to let you know the
types of parameters that Microchip specifies. The value of each specification is device dependent, though we strongly attempt to keep them consistent across all devices.
Table 1-5:
Electrical Specification Parameter Numbering Convention
Parameter
Number
Format
Comment
Dxxx
DC Specification
Axxx
DC Specification for Analog peripherals
xxx
Timing (AC) Specification
PDxxx
Device Programming DC Specification
Pxxx
Device Programming Timing (AC) Specification
Legend: xxx: represents a number.
 1997 Microchip Technology Inc.
DS31001A-page 1-13
Introduction
Throughout this manual there will be references to electrical specification parameter numbers. A
parameter number represents a unique set of characteristics and conditions that is consistent
between every data sheet, though the actual parameter value may vary from device to device.
PICmicro MID-RANGE MCU FAMILY
1.7
Related Documents
Microchip, as well as other sources, offers additional documentation which can aid in your development with PICmicro MCUs. These lists contain the most common documentation but other
documents may also be available. Please check the Microchip web site (www.microchip.com) for
the latest published technical documentation.
1.7.1
Microchip Documentation
The following documents are available from Microchip. Many of these documents provide application specific information that give actual examples of using, programming and designing with
PICmicro MCUs.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
DS31001A-page 1-14
MPASM User’s Guide (DS33014)
This document explains how to use Microchip’s MPASM assembler.
MPLAB™-C Compiler User’s Guide (DS51014)
This document explains how to use Microchip’s MPLAB-C C compiler.
MPLAB User’s Guide (DS51025)
This document explains how to use Microchip’s MPLAB Integrated Development Environment.
MPLAB Editor User’s Guide (DS30420)
This document explains how to use Microchip’s MPLAB built-in editor.
PICMASTER® User’s Guide (DS30421)
This document explains how to use Microchip’s PICMASTER In-Circuit Emulator.
MPSIM User’s Guide (DS30027)
This document explains how to use Microchip’s MPLAB Simulator.
PRO MATE® User’s Guide (DS30082)
This document explains how to use Microchip’s PRO MATE universal programmer.
PICSTART®-Plus User’s Guide (DS51028)
This document explains how to use Microchip’s PICSTART-Plus low-cost universal programmer.
fuzzyTECH®-MP User’s Guide (DS30389)
This document explains how to use the fuzzyTECH-MP fuzzy logic code generator.
MP-DriveWay™ User’s Guide (DS51027)
This document explains how to use the MP-DriveWay code generator.
fuzzyTECH-MP Fuzzy Logic Handbook (DS30238)
This document explains the basics of fuzzyTECH-MP fuzzy.
Embedded Control Handbook Volume I (DS00092)
This document contains a plethora of application notes. This is useful for insight on how
to use the device (or parts of it) as well as getting started on your particular application
due to the availability of extensive code files.
Embedded Control Handbook Volume II (DS00167)
This document contains the Math Libraries for PICmicro MCUs.
In-Circuit Serial Programming Guide™ (DS30277)
This document discusses implementing In-Circuit Serial Programming.
PICDEM-1 User’s Guide (DS351079)
This document explains how to use Microchip’s PICDEM-1 demo board.
PICDEM-2 User’s Guide (DS30374)
This document explains how to use Microchip’s PICDEM-2 demo board.
PICDEM-3 User’s Guide (DS33015)
This document explains how to use Microchip’s PICDEM-3 demo board.
Third Party Guide (DS00104)
This document lists Microchip’s third parties, as well as various consultants.
DIE Support (DS30258)
This document gives information on using Microchip products in DIE form.
 1997 Microchip Technology Inc.
Section 1. Introduction
1.7.2
1
Third Party Documentation
DOCUMENT
LANGUAGE
The PIC16C5X Microcontroller: A Practical Approach to
Embedded Control
Bill Rigby/ Terry Dalby, Tecksystems Inc.
0-9654740-0-3............................................................................................................ English
Easy PIC'n
David Benson, Square 1 Electronics
0-9654162-0-8............................................................................................................ English
A Beginners Guide to the Microchip PIC®
Nigel Gardner, Bluebird Electronics
1-899013-01-6............................................................................................................ English
PIC Microcontroller Operation and Applications
DN de Beer, Cape Technikon ..................................................................................... English
Digital Systems and Programmable Interface Controllers
WP Verburg, Pretoria Technikon ................................................................................ English
Mikroprozessor PIC16C5X
Michael Rose, Hüthig
3-7785-2169-1...........................................................................................................German
Mikroprozessor PIC17C42
Michael Rose, Hüthig
3-7785-2170-5...........................................................................................................German
Les Microcontrolleurs PIC et mise en oeuvre
Christian Tavernier, Dunod
2-10-002647-X ............................................................................................................French
Micontrolleurs PIC a structure RISC
C.F. Urbain, Publitronic
2-86661-058-X ............................................................................................................French
New Possibilities with the Microchip PIC
RIGA ......................................................................................................................... Russian
 1997 Microchip Technology Inc.
DS31001A-page 1-15
Introduction
There are several documents available from third party sources around the world. Microchip
does not review these documents for technical accuracy, however they may be a helpful source
for understanding the operation of Microchip MCU devices. This is not necessarily a complete
list, but are the documents that we were aware of at the time of printing. For more information on
how to contact some of these sources, as well as any new sources that we become aware of,
please visit the Microchip web site.
PICmicro MID-RANGE MCU FAMILY
DOCUMENT
LANGUAGE
PIC16C5X/71/84 Development and Design, Part 1
United Tech Electronic Co. Ltd
957-21-0807-7.......................................................................................................... Chinese
PIC16C5X/71/84 Development and Design, Part 2
United Tech Electronic Co. Ltd
957-21-1152-3.......................................................................................................... Chinese
PIC16C5X/71/84 Development and Design, Part 3
United Tech Electronic Co. Ltd
957-21-1187-6.......................................................................................................... Chinese
PIC16C5X/71/84 Development and Design, Part 4
United Tech Electronic Co. Ltd
957-21-1251-1.......................................................................................................... Chinese
PIC16C5X/71/84 Development and Design, Part 5
United Tech Electronic Co. Ltd
957-21-1257-0.......................................................................................................... Chinese
PIC16C84 MCU Architecture and Software Development
ICC Company
957-8716-79-6.......................................................................................................... Chinese
DS31001A-page 1-16
 1997 Microchip Technology Inc.
Section 1. Introduction
1.8
1
Related Application Notes
Title
Application Note #
A Comparison of Low End 8-bit Microcontrollers
AN520
PIC16C54A EMI Results
AN577
Continuous Improvement
AN503
Improving the Susceptibility of an Application to ESD
AN595
Plastic Packaging and the Effects of Surface Mount Soldering Techniques
AN598
 1997 Microchip Technology Inc.
DS31001A-page 1-17
Introduction
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the PIC16CXXX Mid-Range MCU family (that is they
may be written for the Base-Line, or the High-End families), but the concepts are pertinent, and
could be used (with modification and possible limitations). The current application notes related
to an introduction to Microchip’s PICmicro MCUs are:
PICmicro MID-RANGE MCU FAMILY
1.9
Revision History
Revision A
This is the initial released revision of Microchip’s PICmicro MCUs Introduction.
DS31001A-page 1-18
 1997 Microchip Technology Inc.
M
Section 2. Oscillator
HIGHLIGHTS
This section of the manual contains the following major topics:
Introduction ....................................................................................................................2-2
Oscillator Configurations ................................................................................................2-2
Crystal Oscillators / Ceramic Resonators ......................................................................2-4
External RC Oscillator..................................................................................................2-12
Internal 4 MHz RC Oscillator .......................................................................................2-13
Effects of Sleep Mode on the On-chip Oscillator .........................................................2-17
Effects of Device Reset on the On-chip Oscillator .......................................................2-17
Design Tips ..................................................................................................................2-18
Related Application Notes............................................................................................2-19
Revision History ...........................................................................................................2-20
 1997 Microchip Technology Inc.
DS31002A page 2-1
Oscillator
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
2.10
2
PICmicro MID-RANGE MCU FAMILY
2.1
Introduction
The internal oscillator circuit is used to generate the device clock. The device clock is required
for the device to execute instructions and for the peripherals to function. Four device clock periods generate one internal instruction clock (TCY) cycle.
There are up to eight different modes which the oscillator may have. There are two modes which
allow the selection of the internal RC oscillator clock out (CLKOUT) to be driven on an I/O pin, or
allow that I/O pin to be used for a general purpose function. The oscillator mode is selected by
the device configuration bits. The device configuration bits are nonvolatile memory locations and
the operating mode is determined by the value written during device programming. The oscillator
modes are:
•
•
•
•
•
•
•
•
LP
XT
HS
RC
EXTRC
EXTRC
INTRC
INTRC
Low Frequency (Power) Crystal
Crystal/Resonator
High Speed Crystal/Resonator
External Resistor/Capacitor (same as EXTRC with CLKOUT)
External Resistor/Capacitor
External Resistor/Capacitor with CLKOUT
Internal 4 MHz Resistor/Capacitor
Internal 4 MHz Resistor/Capacitor with CLKOUT
These oscillator options are made available to allow a single device type the flexibility to fit applications with different oscillator requirements. The RC oscillator option saves system cost while
the LP crystal option saves power. Configuration bits are used to select the various options. For
more details on the device configuration bits, see the “Device Characteristics” section.
2.2
Oscillator Configurations
2.2.1
Oscillator Types
Mid-Range devices can have up to eight different oscillator modes. The user can program up to
three device configuration bits (FOSC2, FOSC1 and FOSC0) to select one of these eight modes:
•
•
•
•
•
•
•
•
LP
XT
HS
RC
EXTRC
EXTRC
INTRC
INTRC
Low Frequency (Power) Crystal
Crystal/Resonator
High Speed Crystal/Resonator
External Resistor/Capacitor (same as EXTRC with CLKOUT)
External Resistor/Capacitor
External Resistor/Capacitor with CLKOUT
Internal 4 MHz Resistor/Capacitor
Internal 4 MHz Resistor/Capacitor with CLKOUT
The main difference between the LP, XT, and HS modes is the gain of the internal inverter of the
oscillator circuit which allows the different frequency ranges. Table 2-1 and Table 2-2 give information to aid in selecting an oscillator mode. In general, use the oscillator option with the lowest
possible gain which still meet specifications. This will result in lower dynamic currents (IDD). The
frequency range of each oscillator mode is the recommended (tested) frequency cutoffs, but the
selection of a different gain mode is acceptable as long as a thorough validation is performed
(voltage, temperature, component variations (Resistor, Capacitor, and internal microcontroller
oscillator circuitry)).
The RC mode and the EXTRC with CLKOUT mode have the same functionality. They are named
like this to help describe their operation vs. the other oscillator modes.
DS31002A-page 2-2
 1997 Microchip Technology Inc.
Section 2. Oscillator
Table 2-1:
Selecting the Oscillator Mode for Devices with FOSC1:FOSC0
Configuration bits OSC
FOSC1:FOSC0
Mode
RC
1 0
HS
0 1
XT
0 0
LP
Table 2-2:
1 1 0
1 0 1
1 0 0
0 1 1
0 1 0
0 0 1
0 0 0
 1997 Microchip Technology Inc.
—
Least expensive solution for device oscillation
(only an external resistor and capacitor is
required). Most variation in time-base.
Device’s default mode.
High Gain
High frequency application.
Oscillator circuit’s mode consumes the most
current of the three crystal modes.
Medium Gain Standard crystal/resonator frequency.
Oscillator circuit’s mode consumes the middle
current of the three crystal modes.
Low Gain
Low power/frequency applications.
Oscillator circuit’s mode consumes the least
current of the three crystal modes.
Selecting the Oscillator Mode for Devices with FOSC2:FOSC0
Configuration
bits
FOSC2:FOSC0
1 1 1
Comment
OSC
Mode
EXTRC
with
CLKOUT
EXTRC
OSC
Feedback
Inverter
Gain
Comment
—
Inexpensive solution for device oscillation. Most
variation in timebase. CLKOUT is enabled on
pin. Device’s default mode.
—
Inexpensive solution for device oscillation. Most
variation in timebase.
CLKOUT is disabled (use as I/O) on pin.
INTRC
—
Least expensive solution for device oscillation.
with
4 MHz oscillator, which can be tuned.
CLKOUT
CLKOUT is enabled on pin.
INTRC
—
Least expensive solution for device oscillation.
4 MHz oscillator, which can be tuned.
CLKOUT is disabled (use as I/O) on pin.
—
—
Reserved
HS
High Gain High frequency application.
Oscillator circuit’s mode consumes the most
current of the three crystal modes.
XT
Medium Gain Standard crystal/resonator frequency.
Oscillator circuit’s mode consumes the middle
current of the three crystal modes.
LP
Low Gain
Low power/frequency applications.
Oscillator circuit’s mode consumes the least
current of the three crystal modes.
DS31002A-page 2-3
2
Oscillator
1 1
OSC
Feedback
Inverter
Gain
PICmicro MID-RANGE MCU FAMILY
2.3
Crystal Oscillators / Ceramic Resonators
In XT, LP or HS modes a crystal or ceramic resonator is connected to the OSC1 and OSC2 pins
to establish oscillation (Figure 2-1). The PICmicro oscillator design requires the use of a parallel
cut crystal. Using a series cut crystal may give a frequency out of the crystal manufacturer’s
specifications. When in XT, LP or HS modes, the device can have an external clock source drive
the OSC1 pin (Figure 2-3).
Figure 2-1: Crystal or Ceramic Resonator Operation (HS, XT or LP Oscillator Mode)
OSC1
C1
To internal logic
XTAL
RF (2)
(3)
SLEEP
OSC2
Rs (1)
C2
To internal logic (3)
PIC16CXXX
Note 1: A series resistor, RS, may be required for AT strip cut crystals.
2: The feedback resistor, RF, is typically in the range of 2 to 10 MΩ.
3: Depending on the device, the buffer to the internal logic may be
either before or after the oscillator inverter.
DS31002A-page 2-4
 1997 Microchip Technology Inc.
Section 2. Oscillator
2.3.1
Oscillator / Resonator Start-up
As the device voltage increases from VSS, the oscillator will start its oscillations. The time
required for the oscillator to start oscillating depends on many factors. These include:
•
•
•
•
•
•
•
•
•
Crystal / resonator frequency
Capacitor values used (C1 and C2 in Figure 2-1)
Device VDD rise time
System temperature
Series resistor value (and type) if used (Rs in Figure 2-1)
Oscillator mode selection of device (which selects the gain of the internal oscillator inverter)
Crystal quality
Oscillator circuit layout
System noise
Figure 2-2: Example Oscillator / Resonator Start-up Characteristics
Maximum VDD of System
Device VDD
Voltage
0V
Crystal Start-up Time
 1997 Microchip Technology Inc.
Time
DS31002A-page 2-5
2
Oscillator
Figure 2-2 graphs an example oscillator / resonator start-up. The peak-to-peak voltage of the
oscillator waveform can be quite low (less than 50% of device VDD) where the waveform is centered at VDD/2 (refer to parameters D033 and D043 in the “Electrical Specifications” section).
PICmicro MID-RANGE MCU FAMILY
2.3.2
Component Selection
Figure 2-1 is a diagram of the devices crystal or ceramic resonator circuitry. The resistance for
the feedback resistor, RF, is typically within the 2 to 10 MΩ range. This varies with device voltage,
temperature, and process variations. A series resistor, Rs, may be required if an AT strip cut crystal is used. Be sure to include the device’s operating voltage and the device’s manufacturing process when determining resistor requirements. As you can see in Figure 2-1, the connection to
the device’s internal logic is device dependent. See the applicable data sheet for device specifics.
The typical values of capacitors (C1, C2) are given in Table 2-3 and Table 2-4. Each device’s data
sheet will give the specific values that Microchip tested.
Table 2-3:
Typical Capacitor Selection for Ceramic Resonators
Ranges tested:
Mode
Frequency
C1 / C2(1)
XT
455 kHz
2.0 MHz
4.0 MHz
8.0 MHz
16.0 MHz
20.0 MHz
22 - 100 pF
15 - 68 pF
15 - 68 pF
10 - 68 pF
10 - 22 pF
TBD
HS
Resonators used:
455 kHz
Panasonic EFO-A455K04B
±0.3%
2.0 MHz
Murata Erie CSA2.00MG
±0.5%
4.0 MHz
Murata Erie CSA4.00MG
±0.5%
8.0 MHz
Murata Erie CSA8.00MT
±0.5%
16.0 MHz
Murata Erie CSA16.00MX
±0.5%
20.0 MHz
TBD
TBD
Note 1: Recommended values of C1 and C2 are identical to the ranges tested above.
Higher capacitance increases the stability of the oscillator but also increases the
start-up time. These values are for design guidance only. Since each resonator has
its own characteristics, the user should consult the resonator manufacturer for appropriate values of external component or verify oscillator performance.
2: All resonators tested required external capacitors.
DS31002A-page 2-6
 1997 Microchip Technology Inc.
Section 2. Oscillator
Table 2-4:
Typical Capacitor Selection for Crystal Oscillator
Mode
Freq
C1(1)
C2(1)
LP
32 kHz
200 kHz
100 kHz
2 MHz
4 MHz
8 MHz
10 MHz
20 MHz
68 - 100 pF
15 - 30 pF
68 - 150 pF
15 - 30 pF
15 - 30 pF
15 - 30 pF
15 - 30 pF
15 - 30 pF
68 - 100 pF
15 - 30 pF
150 - 200 pF
15 - 30 pF
15 - 30 pF
15 - 30 pF
15 - 30 pF
15 - 30 pF
XT
HS
2
Crystals used:
 1997 Microchip Technology Inc.
DS31002A-page 2-7
Oscillator
32.768 kHz
Epson C-001R32.768K-A
± 20 PPM
100 kHz
Epson C-2 100.00 KC-P
± 20 PPM
200 kHz
STD XTL 200.000 kHz
± 20 PPM
2.0 MHz
ECS ECS-20-S-2
± 50 PPM
4.0 MHz
ECS ECS-40-S-4
± 50 PPM
10.0 MHz
ECS ECS-100-S-4
± 50 PPM
20.0 MHz
ECS ECS-200-S-4
± 50 PPM
Note 1: Higher capacitance increases the stability of the oscillator but also increases the
start-up time. These values are for design guidance only. A series resistor, Rs, may
be required in HS mode as well as XT mode to avoid overdriving crystals with low
drive level specification. Since each crystal has its own characteristics, the user
should consult the crystal manufacturer for appropriate values of external components or verify oscillator performance.
PICmicro MID-RANGE MCU FAMILY
2.3.3
Tuning the Oscillator Circuit
Since Microchip devices have wide operating ranges (frequency, voltage, and temperature;
depending on the part and version ordered) and external components (crystals, capacitors,...),
of varying quality and manufacture; validation of operation needs to be performed to ensure that
the component selection will comply with the requirements of the application.
There are many factors that go into the selection and arrangement of these external components.
These factors include:
•
•
•
•
•
•
•
•
•
•
•
•
DS31002A-page 2-8
amplifier gain
desired frequency
resonant frequency(s) of the crystal
temperature of operation
supply voltage range
start-up time
stability
crystal life
power consumption
simplification of the circuit
use of standard components
combination which results in fewest components
 1997 Microchip Technology Inc.
Section 2. Oscillator
2.3.3.1
Determining Best Values for Crystals, Clock Mode, C1, C2, and Rs
The best method for selecting components is to apply a little knowledge and a lot of trial, measurement, and testing.
Crystals are usually selected by their parallel resonant frequency only, however other parameters may be important to your design, such as temperature or frequency tolerance. Application
Note AN588 is an excellent reference if you would like to know more about crystal operation and
their ordering information.
The PICmicros™ internal oscillator circuit is a parallel oscillator circuit, which requires that a parallel resonant crystal be selected. The load capacitance is usually specified in the 20 pF to 32 pF
range. The crystal will oscillate closest to the desired frequency with capacitance in this range. It
may be necessary to sometimes juggle these values a bit, as described later, in order to achieve
other benefits.
C1 and C2 should also be initially selected based on the load capacitance as suggested by the
crystal manufacturer and the tables supplied in the device data sheet. The values given in the
Microchip data sheet can only be used as a starting point, since the crystal manufacturer, supply
voltage, and other factors already mentioned may cause your circuit to differ from the one used
in the factory characterization process.
Ideally, the capacitance is chosen (within the range of the recommended crystal load preferably)
so that it will oscillate at the highest temperature and lowest VDD that the circuit will be expected
to perform under. High temperature and low VDD both have a limiting affect on the loop gain, such
that if the circuit functions at these extremes, the designer can be more assured of proper operation at other temperatures and supply voltage combinations. The output sine wave should not
be clipped in the highest gain environment (highest VDD and lowest temperature) and the sine
output amplitude should be great enough in the lowest gain environment (lowest VDD and highest
temperature) to cover the logic input requirements of the clock as listed in the device data sheet.
A method for improving start-up is to use a value of C2 greater than C1. This causes a greater
phase shift across the crystal at power-up, which speeds oscillator start-up.
Besides loading the crystal for proper frequency response, these capacitors can have the effect
of lowering loop gain if their value is increased. C2 can be selected to affect the overall gain of
the circuit. A higher C2 can lower the gain if the crystal is being over driven (see also discussion
on Rs). Capacitance values that are too high can store and dump too much current through the
crystal, so C1 and C2 should not become excessively large. Unfortunately, measuring the wattage through a crystal is tricky business, but if you do not stray too far from the suggested values
you should not have to be concerned with this.
A series resistor, Rs, is added to the circuit if, after all other external components are selected to
satisfaction, the crystal is still being over driven. This can be determined by looking at the OSC2
pin, which is the driven pin, with an oscilloscope. Connecting the probe to the OSC1 pin will load
the pin too much and negatively affect performance. Remember that a scope probe adds its own
capacitance to the circuit, so this may have to be accounted for in your design, i.e. if the circuit
worked best with a C2 of 20 pF and scope probe was 10 pF, a 30 pF capacitor may actually be
called for. The output signal should not be clipping or squashed. Overdriving the crystal can also
lead to the circuit jumping to a higher harmonic level or even crystal damage.
 1997 Microchip Technology Inc.
DS31002A-page 2-9
Oscillator
Clock mode is primarily chosen by using the FOSC parameter specification (parameter 1A) in the
device’s data sheet, based on frequency. Clock modes (except RC) are simply gain selections,
lower gain for lower frequencies, higher gain for higher frequencies. It is possible to select a
higher or lower gain, if desired, based on the specific needs of the oscillator circuit.
2
PICmicro MID-RANGE MCU FAMILY
The OSC2 signal should be a nice clean sine wave that easily spans the input minimum and maximum of the clock input pin (4V to 5V peak to peak for a 5V VDD is usually good). An easy way
to set this is to again test the circuit at the minimum temperature and maximum VDD that the
design will be expected to perform in, then look at the output. This should be the maximum amplitude of the clock output. If there is clipping or the sine wave is squashing near VDD and VSS at
the top and bottom, and increasing load capacitors will risk too much current through the crystal
or push the value too far from the manufacturer’s load specification, then add a trimpot between
the output pin and C2, and adjust it until the sine wave is clean. Keeping it fairly close to maximum
amplitude at the low temperature and high VDD combination will assure this is the maximum
amplitude the crystal will see and prevent overdriving. A series resistor, Rs, of the closest standard value, can now be inserted in place of the trimpot. If Rs is too high, perhaps more than
20k ohms, the input will be too isolated from the output, making the clock more susceptible to
noise. If you find a value this high is needed to prevent overdriving the crystal, try increasing C2
to compensate. Try to get a combination where Rs is around 10k or less, and load capacitance
is not too far from the 20 pF or 32 pF manufacturer specification.
2.3.3.1.1
Start-up
The most difficult time for the oscillator to start-up is when waking up from sleep. This is because
the load capacitors have both partially charged to some quiescent value, and phase differential
at wake-up is minimal. Thus, more time is required to achieve stable oscillation. Remember also
that low voltage, high temperatures, and the lower frequency clock modes also impose limitations
on loop gain, which in turn affects start-up. Each of the following factors makes thing worse:
•
•
•
•
•
•
a low frequency design (with its low gain clock mode)
a quiet environment (such as a battery operated device)
operating outside the noisy RF area (such as in a shielded box)
low voltage
high temperature
waking up from sleep.
Noise actually helps a design for oscillator start-up, since it helps kick start the oscillator.
2.3.4
External Clock Input
If the PICmicro’s internal oscillator is not being used, and the device will be driven from an external clock, be sure to set the oscillator mode to one of the crystal modes (LP, XT, or HS). That is,
something other than one of the RC modes, since RC mode will fight with the injected input. Ideally you would select the mode that corresponds to the frequency injected, but this is of less
importance here since the clock is only driving its internal logic, and not a crystal loop circuit. It
may be possible to select a clock mode lower than would be needed by an oscillator circuit, and
thereby save some of the power that would be used exercising the inverting amplifier. Make sure
the OSC2 signal amplitude covers the needed logic thresholds of the device.
Figure 2-3: External Device Clock Input Operation (HS, XT or LP Oscillator Modes)
clock from
external system
OSC1
PIC16CXXX
(1)
Open
OSC2
Note 1: A resistor to ground may be used to reduce system noise.
This may increase system current.
DS31002A-page 2-10
 1997 Microchip Technology Inc.
Section 2. Oscillator
2.3.5
External Crystal Oscillator Circuit for Device Clock
Sometimes more than one device needs to be clocked from a single crystal. Since Microchip
does not recommend connecting other logic to the PICmicro’s internal oscillator circuit, an external crystal oscillator circuit is recommended. Each device will then have an external clock source,
and the number of devices that can be driven will depend on the buffer drive capability. This circuit
is also useful when more than one device (PICmicro) needs to operate synchronously to each
other.
Either a prepackaged oscillator can be used or a simple oscillator circuit with TTL gates can be
built. Prepackaged oscillators provide a wide operating range and better stability. A well-designed
crystal oscillator will provide good performance with TTL gates. Two types of crystal oscillator circuits can be used; one with series resonance, or one with parallel resonance.
Figure 2-4: External Parallel Resonant Crystal Oscillator Circuit
+5V
To Other
Devices
10kΩ
4.7 kΩ
74AS04
PIC16CXXX
CLKIN
74AS04
10 kΩ
XTAL
10 kΩ
20 pF
20 pF
Figure 2-5 shows an external series resonant oscillator circuit. This circuit is also designed to use
the fundamental frequency of the crystal. The inverter performs a 180-degree phase shift in a
series resonant oscillator circuit. The 330 kΩ resistors provide the negative feedback to bias the
inverters in their linear region.
Figure 2-5: External Series Resonant Crystal Oscillator Circuit
330 kΩ
330 kΩ
74AS04
74AS04
To Other
Devices
74AS04
PIC16CXXX
CLKIN
0.1 µF
XTAL
When the device is clocked from an external clock source (as in Figure 2-4 or Figure 2-5) then
the microcontroller’s oscillator must be configured for LP, XT or HS mode (Figure 2-3).
 1997 Microchip Technology Inc.
DS31002A-page 2-11
2
Oscillator
Figure 2-4 shows implementation of an external parallel resonant oscillator circuit. The circuit is
designed to use the fundamental frequency of the crystal. The 74AS04 inverter performs the
180-degree phase shift that a parallel oscillator requires. The 4.7 kΩ resistor provides the negative feedback for stability. The 10 kΩ potentiometer biases the 74AS04 in the linear region.
PICmicro MID-RANGE MCU FAMILY
2.4
External RC Oscillator
For timing insensitive applications the “EXTRC” device option offers additional cost savings. The
RC oscillator frequency is a function of; the supply voltage, the resistor (REXT) and capacitor
(CEXT) values, and the operating temperature. In addition to this, the oscillator frequency will vary
from unit to unit due to normal process parameter variation. Furthermore, the difference in lead
frame capacitance between package types will also affect the oscillation frequency, especially for
low CEXT values. The user also needs to take into account variation due to tolerance of external
REXT and CEXT components used. Figure 2-6 shows how the RC combination is connected to a
PIC16CXXX. For REXT values below 2.2 kΩ, oscillator operation may become unstable, or stop
completely. For very high REXT values (e.g. 1 MΩ), the oscillator becomes sensitive to noise,
humidity and leakage. Thus, we recommend keeping REXT between 3 kΩ and 100 kΩ.
Figure 2-6: EXTRC Oscillator Mode
V DD
REXT
OSC1
Fosc
CEXT
Internal
clock
PIC16CXXX
VSS
Fosc/4 (1)
OSC2/CLKOUT
Note 1: This output may also be able to be configured as a general purpose I/O pin.
Although the oscillator will operate with no external capacitor (CEXT = 0 pF), we recommend
using values above 20 pF for noise and stability reasons. With no or small external capacitance,
the oscillation frequency can vary dramatically due to changes in external capacitances, such as
PCB trace capacitance and package lead frame capacitance.
See characterization data for RC frequency variation from part to part due to normal process
variation. The variation is larger for larger resistance (since leakage current variation will affect
RC frequency more for large R) and for smaller capacitance (since variation of input capacitance
will affect RC frequency more).
See characterization data for variation of oscillator frequency due to VDD for given REXT/CEXT
values as well as frequency variation due to operating temperature for given REXT, CEXT, and
VDD values.
The oscillator frequency, divided by 4, is available on the OSC2/CLKOUT pin, and can be used
for test purposes or to synchronize other logic (see Figure 4-3: "Clock/Instruction Cycle" in
the “Architecture” section, for waveform).
2.4.1
RC Start-up
As the device voltage increases, the RC will start its oscillations immediately after the pin voltage
levels meet the input threshold specifications (parameters D032 and D042 in the “Electrical
Specifications” section). The time required for the RC to start oscillating depends on many factors. These include:
•
•
•
•
DS31002A-page 2-12
Resistor value used
Capacitor value used
Device VDD rise time
System temperature
 1997 Microchip Technology Inc.
Section 2. Oscillator
2.5
Internal 4 MHz RC Oscillator
The internal RC oscillator (not on all devices) provides a fixed 4 MHz (nominal) system clock at
VDD = 5V and 25°C, see the device data sheet’s “Electrical Specifications” section for information
on variation over voltage and temperature.
The value in the OSCCAL register is used to tune the frequency of the internal RC oscillator. The
calibration value that Microchip programs into the device will “trim” the internal oscillator to
remove process variation from the oscillator frequency. The CAL3:CAL0 bits are used for fine calibration within a frequency window. Higher values of CAL3:CAL0 (from 0000 to 1111) yields
higher clock speeds.
When a 4 MHz internal RC oscillator frequency cannot be achieved by a CAL3:CAL0 value, the
RC oscillator frequency can be increased or decreased by an offset frequency. The CALFST and
CALSLW bits are used to enable a positive or negative frequency offset to place the internal RC
frequency within the CAL3:CAL0 trim window.
Upon a device reset, the OSCCAL register is forced to the midpoint value (CAL3:CAL0 = 7h,
CALFST and CALSLW providing no offset).
Register 2-1: OSCCAL Register
R/W-0
CAL3
bit 7
bit 7:4
R/W-1
CAL2
R/W-1
CAL1
R/W-1
CAL0
R/W-0
CALFST
R/W-0
CALSLW
U-0
—
U-0
—
bit 0
CAL3:CAL0: Internal RC Oscillator Calibration bits
0000 = Lowest clock frequency within the trim range
•
•
•
1111 = Highest clock frequency within the trim range
bit 3
CALFST: Oscillator Range Offset bit
1 = Increases the frequency of the internal RC oscillator into the CAL3:CAL0 trim window
0 = No offset provided
bit 2
CALSLW: Oscillator Range Offset bit
1 = Decreases the frequency of the internal RC oscillator into the CAL3:CAL0 trim window
0 = No offset provided
Note:
bit 1:0
When both bits are set, the CALFST bit overrides the CALSLW bit.
Unimplemented: Read as '0'
Note:
These bits should be written as ‘0’ when modifying the OSCCAL register, for compatibility with future devices.
Legend
R = Readable bit
W = Writable bit
U = Unimplemented bit, read as ‘0’
Note:
 1997 Microchip Technology Inc.
- n = Value at POR reset
OSCCAL is used to remove process variation from the internal RC oscillator of the
device. The OSCCAL value should not be modified from the Microchip supplied
value, and all timing critical functions should be adjusted by the application software.
DS31002A-page 2-13
Oscillator
Setting the CALFST bit offsets the internal RC for a higher frequency, while setting the CALSLW
bit offsets the internal RC for a lower frequency.
2
PICmicro MID-RANGE MCU FAMILY
Figure 2-7 shows the possible device frequencies from the uncalibrated point (at VDD = 5V, 25°C,
and OSCCAL = 70h), and the changes achievable by the OSCCAL register.
Figure 2-7: Ideal Internal RC Oscillator Frequency vs. OSCCAL Register Value
CAL3:CAL0
Trim Window
Frequency
4 MHz
See X-axis
CAL3:CAL0 = 07h
CALFST = 0
CALSLW = 0
CAL3:CAL0 = 0h
CALFST = 0
CALSLW = 1
CAL3:CAL0 = 0h
CALFST = 0
CALSLW = 0
CAL3:CAL0 = Fh
CALFST = 0
CALSLW = 0
(slowest frequency)
CAL3:CAL0 = Fh
CALFST = 1
CALSLW = x
(fastest frequency)
Figure 2-8 shows an example of a device where by selecting one of the CAL3:CAL0 values, the
frequency can corrected to 4 MHz. These bits can be considered the fine trimming of the
frequency. Sometimes the device frequency at the uncalibrated point cannot be corrected to 4
MHz by the fine trimming of the CAL3:CAL0 bits value. Therefore two additional bits are available
which give a large frequency offset (positive and negative) to move the frequency within the
range where the fine trimming can work. These bits are the CALSLW and CALFST bits, which
offset the internal RC frequency. The action of these bits are shown in Figure 2-9, and
Figure 2-10.
Figure 2-8: CAL3:CAL0 Trimming of Internal RC Oscillator Frequency Offset
CAL3:CAL0
Trim Window
Frequency
> 4 MHz
Internal RC
Frequency at
device reset
CALFST = 0
CALFLW = 0
CAL3:CAL0 = 7h
4 MHz ± 1.5%
(@ 5V, 25˚C)
< 4 MHz
CAL3:CAL0 = 0000
CAL3:CAL0 = 1111
One of the 16 possible calibration points
DS31002A-page 2-14
 1997 Microchip Technology Inc.
Section 2. Oscillator
Figure 2-9: CALFST Positive Internal RC Oscillator Frequency Offset
CAL3:CAL0
Trim Window
Internal RC
Frequency with
CALFST = 1
CALSLW = x
Frequency
4 MHz ± 1.5%
(@ 5V, 25˚C)
Internal RC
Frequency at
device reset
CALFST = 0
CALFLW = 0
et
offs
T
LFS
CA
2
< 4 MHz
CAL3:CAL0 = 1111
One of the 16 possible CAL3:CAL0 calibration points
Figure 2-10: CALSLW Negative Internal RC Oscillator Frequency Offset
CAL3:CAL0
Trim Window
Frequency
> 4 MHz
SLW
L
CA
o
t
ffse
Internal RC
Frequency at
device reset
CALSLW = 0
CALFST = 0
Internal RC
Frequency with
CALSLW = 1
CALFST = 0
4 MHz ± 1.5%
(@ 5V, 25˚C)
CAL3:CAL0 = 0000
CAL3:CAL0 = 1111
One of the 16 possible CAL3:CAL0 calibration points
 1997 Microchip Technology Inc.
DS31002A-page 2-15
Oscillator
CAL3:CAL0 = 0000
PICmicro MID-RANGE MCU FAMILY
A calibration instruction is programmed into the last address of the implemented program
memory. This instruction contains the calibration value for the internal RC oscillator. This value
is programmed as a RETLW XX instruction where XX is the calibration value. In order to retrieve
the calibration value, issue a CALL YY instruction where YY is the last location in the device’s user
accessible program memory. The calibration value is now loaded in the W register. The program
should then perform a MOVWF OSCCAL instruction to load the value into the internal RC oscillator
calibration register. Table 2-5 shows the location of the calibration value depending on the size
of the program memory.
Table 2-5:
Calibration Value Location
Program
Memory Size
(Words)
512
1K
2K
4K
8K
Calibration Value
Location
1FFh
3FFh
7FFh
FFFh
1FFFh
Note 1: Erasing the device (windowed devices) will also erase the factory programmed
calibration value for the internal oscillator.
Prior to erasing a windowed device, the internal oscillator calibration value must be
saved. It is a good idea to write this value on the package of the device to ensure
that the calibration value is not accidently lost.
This saved valued must be restored into program memory calibration location before
programming the device.
Note 2: OSCCAL<1:0> are unimplemented and should be written as ‘0’. This will help
ensure compatibility with future devices.
2.5.1
Clock Out
The internal RC oscillator can be configured to provide a clock out signal on the CLKOUT pin
when the configuration word address (2007h) is programmed with FOSC2, FOSC1, FOSC0
equal to ‘101’ for Internal RC or ‘111’ for External RC. CLKOUT, which is divided by 4, can be
used for test purposes or to synchronize other logic.
When the calibration value of the internal RC oscillator is accidently erased, the clock out feature
allows the user to determine what the calibration value should be. This is achieved by writing a
program which modifies (increments/decrements) the value of the OSCCAL register. When the
CLKOUT pin is at 4 MHz (± 1.5%) at 5V and 25˚C, the OSCCAL register has the correct calibration value. This value then needs to be written to a port or shifted out serially, so that the value
can be written down and programmed into the calibration location.
DS31002A-page 2-16
 1997 Microchip Technology Inc.
Section 2. Oscillator
2.6
Effects of Sleep Mode on the On-chip Oscillator
When the device executes a SLEEP instruction, the on-chip clocks and oscillator are turned off
and the device is held at the beginning of an instruction cycle (Q1 state). With the oscillator off,
the OSC1 and OSC2 signals will stop oscillating. Since all the transistor switching currents have
been removed, 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 user can wake from SLEEP through external reset, Watchdog Timer
Reset or through an interrupt.
Table 2-6:
OSC1 and OSC2 Pin States in Sleep Mode
OSC Mode
OSC1 Pin
OSC2 Pin
EXTRC
2.7
Effects of Device Reset on the On-chip Oscillator
Device resets have no effect on the on-chip crystal oscillator circuitry. The oscillator will continue
to operate as it does under normal execution. While in reset, the device logic is held at the Q1
state so that when the device exits reset, it is at the beginning of an instruction cycle.
The OSC2 pin, when used as the external clockout (EXTRC mode), will be held low during
reset, and as soon as the MCLR pin is at VIH (input high voltage), the RC will start to oscillate.
See Table 3-1, in the “Reset” section, for time-outs due to Sleep and MCLR reset.
2.7.1
Power-up Delays
There are two timers that offer necessary delays on power-up. One is the Oscillator Start-up
Timer, OST, intended to keep the chip in RESET until the crystal oscillator is stable. The other is
the Power-up Timer (PWRT), which provides a fixed delay of 72 ms (nominal) on power-up only
(POR and BOR). The PWRT is designed to keep the part in RESET while the power supply stabilizes. With these two timers on-chip, most applications need no external reset circuitry. For
additional information on reset operation, see the “Reset” section.
 1997 Microchip Technology Inc.
DS31002A-page 2-17
2
Oscillator
Floating, external resistor should At logic low
pull high
INTRC
N.A.
N.A.
LP, XT, and HS
Feedback inverter disabled, at
Feedback inverter disabled, at
quiescent voltage level
quiescent voltage level
See Table 3-1, in the “Reset” section, for time-outs due to Sleep and MCLR reset.
PICmicro MID-RANGE MCU FAMILY
2.8
Design Tips
Question 1:
When looking at the OSC2 pin after power-up with an oscilloscope, there is
no clock. What can cause this?
Answer 1:
1.
2.
3.
4.
Executing a SLEEP instruction with no source for wake-up (such as, WDT, MCLR, or an
Interrupt). Verify that the code does not put device to sleep without providing for wake-up.
If it is possible, try waking it up with a low pulse on MCLR. Powering up with MCLR held
low will also give the crystal oscillator more time to start-up, but the Program Counter will
not advance until the MCLR pin is high.
The wrong clock mode is selected for the desired frequency. For a blank device, the
default oscillator is EXTRC. Most parts come with the clock selected in the default RC
mode, which will not start oscillation with a crystal or resonator. Verify that the clock mode
has been programmed correctly.
The proper power-up sequence has not been followed. If a CMOS part is powered through
an I/O pin prior to power-up, bad things can happen (latch up, improper start-up etc.) It is
also possible for brown-out conditions, noisy power lines at start-up, and slow VDD rise
times to cause problems. Try powering up the device with nothing connected to the I/O,
and power-up with a known, good, fast-rise, power supply. It is not as much of a problem
as it may sound, but the possibility exists. Refer to the power-up information in the device
data sheet for considerations on brown-out and power-up sequences.
The C1 and C2 capacitors attached to the crystal have not been connected properly or are
not the correct values. Make sure all connections are correct. The device data sheet values for these components will almost always get the oscillator running, they just might not
be the optimal values for your design.
Question 2:
The PICmicro starts, but runs at a frequency much higher than the resonant
frequency of the crystal.
Answer 2:
The gain is too high for this oscillator circuit. Refer to subsection 2.3 “Crystal Oscillators /
Ceramic Resonators” to aid in the selection of C2 (may need to be higher) Rs (may be needed)
and clock mode (wrong mode may be selected). This is especially possible for low frequency
crystals, like the common 32.768 kHz.
Question 3:
The design runs fine, but the frequency is slightly off, what can be done to
adjust this?
Answer 3:
Changing the value of C1 has some affect on the oscillator frequency. If a SERIES resonant crystal is used, it will resonate at a different frequency than a PARALLEL resonant crystal of the same
frequency call-out.
Question 4:
The board works fine, then suddenly quits, or loses time.
Answer 4:
Other than the obvious software checks that should be done to investigate losing time, it is possible that the amplitude of the oscillator output is not high enough to reliably trigger the oscillator
input.
Question 5:
I’m using a device with the internal RC oscillator and I have accidently
erased the calibration value. What can I do?
Answer 5:
If the frequency of the device does not matter, you can continue to use the device.
If the frequency of the device does matter, you can purchase a new windowed device, or follow
the suggestion in subsection 2.5.1 “Clock Out.”
DS31002A-page 2-18
 1997 Microchip Technology Inc.
Section 2. Oscillator
2.9
Related Application Notes
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the Mid-Range MCU family (that is they may be written for the Base-Line, or High-End families), but the concepts are pertinent, and could be used
(with modification and possible limitations). The current application notes related to the oscillator
are:
Title
Application Note #
PIC16/17 Oscillator Design Guide
AN588
Low Power Design using PIC16/17
AN606
2
Oscillator
 1997 Microchip Technology Inc.
DS31002A-page 2-19
PICmicro MID-RANGE MCU FAMILY
2.10
Revision History
Revision A
This is the initial released revision of the PICmicro oscillators description.
DS31002A-page 2-20
 1997 Microchip Technology Inc.
M
Section 3. Reset
HIGHLIGHTS
This section of the manual contains the following major topics:
3.1
3.2
3.3
3.4
3.5
3.6
Introduction ....................................................................................................................3-2
Power-on Reset (POR), Power-up Timer (PWRT), Oscillator Start-up Timer (OST),
Brown-out Reset (BOR), and Parity Error Reset (PER).................................................3-4
Registers and Status Bit Values ...................................................................................3-10
Design Tips ..................................................................................................................3-16
Related Application Notes............................................................................................3-17
Revision History ...........................................................................................................3-18
3
Reset
 1997 Microchip Technology Inc.
DS31003A page 3-1
PICmicro MID-RANGE MCU FAMILY
3.1
Introduction
The reset logic is used to place the device into a known state. The source of the reset can be
determined by using the device status bits. The reset logic is designed with features that reduce
system cost and increase system reliability.
Devices differentiate between various kinds of reset:
a)
b)
c)
d)
e)
f)
Power-on Reset (POR)
MCLR reset during normal operation
MCLR reset during SLEEP
WDT reset during normal operation
Brown-out Reset (BOR)
Parity Error Reset (PER)
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” on Power-on Reset, MCLR, WDT
reset, Brown-out Reset, Parity Error Reset, and on MCLR reset during SLEEP.
The on-chip parity bits that can be used to verify the contents of program memory.
Most registers are not affected by a WDT wake-up, since this is viewed as the resumption of normal operation. Status bits TO, PD, POR, BOR, and PER are set or cleared differently in different
reset situations as indicated in Table 3-2. These bits are used in software to determine the nature
of the reset. See Table 3-4 for a full description of the reset states of all registers.
A simplified block diagram of the on-chip reset circuit is shown in Figure 3-1. This block diagram
is a superset of reset features. To determine the features that are available on a specific device,
please refer to the device’s Data Sheet.
Note:
While the PICmicro™ is in a reset state, the internal phase clock is held at Q1
(beginning of an instruction cycle).
All new devices will have a noise filter in the MCLR reset path to detect and ignore small pulses.
See parameter 30 in the “Electrical Specifications” section for pulse width specification.
DS31003A-page 3-2
 1997 Microchip Technology Inc.
Section 3. Reset
Figure 3-1: Simplified Block Diagram of a Super-set On-chip Reset Circuit
VDD
I/O Pull-up
Enable
Weak Pull-up (2)
MCLRE
(2)
MCLR / VPP Pin (3)
MCLRE
Program
Memory
Parity
MPEEN
WDT
Module
SLEEP
(2)
WDT Time-out
VDD rise
detect
Power-on Reset
VDD
Brown-out
Reset
BODEN
(2)
S
3
OST/PWRT
OST
Chip_Reset
10-bit Ripple-counter
On-chip(1)
RC OSC
Q
Reset
OSC1/
CLKIN
Pin
R
PWRT
10-bit Ripple-counter
Enable PWRT (4)
See Table 3-1 for time-out situations.
Enable OST
Note 1:
2:
3:
4:
This is a separate oscillator from the RC oscillator of the CLKIN pin or the INTRC oscillator.
Features in dashed boxes not available on all devices, see device’s Data Sheet.
In some devices, this pin may be configured as a general purpose Input.
The early PICmicro devices have the configuration bit defined as PWRTE = 1 is enabled, while all other
devices the configuration bit is defined as PWRTE = 0 is enabled.
 1997 Microchip Technology Inc.
DS31003A-page 3-3
PICmicro MID-RANGE MCU FAMILY
3.2
Power-on Reset (POR), Power-up Timer (PWRT),
Oscillator Start-up Timer (OST), Brown-out Reset (BOR), and Parity Error Reset (PER)
3.2.1
Power-on Reset (POR)
A Power-on Reset pulse is generated on-chip when VDD rise is detected. To take advantage of
the POR, just tie the MCLR pin directly (or through a resistor) to VDD as shown in Figure 3-2. This
will eliminate external RC components usually needed to create a Power-on Reset. A minimum
rise time for VDD is required. See parameter D003 and parameter D004 in the “Electrical Specifications” section for details.
Figure 3-2: Using On-Chip POR
VDD
VDD
R
(1)
MCLR
PIC16CXXX
Note:
The resistor is optional.
When the device exits the reset condition (begins normal operation), the device operating parameters (voltage, frequency, temperature, etc.) must be within their operating ranges, otherwise the
device will not function correctly. Ensure the delay is long enough to get all operating parameters
within specification.
Figure 3-3 shows a possible POR circuit for a slow power supply ramp up. The external Power-on
Reset circuit is only required if VDD power-up time is too slow. The diode, D, helps discharge the
capacitor quickly when VDD powers down.
Figure 3-3: External Power-on Reset Circuit (For Slow VDD Power-up)
VDD
VDD
VDD
D
R
MCLR
C
Note:
DS31003A-page 3-4
PIC16CXXX
R < 40 kΩ is recommended to ensure that the voltage drop across R does not
exceed 0.2V. A larger voltage drop will degrade VIH level on the MCLR/VPP pin.
 1997 Microchip Technology Inc.
Section 3. Reset
3.2.2
Power-up Timer (PWRT)
The Power-up Timer provides a nominal 72 ms delay on Power-on Reset (POR) or Brown-out
Reset (BOR), see parameter 33 in the “Electrical Specifications” section. The Power-up Timer
operates on a dedicated internal RC oscillator. The device is kept in reset as long as the PWRT
is active. The PWRT delay allows VDD to rise to an acceptable level. The power-up timer enable
configuration bit can enable/disable the Power-up Timer. The Power-up Timer should always be
enabled when Brown-out Reset is enabled. The polarity of the Power-up Timer configuration bit
is now PWRTE = 0 for enabled, while the initial definition of the bit was PWRTE = 1 for enabled.
Since all new devices will use the PWRTE = 0 for enabled, the text will describe the operation for
such devices. Please refer to the individual Data Sheet to ensure the correct polarity for this bit.
The power-up time delay will vary from device to device due to VDD, temperature, and process
variations. See DC parameters for details.
3.2.3
Oscillator Start-up Timer (OST)
The Oscillator Start-Up Timer (OST) provides a 1024 oscillator cycle delay (from OSC1 input)
after the PWRT delay is over. This ensures that the crystal oscillator or resonator has started and
is stable.
The OST time-out is invoked only for XT, LP and HS modes and only on Power-on Reset,
Brown-out Reset, or wake-up from SLEEP.
The OST counts the oscillator pulses on the OSC1/CLKIN pin. The counter only starts incrementing after the amplitude of the signal reaches the oscillator input thresholds. This delay allows the
crystal oscillator or resonator to stabilize before the device exits the OST delay. The length of the
time-out is a function of the crystal/resonator frequency.
Figure 3-4: Oscillator Start-up Time
POR or BOR Trip Point
VDD
MCLR
Oscillator
TOSC1
TOST
OST TIME_OUT
TDEADTIME
PWRT TIME_OUT
TPWRT
INTERNAL RESET
Tosc1
= time for the crystal oscillator to react to an oscillation level detectable by the
Oscillator Start-up Timer (OST).
TOST
= 1024TOSC.
 1997 Microchip Technology Inc.
DS31003A-page 3-5
3
Reset
Figure 3-4 shows the operation of the OST circuit in conjunction with the power-up timer. For low
frequency crystals this start-up time can become quite long. That is because the time it takes the
low frequency oscillator to start oscillating is longer than the power-up timer’s delay. So the time
from when the power-up timer times-out, to when the oscillator starts to oscillate is a dead time.
There is no minimum or maximum time for this dead time (TDEADTIME).
PICmicro MID-RANGE MCU FAMILY
3.2.4
Power-up Sequence
On power-up, the time-out sequence is as follows: First the internal POR is detected, then, if
enabled, the PWRT time-out is invoked. After the PWRT time-out is over, the OST is activated.
The total time-out will vary based on oscillator configuration and PWRTE bit status. For example,
in RC mode with the PWRTE bit set (PWRT disabled), there will be no time-out at all. Figure 3-5,
Figure 3-6 and Figure 3-7 depict time-out sequences.
Since the time-outs occur from the internal POR pulse, if MCLR is kept low long enough, the
time-outs will expire. Then bringing MCLR high will begin execution immediately (Figure 3-7).
This is useful for testing purposes or to synchronize more than one device operating in parallel.
If the device voltage is not within the electrical specifications by the end of a time-out, the
MCLR/VPP pin must be held low until the voltage is within the device specification. The use of an
external RC delay is sufficient for many of these applications.
Table 3-1 shows the time-outs that occur in various situations, while Figure 3-5 through
Figure 3-8 show four different cases that can happen on powering up the device.
Table 3-1:
Time-out in Various Situations
Oscillator
Configuration
Power-up Timer
Brown-out Reset
Wake-up
from
SLEEP
Enabled
Disabled
XT, HS, LP
72 ms + 1024TOSC
1024TOSC
72 ms + 1024TOSC
1024TOSC
RC
72 ms
— (1)
72 ms
— (1)
Note 1: Devices with the Internal/External RC option have a nominal 250 µs delay.
Figure 3-5: Time-out Sequence on Power-up (MCLR Tied to VDD)
VDD
MCLR
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
DS31003A-page 3-6
 1997 Microchip Technology Inc.
Section 3. Reset
Figure 3-6:
Time-out Sequence on Power-up (MCLR not Tied to VDD): Case 1
VDD
MCLR
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
Figure 3-7:
Time-out Sequence on Power-up (MCLR not Tied to VDD): Case 2
VDD
MCLR
3
INTERNAL POR
TPWRT
Reset
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
Figure 3-8:
Slow Rise Time (MCLR Tied to VDD)
5V
VDD
0V
MCLR
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
 1997 Microchip Technology Inc.
DS31003A-page 3-7
PICmicro MID-RANGE MCU FAMILY
3.2.5
Brown-out Reset (BOR)
On-chip Brown-out Reset circuitry places the device into reset when the device voltage falls
below a trip point (BVDD). This ensures that the device does not continue program execution outside the valid operation range of the device. Brown-out resets are typically used in AC line applications or large battery applications where large loads may be switched in (such as automotive),
and cause the device voltage to temporarily fall below the specified operating minimum.
Note:
Before using the on-chip brown-out for a voltage supervisory function (monitor battery decay), please review the electrical specifications to ensure that they meet your
requirements.
The BODEN configuration bit can disable (if clear/programmed) or enable (if set) the Brown-out
Reset circuitry. If VDD falls below BVDD (Typically 4.0V, parameter D005 in the “Electrical Specifications” section), for greater than parameter 35, the brown-out situation will reset the chip. A
reset is not guara