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 provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED,
WRITTEN OR ORAL, STATUTORY OR OTHERWISE,
RELATED TO THE INFORMATION, INCLUDING BUT NOT
LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE,
MERCHANTABILITY OR FITNESS FOR PURPOSE.
Microchip disclaims all liability arising from this information and
its use. Use of M icrochip’s prod ucts 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 Microchip 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, Migratable Memory, 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
Programmin g, IC SP, ICEPIC, MPASM, MPLIB, MPLI N K ,
MPSIM, PICkit, PICDEM, PICDEM.net, PICLAB, PICtail,
PowerCal, PowerInfo, PowerMate, PowerTool, rfLAB,
rfPICDEM, Select Mode, Smart Serial, SmartTel and Total
Endurance are trademarks of Microchip Technology
Incorporated in the U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
Microchip received ISO/TS-16949:2002 quality system certification for
its worldwide headquarters, design and wafer fabrication facilities in
Chandler and Tempe, Arizona and Mountain View, California in
October 2003. The Company’s quality system processes and
procedures are for its PICmicro
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
11.0 Analog Front-End (AFE) Functional Description (PIC16F639 Only) .......................................................................................... 79
12.0 Special Features of the CPU......................... ........................... ........................................ ........................................................ 111
13.0 Instruction Set Summary.......................................................................................................................................................... 131
14.0 Development Support............................................................................................................................................................... 141
16.0 DC and AC Characteristics Graphs and Tables....................................................................................................................... 173
Systems Information and Upgrade Hot Line..................................................................................................................................... 185
Worldwide Sales and Service ............................................. ........................................ ...................................................................... 19
4
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@microchip.com or fax the Reader Response Form in the back of this data sheet to (480) 792-4150. We
welcome your feedback.
Most Current Data Sheet
To obtain the most up-to-date version of this data sheet, please register at our Worldwide Web site at:
http://www.microchip.com
You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page.
The last character of the literature number is the version number, (e.g., DS30000A is version A of document DS30000).
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current
devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision
of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Microchip’s Worldwide Web site; http://www.microchip.com
• Your local Microchip sales office (see last page)
When contacting a sales office, please specify which device, revision of silicon and data sheet (include literature number) you are
using.
Customer Notification System
Register on our web site at www.microchip.com to receive the most current information on all of our products.
This document contains device specific information for
the PIC12F635/PIC16F636/639 devices. Additional
information may be found in the “PICmicro® Mid-Range
MCU Family Reference Manual” (DS33023), which m ay
be obtained from your local Microchip Sales
Representative or downloaded from the Microchip web
site. The reference manual should be considered a
complementary document to this data sheet and is
highly recommended reading for a better understanding
of the device architecture and operation of the peripheral
modules.
FIGURE 1-1:PIC12F635 BLOCK DIAGRAM
Program
Bus
Configuration
Flash
1K x 14
Program
Memory
14
Instruction reg
13
Program Counter
8-level Stack
(13-bit)
Direct Addr
RAM Addr
7
The PIC12F635/PIC16F636/639 devices are covered
by this data sh eet. Figure 1-1 shows a block diagram of
the PIC12F635/PIC16F636/639 devices. Table 1-1
shows the pinout description.
DDTVDDTD—P owe r supply for Analog Front-End. In this document, VDDT is treated
V
LCZLCZAN—125 kHz analog Z channel input
LCYLCYAN—125 kHz analog Y channel input
LCXLCXAN—125 kHz analog X channel input
LCCOMLCCOMAN—Common reference for analog inputs
SSTVSSTD—Ground reference for Analog Front-End. In this document, VSST is
LFDATA—CMOSDigital output representation of analog input signal to LC pins.
RSSI—Current Received signal strength indicator. Analog current that is proportional
CCLK——Carrier clock output
SDIOTTLCMOSInput/Output for SPI communication
RC2TTLCMOSGeneral purpose I/O
SCLKTTL—Digital clock input for SPI communica tion
ALERT
RC1TTLCMOS
C2IN-AN—
CS
C2IN+AN—
T0CKIST—External clock fo r Timer0
INTST—External Interrupt
C1OUT—CMOSComparator1 output
C1IN-AN—Comparator1 input – negative
ICSPCLKST—Serial Programming Clock
C1IN+AN—Comparator1 inpu t – positive
ICSPDATTTLCMOSSerial Programming Data IO
ULPWUAN—Ultra Low-Power Wake-up input
Input
Type
TTL—
Output
Type
Individually enabled pull-up/pull-down.
OSC/4 reference clock
Individually enabled pull-up/pull-down.
ST—Timer1 gate
General purpose input. Individually controlled interrupt-on-change.
—
ST—
—OD
Master Clear Reset. Pull-up enabled when configured as MCLR
to input amplitude.
the same as VDD, un less otherwis e stated.
treated the same as V
Output with internal pull-up resistor for AFE error signal
General purpose I/O
Comparator1 input - negative
Chip select input for SPI communication with internal pull-up resistor
The PIC12F635/PIC16F636/639 devices have a 13-bit
program counter capable of addressing an 8K x 14
program memory space. Only the first 1K x 14
(0000h-03FFh, for the PIC12F635) and 2K x 14
(0000h-07FFh, for the PIC16F636/639) 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).
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 GPRs,
implemented as static RAM for the PIC16F636/639.
For the PIC12F635, reg ister locat ions 4 0h throug h 7Fh
are GPRs implemented as static RAM. Register
locations F0h-FFh in Bank 1 point to addresses 70h7Fh in Bank 0. All other RAM is unimplemented and
returns ‘0’ when read. RP0 (STATUS<5>) is the bank
select bit.
The register file is organized as 64 x 8 for the
PIC12F635 and 128 x 8 for the PIC16F636/639. Each
register is accessed, either directly or indirectly,
through the File Select R egister, FSR (see Section 2.4“Indirect Addressing, INDF and FSR Registers”).
2.2.2SPECIAL FUNCTION REGISTERS
The Special Function Registers (SFRs) are registers
used by the CPU and peripheral functions for controlling
the desired operation of the device (see Figure 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.
EELOQ hardware peripheral related registers and require the execution of the “KEELOQ
Encoder License Agreem ent” regarding im plement ation of the modu le and access to related registe rs. Th
“KEELOQ® Encoder License Agreement” may be accessed through the Microchip web site located a
www.microchip.com/KEELOQ or by contacting your local Microchip Sales Representative.
The Status register, shown in Register 2-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 S tatus register is
the destination for an instruction that affects the Z, D C 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
Therefore, the result of an instruction with the Status
register as destination may be different than intended.
and PD bits are not writable.
For example, CLRF STATUS, w ill c lear the upper three
bits and set the Z bit. Thi s leaves the Status regis ter as
000u u1uu (where u = unchanged).
It is recommended, therefore, that only BCF, BSF, SWAPF
and MOVWF instructions are used to alter the Status
register, because these instructions do not affect any
Status bits. For other instructions not affecting any Status
bits, see Section 13.0 “Instruction Set Summary”.
Note 1: 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)
R/W-0R/W-0R/W-0R-1R-1R/W-xR/W-xR/W-x
IRPRP1RP0TO
bit 7bit 0
bit 7IRP: Register Bank Select bit (used for indire ct addressing)
1 = Bank 2, 3 (100h-1FFh)
0 = Bank 0, 1 (00h-FFh)
bit 6-5RP<1:0>: Register Bank Select bits (used for direct addressing)
11 = Bank 3 (180h-1FFh)
10 = Bank 2 (100h-17Fh)
01 = Bank 1 (80h-FFh)
00 = Bank 0 (00h-7Fh)
Each bank is 128 bytes.
bit 4TO
bit 3PD
bit 2Z: Zero bit
bit 1DC: Digit Carry/B
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
: Power-down bit
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
orrow bit (ADDWF, ADDLW, SUBLW, SUBWF instructions)
For Borrow, the polarity is reversed.
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
PDZDCC
Note:For Borrow, the polarity is reversed. A subtraction is executed by adding the two’s
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
The INTCON register is a readable and writable
register which co nta ins th e vari ous e nable 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 interrupt
condition occurs, regard less of the state of
its corresponding enable bit or the Global
Interrupt Enable bit, GIE (INTCON<7>).
User software should ensu re 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
GIEPEIET0IEINTERAIE
bit 7bit 0
bit 7GIE: Global Interrupt Enable bit
1 = Enables all unmasked interrupts
0 = Disables all interrupts
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 over flowed (must be cleared in software)
0 = TMR0 register did not overflow
bit 1INTF: RA2/INT External Interrupt Flag bit
1 = The RA2/INT external interru pt 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
(2)
(3)
(1)
(1)
T0IF
(2)
INTFRAIF
(3)
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 the T0IF bit.
3: MCLR
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 6LVDIF: Low-Voltage Detect Interrupt Flag bit
1 = The supply voltage has crossed selected LVD voltage (must be cleared in software)
0 = The supply voltage has not crossed selected LVD voltage
bit 5CRIF: Cryptographic Interrupt Flag bit
1 = The Cryptographic module has completed an operation (must be cleared in software)
0 = The Cryptographic module has not completed an operation or is Idle
bit 4C2IF: Comparator 2 Interrupt Flag bit
1 = Comparator output (C2OUT bit) has changed (must be cleared in software)
0 = Comparator output (C2OUT bit) has not changed
bit 3C1IF: Comparator 1 Interrupt Flag bit
1 = Comparator output (C1OUT bit) has changed (must be cleared in software)
0 = Comparator output (C1OUT bit) has not changed
bit 2OSFIF: Oscillator Fail Interrupt Flag bit
1 = System oscillator failed, clock input has changed INTOSC (must be cleared in software)
0 = System clock operating
bit 1Unimplemented: Read as ‘0’
bit 0TMR1IF: Timer1 Interrupt Flag bit
1 = Timer1 rolled ov er (must be cleared in software)
0 = Timer1 has not rolled over
Note:Interrupt flag bits are set when an interrupt
condition occurs, regar dless of the st ate of
its corresponding enable bit or the Global
Interrupt Enable bit, GIE (INTCON<7>).
User software should ensure the
appropriate interrupt flag bits are clear
prior to enabling an interrupt.
(1)
(1)
C1IFOSFIF—TMR1IF
Note 1: PIC16F636/639 only.
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
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-5 shows the
two situations for the loading of the PC. The upper
example in Figure 2-5 shows how the PC is loaded on a
write to PCL (PCLATH<4:0> → PCH). The lower
example in Figure 2-5 shows how the PC is loaded
during a CALL or GOTO instruction (PCLATH<4:3> →
PCH).
FIGURE 2-5: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
11
Instruction with
PCL as
Destination
8
ALU Result
GOTO, CALL
Opcode<10:0>
2.3.1COMPUTED GOTO
A computed GOTO is accomplished by adding an offset
to the program counter (ADDWF PCL). When
performing a table read using a computed GOTO
method, care should be exercised if the table location
crosses a PCL memory boundary (each 256-byte
block). Refer to the Application Note AN556,“Implementing a Table Read” (DS00556).
2.3.2STACK
The PIC12F635/PIC16F636/639 family has an 8level x 13-bit wide hardware stack (see Figure 2-1).
The stack space is not part of either program or data
space and the S ta ck Pointer i s not rea dable or writa ble.
The PC is PUSHed onto the stack when a CALL
instruction is execute d or an interrupt ca uses a branc h.
The stack is POP ed in the event of a RETURN, RETLW
or a RETFIE instruction execution. PCLATH is not
affected by a P USH or POP operation.
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 the va lue tha t was s tored fro m the first
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 exec ution of the CALL,RETURN, RETLW and RETFIE instru ction s
or the vectoring to an interrupt address.
The INDF register is not a physi cal register. Addres sing
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
A simple program to clear RAM lo catio n 20h-2Fh usin g
indirect addressing is shown in Example 2-1.
EXAMPLE 2-1:INDIRECT ADDRESSING
MOVLW 0x20;initialize pointer
MOVWF FSR;to RAM
NEXTCLRFINDF;clear INDF register
INCFFSR;INC POINTER
BTFSS FSR,4;all done?
GOTONEXT;no clear next
CONTINUE;yes continue
affected). An effective 9-bit address is obtained by
concatenating the 8-bit FSR and the IRP bit
(STATUS<7>), as shown in Figure 2-6.
The PIC12F635/PIC16F636/639 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
PIC12F635/PIC16F636/639 clock sources.
Clock sources can be configured from external oscillators,
quartz crystal resonators, ceramic resonators and
Resistor-Capacitor (RC) circuits. In add ition, the system
clock source can be configured from one of two in ternal
oscillators, with a choice of speeds selectable via
software. Additional clock features include:
• Selectable system clock source between external
or internal via software.
• Two-Speed Clock Start-up mode, which
minimizes latency between external oscillator
start-up and code execu t io n.
• 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 PIC12F635/PIC16F636/639 can be configured in
one of eight clock modes.
1.EC – External clock with I/O on RA4.
2.LP – Low gain crystal or Ceramic Resonator
Oscillator mode.
3.XT – Medium gain c rysta l or Ce ramic Resonat or
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 (RC) with I/O
on RA4.
7.INTOSC – Internal oscillator with F
OSC/4 output
on RA4 and I/O on RA5.
8.INTOSCIO – Internal oscillator with I/O on RA4
and RA5.
Clock source modes are configured by the 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 cloc k modes rely on exter nal circuitry for the
clock source. Examples are oscillator modules (EC
mode), quartz crystal re sonators or c eramic resonators
(LP, XT and HS modes) and Resistor-Capacitor (RC
mode) circuits.
Internal clock sources are contained internally within
PIC12F635/PIC16F636 /63 9. The devic e has two in ternal oscillators: the 8 MHz High-Frequency Internal
Oscillator (HFINTOSC) and 31 kHz Low-Frequency
Internal Oscillator (LFINTOSC).
The system clock can be selected between extern al 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 PIC12F635/PIC16F636/639 is configured for LP,
XT or HS modes, the Oscillator Start-up Timer (OST)
counts 1024 oscillations from the OSC1 pin following a
Power-on Reset (POR) and the Power-up Timer
(PWRT) has expired (if configured), or a wake-up from
Sleep. During this time, 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 started and
is providing a stable system clock to the PIC12F635/
PIC16F636/639.
When switching between clock sources, a delay is
required to allow the new clock to stabilize. Table 3-1
shows oscillator delay examples.
In order to minimize latency between external oscillator
start-up and code execution, the T wo-Speed Clock S tartup mode can be selected (see Section 3.6 “T wo-Speed
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 PIC12F635/PIC16F636/639
design is full y static, stoppi ng the extern al clock input
will have the ef fect of halting th e device while leaving all
data intact. Upon restarting the external clock, the
device will resum e ope ration as if no ti me ha d elap se d.
FIGURE 3-2:EXTERNAL CLOCK (EC)
MODE OPERATION
Clock from
Ext. System
RA4
OSC1/CLKIN
PIC12F635/PIC16F636/639
I/O (OSC2)
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. T his mode
is best suited to drive resonators with a low drive level
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 better suited to drive resonators with a
medium drive level specification, for example, lowfrequency 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 better suited for resonat ors that requ ire a hig h
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-3:QUARTZ CRYSTAL
OPERATION (LP, XT OR
HS MODE)
PIC12F635/PIC16F636/639
OSC1
C1
Quartz
Crystal
OSC2
(1)
S
C2
Note 1: A series resistor (RS) may be required for
R
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
Sleep
To Internal
Logic
Note 1: Quartz crystal characteristics vary
according to type, package and
manufacturer. The user should consult the
manufacturer data sheets for specifications
and recommended application.
2: Always verify oscillator performance over
DD and temperature range that is
the V
expected for the application.
FIGURE 3-4:CERAMIC RESONATOR
OPERATION
(XT OR HS MODE)
PIC12F635/PIC16F636/639
OSC1
C1
(3)
RP
OSC2
(1)
R
S
C2
Ceramic
Resonator
Note 1: A series resistor (RS) may be required for
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 resonator
operation (typical value 1 MΩ).
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
OSC/4
Recommended values: 3 kΩ ≤ REXT ≤ 100 kΩ
PIC12F635/PIC16F636/639
OSC2/CLKOUT
EXT > 20 pF
C
Internal
Clock
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
REXT
OSC1
CEXT
VSS
RA4
Recommended values: 3 kΩ ≤ REXT ≤ 100 kΩ
PIC12F635/PIC16F636/639
I/O (OSC2)
EXT > 20 pF
C
The RC oscillator frequency is a function of the supply
voltage, the resistor (R
EXT) and capacitor (CEXT)
values and the operating temperature. In addition to
this, the oscillator frequency will vary from unit to unit
due to normal threshold voltage. Furthermore, the
difference in le ad fram e c apacitance be twee n package
types will also a ffe ct the oscil lation fre quency o r for low
EXT values. The user also needs to take into account
C
variation due to tolerance of external RC components
used.
Internal
Clock
3.4Internal Clock Modes
The PIC12F635/PIC16F6 36/639 has two i ndepen dent,
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 (Reg ister3-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.1LFINTOSC AND LFINTOSCIO
MODES
The LFINTOSC and LFINTOSCIO modes configure
the internal oscillators as the system clock source
when the device is programmed using the oscillator
selection (FOSC) bits in the Configuration Word
register (Register 12-1).
In LFINTOSC mode, the OSC1 pin is available for
general purpose I/O. The OSC2/CLKOUT pin outputs
the selected internal oscillator frequency divided by 4.
The CLKOUT signal may be us e d t o provi de a clock for
external circuitry, synchronization, calibration, test or
other application require me nt s .
In LFINTOSCIO mode, the OSC1 and OSC2 pins are
available for general purpose I/O.
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 OSCTU NE
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(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 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
approximately ±12%. The default value of the
OSCTUNE register is ‘0’. The value is a 5-bit two’s
complement number. Due to process variation, the
monotonici ty and frequency 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 affected 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 clock source 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, the IR CF bits 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.5HFINTOSC AND LFINTOSC 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 sh ut 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.
Note:Care must be taken to ensure a valid
voltage or frequency selection is chosen.
See voltage vs. frequency diagrams
(Figure 15-2, Figure 15-3 and Figure 15-4)
for more detail.
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 s y ste m cl oc k so urc e i s determined
by configuration of the FOSC<2:0> bits in the
Configuration Word register (Register12-1).
When SCS = 1, the system clock sourc e is c hos en 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 FailSafe 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.2OSCILLAT OR 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 the 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
Star t-up will remove the extern al 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 f ew inst ructio ns using th e I NTO SC as
the clock source and go back to Sleep without waiting
for the primary oscillator to become stable.
Note:Executing a SLEEP instruction will abort
the oscillator start-up time and will cause
the OSTS bit (OSCCON<3>) to remain
clear.
When the PIC12F635/PIC 16F636/639 is c onfigured 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 ( OSCC O N<3> ) is se t, pro gram
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
Switchover 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 enabled, afte r
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 TwoSpeed Start-up is disabled. This is beca use the external
clock oscillator does not require any stabilization time
after POR or an exit from Sleep.
3.6.2TWO-SPEED START-UP
SEQUENCE
The Two-Speed Start-up sequence is listed below.
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.
3.6.3CHECKING EXTERNAL/INTERNAL
CLOCK STATUS
Checking the state of the OSTS bit (OSCCON<3>) will
confirm if the PIC12F635/PIC16F636/639 is running
from the external clock source, as defined by the FOSC
bits in the Configuration Word register (Register 12-1)
or the internal oscillator.
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 Configu ration W ord regis ter (Regist er 12-1). It
is applicable to all external clock options (LP, XT, HS,
EC, RC or I/O modes).
In the event of an external clock failure, the FSCM will
set the OSFIF bit (PIR1< 2>) and g enerate an oscil lator
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 cloc k 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 updated. Enabling
FSCM does not affect the LTS bit.
The FSCM sample clock is generated by dividing the
LFINTOSC 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 dg e o f th e s am pl e
clock occurs and the monitoring latch is not set, a clock
failure has been detected. The assigned internal
oscillator is enabled when FSCM is enabled, as
reflected by the IRCF.
Note 1: Two-Speed Start-up is automatically
enabled when the Fail-Safe Clock
Monitor mode is enabled.
2: Primary clocks with a frequency of
≤ ~488 Hz will be considered failed by
FSCM. A slow starting oscillator can
cause an FCSM interrupt.
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 PIC12F635/
PIC16F636/639 uses the internal oscillator as the
system clock source. 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.
FIGURE 3-9:FSCM TIMING DIAGRAM
Sample Clock
System
Clock
Output
CM Output
(Q)
OSCFIF
CM Test
Note:The system clock is normally at a much higher frequency than the sample clock. The relative
frequencies in this example have been chosen for clarity.
Oscillator
Failure
Failure
Detected
CM TestCM Test
3.7.2RES E T OR WAKE-UP FR OM SLEE P
The FSCM is design ed to detect osc illator failu re 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 cloc k time or a fa lse clock failure may b e
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 stab le (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 oscillator st art-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 sho uld check the
OSTS bit (OSCCON<3>) to verify the
oscillator start-up and system clock
switchover has successfully completed.
bit 3OSTS: Oscillator Start-up Time-out Status bit
(1)
1 = Device is running from the external system clock defined by FOSC<2:0>
0 = Device is running from the internal system clock (HFINTOSC or LFINTOSC)
bit 2HTS: HFINTOSC (High Frequency – 8 MHz to 125 kHz) Status bit
1 =HFINTOSC is stable
0 = HFINTOSC is not stable
bit 1LTS: LFINTOSC (Low Frequency – 31 kHz) Stable bit
1 = LFINTOSC is stable
0 = LFINTOSC is not stable
bit 0SCS: System Clock Select bit
1 = Internal oscillator is used for system clock
0 = Clock source def ined by FOSC<2:0>
(1)
HTSLTSSCS
Note 1: Bit resets to ‘0’ with T wo-Spee d S tart-up and LP, XT or HS selected as the Osc illator
mode or Fail-Safe mode is enabled.
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
TABLE 3-2:SUMMARY OF REGISTERS ASSOCIATED WITH CLOCK SOURCES
AddressNa m eB it 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
0ChPIR1
8ChPIE1
8FhOSCCON
90hOSCTUNE
(1)
2007h
Legend:x = unknown, u = unchanged, — = unimplemented locations read as ‘0’. Shaded cells are not used by oscillators.
Note 1:S ee Register 12-1 for operation of all Configuration Word register bits.
There are as many as twelve general purpose I/O pins
available. Depending on which peripherals are
enabled, some or all of the pins may not be a vailable a s
general purpose I/O. In general, when a peripheral is
enabled, the associated pin may not be used as a
general purpose I/O pin.
4.1PORTA and the TRISA Registers
PORTA is a 6-bit wide, bidirectional port. The
corresponding data direction register is TRISA
(Register 4-4). Setting a TRISA bit (= 1) will make the
corresponding PORTA pin an input (i.e., put the
corresponding output driver in a High-impedance
mode). Clearing a TRISA bit (= 0) will make the
corresponding PORTA pin an output (i.e., put the
contents of the output latch on the selected pin). The
exception is RA3, which is input only and it s TRIS bit will
always read as ‘1’. Example4-1 shows how to initialize
PORT A.
Reading the PORTA register (Register 4-3) reads the
status of the pins, whereas writing to it will write to the
port latch. All write operations are read-modify-write
operations. Therefore, a write to a port implies that the
port pins are read, this value is modified a nd then written
to the port data latch. RA3 reads ‘0’ when MCLRE = 1.
The TRISA register controls the direction of the
PORT A pins, even when they are being us ed as analog
inputs. The user must ensure the bits in the TRISA
register are maint ai ned set when using the m as an alog
inputs. I/O pins configured as analog inputs always
read ‘0’.
4.2Additional Pin Functions
Every PORTA pin on the PIC12F635/PIC16F636/639
has an interrupt-on-change option and a weak pull-up/
pull-down option. RA0 has an Ultra Low-Power Wakeup option. The next three sections describe these
functions.
4.2.1WEAK PULL-UP/PULL-DOWN
Each of th e PORTA pins, excep t RA3, has a n inte rnal
weak pull-up and pull-down . The WDA bits select either
a pull-up or pull-down for an individual port bit.
Individual control bits can turn on the pull-up or pulldown. These pull-ups/pull-downs are automatically
turned off when the port pin is configured as an output,
as an alternate function or on a Power-on Reset,
setting the RAPU
up on RA3 is enabl ed whe n con fig ured a s MCLR
Configuration Word register and disabled when high
voltage is detected, to reduce current consumption
through RA3, while in Programming mode.
Note:PORTA = GPIO
bit (OPTION_REG <7>). A we ak pul l-
in the
TRISA = TRISIO
Note:The CMCON0 (19h) register must be
initialized to configure an analog channel
as a digital input. Pins configured as
analog inputs will read ‘0’.
EXAMPLE 4-1:INITIALIZING PORTA
BCFSTATUS,RP0;Bank 0
BCFSTATUS,RP1;
CLRFPORTA;Init PORTA
MOVLW07h;Set RA<2:0> to
MOVWFCMCON0;digital I/O
BSFSTATUS,RP0;Bank 1
BCFSTATUS,RP1;
MOVLW0Ch;Set RA<3:2> as inputs
MOVWFTRISA;and set RA<5:4,1:0>
bit 7-6Unimplemented: Read as ‘0’
bit 5-4WDA<5:4>: Pull-up/Pull-down Selection bits
1 = Pull-up selected
0 = Pull-down selected
bit 3Unimplemented: Read as ‘0’
bit 2-0WDA<2:0>: Pull-up/Pull-down Selection bits
1 = Pull-up selected
0 = Pull-down selected
Note 1: The weak pull-up/pull-down device is enabled only when the global RAPU
enabled, the pin is in Input mode (TRIS = 1), the individual WDA bit is enabled
(WDA = 1) and the pin is not configured as an analog input or clock function.
2: RA3 pull-up is enabled when the pin is configured as MCLR
Word register and the device is not in Programming mode.
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
in the Configuration
bit is
REGISTER 4-2:WPUDA – WEAK PULL-UP/PULL-DOWN DIRECTION REGISTER (ADDRESS: 95h)
U-0U-0R/W-1R/W-1U-0R/W-1R/W-1R/W-1
——WPUDA5
bit 7bit 0
bit 7-6Unimplemented: Read as ‘0’
bit 5-4WPUDA<5:4>: Pull-up/Pull-down Direction Selection bits
Note 1: The weak pull-up/pull-down direction device is enabled only when the global RAPU
is enabled, the pin is in Input mode (TRIS = 1), the individual WPUDA bit is enabled
(WPUDA = 1) and the pi n is not configur e d a s an an al og i np ut or cl oc k fu nc ti on .
2: RA3 pull-up is enabled when the pin is configured as MCLR
Word register and the device is not in Programming mode.
3: WPUDA5 bit can be written if INTOSC is enabled and T1OSC is disabled;
otherwise, the bit can not be written and reads as ‘1’. WPUDA4 bit can be written
if not configured as OSC2; otherwise, the bit can not be written and reads as ‘1’.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
Each of the PORTA pins is individually configurable as
an interrupt-on-chang e pin. Control bit s, IOCAx, enable
or disable the interrupt function for each pin. Refer to
Register 4-5. The interrupt-on-change is disabled on a
Power-on Reset.
For enabled interrupt-on-change pins, the values are
compared with the old value la tched on the last rea d of
PORTA. The ‘mismatch’ outputs of the last read are
OR’d together to set t he PORT A C hange Interrupt Flag
bit (RAIF) in the INTCON r egister (Register 2 -3).
This interrupt can wake the device from Sleep. The
user, in the Interrupt Service Routine, clears the
interrupt by:
a) Any read or write of PORTA. This will end the
mismatch condition, then
b) Clear the flag bit RAIF.
A mismatch c ond it i on wi ll cont i n ue to s et f lag bi t RA IF.
Reading PORTA will end the mismatch condition and
allow flag bit RAIF to be cleared. The latch holding the
last read value is not affected by a MCLR
Reset. After these Resets, the RAIF flag will continue
to be set if a mismatch is present.
Note:If a change on the I/O pin should occur
when the read operation is bei ng executed
(start of the Q2 cycle), then the RAIF
interrupt flag may not get set.
nor BOD
REGISTER 4-5:IOCA – INTERRUPT-ON-CHANGE PORTA REGISTER (ADDRESS: 96h)
U-0U-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
——IOCA5
bit 7bit 0
(2)
IOCA4
(2)
IOCA3
(3)
IOCA2IOCA1IOCA0
bit 7-6Unimplemented: Read as ‘0’
bit 5-0IOCA<5:0>: Interrupt-on-change PORTA Control bits
The Ultra Low-Power Wake-up (ULPWU) on RA0 allows
a slow falling voltage to generate an interrupt-on-change
on RA0 without excess current consumption. The mode
is selected by setting the ULPWUE bit (PCON<5>). This
enables a small current sink which can be used to
discharge a capacitor on RA0.
To use this feature, the RA0 pin is configured to output
‘1’ to charge the capacitor, interrupt-on-change for RA0
is enabled and RA0 is configured as an input. The
ULPWUE bit is set to begin the discharge and a SLEEP
instruction is performed. When the voltage on RA0 drops
below V
the device to wake-up. Depending on the state of the
GIE bit (INTCON<7>), the device will either jump to the
interrupt vector (0004h) or execute the next instruction
when the interrupt event occurs. See Section 4.2.2
“Interrupt-on-change” and Section 12.9.3 “PORTA
Interrupt” for more information.
This feature provides a low power technique for
periodically wakin g up the device from Sleep. Th e timeout is dependent on the disch arge time of the RC circuit
on RA0. See Example 4-2 for initializing the Ultra Low
Power Wake-up module.
The series resistor provides overcurrent protection for the
RA0 pin and can allow for software calibration of the timeout (see Figure 4-1). A timer can be used to measure the
charge time and discharge time of the capacitor. The
charge time can then be adjusted to provide the desired
interrupt delay. This technique will compensate for the
affects of temperature, voltage and component accuracy.
The Ultra Low-Power Wake-up peripheral can also be
configured as a simple Programmable Low-Voltage
Detect or temperature sensor.
IL, an interrupt will be generated which will cause
BCFSTATUS,RP0;Bank 0
BCFSTATUS,RP1;
BSFPORTA,0;Set RA0 data latch
MOVLWH’7’;Turn off
MOVWFCMCON0; comparators
BSFSTATUS,RP0;Bank 1
BCFSTATUS,RP1;
BCFTRISA,0;Output high to
CALLCapDelay; charge capacitor
BSFPCON,ULPWUE ;Enable ULP Wake-up
BSFIOCA,0;Select RA0 IOC
BSFTRISA,0;RA0 to input
MOVLWB’10001000’ ;Enable interrupt
MOVWFINTCON; and clear flag
SLEEP;Wait for IOC
Each PORT A pin is multiplexed with other functio ns. The
pins and their combined functions are briefly described
here. For specific information about individual functions,
such as the comparator , refe r to the appropriate section
in this data sheet.
FIGURE 4-1:BLOCK DIAGRAM OF RA0
Analog
(1)
RAPU
Data Bus
WR
WPUDA
RD
WPUDA
WR
WDA
RD
WDA
Input Mode
D
Q
CK
Q
D
Q
CK
Q
4.2.4.1RA0/C1IN+/ICSPDAT/ULPWU
Figure 4-2 shows the diagra m for this pi n. The RA 0 pin
is configurable to function as one of the following:
• a general purpose I/O
• an analog input to the comparator
• In-Circuit Serial Programming™ data
• an analog input for the Ultra Low-Power Wake-up
VDD
Weak
Weak
VDD
WR
PORTA
WR
TRISA
RD
TRISA
RD
PORTA
WR
IOCA
RD
IOCA
Interrupt-on-
Change
D
Q
CK
Q
–
D
Q
CK
Q
01
Analog
Input Mode
D
Q
CK
Q
RD PORTA
(1)
D
Q
EN
D
Q
EN
+
ULPWUE
Q3
VT
IULP
SS
V
I/O pin
VSS
Note 1: Comparator mode determines Analog Input mode.
PORTC is a general purpose I/O port consisting of 6
bidirectional pins . The pins can be con figured for e ither
digital I/O or analog input to comparator. For specific
information about individual functions, refer to the
appropriate section in this data sheet.
Note:The CMCON0 (19h) registe r must be ini-
tialized to configure an analog channel as
a digital input. Pins configured as analog
inputs will read ‘0’.
EXAMPLE 4-3:INITIALIZING PORTC
BCFSTATUS,RP0;Bank 0
BCFSTATUS,RP1;
CLRFPORTC;Init PORTC
MOVLW07h;Set RC<4,1:0> to
MOVWFCMCON0;digital I/O
BSFSTATUS,RP0;Bank 1
BCFSTATUS,RP1
MOVLW0Ch;Set RC<3:2> as inputs
MOVWFTRISC;and set RC<5:4,1:0>
;as outputs
BCFSTATUS,RP0;Bank 0
BCFSTATUS,RP1;
4.3.1RC0/C2IN+
The RC0 pin is configurable to function as one of the
following:
• a general purpose I/O
• an analog input to the comparator
4.3.2 RC1/C2IN-
The RC1 pin is configurable to function as one of the
following:
• a general purpose I/O
• an analog input to the comparator
FIGURE 4-7:BLOCK DIAGRAM OF RC0
AND RC1
Data Bus
VDD
I/O pin
VSS
WR
PORTC
WR
TRISC
RD
TRISC
RD
PORTC
D
Q
CK
Q
D
Q
CK
Q
To Comparators
Analog Input
Mode
4.3.3RC2
The RC2 pin is configurable to function as a general
purpose I/ O.
4.3.4RC3
The RC3 pin is configurable to function as a general
purpose I/ O.
4.3.5RC5
The RC5 pin is configurable to function as a general
purpose I/ O.
The Timer0 module timer/counter has the following
features:
• 8-bit timer/counter
• Readable and writable
• 8-bit software programmable prescaler
• Internal or external clock select
• Interrupt on overflow from FFh to 00h
• Edge select for external clock
Figure 5-1 is a block diagram of th e Ti mer0 module and
the prescaler shared with the WDT.
Note:Additional information on the Timer0
module is available in the “PICmicro
Range MCU Family Reference Manual”
(DS33023).
5.1Timer0 Operation
Timer mode is selected by clearing the T0CS bit
(OPTION_REG<5>). In Timer mode, the Timer0
module will increment every instruction cycle (without
prescaler). If TMR0 is written , the increment is inhibited
for the following two instruction cycles. The user can
work around this by writing an adjusted value to the
TMR0 register.
®
Mid-
Counter mode is selected by setting the T0CS bit
(OPTION_REG<5>). In this mode, the Timer0 module
will increment either on every rising or falling edge of
pin RA2/T0CKI. The incrementing edge is determined
by the source edge (T0SE) control bit
(OPTION_REG<4>). Clearing the T0SE bit selects the
rising edge.
Note:Counter mode has specific external clock
requirements. Additional information on
these requirements is available in the
®
“PICmicro
Mid-Range MCU Family
Reference Manual” (DS33023).
5.2Timer0 Interrupt
A Timer0 interrupt is generated when the TMR0
register timer/counter overflows from FFh to 00h. This
overflow sets the T0IF bit (INTCON<2>). The interrupt
can be masked by clearing the T0IE bit (INTCON<5>).
The T0IF bit must be cleared in softwa re by the T i mer0
module Interrupt Service Routine before re-enabling
this interrupt. The Timer0 interrupt cannot wake the
processor from Sleep since the timer is shut off during
Sleep.
FIGURE 5-1:BLOCK DIAGRAM OF THE TIMER0/WDT PRESCALER
CLKOUT
(= FOSC/4)
0
1
1
T0CKI
pin
T0SE
WDTE
SWDTEN
LFINTOSC
Note 1: T0SE, T0CS, PSA, PS<2:0> are bits in the Option register, WDTPS<3:0> are bits in the WDTCON register.
When no prescaler is used, the external clock input is the
same as the prescaler output. The synchronization of
T0CKI, with the in ternal phase clock s, is accomplished
by sampling the prescaler output on the Q2 and Q4
cycles of the internal phase clocks. Therefore, it is
necessary for T0CKI to be hi gh for a t least 2 T
small RC delay of 20ns) and low for at least 2 T
a small RC delay of 20 ns). Refer to the electrical
specification o f th e desired device.
Note:The CMCON0 (19h) registe r must be ini-
tialized to configure an analog channel as
a digital input. Pins configured as analog
inputs will read ‘0’.
An 8-bit counter is available as a prescaler for the
Timer0 module, or as a postscaler for the Watchdog
Timer. For simplicity, this counter will be referred to as
“prescaler” throughout this data sheet. The prescaler
assignment is controlled in software by the control bit,
PSA (OPTION_REG<3>). Clearing the PSA bit will
assign the prescaler to Timer0. Prescale values are
selectable via the PS<2:0> bits (OPTION_REG<2:0>).
The prescaler is not readable or writable. When
assigned to the Timer0 module, all instructions writing
to the TMR0 register (e .g., CLRF 1, MOVWF 1, BSF 1,
x....etc.) wil l clear t he pres caler. When ass igned t o
WDT, a CLRWDT instruction will clear the prescaler
along with the Watchdog Timer.
5.4.1SWITCHING PRESCALER
ASSIGNMENT
The prescaler assignment is fully under software control
(i.e., it can be changed “on the fly” during program
execution). To avoid an unintended device Reset, the
following instruction sequence (Example 5-1 and
Example 5-2) must be executed when changing the
prescaler assignment from Timer0 to WDT.
EXAMPLE 5-1:CHANGING PRESCALER
(TIMER0
BCFSTATUS,RP0;Bank 0
BCFSTATUS,RP1;
CLRWDT;Clear WDT
CLRFTMR0;Clear TMR0 and
BSFSTATUS,RP0;Bank 1
BCFSTATUS,RP1;
MOVLWb’00101111’;Required if desired
MOVWFOPTION_REG; PS2:PS0 is
CLRWDT; 000 or 001
MOVLWb’00101xxx’;Set postscaler to
MOVWFOPTION_REG; desired WDT rate
BCFSTATUS,RP0;Bank 0
BCFSTATUS,RP1;
To change prescaler from the WDT to the TMR0
module, use the se quence sh own in Examp le 5-2. This
precaution must be t aken even if the WDT is disabled.
• 16-bit asynchronous counter
In Timer mode, Timer1 is incremented on every
instruction cycle. In Counter mode, Timer1 is incremented
on the rising edge of the external clock input T1CKI. In
addition, the Counter mode clock can be synchronized to
the microcontroller system clock or run asynchronously .
In Counter and Timer modules, the counter/timer clock
can be gated by the T imer1 gate, w hich can be selected
as either the T1G
If an external clock oscillator is needed (and the
microcontroller is using the INTOSC w/o CLKOUT),
Timer1 can use the LP oscillator as a clock source.
Note:In Counter mode, a falling edge must be
pin or the Comparator 2 output.
registered by the counter prior to the first
incrementing rising edge.
6.2Timer1 Interrupt
The Timer1 register pair (TMR1H:TMR1L) increments
to FFFFh and rolls over to 0000h. When Timer1 rolls
over, the Timer1 interrupt flag bit (PIR1<0>) is set. To
enable the inte rrupt on rollo ver , you must set these bits :
• Timer1 interrupt enable bit (PIE1<0>)
• PEIE bit (INTCON<6>)
• GIE bit (INTCON<7>).
The interrupt is cleared by clearing the TMR1IF bit in
the Interrupt Service Routine.
Note:The TMR1H:TTMR1L register pair and the
TMR1IF bit should be cleared before
enabling interrupts.
6.3Timer1 Prescaler
Timer1 has four pre scale r opti ons , all owin g 1, 2, 4 or 8
divisions of the clock input. The T1CKPS bits
(T1CON<5:4>) control the prescale counter. The
prescale counter is not directly readable or writable;
however, the prescaler counter is cleared upon a write
to TMR1H or TMR1L.
6.4Timer1 Gate
Timer1 gate source is software configurable to be the
T1G
pin or the output of Comp ara t or 2. This all ows th e
device to directly time external events using T1G
analog events using Comparator 2. See CMCON1
(Register 7-2) for selecting the Timer1 gate source.
This feature can simplify the software for many other
applications.
Note:TMR1GE bit (T1CON<6>) must be set to
use either T1G
gate source. See Register 7-2 for more
information on selecting the Timer1 gate
source.
Timer1 gate can be inverted using the T1GINV bit
(T1CON<7>), whether it origin ates fro m the T1G
Comparator 2 output. This configures Timer1 to
measure either the active-high or active-low time
between events.
or C2OUT as the Timer1
or
pin or
FIGURE 6-2:TIMER1 INCREMENTING EDGE
T1CKI = 1
when TMR1
Enabled
T1CKI = 0
when TMR1
Enabled
Note 1: Arrows indicate counter increments.
2: In C ounter mode, a falling edge must be registered by the counter prior to the first increm enting rising edge of
If control bit T1SYNC (T1CON<2>) is set, the external
clock input is not synchronized. The timer continues to
increment asynchronous to the internal phase clocks.
The timer will continue to run during Sleep and can
generate an interrupt on overflow, w hich will wake-up the
processor. H owever , special precautions in software are
needed to read/write the timer (see Section 6.5.1
“Reading and Writing Timer1 in Asynchronous
Counter Mode”).
Note:The CMCON0 (19h) register must be
initialized to configure an analog channel
as a digital input. Pins configured as
analog inputs will read ‘0’.
6.5.1READING AND WRITING TIMER1 IN
ASYNCHRONOUS COUNTER
MODE
Reading TMR1H or TMR1L while the timer is running
from an external asy nchronous cl ock will ens ure a valid
read (taken care of in hardware). However, the user
should keep in min d that re ading t he 16-b it time r in tw o
8-bit values itself, poses certain problems, since the
timer may overflow between the reads.
For writes, it is recomm ended that the us er simply stop
the timer and write the desired values. A write
contention may occur by writing to the timer registers
while the register is incrementi ng. This may pro duce an
unpredictable value in the timer register.
Reading the 16-bit value requires some care.
Examples in the “PICmicroReference Manual” (DS33023) show how to read and
write Ti mer1 wh en it i s runni ng in Async hronou s mode.
®
Mid-Range MCU Fami ly
6.6Timer1 Oscillator
A crystal oscilla tor circuit is built-in between pin s OSC1
(input) and OSC2 (amplifier output). It is enabled by
setting control bit, T1OSCEN (T1CON<3>). The
oscillator is a low-p ower oscil lator rated up to 31 kHz . It
will continue to run durin g Sleep. It is primarily intended
for a 32 kHz crystal. Table 3-1 shows the capacitor
selection for the T im er1 osc il lat or.
The Timer1 oscillator is shared with the system LP
oscillator. Thus, Timer1 can use this mode only when
the primary system clock is derived from the internal
oscillator. As with the system LP oscillator, the user
must provide a software time delay to ensure proper
oscillator start-up.
TRISA5 and TRISA4 bits are set when the Timer1
oscillator is enabled. RA5 and RA4 bit s rea d a s ‘0’ an d
TRISA5 and TRISA4 bits read as ‘1’.
Note:The oscillator requires a start-up and
stabilization time before use. Thus,
T1OSCEN should be set and a suitable
delay observed prior to enabling Timer1.
6.7Timer1 Operation During Sleep
Timer1 can only operate during Sleep when set up in
Asynchronous Counte r mode. In this mode, an external
crystal or clock source can be used to increment the
counter. To set up the timer to wake the device:
• Timer1 must be on (T1CON<0>)
• TMR1IE bit (PIE1<0>) must be set
• PEIE bit (INTCON<6>) must be set
The device will wake-up on an overflow. If the GIE bit
(INTCON<7>) is set, the devi ce w il l wake -up and jump
to the Interrupt Service Routine (0004h) on an overflow .
If the GIE bit is clear, executio n will contin ue with the
next instruction.
TABLE 6-1:REGISTERS ASSOCIATED WITH TIMER1
AddrNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
0Bh/
INTCONGIEPEIE
8Bh
0ChPIR1
0EhTMR1LHolding Register for the Least Significant Byte of the 16-bit TMR1 Registerxxxx xxxx uuuu uuuu
0FhTMR1HHolding Register for the Most Significant Byte of the 16-bit TMR1 Registerxxxx xxxx uuuu uuuu
The CMCON0 register (Register 7-1) controls the
comparator input and output multiplexers. A block
The comparator module contains two analog
comparators. The inputs to the comparators are
diagram of the various comparator configurations is
shown in Figure 7-4.
multiplexed with I /O port pins RA0 , RA1, RC0 and R C1,
while the output s are multi plexed to pin s RA2 and RC4.
An on-chip Comparator Voltage Reference (CVREF)
can also be applied to the inputs of the comparators.
Note:The PIC12F635 has only 1 comparator.
The comparator on the PIC12F635
behaves like comparator 2 of the
PIC16F636/639.
REGISTER 7-1:CMCON0 – COMPARATOR CONTROL 0 REGISTER (ADDRESS: 19h)
R-0R-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
(1)
C2OUT
C1OUT
bit 7bit 0
bit 7C2OUT: Comparator 2 Output bit
When C2INV = 0:
1 = C2 VIN+ > C2 VIN0 = C2 V
IN+ < C2 VIN-
When C2INV = 1:
1 = C2 VIN+ < C2 VIN0 = C2 V
IN+ > C2 VIN-
bit 6C1OUT: Comparator 1 Output bit
When C1INV = 0:
1 = C1 VIN+ > C1 VIN0 = C1 V
IN+ < C1 VIN-
When C1INV = 1:
1 = C1 VIN+ < C1 VIN0 = C1 V
IN+ > C1 VIN-
bit 5C2INV: Comparator 2 Output Inversion bit
1 = C2 output inverted
0 = C2 output not inverted
bit 4C1INV: Comparator 1 Output Inversion bit
1 = C1 output inverted
0 = C1 output not inverted
bit 3CIS: Compar ator Input Switch bit
When CM<2:0> =
1 =C1 VIN- connects to RA0
C2 V
IN- connects to RC0
0 =C1 V
IN- connects to RA1
IN- connects to RC1
C2 V
When CM<2:0> = 001:
1 =C1 VIN- connects to RA0
0 =C1 V
IN- connects to RA1
bit 2-0CM<2:0>: Comparator Mode bits
Figure 7-4 shows the Comparator modes and CM<2:0> bit settings.
(2)
010:
C2INV
(1)
(1)
(2)
C1INV
(1)
(2)
(2)
CISCM2CM1CM0
Note 1: PIC16F636/639 only. Reads as ‘0’ for PIC12F635.
2: PIC12F635 bit names are COUT and CINV.
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
A single comparator is shown in Figure 7-1 along with
the relationship between the analog input levels and
the digital output . When the analo g input at V
than the analog input V
IN-, the output of the compara tor
is a digital low level. When the analog input at V
greater than the analog input V
IN-, the output of the
comparator is a digital high level. The shaded areas of
the output of the comparator in Figure 7-1 represent
the uncertainty due to input offsets and response time.
Note:To use CIN+ and CIN- pins as analog
inputs, the appropriate bits must be
programmed in the CMCON0 (19h)
register.
The polarity of the comparator output can be inverted
by setting the CxINV bits (CMCON0<5:4>). Clearing
CxINV results in a non-inverted output. A complete
table showing the output state versus input conditions
and the polarity bit is shown in Table 7-1.
TABLE 7-1:OUTPUT STATE VS. INPUT
CONDITIONS
Input ConditionsCINVCxOUT
IN- > VIN+00
V
IN- < VIN+01
V
VIN- > VIN+11
VIN- < VIN+10
IN+ is less
IN+ is
FIGURE 7-1:SINGLE COMPARATOR
VIN-
V
IN–
VIN+
V
IN+
Output
utput
VIN+
VIN-
+
Output
–
7.2Analog Input Connection
Considerations
A simplified circuit for an analog input is shown in
Figure 7-2. Since the analog pins are connected to a
digital output, they have reverse biased diodes to VDD
and VSS. The analog input, therefore, must be between
SS and VDD. If the input voltage deviates from this
V
range by more than 0.6V in either direction, one of the
diodes is forward biased and a latch-up may occur. A
maximum source impedance of 10 kΩ is recommended
for the analog sources. Any external component
connected to an analog input pin, such as a cap acitor or
a Zener diode, should have very little leakage current.
Note 1: When reading the Port register, all pins
configured as anal og inp uts will read as a
‘0’. Pins configured as digital inputs will
convert as analog inpu t s acc ord ing to th e
input specification.
2: Analog levels on any pin defined as a
digital input may cau se the in put bu ffer to
consume more current than is specified.
FIGURE 7-2:ANALOG INPUT MODEL
DD
V
Rs < 10 kΩ
VA
A
IN
CPIN
5 pF
VT = 0.6V
V
T = 0.6V
ILEAKAGE
±500 nA
Vss
Legend:CPIN= Input Capacitance
T= Threshold Voltage
V
I
LEAKAGE = Leakage Current at the pin due to various junctions
There are eight modes of operation for the comp arators.
The CMCON0 register is used to select these modes.
Figure 7-3 and Figure 7-4 show the eight possible
modes. The TRISA and TRISC registers control the data
direction of the comparator output pins for each mode. If
the Comparator mode is changed, the comparator
output level may not be valid for the specified mode
change delay shown in Section 15.0 “Electrical
Specifications”.
Note:Comparator interrupts should be disabled
during a Comparator mode change.
Otherwise, a false interrupt may occur.
FIGURE 7-3:COMPARATOR I/O OPERATING MODES FOR PIC12F635
The comparator outputs are read through the
CMCON0 register. These bits are read-only. The
comparator outputs may also be directly output to the
RA2 and RC 4 I /O pins . W he n en abl ed, mul tip le xer s i n
the output path of the RA2 and RC4 pins will switch
and the output of each pin will be the unsynchronized
output of the com parator. The uncertainty of each of
the comparators is related to t he input offset vo ltage
and the response time given in the specifications.
Figure 7-5 and Figure 7-6 show the output block
diagrams for Co mparator 1 and 2.
The TRIS bits will still function as an output enable/
disable for the RA2 and RC4 pins while in this mode.
The polarity of the comparator outputs can be changed
using the C1INV and C2INV bits (CMCON0<5:4>).
Timer1 gate source can be configured to use the T1G
pin or Comparator 2 output as selected b y the T1GSS bit
(CMCON1<1>). This feature can be used to time the
duration or interval of analog events. The output of
Comparator 2 can also be synchronized with Timer1 by
setting the C2SYNC bit (CMCON1<0>). When enabled,
the output of Comparator 2 is latched on the falling edge
of the Timer1 clock source. If a prescaler is used with
Timer1, Comparator 2 is latched after the prescaler. To
prevent a race condition, the Comparator 2 output is
latched on the falling edge of the Timer1 clock source
and Timer1 increments on the rising edge of its clock
source. See Figure 7-6, Comparator C2 Output Block
Diagram and Figure 5-1, Timer1 on the PIC12F635/
PIC16F636/639 Block Diagram for more information.
It is recommended to synchronize Comparator 2 with
Timer1 by setting the C2SYNC bit when Comparator 2
is used as the Timer1 gate source. This ensures Timer1
does not mi ss an inc rement if Comparator 2 changes
during an increment.
The CxIE bits (PIE1<4:3>) and the PEIE bit
(INTCON<6>) must be set to enable the interrupts. In
addition, the GIE bit must also be set. If any of these
bits are cleared, th e interrupt is n ot enabled, th ough the
CxIF bits will still be se t if an interru pt condi tion occ urs.
The user , in the Interru pt Service Routi ne, can cle ar the
interrupt in the following manner:
a) Any read or write of CMCON0. This will end the
mismatch condition.
b) Clear flag bits CxIF.
A mismatch conditi on will co ntinue to se t flag bit s CxIF.
Reading CMCON0 w ill end the m ismatch co ndition and
allow flag bits CxIF to be cleared.
Note:If a change in the CMCON0 register
(CxOUT) should occur when a read
operation is being executed (start of the
Q2 cycle), then the CxIF (PIR1<4:3>)
interrupt flags may not get set.
7.5 Comparator Interrupts
The comparator interrupt flags are set whenever there
is a change in the output value of its respective
comparator. Software will need to maintain information
about the status of the output bits, as read from
CMCON0<7:6>, to determine the actual change that
has occurred. The CxIF bits (PIR1<4:3>) are the
Comparator Interrupt Flags. These bits must be reset in
software by clearing them to ‘0’. Sin ce it is also possible
to write a ‘1’ to this register, a simulated interrupt may
be initiated.
The comparato r m od ule al so allows the selec tio n of a n
internally generated voltage reference for one of the
comparator input s. The VRCON reg ister (R egister7-3)
controls the voltage reference module shown in
Figure 7-8.
Response time is the minimum time, after selecting a
new reference voltage or input source, before the
comparator output is ensured to have a valid level. If
the internal reference is changed, the maximum delay
of the internal voltage reference must be considered
when using the comparator outputs. Otherwise, the
maximum delay of the comparators should be used
(Table 15-7).
7.8Operation During Sleep
The comparators and voltage reference, if enabled
before entering Sleep mode, remain active during
Sleep. This results in higher Sleep curre nts than sh own
in the power-down specifications. The additional
current consumed by the comparator and the voltage
reference is shown separately in the specifications. To
minimize power cons umption whil e in Sleep mod e, turn
off the comparator, CM<2:0> = 111 and voltage
reference, VRCON<7> = 0.
While the comparator is enabled during Sleep, an
interrupt will wake-up the device. If the GIE bit
(INTCON<7>) is set, the device will jump to the
interrupt vector (0004h) and if clear, continues
execution with the next instruction. If the device wakes
up from Sleep, th e content s of the C MCON0, CMCO N1
and VRCON registers are not affected.
7.9Effects of a Reset
A device Reset forces the CMCON0, CMCON1 and
VRCON registers to their Reset states. This forces the
comparator module to be in the Comparator Reset
mode, CM<2:0> = 000 and the voltage reference to its
OFF state. Thus, all potential inputs are analog inputs
with the comparator and voltage reference disabled to
consume the smallest current possible.
REGISTER 7-3:VRCON – VOLTAGE REFERENCE CONTROL REGISTER (ADDRESS: 99h)
R/W-0U-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
VREN—VRR—VR3VR2VR1VR0
bit 7bit 0
bit 7VREN: CV
1 = CVREF circuit powered on
0 = CV
bit 6Unimplemented: Read as ‘0’
bit 5VRR: CVREF Range Selection bit
1 = Low range
0 = High range
bit 4Unimplemented: Read as ‘0’
bit 3-0VR<3:0>: CV
W
hen VRR = 1:
CV
REF = (VR<3:0>/24) * VDD
When VRR = 0:
CV
REF = VDD/4 + (VR<3:0>/32) * VDD
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
REF Enable bit
REF circuit powered down, no IDD drain and CVREF = VSS
The PIC12F635/PIC16F63 6/6 39 de vi ce supp ort s eig ht
internal PL VD tri p points. Se e Register 8-1 for available
PLVD trip point voltages.
interrupt driven supply level detection. The voltage
detection monitors the internal power supply.
REGISTER 8-1:LVDCON – LOW-V OLTAGE DETECT CONTROL REGISTER (ADDRESS: 94h)
U-0U-0R-0R/W-0U-0R/W-1R/W-0R/W-0
——IRVSTLVDEN—LVDL2LVDL1LVDL0
bit 7bit 0
bit 7-6Unimplemented: Read as ‘0’
bit 5IRVST: Internal Reference Voltage Stable Status Flag bit
1 = Indicates that the PLVD is stable and PLVD interrupt is reliable
0 = Indicates that the PLVD is not stable and PLVD interrupt should not be enabled
bit 4LVDEN: Low-Voltage Detect Power Enable bit
1 = Enables PLVD, powers up PLVD circuit and supporting reference circuitry
0 = Disables PLVD, powers down PLVD and supporting circuitry
bit 3Unimplemented: Read as ‘0’
bit 2-0LVDL<2:0>: Low-Voltage Detection Limit bits (nominal values)
94hLVDCON
0Bh/8Bh INTCONGIEPEIE
0ChPIR1
8ChPIE1
Legend:x = unknown, u = unchanged, — = unimplemented, read as ‘0’. Shaded cells are not used by the comparator or
The EEPROM data memory is readable and writable
during normal operation (full V
is not directly mapped in the register file space.
Instead, it is indirectly addressed through the Special
Function Registers. There are four SFRs used to read
and write this memory:
• EECON1
• EECON2 (not a physically implemented register)
• EEDA T
• EEADR
EEDAT holds the 8-bit data for read/write and EEADR
holds the address of the EEPROM location being
accessed. PIC16F636/639 has 256 bytes of data
EEPROM and the PIC12F635 has 64 bytes.
DD range). This memory
The EEPROM data memory allows b yte read and write.
A byte write automatically erases the location and
writes the new data (erase be fore write). The EEPROM
data memory is rated fo r high er ase/writ e cycles. T he
write time is controlled by an on-chip timer. The write
time will vary with voltage and temperature as well as
from chip-to-chip. Please refer to A/C specifications in
Section 15.0 “Electrical Specifications” for exact
limits.
When the data memory is code-protected, the CPU
may continue to read and write the data EEPROM
memory . The device progra mmer can no longer access
the data EEPROM data and will read zeroes.
Additional information on the data EEPROM is
available in the “PICmicroReference Manual” (DS33023).
®
Mid-Range MCU Family
REGISTER 9-1:EEDAT – EEPROM DATA RE GISTER (ADDRESS: 9Ah)
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
EEDAT7EEDAT6EEDAT5EEDAT4EEDAT3EEDAT2EEDAT1EEDAT0
bit 7bit 0
bit 7-0EEDATn: Byte Value to Write to or Read From Data EEPROM bits
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
EECON1 is the control register with four low-order bits
physically implemented. The upper four bits are nonimplemented and read as ‘0’s.
Control bits RD and WR initiate read and write,
respectively. These bits cannot be cleared, only set in
software. They are cleared in hardware at completion
of the read or wr i t e ope r a tio n. T he ina bi l it y t o cl ea r t he
WR bit in software prevents the accidental, premature
termination of a write operation.
The WREN bit, when set, will allow a write operation.
On power-up, the WREN bit is c lear . T he WRERR bit is
set when a write operation is interrupted by a MCLR
Reset, or a WDT Time-out Reset during normal
operation. In these situ ations, fol lowing Re set, the user
can check the WRERR bit, clear it and rewrite the
location. The data and address will be cleared.
Therefore, the EEDAT and EEADR registers will need
to be re-initialized.
Interrupt flag, EEIF bit (PIR1<7>), is set when write is
complete. This bit must be cleared in software.
EECON2 is not a physical register. Reading EECON2
will read all ‘0’s. The EECON2 register is used
exclusively in the data EEPROM write sequence.
Note:The EECON1, EEDAT and EEADR
registers should not be modified during a
data EEPROM write (WR bit = 1).
REGISTER 9-3:EECON1 – EEPROM CONTROL 1 REGISTER (ADDRESS: 9Ch)
U-0U-0U-0U-0R/W-xR/W-0R/S-0R/S-0
————WRERRWRENWRRD
bit 7bit 0
bit 7-4Unimplemented: Read as ‘0’
bit 3WRERR: EEPROM Error Flag bit
1 = A wri te operation is prematurely terminated (any MCLR
normal operation or BOD detect)
0 = The write operation completed
bit 2WREN: EEPROM Write Enable bit
1 = Allows write cycles
0 = Inhibits write to the data EEPROM
bit 1WR: Write Control bit
1 = Initiates a write cycle (The bit is cleared by hardware once write is complete. The WR bit
can only be set, not cleared, in software.)
0 = Write cycle to the data EEPROM is complete
bit 0RD: Read Control bit
1 = Initiates an EEPROM read (Read takes one cycle. RD is cleared in hardware. The RD bit
can only be set, not cleared, in software.)
0 = Does not initiate an EEPROM read
Legend:
S = Bit can only be set
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
T o read a d ata memory loca tion, the user must write the
address to the EEADR register and then set control bit
RD (EECON1<0>), as shown in Exam ple 9-1. The data
is available, in the very next cycle, in the EEDAT
register. Therefore, it can be read in the next
instruction. EEDAT holds this value until another read,
or until it is written to by the user (during a write
operation).
EXAMPLE 9-1:DATA EEPROM READ
BSFSTATUS,RP0;Bank 1
BCFSTATUS,RP1;
MOVLWCONFIG_ADDR;
MOVWFEEADR;Address to read
BSFEECON1,RD;EE Read
MOVFEEDAT,W;Move data to W
9.3Writing to the EEPROM Data
Memory
To write an EEPROM data location, the user must first
write the address to the EEADR register and the data
to the EEDAT register. Then the user must follow a
specific sequence to initiate the write for each byte, as
shown in Example 9-2.
BSFEECON1,WR;Start the write
BSFINTCON,GIE;Enable INTS
The write will not initiate if the above sequence is not
exactly followed (write 55h to EECON2, write AAh to
EECON2, then set WR bit) for each byte. We strongly
recommend that interrupts be disabled during this
code segment. A cycle count is executed during the
required sequence. A ny number th at is not equa l to the
required cycles to execute the required sequence will
prevent the data from being writte n into the EEPROM.
Additionally, the WREN bit in EECON1 must be set to
enable write. This mechanism prevents accidental
writes to data EEPROM due to errant (unexpected)
code execution (i.e., lost programs). The user should
keep the WREN bit clear at all times, except when
updating EEPROM. The WREN bit is not cleared
by hardware.
After a write sequence has been initiated, clearing the
WREN bit will not af fect this writ e cycle. The WR bit will
be inhibited from being s et u nle ss the WREN bit is set.
At the completion of the write cycle, the WR bit is
cleared in hardware and the EE Write Complete
Interrupt Flag bit (EEIF) is set. The user can either
enable this interrupt or poll this bit. The EEIF bit
(PIR1<7>) must be cleared by software.
9.4Wri te Verify
Depending on the application, good programming
practice may dictate that the value written to the data
EEPROM should be verified (see Example 9-3) to the
desired value to be written.
EXAMPLE 9-3:WRITE VERIFY
BSFSTATUS,RP0;Bank 1
BCFSTATUS,RP1;
MOVFEEDAT,W;EEDAT not changed
;from previous write
BSFEECON1,RD;YES, Read the
;value written
XORWF EEDAT,W
BTFSS STATUS,Z;Is data the same
GOTOWRITE_ERR;No, handle error
:;Yes, continue
9.4.1USING THE DATA EEPROM
The data EEPROM is a high-endurance, byte
addressable array that has been optimized for the
storage of frequently changing information (e.g.,
program variables or other data that are updated often).
The maximum endurance for any EEPROM cell is
specified as D120. D124 specifies a maximum number
of writes to any EEPROM location before a refresh is
required of infrequently changing memory locations.
9.4.2EEPROM ENDURANCE
As an example, hypothetically, a data EEPROM is
64 bytes long and has an endurance of 1M writes. It
also has a re fresh parameter of 10 M writes. If every
memory location in the cell were written the maximum
number of times, the data EEPROM would fail after
64M write cycles. If every memory location, save 1,
were written the maximum number of times, the data
EEPROM would fail after 63M writ e cyc les, but the on e
remaining location could fail afte r 10M cycles . If proper
refreshes occurred, then the lone memory location
would have to be refreshed 6 times for the data to
remain correct.
There are c onditions when the user may no t want to
write to the data EEPROM memory. To protect against
spurious EEPROM writes, various mechanisms have
been built in. On power-up, WREN is cleared. Als o, the
Power-up Timer (nominal 64 ms duration) prevents
EEPROM write.
The write initiate se quence and the WREN bit together
help preven t an acciden tal write during:
• Brown-out
• Power glitch
• Software malfunction
9.6Data EEPROM Operation During
Code Protection
Data memory can be code-p rotected by progr amming
the CPD bit in the Co nfigur ation Word (Regis ter 1 2-1)
to ‘0’.
When the data memory is code-protected, the CPU is
able to read and write data to the data EEPROM. It is
recommended to code-protect the program memory
when code-protecting data memory. This prevents
anyone from programming zeroes over the existing
code (which will execute as NOPs) to reach an added
routine, programmed in unused program memory,
which outputs the contents of data memory.
Programming unused locations in program memory to
‘0’ will also help prevent data memory code protection
from becoming breached.
TABLE 9-1:REGISTERS/BITS ASSOCIATED WITH DATA EEPROM
Value on
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
0Bh/8Bh INTCONGIEPEIE
0ChPIR1EEIF
8ChPIE1
9AhEEDATEEDAT7 EEDAT6 EEDAT5 EEDAT4 EEDAT3 EEDAT2 EEDAT1 EEDAT0 0000 0000 0000 0000
9BhEEADREEADR7
9ChEECON1
9DhEECON2 EEPROM Control Register 2 (not a physical register)---- ---- ---- ---Legend:x = unknown, u = unchanged, — = unimplemented read as ‘0’, q = value depends upon condition.
Shaded cells are not used by the data EEPROM module.
To obtain information regarding the implementation of
EELOQ module, Microchip Technology requires
the K
the execution of the “K
Agreement”.
The “KEELOQ® Encoder Lice nse Agreement” may be
accessed through the Microchip web site located at
www.microchip.com/K
be obtained by contacting you r local Microc hip Sales
Representative.
The PIC16F639 device consists of the PIC16F636
device and low frequency (LF) Analog Front-End
(AFE), with the AFE section containing three analoginput channels for signal detection and LF talk-back.
This section describes the Analog Front-End (AFE) in
detail.
The PIC16F639 device can detect a 125 kHz input
signal as low as 1 mVpp and transmit data by using
internal LF talk-back modulation or via an external
transmitter. The PIC16F639 can also be used for
various bidirectional communication applications.
Figure 11-3 and Figure 11-4 show application examples
of the device.
Each analog input channel has internal tuning
capacitance, sensitivity control circuits, an input signal
strength limiter and an LF talk-back modulation
transistor. An Automatic Gain Control (AGC) loop is
used for all three input channel gains. The output of
each channel is OR'd and fed into a demodulator. The
digital output is passed to the LFDATA pin. Figure 11-1
shows the block diagram of the AFE and Figure 11-2
shows the LC input path.
There are a total of eig ht Confi guratio n regis ter s. Six of
them are used for AFE operation options, one for
column parity bits and one for status indication of AFE
operation. Each register has 9 bits including one row
parity bit. These regis te rs are readable and writab le by
SPI (Serial Protocol Interface) commands except for
the Status register, which is read-only.
11.1RF Limiter
The RF Limiter limits LC pin input voltage by de-Q’ing
the attached LC resonant circuit. The absolute voltage
limit is defined by the silicon process’s maximum
allowed input voltage (see Section 15.0 “ElectricalSpecifications”). The limiter begins de-Q’ing the
external LC antenna when the input voltage exceeds
VDE_Q, progressively de-Q’ing harder to reduce the
antenna input voltage.
The signal levels from all 3 channels are combined
such that the limiter attenuates all 3 channels
uniformly, in respect to the channel with the strongest
signal.
11.2Modulation Circuit
The modulation circuit consists of a modulation
transistor (FET), internal tunin g capacitors and ext ernal
LC antenna components. The modulation transistor
and the internal tuning capacitors are connected
between the LC input pin and LCCOM pin. Each LC
input has its own modulation transistor.
When the modulation transistor turns o n, it s low T urn-on
Resistance (R
voltage. The coil voltage is minimized when the
modulation transistor turns-on and maximized when the
modulation transistor turns-off. The modulation
transistor’s low Turn-on Resistance (R
high modulation depth.
The LF talk-back is achieved by turning on and off the
modulation transistor.
The modulation data comes from the microcontroller
section via the digital SPI interface as “Clamp On”,
“Clamp Off” commands. Only those inputs that are
enabled will execute the clamp command. A basic
block diagram of the modulation circuit is shown in
Figure 11-1 and Figure 11-2.
The modulation FET is also shorted momentarily after
Soft Reset and Inactivity timer time-out.
M) clamps the induced LC antenna
M) results in a
11.3Tuning Capacitor
Each channel has internal tuning capacitors for external
antenna tuning. The capacitor values are programmed
by the Configuration registers
Note:The user can con trol the tu ning capaci tor
by programming the AFE Configuration
registers.
up to 63 pF , 1 pF per step.
11.4Variable Attenuator
The variable attenuator is used to attenuate, via AGC
control, the input signal voltage to avoid saturating the
amplifiers and demodulators.
Note:The variable attenuator function is
accomplished by the device itself. The
user cannot control its function.
11.5Sensitivity Control
The sensitivity of each channel can be reduced by the
channel’s Configuration register sensitivity setting.
This is used to desensitize the channel from optimum.
Note:The user can desensitize the channel
sensitivity by programming the AFE
Configura tion registers.
The AGC controls the variable attenuator to limit the
internal signal voltage to avoid saturation of internal
amplifiers and demodulators (Refer to Section 11.4“Varia ble A ttenu ator”).
The signal levels from all 3 channels are combined
such that AGC attenuates all 3 channels uniformly in
respect to the channel with the strongest signal.
Note:The AGC control function is accompli shed
by the device itself. The user cannot
control its function .
11.7Fixed Gain Amplifiers 1 and 2
FGA1 and FGA2 provides a maximum two-stage gain
of 40 dB.
Note:The user cannot control the gain of these
two amplifiers.
11.8Auto Channel Selection
The Auto Channel Selection feature is enabled if the
Auto Channel Select bit AUTOCHSEL<8> in Configuration Register 5 (Register 11-6) is set, and disabled if
the bit is cleared. When this feature is active (i.e.,
AUTOCHSE <8> = 1), the control circuit checks the
demodulator output of each input channel immediately
after the AGC settling time (T
it allows this channel to pass data, otherwise it is
blocked.
The status of this operation is monitored by AFE Status
Register 7 bits <8:6> (Register 1 1-8). These bits indicate
the current status of the channel selection activity, and
automatically updates for every Soft Reset period. The
auto channel selection function resets after each Soft
Reset (or after Inactivity timer time- out) . Ther efor e, th e
blocked channels are reenabled after Soft Reset.
This feature can make the output signal cleaner by
blocking any channel that was not high at the end of
AGC. This function works only for demodulated data
T
output, and is not applied for carrier clock or RSSI
output.
STAB). If the output is hig h,
11.10 Demodulator
The Demodulator consists of a full-wave rectifier, low
pass filter, peak detector and Data Slicer that detects
the envelope of the input signal.
11. 11Data Slicer
The Data Slicer consists of a reference generator and
comparator. The Data Slicer compares the input with
the reference voltage. The reference voltage comes
from the minimum modulation depth requirement
setting and input peak voltage. The data from all 3
channels are OR’d together and sent to the output
enable filter.
11.12 Output Enable Filter
The Output Enable Filter enables the LFDATA output
once the incoming signal meets the wake-up sequence
requirements (see Section 11.15 “Configurable
Output Enable Filter”).
11. 1 3 RSSI (Received Signal Strength
Indicator)
The RSSI provides a current which is propo rtional to the
input signal amplitude (see Section 11.31.3 “Received
Signal Strength Indicator (RSSI) Output”).
11.14 Analog Front-End Timers
The AFE has an internal 32 kHz RC oscillator. The
oscillator is used in several timers:
• Inactivity timer
• Alarm timer
• Pulse Width timer
• Period timer
• AGC settling timer
11.14.1RC OSCILLATOR
The RC oscillator is low power, 32 kHz ± 10% over
temperature and volta ge variations.
11. 9Carrier Clock Detector
The Detector senses the input carrier cycles. The
output of the Detector switches di gitally at the signal
carrier frequency. Carrier clock output is available
when the output is selected by the DATOUT bit in the
AFE Configuration Register 1 (Register 11-2).
The Inactivity Timer is used to automatically return the
AFE to Standby mode, if there is no input signal. The
time-out period is approximately 16 ms (T
on the 32 kHz internal clock.
The purpose of the Inactivity Timer is to minimize AFE
current draw by automatically returning the AFE to the
lower current Standby mode, if there is no input signal
for approximately 16ms.
The timer is reset when:
• An amplitude change in LF input signal, either
high-to-low or low-to-high
pin is low (any SPI™ command)
•CS
• Timer-related Soft Reset
The timer starts when:
• AFE receives any LF signal
The timer causes an AFE Soft Reset when:
• A previously received LF signal does not change
either high-to-low or low-to-high for T
The Soft Reset re turns the AFE t o St andby mo de where
most of the analog circuits, such as the AGC,
demodulator and RC oscillator, are powered down. This
returns the AFE to the lower Standby Current mode.
INACT), based
INACT
11.14.3ALARM TIMER
The Alarm Timer is used to notify the MC U that the AFE
is receiving LF signal that does not pass the output
enable filter requirement. The time-out period is
approximately 32 ms (T
continuing noise.
The Alarm Timer time-out occurs if there is an input
signal for longer than 32 ms that does not meet the
output enable filter requirements. The Alarm Timer
time-out causes:
a) The ALERT
b) The ALARM bit to set in the AFE Status
Configuration 7 register (Register 11-8).
The MCU is infor med of the Alarm timer time-out by
monitoring the ALERT
occurs, the MCU can take appropriate actions such as
lowering channel sensitivity or disabling channels. If
the noise source is ignored, the AFE can return to a
lower standby current draw state.
pin to go low.
ALARM) in the presence of
pin. If the Alarm timer time-out
The timer is reset when the:
pin is low (any SPI command).
•CS
• Output enable filter is disabled.
• LFDATA pin is enabled (signal passed output
enable filter).
The timer starts when:
• Receiving a LF signal.
The timer causes a low output o n the ALER T
• Output enable filter is enabled and modulated
input signal is present for T
pass the output enable filter requirement.
Note:The Alarm timer is disabled if the output
enable filter is disabled.
ALARM, but does not
pin when:
11.14.4PULSE WIDTH TIMER
The Pulse Width Timer is used to verify that the
received output enable sequence meets both the
minimum T
OEH and minimum TOEL requirements.
11.14.5PERIOD TIMER
The Period Timer is used to verify that the received
output enable sequence meets the maximum T
requirement.
OET
11.14.6AGC SETTLING TIMER (TAGC)
This timer is used to keep the output enab le filter in
Reset while the AGC settles on the input signal. The
time-out period is approximately 3.5 ms. At end of this
AGC), the input should remain high (TPAGC),
time (T
otherwise the counting is aborted and a Soft Reset is
issued. See Figure 11-6 for details.
Note 1: The AFE needs continuous and
uninterrupted high input signal during
AGC settling time (TAGC). Any absence of
signal during this tim e may reset the timer
and a new input signa l is neede d for AGC
settling time, or may result in improper
AGC gain settings which will produce
invalid output.
2: The rest of the A FE section wa kes up if any
of these input channels receive the AGC
settling time c orrec tly. AFE Status Registe r
7 bits <4:2> ( Reg ist e r 11-8) indicate w hich
input channels have waken up the AFE
first. V alid inp ut signal on mu ltiple input pi ns
can cause more than one channel's
indicator bit to b e se t.
The purpose of this filter is to enable the LFDATA output
and wake the microcontroller only after receiving a
specific sequence of pulses on the LC input pins.
Therefore, it prevents the AFE from waking up the
microcontroller due to noise or unwanted input signals.
The circuit compares the timing of the demodulated
header waveform with a pre-defined value, and enables
the demodulated LFDATA output when a match occurs.
The output enable filter consists of a high (T
low duration (T
OEL) of a pulse immediately after the
AGC settling gap time. The selection of high and low
times further implies a max period time. The output
enable high and low times are determined by SPI
interface programming. Figure 11-5 and Figure11-6
show the output enable filter waveform s .
There should be no missing cycles during T
Missing cycles may result in failing the output enable
condition.
TOEH is measured from the rising edge of the demodulator
output to the first falling edge. The pulse width must fall
within TOEH≤t≤ TOET.
OEL is measured from the falling edge of the
T
demodulator output to the rising edge of the ne xt pulse.
The pulse width must fall within TOEL≤t≤ TOET.
OET is measured from rising edge to the next rising
T
edge (i.e., the sum of T
must be t ≤ T
OEH and TOEL). The pulse wid th
OET. If the Configuration Register 0
(Register 11-1), OEL<8:7> is set to ‘00’, then T
must not exceed TOET and TOEL must not exceed
INACT.
T
The filter will reset, requiring a complete new successive
high and low period to enable LFDATA, under the
following conditions.
• The received high is not greater than the
configured minimum T
OEH value.
•During TOEH, a loss of signal > 56 μs. A loss of
signal < 56 μs may or may not cause a filter
Reset.
• The received low is not greater than the
configured minimum T
OEL value.
• The received sequence exceeds the maximum
T
OET value:
-T
OEH + TOEL > TOET
-or TOEH > TOET
-or TOEL > TOET
• A Soft Reset SPI command is received.
OEL
T
(ms)
OET
T
(ms)
OEH
If the filter resets due to a long high (T
OEH > TOET), the
high-pulse timer will not begin timing again until after a
gap of TE and another low-to-high transition occurs on
the demodulator output.
Disabling the output enable filter disables the T
OEL requirement and the A FE passes all received LF
T
OEH and
data. See Fi gure 11-10, Figu re 11-11 and Figure 11-12
for examples.
When viewed from an appl ication perspe ctive, f rom the
pin input, the actual output ena ble filter timin g must factor in the analog delays in the input path (such as
demodulator charge and discharge times).
OEH - TDR + TDF
• T
• TOEL + TDR - TDF
The output enable filter starts immediately after TGAP,
the gap after AGC stabilization period.
11.16 Input Sensitivity Control
The AFE is designed to have typical input sensitivity of
PP. This means any input signal with amplitude
3mV
greater than 3 mV
AGC loop regulates the detecting signal amplitude when
the input level is greater than approximately 20 mV
This signal amplitude is called “AGC-active level”. The
AGC loop regulates the input voltage so that the input
signal amplitude range w ill be kept within the linear rang e
of the detection circuits without saturation. The AGC
Active Status bit (AGCACT<5>) in the AFE Status
Register 7 (Register 11-8) is set if the AGC loop
regulates the input vo lt ag e.
Table 11-2 shows the input sensitivity comparison when
the AGCSIG option is used. When AGCSIG option bit is
set, the demodulated output is available only when the
AGC loop is active (see Table 11-1). The AFE has also
input sensitivity reduction options per each channel. The
Configuration Register 3 (Register 11-4), Configuration
Register 4 (Register 11-5) and Configuration Register 5
(Register 11-6) have the option to reduce the channel
gains from 0 dB to approximately -30 dB.
TABLE 11-2:INPUT SENSITIVITY VS. MODULATED SIGNAL STRENGTH SETTING (AGCSIG <7>)
AGCSIG<7>
(Config. Register 5 )
0Disabled – the AFE passes signal of any amplitude level it is capable of
1Enabled – No output until AGC Status = 1 (i.e., VPEAK≈ 20 mVPP)
Description
detecting (demodulated data and carrier clock).
(demodulated data and carrier clock).
• Provides the best signal to noise ratio.
Input
Sensitivity
(Typical)
PP
3.0 mV
20 mV
PP
11. 17 Input Channels (Enable/Disable)
Each channel can be individually enabled or disabled
by programming bits in Configuration Register 0<3:1>
(Register 11-1).
The purpose of having an option to disable a pa rtic ul ar
channel is to minimize current draw by powering down
as much circuitry as possible, if the channel is not
needed for operatio n. The exact ci rcuit s di sable d when
an input is disabled are amplifiers, detector, full-wave
rectifier, data slicer, and modulation FET. However, the
RF input limiter remains active to protect the silicon
from excessive antenna input voltages.
11.18 AGC Amplifier
The circuit automatically amplifies input signal voltage
levels to an acceptable level for the data slicer. Fast
attack and slow release by nature, the AGC tracks the
carrier signal level and not the modulated data bits.
The AGC inherently tracks the strongest of the three
antenna input signals. The AGC requires an AGC
stabilization time (T
The AGC will attempt to regulate a channel’s peak
signal voltage into the data slicer to a des ired regulated
AGC voltage – reducing the input path’s gain as the
signal level atte mp t s t o increase above regulated AGC
voltage, and allowing full amplification on signal levels
below the regulated AGC voltage.
The AGC has two modes of operation:
1.During the AGC settling time (T
time constant is fast, allowing a reasonably short
acquisition time of the continuous input signal.
2.After T
Also, the AGC is froze n when the input signal envelop e
is low. The AGC tracks only high envelope levels.
AGC, the AGC switches to a slower time
constant for data slicing.
AGC).
AGC), the AGC
11.19 AGC Preserve
The AGC preserve feature allows the AFE to preserve
the AGC value during the AGC settling time (T
apply the value to the data slicing circuit for the following
data streams instead of using a new tracking value. This
feature is useful to demodulate the input signal correctly
when the input has random amplitude variations at a
given time period. This feature is enabled when the AFE
receives an AGC Preserve On command and disabled
if it receives an AGC Preserve Off command. Once the
AGC Preserve On command is received, the AFE
acquires a new AGC value during each AGC settling
time and preserves the value until a Soft Reset or an
AGC Preserve Off command is issued. Therefore, it
does not need to issue another AGC Preserve On
command. An AGC Preserve Off command is needed to
disable the AGC preserve feature (see
Section 11.32.2.5 “AGC Preserve On Command”
and Section 11.32.2.6 “AGC Preserve Off
Command” for AGC Preserve commands).
The AFE issues a Soft Reset in the following events:
a) After Power-on Reset (POR),
b) After Inactivity timer time-out,
c)If an “Abort” occurs,
d) After receiving SPI Soft Reset command.
The “Abort” occurs if there is no positive signal
detected at the end of the AGC stabilization period
AGC). The Soft Reset initializes internal circuits and
(T
brings the AFE into a low current Standby mode
operation. The intern al circuits that are initial ized by the
Soft Reset include:
• Output Enable Filter
•AGC circuits
• Demodulator
• 32 kHz Internal Oscillator
The Soft Reset has no effect on the Configuration register
setup, except for some of the AFE Status Register 7 bits.
(Register 11-8).
The circuit initialization takes one internal clock cycle
(1/32 kHz = 31.25 μs). During the initialization, the
modulation transistors between each input and
LCCOM pins are turned-on to discharge any internal/
external para sitic char ges. The modu lation tra nsistors
are turned-off immediately after the initialization time.
The Soft Reset is executed in Active mode only . It is not
valid in Standby mode.
TABLE 11-3:SETTING FOR MINIMUM
MODULATION DEPTH
REQUIREMENT
MODMIN Bits
(Config. Register 5)
Bit 6Bit 5
00
01
10
11
Modulation Depth
50% (default)
75%
25%
12%
11. 21 Minimum Modulation Depth
Requirement for Input Signal
The AFE demodulates the modulated input signal if the
modulation depth of the input signal is greater than the
minimum requirement that is programmed in the AFE
Configuration Register 5 (Register 11-6). Figure 11-7
shows the definition of the modulation depth and
examples. MODMIN<6:5> of the Configuration Register
5 offer four options. They are 75%, 50%, 25% and 12%,
with a default setting of 50%.
The purpose of this feature is to enhance the
demodulation integrity of the input signal. The 12%
setting is the best choice for the in put si gn al with weak
modulation depth, which is typically observed near the
high-voltage base station antenna and also at fardistance from the base station antenna. It gives the
best demodulation sensitivity, but is very susceptible to
noise spikes that can res ult in a bi t detect ion error. The
75% setting can reduce the bit errors caused by noise,
but gives the least demodulation sensitivity. See
Table 11-3 for minimum modulation depth requirement
settings.
The Sleep command from the microcontroller, via an
SPI Interface command, places the AFE into an ultra
Low-current mode. All c irc ui ts including the RF Lim ite r,
except the minimum circui try requ ired to re tain register
memory and SPI capability, will be powered down to
minimize the AFE current draw . Pow er-on Reset or any
SPI command, other than Sleep comm and , is require d
to wake the AFE from Sleep.
11. 23 Low Current Standby Mode
The AFE is in Standby mode when no LF signal is
present on the antenna inputs but the AFE is powered
and ready to receive any incoming signals.
11. 24 Low Current Operating Mode
The AFE is in Low-current Operating mode when a LF
signal is present on an LF antenna input and internal
circuitry is switching with the received data.
11.25 Error Detection of AFE
Configuration Register Data
The AFE's Configurati on regis ters ar e vo latile memo ry.
Therefore, the contents of the registers can be
corrupted or cleared by any electrical incidence such
as battery disconnect. To ensure the data integrity, the
AFE has an error detection mechanism using row and
column parity bi ts of the Confi guration regi ster memor y
map. The bit 0 of each reg is ter i s a ro w p arity bit which
is calculated over the eight configuration bits (from bit 1
to bit 8). The Column Parity Register (Configuration
Register 6) holds column parity bits; each bit is
calculated over the respective columns (Configuration
registers 0 to 5) of the Configuration bits. The Status
register is not included for the column parity bit
calculation. Parity is to be odd. The parity bit set or
cleared makes an odd number of set bits. The user
needs to calcula te the ro w and colum n p arity b its usin g
the contents of the registers and program them. Durin g
operation, the AFE co ntinuously c alculates the row and
column parity bits of the configuration memory map. If
a parity error occu rs, the AFE lowe rs the SCLK/AL ER T
pin (interrupting the microcontroller section) indicating
the configuration memory has been corrupted or
unloaded and needs to be reprogrammed.
At an initial condition after a Power-On-Reset, the
values of the registers are all clear (default condition).
Therefore, the AFE will issue the parity bit error by
lowering the SCLK/ALERT
registers with correct parity bits, the SCLK/ALERT
will be toggled to logic high level immediatel y.
The parity bit errors do not change or affect the AFE's
functional operation.
Table 11-4 shows an example of the register values
and corresponding parity bits.
pin. If user reprograms the
pin
TABLE 11-4:AFE CONFIGURATION REGISTER PARITY BIT EXAMPLE
Configurat ion Register 0101010000
Configurat ion Register 1000000001
Configurat ion Register 2000000001
Configurat ion Register 3000000001
Configurat ion Register 4000000001
Configurat ion Register 5100000000
Microchip calibrates the AFE to reduce the device-todevice variation in standby current, internal timing and
sensitivity, as well as channel-to-channel sensitivity
variation.
11.27 De-Q’ing of Antenna Circuit
When the transponder is close to the base station, the
transponder coil may develop coil voltage higher than
DE_Q. This condition is called “near field”. The AFE
V
detects the strong near field signal through the AGC
control, and de-Q’ing the antenna circuit to reduce the
input signal amplitude.
11.28 Battery Back-up and Batteryless
Operation
The device supports both battery back-up and
batteryless operation by the addition of external
components, allowing the device to be partially or
completely powered from the field.
Figure 11-8 shows an example of the external circuit for
the battery back-up.
Note:Voltage on LCCOM combined wi th coil input
voltage must n ot ex ce ed the maximum LC
input voltage.
FIGURE 11-8:LF FIELD POWERING AND BATTERY BACK-UP EXAMPLE
VBAT
DBLOCK
DLIM
VDD
CPOOL
DFLAT1
LX
Air Coil
CX
LY
RLIM
CY
LCX
LCY
LCZ
D
FLAT2
Legend:CCOM = LCCOM charging capacitor.
POOL = Pool capacitor (or battery back-up capacitor), charges in field and powers device.
C
BLOCK = Battery protection from reverse charge.
D
Schottky for low forward bias drop.
DFLAT = Field rectifier diodes.
LIM = Voltage limiting diode, may be required to limit VDD voltage when in strong fields .
D
R
COM = Ccom discharge path.
LIM = Current limiting resistor, required for air coil in strong fields.
The demodulator r ecovers the modula tion data from
the received si gnal, containing carrier plus data, by
appropriate envelope detection. The demodulator has
a fast rise (charge) time (T
appropriate to an envelope of input signal (see
Section 15.0 “Electrical Specifications” for T
and TDF specifications). The demodulator contains
the full-wave rectifier, low-pass filter, peak detector
and data slicer.
FIGURE 11-9:DEMODULATOR CHARGE AND DISCHARGE
Signal into LC input pins
Full-wave Rectifier output
DR) and a fall time (TDF)
DR
Data Slicer output
(demodulator output)
TDR
11.30 Power-On Reset
This circuit remains in a Reset state until a sufficient
supply voltage is applied to the AFE. The Reset
releases when the supply is sufficient for correct AFE
operation, nominally
The Configuration regis ters a re all cle ared o n a Pow eron Reset. A s the Co nf i gu ra t io n r eg i ster s a re pr o tec t ed
by odd row an d column parit y, the ALERT
pulled down – indicating to the microcontroller section
that the AFE configuration memory is cleared and
requires loading.
VPOR of AFE.
pin will be
11.31 LFDATA Output Selection
The LFDATA output can be configured to pass the
Demodulator output, Received Signal Strength Indicator
(RSSI) output, or Carrier Clock. See Configuration
Register 1 (Register 1 1-2) for more details.
11.31.1DEMODULATOR OUTPUT
The demodulator output is the default configuration of
the output selection. This is the output of an envelope
detection circuit. See Figure 11-9 for the demodulator
output.
TDF
For a clean data output or to save operating power, the
input channels can be individua lly enabled or disabl ed. If
more than one cha nnel i s enab led, th e outpu t is the su m
of each output of all enabled channels. There will be no
valid output if all three channels are disabled. When the
demodulated output is sele cted, the output is available in
two different con ditions depend ing on how the options of
Configuration Register 0 (Register 11-1) are set: Output
Enable Filter is disabled or enabled.
Case I. When Output Enable Filter is disabled: Demodula ted output is available immediately after the AGC stabiliz ation
AGC). Figure 11-10 shows an example of demodulated output when the Output Enabl e Filter is disa bled.
time (T
FIGURE 11-10:INPUT SIGNAL AND DEMODULATOR OUTPUT WHEN THE OUTPUT ENABLE
FILTER IS DISABLED
Input Signal
LFDATA Output
Case II. When Output Enable Filter is enable d: Demodulat ed output is available only if the inc oming sig nal meets the
enable filter timi ng crit eria that is defin ed in th e Config urat ion R egist er 0 (Regi ster11-1). If the crit eria is met, th e outp ut
is available after the low timing (TOEL) of the Enable Filter. Figure 11-11 and Figure 11-12 shows examples of
demodulated output when the Output Enable Filter is enabled.
FIGURE 11-11:INPUT SIGNAL AND DEMODULATOR OUTPUT (WHEN OUTPUT ENABLE
FILTER IS ENABLED AND INPUT MEETS FILTER TIMING REQUIREMENTS)
When the Carrier Clock output is selected, the LFDATA
output is a square pulse of the input carrier clock and
available as soon as the AGC st abilization time (T
completed. There are two Configuration register options
for the carrier clock output: (a) clock divide-by one or (b)
clock divide-by four, depending on bit DATOUT<7> of
Configuration Register 2 (Register 11-3). The carrier
clock output is available immediately after the AGC
settling time. The Output Enable Filter, AGCSIG, and
MODMIN options are applicable for the carrier clock
output in the same way as the demodulated output. The
input channel can be individually enabl ed or disabled for
the output. If more than one channel is enabled, the
output is the sum of each output of all enabled channels.
Therefore, the carrier clock output waveform is not as
precise as when only one channel is enabled. It is
recommended to enable one channel only if a precise
output waveform is desired.
There will be no valid output if all three channels are
disabled. See Figure 11-13 for carrier clock output
examples.
An analog cu rrent is availabl e at the LFDATA pin when
the Received Signal Strength Indicator (RSSI) output is
selected for the AFE’s Configuration register. The analog
current is lin early pro portion al to t he inpu t signal strengt h
(see Figure 11-15).
All timers in the circuit, such as inactivity timer, alarm
timer, and AGC settling time, are disabled during the
RSSI mode. Therefore, the RSSI ou tpu t is not a f fe cte d
by the AGC settling time, and available immediately
when the RSSI option is selected. The AFE enters
Active mode immediately when the RSSI output is
selected. The MCU I/O pin (RC3) connected to the
LFDATA pin, must be set to high-impedance state
during the RSSI Output mode.
When the AFE receives an SPI command during the
RSSI output, the RSSI mode is temporary disabled
until the SPI interface communication is completed. It
returns to the RSSI mode again after the SPI interface
communication is compl ete d. The AFE holds the RSSI
mode until another output type is selected (CS
turns off the RSSI signal). To obtain the RSSI output
for a particular input channel, or to save operating
power, the input channel can be individually enabled
or disabled. If more than one channel is enabled, the
RSSI output is from the strongest signal channel.
There will be no valid output if all three channels are
disabled.