Note the following details of the code protection feature on Microchip devices:
•Microchip products meet the specification contained in their particular Microchip Data Sheet.
•Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•Microchip is willing to work with the customer who is concerned about the integrity of their code.
•Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digit al Millennium Copyright Act. If suc h a c t s
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is intended through suggestion only
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
No representation or warranty is given and no liability is
assumed by Microchip Technology Incorporated with respect
to the accuracy or use of such information, or infringement of
patents or other intellectual property rights arising from such
use or otherwise. Use of Microchip’s products as critical
components in life support systems is not authorized except
with express written approval by Microchip. No licenses are
conveyed, implicitly or otherwise, under any intellectual
property rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, K
EELOQ, microID, MPLAB, PIC, PICmicro, PICSTART,
PRO MATE, PowerSmart, rfPIC, and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, MXDEV, MXLAB, PICMASTER, SEEVAL,
SmartSensor and The Embedded Control Solutions Company
are registered trademarks of Microchip Technology
Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, dsPICDEM,
dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR,
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial
Programming, ICSP, ICEPIC, Migratable Memory, MPASM,
MPLIB, MPLINK, MPSIM, PICkit, PICDEM, PICDEM.net,
PICLAB, PICtail, PowerCal, PowerInfo, PowerMate,
PowerTool, rfLAB, rfPICDEM, Select Mode, Smart Serial,
SmartTel and Tot al Endurance are trademarks of Microchip
Technology Incorporated in the U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
Microchip received ISO/TS-16949:2002 quality system certification for
its worldwide headquarters, design and wafer fabrication facilities in
Chandler and Tempe, Arizona and Mountain View, California in
October 2003. The Company’s quality system processes and
procedures are for its PICmicro
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
®
8-bit MCUs, KEELOQ
®
code hopping
DS41202C-page iiPreliminary 2004 Microchip Technology Inc.
PIC16F684
14-Pin Flash-Based, 8-Bit CMOS Microcontrollers with nanoWatt Technology
High-Performance RISC CPU:
• Only 35 instructions to learn:
- All single-cycle instructions except branches
• Operating speed:
- DC – 20 MHz oscillator/clock input
- DC – 200 ns instruction cycle
• Interrupt capability
• 8-level deep hardware stack
• Direct, Indirect and Relative Addressing modes
Special Microcontroller Features:
• Precision Internal Oscillator:
- Factory calibrated to ±1%
- Software selectable frequency range of
8 MHz to 31 kHz
- Software tunable
- Two-speed Start-up mode
- Crystal fail detect for critical applications
- Clock mode switching during operation for
power savings
• Power-saving Sleep mode
• Wide operating voltage range (2.0V-5.5V)
• Industrial and Extended Temperature range
• Power-on Reset (POR)
• Power-up Timer (PWRT) and Oscillator Start-up
Timer (OST)
• Brown-out Detect (BOD) with software control
option
• Enhanced low-current Watchdog Timer (WDT)
with on-chip oscillator (software selectable
nominal 268 seconds with full prescaler) with
software enable
• Multiplexed Master Clear with pull-up/input pin
• Programmable code protection
• High Endurance Flash/EEPROM cell:
- 100,000 write Flash endurance
- 1,000,000 write EEPROM endurance
- Flash/Data EEPROM retention: > 40 years
Low-Power Features:
• Standby Current:
- 1 nA @ 2.0V, typical
• Operating Current:
-8.5µA @ 32 kHz, 2.0V, typical
-100µA @ 1 MHz, 2.0V , typical
• Watchdog Timer Current:
-1µA @ 2.0V, typical
Peripheral Features:
• 12 I/O pins with individual direction control:
- High current source/sink for direct LED drive
- Interrupt-on-pin change
- Individually programmable weak pull-ups
- Ultra Low-power Wake-up (ULPWU)
• Analog comparator module with:
- Two analog comparators
- Programmable on-chip voltage reference
(CVREF) module (% of VDD)
- Comparator inputs and outputs externally
accessible
• A/D Converter:
- 10-bit resolution and 8 channels
• Timer0: 8-bit timer/counter with 8-bit
programmable prescaler
• Enhanced Timer1:
- 16-bit timer/counter with prescaler
- External Gate Input mode
- Option to use OSC1 and OSC2 in LP mode
as Timer1 oscillator if INTOSC mode
selected
• Timer2: 8-bit timer/counter with 8-bit period
register, prescaler and postscaler
12.0 Special Features of the CPU........................................... ................. ................. ................. ....................................................... 91
13.0 Instruction Set Summary......................................................................................................................................................... 111
14.0 Development Support.............................................................................................................................................................. 121
16.0 DC and AC Characteristics Graphs and Tables........................................................................... ........................................... 147
Appendix A: Data Sheet Revision History......................................................................................................................................... 153
Appendix B: Migrating from other PICmicro® Devices ..................................................................................................................... 153
Index ................................................................................................................................................................................................. 155
Systems Information and Upgrade Hot Line..................................................................................................................................... 159
Product Identification System ........................................................................................................................................................... 161
TO OUR VALUED CUSTOMERS
It is our intention to provide our valued customers with the best documentation possible to ensure successful use of your Microchip
products. To this end, we will continue to improve our publications to better suit your needs. Our publications will be refined and
enhanced as new volumes and updates are introduced.
If you have any questions or c omm ents regarding t his publication, p lease c ontact the M arket ing Co mmunications Department via
E-mail at docerrors@mail.microchip.com or fax the Reader Response Form in the back of this data sheet to (480) 792-4150.
We welcome your feedback.
Most Current Data Sheet
To obtain the most up-to-date version of this data sheet, please register at our Worldwide Web site at:
http://www.microchip.com
You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page.
The last character of the literature number is the version number, (e.g., DS30000A is version A of document DS30000).
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current
devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision
of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Microchip’s Worldwide Web site; http://www.microchip.com
• Your local Microchip sales office (see last page)
• The Microchip Corporate Literature Center; U.S. FAX: (480) 792-7277
When contacting a sales office or the literature center, please specify which device, revision of silicon and data sheet (include
literature number) you are using.
Customer Notification System
Register on our web site at www.microchip.com/cn to receive the most current information on all of our products.
DS41202C-page 4Preliminary 2004 Microchip Technology Inc.
PIC16F684
1.0DEVICE OVERVIEW
This documen t conta i ns dev ic e spec if i c in for m at i on fo r
the PIC16F684. Addition al informa tion may b e found in
the “PICmicro® Mid-Range MCU Family Reference
Manual” (DS33023), which may be obtained from your
local Microchip Sales Representative or downloaded
from the Microchip web site.
FIGURE 1-1:PIC16F684 BLOCK DIAGRAM
INT
Program Counter
8-Level Stack128 Bytes
(13-Bit)
Addr
Direct
Power-up
Timer
Oscillator
Start-up Timer
Power-on
Reset
Watchdog
Timer
Brown-out
Detect
VDD
MCLR
VSS
OSC1/CLKIN
OSC2/CLKOUT
T1G
Program
Bus
Internal
Oscillator
Block
Configuration
Flash
2k X 14
Program
Memory
14
Instruction Reg
Instruction
Decode &
Control
Timing
Generation
13
8
The reference manual shou ld be cons ider ed a com plementary document to this data sheet and is highly
recommended reading for a better unders tanding of the
device architecture and operation of the peripheral
modules.
The PIC16F684 is covered by this data sheet. It is
available in 14-pin PDIP, SOIC and TSSOP packages.
Figure 1-1 shows a block diagram of the PIC16F684
device. Table 1-1 shows the pinout description.
RA0/AN0/C1IN+/ICSPDAT/ULPWURA0TTLCMOS PORTA I/O w/programmable pull-up and interrupt-on-change
AN0AN—A/D Channel 0 input
C1IN+AN—Comparator 1 input
ICSPDATTTLCMOS Serial Program ming Da ta I/O
ULPWUAN—Ultra Low-power Wake-up input
RA1/AN1/C1IN-/V
RA2/AN2/T0CKI/INT/C1OUTRA2STCMOS PORTA I/O w/programmable pull-up and interrupt-on-change
RA3/MCLR
RA4/AN3/T1G
RA5/T1CKI/OSC1/CLKINRA5TTLCMOS PORTA I/O w/programmable pull-up and interrupt-on-change
RC0/AN4/C2IN+RC0TTLCMOS PORTC I/O
RC1/AN5/C2IN-RC1TTLCMOS PORTC I/O
RC2/AN6/P1DRC2TTLCMOS PORTC I/O
RC3/AN7/P1CRC3TTLCMOS PORTC I/O
RC4/C2OUT/P1BRC4TTLCMOS PORTC I/O
RC5/CCP1/P1ARC5TTLCMOS PORTC I/O
SSVSSPower—Ground reference
V
DDVDDPower—Positive supply
V
Legend:TTL = TTL input buffer, ST = Schmitt Trigger input buffer, AN = Analog input
REF/ICSPCLKRA1TTLCMOS PORTA I/O w/programmable pull-up and interrupt-on-change
AN1AN—A/D Channel 1 input
C1IN-AN—Comparator 1 input
REFAN—External Voltage Reference for A/D
V
ICSPCLKST—Serial Programming Clock
AN2AN—A/D Channel 2 input
T0CKIST—Timer0 clock input
INTST—External Interru p t
C1OUT—CMOS Comparator 1 output
/VPPRA3TTL—PORTA input with interrupt-on-change
MCLR
PPHV—Programming voltage
V
/OSC2/CLKOUTRA4TTLCMOS PORTA I/O w/programmable pull-up and interrupt-on-change
AN3AN—A/D Channel 3 input
T1G
OSC2—XTALCrystal/Resonator
CLKOUT—CMOS F
T1CKIST—Timer1 clock
OSC1XTAL—Crystal/Resonator
CLKINST—Ex tern al clock input/RC oscillator connection
AN4AN—A/D Channel 4 input
C2IN+AN—Comparator 2 input
AN5AN—A/D Channel 5 input
C2IN-AN—Comparator 2 input
AN6AN—A/D Channel 6 input
P1D—CMOS PWM output
AN7AN—A/D Channel 7 input
P1C—CMOS PWM output
C2OUT—CMOS Comparator 2 output
P1B—CMOS PWM output
CCP1STCMOS Capture input/Compare output
P1A—CMOS PWM output
Input
Type
Output
Type
ST—Master Clear w/internal pull-up
ST—Timer1 gate
OSC/4 output
Description
DS41202C-page 6Preliminary 2004 Microchip Technology Inc.
PIC16F684
2.0MEMORY ORGANIZATION
2.1Program Memory Organization
The PIC16F684 has a 13-bit program counter capable
of addressing an 8k x 14 pr ogram mem ory spac e. Only
the first 2k x 14 (0000h-07FFh) for the PIC16F684 is
physically implemented. Accessing a location above
these boundaries will cause a wrap around within the
first 2k x 14 space. The Reset vector is at 0000h and
the interrupt vector is at 0004h (see Figure 2-1).
FIGURE 2-1:PROGRAM MEMORY MAP
AND STACK FOR THE
PIC16F684
PC<12:0>
CALL, RETURN
RETFIE, RETLW
Stack Level 1
Stack Level 2
Stack Level 8
Reset Vector
13
000h
2.2Data Memory Organization
The data memory (see Figure 2-2) is partitioned into
two banks, which contain the General Purpose Registers (GPR) and the Special Function Registers (SFR).
The Special Function Registers are located in the first
32 locations of each bank. Register locations 20h-7Fh
in Bank 0 and A0h-BFh in Bank 1 are General Purpose
Registers, implemented as static RAM. Register
locations F0h-FFh in Bank 1 point to addresses
70h-7Fh in Bank 0. All other RAM is unimplemented
and returns ‘0’ when re ad. RP0 (Status<5>) is t he bank
select bit.
RP0 = 0: → Bank 0 is selected
RP0 = 1: → Bank 1 is selected
The register file is organized as 128 x 8 in the
PIC16F684. Each register is accessed, either directly
or indirectly, through the File Select Register (FSR)
(see Section 2.4 “Indirect Addressing, INDF andFSR Registers”).
2.2.2SPECIAL FUNCTION REGISTERS
The Special Function Registers are registers used by
the CPU and peripheral functions for controlling the
desired operation of the device (see Table 2-1). These
registers are static RAM.
The special re gisters can be classifi ed into two sets:
core and peripheral. The Special Function Registers
associated with the “c ore” are des cribed in this sect ion.
Those related to the operation of the peripheral
features are described in the section of that peripheral
feature.
DS41202C-page 8Preliminary 2004 Microchip Technology Inc.
PIC16F684
TABLE 2-1:PIC16F684 SPECIAL REGISTERS SUMMARY BANK 0
AddrNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
Bank 0
00hINDFAddressing this location uses contents of FSR to address data memory (not a physical register)xxxx xxxx 17, 99
01hTMR0Timer0 Module’s registerxxxx xxxx 45, 99
02hPCLProgram Counter’s (PC) Least Significant Byte0000 0000 17, 99
03hSTATUSIRP
04hFSRIndirect Data Memory Address Pointerxxxx xxxx 17, 99
05hPORTA
06h—Unimplemented——
07hPORTC
08h—Unimplemented——
09h—Unimplemented——
0AhPCLATH
0BhINTCONGIE PEIE T0IE INTERAIE T0IFINTF RAIF0000 0000 13, 99
0ChPIR1
0Dh—Unimplemented——
0EhTMR1LHolding Register for the Least Significant Byte of the 16-bit TMR1xxxx xxxx 49, 99
0FhTMR1HHolding Register for the Most Significant Byte of the 16-bit TMR1xxxx xxxx 49, 99
ECCPASECCPASE ECCPAS2 ECCPAS1 ECCPAS0 PSSAC1PSSAC0PSSBD1PSSBD0
18hWDTCON
19hCMCON0C2OUTC1OUT
1AhCMCON1
1Bh—Unimplemented——
1Ch—Unimplemented——
1Dh—Unimplemented——
1EhADRESHMost Significant 8 bits of the left shifted A/D result or 2 bits of right shifted result xxxx xxxx 65, 99
1FhADCON0ADFMVCFG
(1)
——RA5RA4RA3RA2RA1RA0--xx xxxx 31, 99
——RC5RC4RC3RC2RC1RC0--xx xxxx 40, 99
———Write Buffer for upper 5 bits of Program Counter---0 0000 17, 99
TABLE 2-2:PIC16F684 SPECIAL FUNCTION REGISTERS SUMMARY BANK 1
AddrNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
Bank 1
80hINDFAddressing this location uses contents of FSR to address data memory (not a physical register)xxxx xxxx 17, 99
81hOPTION_REGRAPU
82hPCLProgram Counter’s (PC) Least Significant Byte0000 0000 17, 99
83hSTATUSIRP
84hFSRIndirect Data Memory Address Pointerxxxx xxxx 17, 99
85hTRISA
86h—Unimplemented——
87hTRISC
88h—Unimplemented——
89h—Unimplemented——
8AhPCLATH
8BhINTCONGIEPEIET0IEINTERAIET0IFINTFRAIF0000 0000 13, 99
8ChPIE1EEIEADIECCP1IEC2IEC1IEOSFIETMR2IETMR1IE0000 0000 14, 99
8Dh—Unimplemented——
8EhPCON
8FhOSCCON
90hOSCTUNE
91hANSELANS7ANS6ANS5ANS4ANS3ANS2ANS1ANS01111 1111 65, 99
92hPR2Timer2 Module P erio d Re gis te r1111 1111 53, 99
93h—Unimplemented——
94h—Unimplemented——
95hWPUA
96hIOCA
97h—Unimplemented——
98h—Unimplemented——
99hVRCONVREN
9AhEEDATEEDAT7EEDAT6EEDAT5EEDAT4EEDAT3EEDAT2EEDAT1EEDAT0 0000 0000 71, 100
9BhEEADREEADR7EEADR6EEADR5 EEADR4EEADR3EEADR2EEADR1EEADR0 0000 0000 71, 100
9ChEECON1
9DhEECON2EEPROM Control Register 2 (not a physical register)---- ---- 72, 100
9EhADRESLLeast Significant 2 bits of the left shifted result or 8 bits of the right shifted resultxxxx xxxx 65, 100
9FhADCON1
Legend:— = Unimplemented locations read as ‘0’, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented
Note 1:IRP and RP1 bits are reserved, always maintain these bits clear.
(3)
2:OSTS bit OSCCON <3> reset to ‘0’ with Dual Speed Start-up and LP, HS or XT selected as the oscillator.
3:RA3 pull-up is enabled when MCLRE is ‘1’ in the Configuration Word register.
DS41202C-page 10Preliminary 2004 Microchip Technology Inc.
PIC16F684
2.2.2.1Status Register
The Status register, shown in Register2-1, contains:
• the arithmetic status of the ALU
• the Reset status
• the bank select bits for data memory (SRAM)
The Status register can be the destination for any
instruction, like any other register. If the Status register
is the destination for an instruction that affects the Z,
DC or C bits, then the write to these three bits is disabled. These bits are set or cleared according to the
device logic. Furthermore, the TO
writable. Therefore, the result of an instruction with the
Status register as destination may be different than
intended.
and PD bits are not
For example, CLRF STATUS, will c lea r the up per three
bits and set the Z bit. Thi s leav es the Status register a s
‘000u u1uu’ (where u = unchanged).
It is recommended, therefore, that only BCF, BSF,SWAPF and MOVWF instructions are used to alter the
Stat us register , beca use these instru ctions do not af fect
any Status bits. For other instructions not affecting any
Status bits, see the “Instruction Set Summary”.
Note 1: Bits IRP and RP1 (Status<7:6>) are not
used by the PIC16F684 and should be
maintained as clear. Use of these bits is
not recommended, since this may affect
upward compatibility with future products.
2: The C and DC bits operate as a Borrow
and Digit Borrow out bit, respectively, in
subtraction. See the SUBLW and SUBWF
instructions for examples.
REGISTER 2-1:STATUS – STATUS REGISTER (ADDRESS: 03h OR 83h)
Reserved ReservedR/W-0R-1R-1R/W-xR/W-xR/W-x
IRPRP1RP0TOPDZDCC
bit 7bit 0
bit 7IRP: This bit is reserved and should be maintained as ‘0’
bit 6RP1: This bit is reserved and should be maintained as ‘0’
bit 5RP0: Register Bank Select bit (used for direct addressing)
1 = Bank 1 (80h – FFh)
0 = Bank 0 (00h – 7Fh)
bit 4TO
bit 3PD: Power-down bit
bit 2Z: Zero bit
bit 1DC: Digit carry/borrow bit (ADDWF, ADDLW,SUBLW,SUBWF instructions)
bit 0C: Carry/borrow bit (ADDWF, ADDLW, SUBLW, SUBWF instructions)
: Time-out bit
1 = After power-up, CLRWDT instruction or SLEEP instruction
0 = A WDT time-out occurred
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instruction
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
For borrow ,
1 = A carry-out from the 4th low-order bit of the result occurred
0 = No carry-out from the 4th low-order bit of the result
1 = A carry-out from the Most Significant bit of the result occurred
0 = No carry-out from the Most Significant bit of the result occurred
the polarity is reversed.
Note 1: For borrow,
complement of the second operand. For rotate (RRF, RLF) instructions, this bit is
loaded with either the high-order or low-order bit of the source register.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
DS41202C-page 12Preliminary 2004 Microchip Technology Inc.
PIC16F684
2.2.2.3INTCON Register
The INTCON register is a readable and writable
register , which c ontains the various en able and fl ag bit s
for TMR0 register overflow, PORTA change and
external RA2/INT pin interrupts.
Note:Interrupt flag bits are set when an interr upt
condition occurs, regard less of the st ate of
its corresponding enable bit or the global
enable bit, GIE (INTCON<7>). User
software should ensure the appropriate
interrupt flag bits are clear prior to
enabling an interrupt.
REGISTER 2-3:INTCON – INTERRUPT CONTROL REGISTER (ADDRESS: 0Bh OR 8Bh)
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
GIEPEIET0IEINTERAIET0IFINTFRAIF
bit 7bit 0
bit 7GIE: Global Interrupt Enable bit
1 = Enables all unmasked interrupts
0 = Disables all interru pts
bit 6PEIE: Peripheral Interrupt Enable bit
1 = Enables all unmasked peripheral interrupts
0 = Disables all peripheral interrupts
bit 5T0IE: TMR0 Overflow Interrupt Enable bit
1 = Enables the TMR0 interrupt
0 = Disables the TMR0 interrupt
bit 4INTE: RA2/INT External Interrupt Enable bit
1 = Enables the RA2/INT external interrupt
0 = Disables the RA2/INT external interrupt
bit 3RAIE: PORTA Change Interrupt Enable bit
1 = Enables the PORTA change interrupt
0 = Disables the PORTA change interrupt
bit 2T0IF: TMR0 Overflow Interrupt Flag bit
1 = TMR0 regis ter has overflowed (must be cleared in software)
0 = TMR0 register did not overflow
bit 1INTF: RA2/INT External Interrupt Flag bit
1 = The RA2/INT external interrupt occurred (must be cleared in software)
0 = The RA2/INT external interrupt did not occur
bit 0RAIF: PORTA Change Interrupt Flag bit
1 = When at least one of the PORTA <5:0> pins changed state (must be cleared in software)
0 = None of the PORTA <5:0> pins have changed state
(1)
(2)
Note 1: IOCA register must also be enabled.
2: T0IF bit is set when Timer0 rolls over. Timer0 is unchanged on Reset and should
be initialized before clearing T0IF bit.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
bit 7EEIF: EEPROM Write Operation Interrupt Flag bit
1 = The write operation completed (must be cleared in software)
0 = The write operation has not completed or has not been started
bit 6ADIF: A/D Interrupt Flag bit
1 = A/D conversion complete
0 = A/D conversion has not completed or has not been started
bit 5CCP1IF: CCP1 Interrupt Flag bit
Capture mod
1 = A TMR1 register capture occurred (must be cleared in software)
0 = No TMR1 regi ster capture occurred
Compare mode:
1 = A TMR1 register compare match occurred (must be cleared in software)
0 = No TMR1 register compare match occurred
PWM mode
Unused in this mode
bit 4C2IF: Comparator 2 Interrupt Flag bit
1 = Comparator 2 output has changed (must be cleared in software)
0 = Comparator 2 output has not changed
bit 3C1IF: Comparator 1 Interrupt Flag bit
1 = Comparator 1 output has changed (must be cleared in software)
0 = Comparator 1 output has not changed
bit 2OSFIF: Oscillator Fail Interrupt Flag bit
1 = System oscilla tor failed, clock input h as ch ang ed to INTOSC (must be cle are d i n s oftw a re)
0 = System clock operating
bit 1TMR2IF: Timer2 to PR2 Match Interrupt Flag bit
1 = Timer2 to PR2 match occurred (must be cleared in software)
0 = Timer2 to PR2 match has not occurred
bit 0TMR1IF: Timer1 Overflow Interrupt Flag bit
1 = Timer1 register overflowed (must be cleared in software)
0 = Timer1 has not overflowed
e:
:
Note:Interrupt flag bits are set w hen an in terrupt
condition occurs, regar dless of the st ate of
its corresponding enable bit or the global
enable bit, GIE (INTCON<7>). User
software should ensure the appropriate
interrupt flag bits are clear prior to
enabling an interrupt.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
1 = No Power-on Reset occurred
0 = A Power-on Reset occurred (must be set in software after a Power-on Reset occurs)
: Brown-out Detect Status bit
1 = No Brown-out Detect occurred
0 = A Brown-out Detect occurred (must be set in software after a Brown-out Detect occurs)
Note 1: BODEN<1:0> = 01 in the Configuration W ord register for this bit to control the BO D
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
DS41202C-page 16Preliminary 2004 Microchip Technology Inc.
.
PIC16F684
h
>
s
n
2.3PCL and PCLATH
The Program Counter (PC) is 13 bits wide. The low byte
comes from the PCL register, which is a readable and
writable register. The high byte (PC<12:8>) is not
directly readable or writable and comes from PCLATH .
On any Reset, the PC is cleared. Figure 2-3 shows the
two situations for the loading of the PC. The upper
example in Figure 2-3 shows how the PC is loaded on a
write to PCL (PCLATH<4:0> → PCH). The lower example in Figure 2-3 shows how the PC is loaded during a
CALL or GOTO instruction (PCLATH<4:3> → PCH).
FIGURE 2-3:LOADING OF PC IN
DIFFERENT SITUATIONS
PCHPCL
128 70
PC
PCLATH<4:0>
5
PCLATH
PCHPCL
12 11 100
PC
2
87
PCLATH<4:3>
PCLATH
8
11
2.3.1COMPUTED GOTO
A computed GOTO is accomplish ed by adding an offset
to the program counter (ADDWF PCL). When performing a table read using a computed GOTO method, care
should be exercise d i f the t able loca tio n cros ses a PCL
memory boundary (each 256-byte block). Refer to the
Application Note AN556, “Implementing a Table Read”
(DS00556).
Instruction wit
PCL a
Destinatio
ALU Result
GOTO, CALL
OPCODE <10:0
The stack operat es as a circular buf fer . This means th at
after the stack has been PUSHed eight times, the ninth
push overwrites th e valu e that was s tored fro m the firs t
push. The tenth pus h ov erwr i tes the se co nd push (and
so on).
Note 1: There are no Status bits to indicate stack
overflow or stack underflow conditions.
2: There are no instructions/mnemonics
called PUSH or POP. These are actions
that occur from the execution of the
CALL, RETURN, RETLW and RETFIE
instructions or the vectoring to an
interrupt address.
2.4Indirect Addressing, INDF and
FSR Registers
The INDF register is not a physica l register . Addr essing
the INDF register will cause indirect addressing.
Indirect addressing is possible by using the INDF
register. Any instruction using the INDF register
actually accesses data pointed to by the File Select
Register (FSR). Reading INDF itself indirectly will
produce 00h. Writing to the INDF register indirectly
results in a no operation (although Status bits may be
affected). An effective 9-bit address is obtained by
concatenating the 8-bit FSR and the IRP bit
(Status<7>), as shown in Figure2-4.
A simple program to clear RAM location 20h-2Fh using
indirect addressing is shown in Example 2-1.
EXAMPLE 2-1:INDIRECT ADDRESS ING
MOVLW0x20;initialize pointer
MOVWFFSR ;to RAM
NEXTCLRFINDF ;clear INDF register
INCFFSR ;INC POINTER
BTFSSFSR,4;all done?
GOTONEXT ;no clear next
CONTINUE;yes continue
2.3.2STACK
The PIC16F684 Family has an 8-level x 13-bit wide
hardware s tack (see Figure 2-1). The stack space is
not part of either program or data space and the stack
pointer is n ot re ad a bl e or wr i tabl e. T h e P C i s P U SHed
onto the s tack w hen a CALL instruction is executed or
an interrupt causes a branch. The stack is POPed in
the event of a RETURN, RETLW or a RETFIE
instruction execution. PCLATH is not affected by a
PUSH or POP operation.
Note 1: The RP1 and IRP bits are reserved; always maintain these bits clear.
00011011
NOT USED
Bank 0Bank 1B ank 2Bank 3
Bank Select
180h
1FFh
Location Select
DS41202C-page 18Preliminary 2004 Microchip Technology Inc.
PIC16F684
3.0CLOCK SOURCES
3.1Overview
The PIC16F684 has a wide variety of clock sources
and selection features to allow it to be used in a wide
range of applications while maximizing performance
and minimizing power consumption. Figure 3-1
illustrates a block diagram of the PIC16F684 clock
sources.
Clock sources can be configured from external
oscillators, quartz crystal resonators, ceramic
resonators and Resistor-Capacitor (RC) circuits. In
addition, the system clock source can be configured
from one of two internal oscillators, with a choice of
speeds selectable via software. Additional clock
features i nclude:
• Selectable system clock source between external
or internal via software.
• Two-Speed Clock Start-up mode, which minimizes latency betw e en ext ernal oscillator start-u p
and code execution.
• Fail-Safe Clock Monitor (FSCM) designed to
detect a failure of the external clock source (LP,
XT, HS, EC or RC modes) and switch to the
internal oscillator.
The PIC16F684 can b e conf igured in one of ei ght cloc k
modes.
1.EC – External clock with I/O on RA4.
2.LP – Low gain Crystal or Ceramic Resonator
Oscillator mode.
3. XT – Medium gain Crystal or Ceramic Resonator Oscillator mode.
4.HS – High gain Crystal or Ceramic Resonator
mode.
5.RC – External Resistor-Capacitor (RC) with
OSC/4 out put on RA4.
F
6.RCIO – External Resistor-Capacitor with I/O on
RA4.
7.INTRC – Internal oscillator with F
OSC/4 output
on RA4 and I/O on RA5.
8.INTRCIO – Internal oscillator with I/O on RA4
and RA5.
Clock source m odes are configu red by t he FOSC<2:0 >
bits in the Configuration Word register (see
Section 12.0 “Special Features of the CPU”). The
internal clock can be generated by two oscillators. The
HFINTOSC is a high-frequency calibrated oscillator.
The LFINTOSC is a low-frequency uncalibrated
oscillator.
Clock source modes can be classified as external or
internal.
• External clock mode s rely on ext erna l circuitry for
the clock source. Exam ples are oscillator modules
(EC mode), quartz crystal resonators or ceramic
resonators (LP, XT and HS modes), and
Resistor- Capacitor (RC mode) circuits.
• Internal clock sources are contained internally
within the PIC16F684. The PIC16F684 has two
internal oscillators, the 8 MHz High-Frequency
Internal Oscillator (HFINTOSC) and 31 kHz
Low-Frequency Internal Oscillator (LFINTOSC).
The system clock can be selected between external or
internal clock sources via the System Clock Selection
(SCS) bit (see Section 3.5 “Clock Switching”).
3.3External Clock Modes
3.3.1OSCILLATOR START-UP TIMER (OST)
If the PIC16F684 is co nfigured for LP, XT or HS modes,
the Oscillator Start-up Timer (OST) counts 1024 oscillations from the OSC1 pin, followi ng a Power-on Res et
(POR) and the Power-up T i mer (PWR T ) has ex pired ( if
configured), or a wake -up from Sleep. D urin g this t ime,
the program counter does not increment and program
execution is suspended. The OST ensures that the
oscillator circuit, using a quartz crystal resonator or
ceramic resonator, has st arted and i s providing a stabl e
system clock to the PIC16F684. When switching
between clock sources a delay is required to allow the
new clock to stabilize. These oscillator delays are
shown in Table 3-1.
In order to minimize laten cy between externa l oscillator
start-up and code execution, the Two-Speed Clock
Start-up mode can be selected (see Section 3.6
“Two-Speed Clock Start-up Mode”).
TABLE 3-1:OSCILLATOR DELAY EXAMPLES
Switch FromSwitch ToFrequencyOscillator Delay
Sleep/POR
Sleep/POREC, RCDC – 20 MHz
LFINTOSC (31 kHz)EC, RCDC – 20 MHz
Sleep/PORLP, XT, HS31 kHz to 20 MHz1024 Clock Cycles (OST)
LFINTOSC (31 kHz)HFINTOSC125 kHz to 8 MHz1 µs (approx.)
Note 1: The 5 µs to 10 µs start-up delay is based on a 1MHz system clock.
LFINTOSC
HFINTOSC
31 kHz
125 kHz to 8 MHz
5 µs-10 µs (approx.) CPU Start-up
(1)
3.3.2EC MODE
The External Clock (EC) mode allows an externally
generated logic level as the system clock source.
When operating in this mode, an external clock source
is connected to the OSC1 pin and the RA5 pin is
available for general purpose I/ O. Figure 3-2 shows the
pin connections for EC mode.
The Oscillator Start-up Timer (OST) is disabled when
EC mode is selected. Therefore, there is no delay in
operation after a Power-on Reset (POR) or wake-up
from Sleep. Because the PIC16F684 design is fully
static, stopping the external clock input will have the
effect of halting the device while leaving all data intact.
Upon restarting the external clock, the device will
resume operation as if no time had elapsed.
FIGURE 3-2:EXTERNAL CLOCK (EC)
MODE OPERATION
Clock from
Ext. System
RA4
OSC1/CLKIN
PIC16F684
I/O (OSC2)
DS41202C-page 20Preliminary 2004 Microchip Technology Inc.
PIC16F684
r
r
)
r
3.3.3LP, XT, HS MODES
The LP, XT and HS modes support the use of quartz
crystal resonators or ceramic resonators connected to
the OSC1 and OSC2 pins (Figure 3-1). The mode
selects a low, medium or high gain setting of the
internal inverter-amplifier to support various resonator
types and speed.
LP Oscillator mode selects the lowest gain setting of
the internal inverter-amplifier. LP mode current consumption is the least of the three modes. This mode is
best suited to drive resonator s with a low drive lev el
specification, for example, tuning fork type crystals.
XT Oscillator mode selects the intermediate gain
setting of the internal inverter-amplifier. XT mode
current consumption is the medi um of the three modes.
This mode is best suited to drive resonators with a
medium drive level specification, for example,
low-frequency/AT-cut quartz crystal resonators.
HS Oscillator mode selects the highest gain setting of
the internal inverter-amplifier. HS mode current
consumption is the highest of the three modes. This
mode is best suited for resonato rs that req uire a hi gh
drive setting, for example, high-frequency/AT-cut
quartz crystal resonators or ceramic resonators.
Figure 3-3 and Figure3-4 show typical circuits for
quartz crystal and ceramic resonators, respectively.
FIGURE 3-4:CERAMIC RESONATOR
OPERATION
(XT OR HS MODE)
PIC16F684
OSC1
C1
(3)
RP
OSC2
(1)
R
S
C2
Ceramic
Resonator
Note 1: A series resistor (RS) may be required fo
ceramic resonators with low drive level.
2: The value of R
mode selected (typically between 2 MΩ to
10 MΩ).
3: An additional parallel feedback resistor (R
may be required for proper ceramic resonato
operation (typical value 1 MΩ).
(2)
RF
F varies with the Oscillato
To Internal
Logic
Sleep
P
FIGURE 3-3:QUARTZ CRYSTAL
OPERATION (LP, XT OR
HS MODE)
PIC16F684
OSC1
C1
Quartz
Crystal
OSC2
(1)
R
S
C2
Note 1: A series resistor (RS) may be required for
quartz crystals with low drive level.
2: The value of R
mode selected (typically between 2 MΩ to
10 MΩ).
(2)
RF
F varies with the Oscillator
Note 1: Quartz crystal characteristics vary
according to type, package and manufacturer. The user should consult the manufacturer data sh eets for speci fications and
recommended application.
The External Resistor-Capacitor (RC) modes support
the use of an external RC circuit. This allows the
designer maximum flexibility in frequency choice while
keeping costs to a minimum when clock accuracy is not
required. There are two modes, RC and RCIO.
In RC mode, the RC circuit connects to the OSC1 pin.
The OSC2/CLKOUT pin outputs the RC oscillator
frequency divided by 4. This signal may be used to
provide a clock for external circuitry, synchronization,
calibration, test or other application requirements.
Figure 3-5 shows the RC mode connections.
FIGURE 3-5: RC MODE
VDD
REXT
OSC1
CEXT
VSS
F
Recommended values: 3 kΩ ≤ REXT ≤ 100 kΩ
OSC/4
OSC2/CLKOUT
C
EXT > 20 pF
Internal
Clock
PIC16F684
In RCIO mode, the RC circuit is connecte d to the OSC1
pin. The OSC2 pin becomes an additional general
purpose I/O pin. The I/O pin becomes bit 4 of PORTA
(RA4). Figure 3-6 shows the RCIO mode connections.
FIGURE 3-6:RCIO MODE
VDD
3.4Internal Clock Modes
The PIC16F684 has two independent, internal
oscillators that can be configured or selected as the
system clock source.
1.The HFINTOSC (High-Frequency Internal
Oscillator) is factory calibrated and operates at
8 MHz. The frequency of t he HFINT OSC can be
user adjusted ±12% via software using the
OSCTUNE register (Register 3-1).
2.The LFINTOSC (Low-Frequency Internal
Oscillator) is uncalibrated and operates at
approximately 31 kHz.
The system cloc k speed ca n be selec ted via sof tware
using the Internal Oscillator Frequency Select (IRCF)
bits.
The system clock ca n be se lec ted betw ee n external or
internal clock sources via the System Clock Selection
(SCS) bit (see Section 3.5 “Clock Switching”).
3.4.1INTRC AND INTRCIO MODES
The INTRC and INTRCIO m odes conf igure the int ernal
oscillators as th e sys tem cl ock so urce when the dev ice
is programmed using the Oscillator Selection (FOSC)
bits in the Configuration Word register (Register 12-1).
In INTRC mode, the OSC1 pin is available for general
purpose I/O. The OSC2/CLKOUT pin outputs the
selected internal os ci lla tor freq uen cy div ide d by 4. The
CLKOUT signal may be used to provide a clock for
external circuitry, synchronization, calibration, test or
other application require me nt s .
In INTRCIO mode, the OSC1 and OSC2 pins are
available for general purpose I/O.
REXT
OSC1
CEXT
VSS
RA4
Recommended values: 3 kΩ ≤ REXT ≤ 100 kΩ
I/O (OSC2)
EXT > 20 pF
C
PIC16F684
Internal
Clock
3.4.2HFINTOSC
The High-Frequency Int ernal Oscillato r (HFINT OSC) is
a factory calibrated 8 MHz internal clock source. The
frequency of the HFINTOSC can be altered
approximately ±12% via software using the OSCT UNE
register (Register 3-1).
The output of the HFINTOSC connects to a postscaler
and multiplexer (see Figure 3-1). One of seven
frequencies can be selected via software using the
IRCF bits (see Section 3.4.4 “Frequency Select Bits
The RC oscillator frequency is a function of the supply
voltage, the resistor (R
EXT) and capacitor (CEXT)
values and the operating temperature. Other factors
affecting the oscillator frequency are:
• threshold voltage variation
• component tolerances
• packaging variations i n capacitance
(IRCF)”).
The HFINTOSC is enabled by selecting any frequency
between 8 MHz and 125 kHz (IRCF ≠ 000) as the
system clock s ource (SCS = 1), or when Two-Speed
Start-up is enabled (IESO = 1 and IRCF ≠ 000).
The HF Internal Oscillator (HTS) bit (OSCCON<2>)
indicates whether the HFINTOSC is stable or not.
The user also needs to take into account variation due
to tolerance of external RC components used.
DS41202C-page 22Preliminary 2004 Microchip Technology Inc.
PIC16F684
3.4.2.1OSCTUNE Register
The HFINTOSC is factory calibrated but can be
adjusted in software by writing to the OSCTUNE
register (Register3-1).
The OSCTUNE register has a tuning range of ±12%.
The default value of the OSCTUNE register is ‘0’. The
value is a 5-bit two’s complement number. Due to
process variatio n, the m onoton icity and freq uency step
cannot be specified.
When the OSCTUNE register is modified, the
HFINTOSC frequency will begin shifting to the new
frequency. The HFINTOSC clock will stabilize within
1 ms. Code execution continues during this shift. There
is no indication that the shift has occurred.
OSCTUNE does not affect the LFINTOSC frequency.
Operation of features that depend on the LFINTOSC
clock source frequency, such as the Power-up Timer
(PWRT), Watchdog Timer (WDT), Fail-Safe Clock
Monitor (FSCM) and peripherals, are not af fected by the
change in frequency.
The Low-Frequency Internal Oscillator (LFINTOSC) is
an uncalibrated (approximate) 31 kHz internal clock
source.
The output of the LFINTOSC connects to a postscaler
and multiplexer (see Figure3-1). 31 kHz can be
selected via software using the IRCF bits (see
Section 3.4.4 “Frequency Select Bits (IRCF)”). The
LFINTOSC is also the frequency for the Power-up
Timer (PWRT), Watchdog Timer (WDT) and Fail-Safe
Clock Monitor (FSCM).
The LFINTOSC is enabled by selecting 31 kHz
(IRCF = 000) as the system clock sourc e (SCS = 1), or
when any of the following are enabled:
• Two-Speed Start-up (IESO = 1 and IRCF = 000)
• Power-up Timer (PWRT)
• Watchdog Timer (WDT)
• Fail-Safe Clock Monitor (FSCM)
The LF Internal Oscillator (LTS) bit (OSCCON<1>)
indicates whether the LFINTOSC is stable or not.
3.4.4FREQUENCY SELECT BITS (IRCF)
The output of the 8 MHz HFINTOSC and 31 kHz
LFINTOSC connects to a postscaler and multiplexer
(see Figure 3-1). The Internal Oscillator Frequency
select bits, IRCF<2:0> (OSCCON<6:4>), select the
frequency output of the internal oscillators. One of eight
frequencies can be selected via software:
•8 MHz
• 4 MHz (Default after Reset)
•2 MHz
•1 MHz
• 500 kHz
• 250 kHz
• 125 kHz
•31 kHz
Note:Following any Reset, t he IR CF bit s are set
to ‘110’ and the frequency selection is set
to 4 MHz. The user can modify the IRCF
bits to select a different frequency.
3.4.5HF AND LF INTOSC CLOCK
SWITCH TIMING
When switching between the LFINTOSC and the
HFINTOSC, the new oscillator may already be shut
down to save power. If this is the case, there is a 10 µs
delay after the IRCF bits are modified before the
frequency selection takes place. The LTS/HTS bits will
reflect the current active status of the LFINTOSC and
the HFINTOSC oscillators. The timing of a frequency
selection is as follows:
1.IRCF bits are modified.
2.If the new clock is shut down, a 10 µs clock
start-up delay is started.
3.Clock switch circuitry waits for a falling edge of
the current clock.
4.CLKOUT is held low and the clock switch
circuitry waits fo r a ris ing edge in the new clock.
5.CLKOUT is now connected with the new clock.
HTS/LTS bits are updated as required.
6.Clock switch is complete.
If the internal oscillator speed selected is between
8 MHz and 125 kHz, there is no start-up delay before
the new frequency is selected. This is because the old
and the new frequencies are derived from the
HFINTOSC via the postscaler and multiplexer.
DS41202C-page 24Preliminary 2004 Microchip Technology Inc.
PIC16F684
3.5Clock Switching
The system clock source can be switched between
external and internal clock sources via software using
the System Clock Select (SCS) bit.
3.5.1SYSTEM CLOCK SELECT (SCS) BIT
The System Clock Select (SCS) bit (OSCCON<0>)
selects the system clock source that is used for the
CPU and peripherals.
• When SCS = 0, the system clock source is
determined by configuration of the FOSC<2:0>
bits in the Configuration Word register (CONFIG).
• When SCS = 1, the system clock source is
chosen by the internal oscillator frequency
selected by the IRCF bits. After a Reset, SCS is
always cleared.
Note:Any automatic clock switch, which may
occur from Two-Speed Start-up or
Fail-Safe Clock Monitor, does not update
the SCS bit. The user can monitor the
OSTS (OSCCON<3>) to determine the
current system clock source.
3.5.2OSCILLATOR START-UP TIME-OUT
STATUS BIT
The Oscillator Start-up Time-out Status (OSTS) bit
(OSCCON<3>) indicates whether the system clock is
running from the external clock source, as defined by
the FOSC bits, or from internal clock source. In
particular, OSTS indicates that the Oscillator Start-up
Timer (OST) has timed out for LP, XT or HS modes.
3.6Two-Speed Clock Start-up Mode
Two-Speed Start-up mode provides additional power
savings by minimizing the latency between external
oscillator start-up and code execution. In applications
that make heavy us e of the Sleep mode, Two-Speed
Start-up will remove the external oscillator start-up
time from the time spent awake and can reduce the
overall power consumption of the device.
This mode allows the application to wake-up from
Sleep, perform a few instructions using the INTOSC
as the clock source and go back to Sleep without
waiting for the primary oscillator to become stable.
When the PIC16F684 is configured for LP, XT or HS
modes, the Oscillator Start-up Timer (OST) is enabled
(see Section 3.3.1 “Oscillator Start-up Timer(OST)”). The OST timer will suspend program execution until 1024 oscillations are counted. Two-Speed
Start-up mode minimizes the delay in code execution
by operating from the internal oscillator as the OST is
counting. When the OST count reaches 1024 and the
OSTS bit (OSCCON<3>) is set, program execution
switches to the external oscillator.
3.6.1TWO-SPEED START-UP MODE
CONFIGURATION
Two-Speed Start-up mode is configured by the
following settings:
• IESO = 1 (CONFIG<10>) Internal/External Switch
Over bit.
•SCS = 0.
• FOSC configured for LP, XT or HS mode.
Two-Speed Start-up mode is entered after:
• Power-on Reset (POR) and, if enabl ed, after
PWRT has expired, or
• Wake-up from Sleep.
If the external clock oscillator is configured to be anything other than LP, XT or HS mode, then Two-Speed
Start-up is disabled. This is because the ex tern al clock
oscillator does not require any stabilization time after
POR or an exit from Sleep.
3.6.2TWO-SPEED START-UP
SEQUENCE
1.Wake-up from Power-on Reset or Sleep.
2.Instructions begin execution by the internal
oscillator at the frequency set in the IRCF bits
(OSCCON<6:4>).
3.OST enabled to count 1024 clock cycles.
4.OST timed out, wait for falling edge of the
internal oscillator.
5.OSTS is set.
6.System clock held low until the next fal ling edg e
of new clock (LP, XT or HS mode).
7.System clock is switched to external clock
source.
Note:Executing a SLEEP instruction will abort
the oscillator start-up time and will cause
the OSTS bit (OSCCON<3>) to remain
clear.
Checking the state of the OSTS bit (OSCCON<3>) will
confirm if the PIC16F684 is running from the external
clock source as defined by the FOSC bits in the
Configuration Word register (CONFIG) or the internal
oscillator.
FIGURE 3-7:TWO-SPEED START-UP
Q1Q2Q3Q4Q1Q2Q3Q4Q1
INTOSC
TOSTT
OSC1
OSC2
Program Counter
System Clock
011022 1023
PCPC + 1PC + 2
DS41202C-page 26Preliminary 2004 Microchip Technology Inc.
PIC16F684
3.7Fail-Safe Clock Monitor
The Fail-Safe Clock Monitor (FSCM) is designed to
allow the device to continue to operate in the event of
an oscillator failure. The FSCM can detect oscillator
failure at any point after the device has exited a Reset
or Sleep condition and the Oscillator Start-up Timer
(OST) has expired.
FIGURE 3-8:FSCM BLOCK DIAGRAM
Clock Monitor
Latch (CM)
Primary
Clock
LFINTOSC
Oscillator
31 kHz
(~32 µs)
÷ 64
488 Hz
(~2 ms)
The FSCM function is enabled by setting the FCMEN
bit in the Confi guration Word regist er (CONFIG). It is
applicable to all ex ternal clo ck options (LP, XT , HS, EC,
RC or IO modes).
In the event of an external clock failure, the FSCM will
set the OSFIF bit (PIR1< 2>) and g enerate an os cilla tor
fail interrupt if the OSFIE bit (PIE1<2>) is set. The
device will then switch the system clock to the internal
oscillator. The system clock will continue to come from
the internal oscill ator unless the external clock recovers
and the Fail-Safe condition is exited.
(edge-triggered)
S
Q
C
Q
Clock
Failure
Detected
The frequency of the internal oscillator will depend
upon the value contained in the IRCF bits
(OSCCON<6:4>). Upon entering the Fail-Safe
condition, the OSTS bit (OSCCON<3>) is automatically cleared to reflect that the internal oscillator is
active and the WDT is cleared. The SCS bit
(OSCCON<0 >) is not upda ted. Enabling FSCM does
not affect the LTS bit.
The FSCM sample clock is generated by dividing the
INTRC clock by 64. This will allow enough time
between FSCM sample clocks for a system clock edge
to occur. Figure 3-8 shows the FSCM block diagram.
On the rising edge of the sample clock, the monitoring
latch (CM = 0) will be cleared. On a falling edge of the
primary system clock, the monitoring latch will be set
(CM = 1). In the event that a fal lin g e dge o f th e s am pl e
clock occurs, and the m onitoring latch is n ot set, a clock
failure has been detected. The assigned internal
oscillator is enabled when FSCM is enabled, as
reflected by the IRCF.
Note:Two-Speed Start-up is automatically
enabled when the Fail-Safe Clock Monit or
mode is enabled.
Note:Primary clocks with a frequency ≤ ~488 Hz
will be considered failed by the FSCM. A
slow starting oscillator can cause an
FSCM interrupt.
3.7.1FAIL-SAFE CONDITION CLEARING
The Fail-Safe condition is cleared after a Reset, the
execution of a SLEEP instruction, or a modification of
the SCS bit. While in Fail-Safe condition, the
PIC16F684 uses the internal oscillator as the system
clock sourc e. The IRCF bits (OSCCON< 6:4>) can be
modified to adjust the internal oscillator frequency
without exiting the Fail-Safe condition.
The Fail-Safe condition must be cleared before the
OSFIF flag can be cleared.
Note:The system clock is normally at a mu ch higher frequency than the sam ple clock. The relative fr equencies in
this example have been chosen for clarity.
Oscillator
Failure
Failure
Detected
CM TestCM Test
3.7.2RESET OR WAKE-UP FROM SLEEP
The FSCM is designed to detect oscillator failure at
any point after the device has exited a Reset or Sleep
condition and the Oscillator Start-up Timer (OST) has
expired. If the external clock is EC or RC mode,
monitoring will begin immediately following these
events.
For LP, XT or HS mode, the external oscillator may
require a start-up time considerably longer than the
FSCM sample clock time, a false clock failure may be
detected (see Figure 3-9). To prevent this, the internal
oscillator is automatically configured as the system
clock and functions until the external clock is stable
(the OST has timed out). This is identical to
Two-Speed Start-up mode. Once the external oscillator is stable, the LFINTOSC returns to its role as the
FSCM source.
Note:Due to the wide range of oscillato r start-u p
times, the Fail-Safe circuit is not active
during oscillator start-up (i.e., after exiting
Reset or Sleep). After an appropriate
amount of time, the u se r should check the
OSTS bit (OSCCON<3>) to verify the
oscillator start-up and system clock
switchover has successfull y com pl ete d.
DS41202C-page 28Preliminary 2004 Microchip Technology Inc.
Loading...
+ 134 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.