PIC18F26 46 56Q83 Data Sheet 40002253C-3366868
PIC18F26 46 56Q83 Data Sheet 40002253C-3366868
Introduction
The PIC18-Q83 microcontroller family is available in 28/40/44/48-pin devices for many automotive and industrial
applications. The many communication peripherals found on the product family, such as Controller Area Network
(CAN), Serial Peripheral Interface (SPI), Inter-Integrated Circuit (I2C), two Universal Asynchronous Receiver
Transmitters (UARTs), can handle a wide range of wired and wireless (using external modules) communication
protocols for intelligent applications. Combined with the Core Independent Peripherals (CIPs) integration capabilities,
this capacity enables functions for motor control, power supply, sensor, signal and user interface applications.
Additionally, this family includes a 12-bit Analog-to-Digital Converter (ADC) with Computation and Context Switching
extensions for automated signal analysis to reduce the complexity of the application.
Numerically Controlled
Device Information Area
Temperature Indicator
Peripheral Pin Select
Vectored Interrupts
16-Bit Dual PWM/
Zero-Cross Detect
Data EEPROM
Comparator/
16-Bit Timers
Data SRAM
8-Bit DAC
Generator
Oscillator
I/O Pins/
SPI/I2C
Device
(bytes)
(bytes)
(bytes)
UART/
CAN
CCP
PIC18F26Q83 64k 8192 1024 Y/Y 25/Y 3/3 4/3 3 1 2 3 8 24 1 2/1 1 Y 2/1 3/2 8 Y Y Y Y Y Y
PIC18F46Q83 64k 8192 1024 Y/Y 36/Y 3/3 4/3 3 1 2 3 8 35 1 2/1 1 Y 2/1 3/2 8 Y Y Y Y Y Y
PIC18F56Q83 64k 8192 1024 Y/Y 44/Y 3/3 4/3 3 1 2 3 8 43 1 2/1 1 Y 2/1 3/2 8 Y Y Y Y Y Y
Features
• C Compiler Optimized RISC Architecture
• Operating Speed:
– DC – 64 MHz clock input
– 62.5 ns minimum instruction cycle
• Eight Direct Memory Access (DMA) Controllers:
– Data transfers to SFR/GPR spaces from either Program Flash Memory, Data EEPROM or SFR/GPR
spaces
– User-programmable source and destination sizes
– Hardware and software triggered data transfers
• Vectored Interrupt Capability:
– Selectable high/low priority
– Fixed interrupt latency of three instruction cycles
– Programmable vector table base address
– Backwards compatible with previous interrupt capabilities
• 128-Level Deep Hardware Stack
• Low-Current Power-on Reset (POR)
• Configurable Power-up Timer (PWRT)
• Brown-out Reset (BOR)
• Low-Power BOR (LPBOR) Option
• Windowed Watchdog Timer (WWDT):
– Watchdog Reset on too long or too short interval between watchdog clear events
– Variable prescaler selection
– Variable window size selection
Memory
Operating Characteristics
Power-Saving Functionality
• Doze: CPU and Peripherals Running at Different Cycle Rates (Typically CPU Is Lower)
• Idle: CPU Halted While Peripherals Operate
• Sleep: Lowest Power Consumption
• Peripheral Module Disable (PMD):
– Ability to selectively disable hardware module to minimize active power consumption of unused peripherals
• Low Power Mode Features:
– Sleep: < 1 µA typical @ 3V
– Operating current:
• 48 µA @ 32 kHz, 3V, typical
Digital Peripherals
• Four 16-Bit Pulse-Width Modulators (PWM):
– Dual outputs for each PWM module
– Integrated 16-bit timer/counter
– Double-buffered user registers for duty cycles
– Right/Left/Center/Variable Aligned modes of operation
– Multiple clock and Reset signal selections
• Three 16-Bit Timers (TMR0/1/3)
• Three 8-Bit Timers (TMR2/4/6) with Hardware Limit Timer (HLT)
• Two Universal Timers (TMRU16A/16B):
– New Timer modules with features of TMR0/TMR1/TMR2 (Gate, Hardware Limit)
– Two 16-bit timers can be chained together to create a combined 32-bit timer
• Eight Configurable Logic Cell (CLC):
– Integrated combinational and sequential logic
• Three Complimentary Waveform Generators (CWG):
– Rising and falling edge dead-band control
– Full-bridge, half-bridge, 1-channel drive
– Multiple signal sources
– Programmable dead band
– Fault-shutdown input
• Three Capture/Compare/PWM (CCP) Modules:
– 16-bit resolution for Capture/Compare modes
– 10-bit resolution for PWM mode
• Three Numerically Controlled Oscillators (NCO):
– Generates true linear frequency control and increased frequency resolution
– Input clock up to 64 MHz
• Signal Measurement Timer (SMT):
– 24-bit timer/counter with prescaler
– Several modes of operation such as Time-of-Flight, Period and Duty Cycle measurement, etc.
• Data Signal Modulator (DSM):
– Multiplex two carrier clocks, with glitch prevention feature
– Multiple sources for each carrier
• Programmable CRC with Memory Scan:
– Reliable data/program memory monitoring for Fail-Safe operation (e.g., Class B)
– Calculate 16-bit CRC over any portion of Program Flash Memory
• CAN Module:
Analog Peripherals
• Analog-to-Digital Converter with Computation and Context Switching:
– Up to 43 external channels
– Automated math functions on input signals:
• Averaging, filter calculations, oversampling and threshold comparison
– Four Separate Contexts (settings and results) saved and accessible separately
– Contexts can be accessed through firmware or DMA
– Operates in Sleep
– Five internal analog channels
– Hardware Capacitive Voltage Divider (CVD) Support:
• Adjustable sample and hold capacitor array
• Guard ring digital output drive
• Automates touch sampling and reduces software size and CPU usage when touch or proximity
sensing is required
• 8-Bit Digital-to-Analog Converter (DAC):
– Buffered output available on two I/O pins
– Internal connections to ADC and Comparators
• Two Comparators (CMP):
– Four external inputs
– Configurable output polarity
– External output via Peripheral Pin Select
• Zero-Cross Detect (ZCD):
– Detect when AC signal on pin crosses ground
• Voltage Reference:
– Fixed Voltage Reference with 1.024V, 2.048V and 4.096V output levels
– Internal connections to ADC, Comparator and DAC
Clocking Structure
• High-Precision Internal Oscillator Block (HFINTOSC):
– Selectable frequencies up to 64 MHz
– ±1% at calibration
– Active Clock Tuning of HFINTOSC for better accuracy
• 32 kHz Low-Power Internal Oscillator (LFINTOSC)
• External 32 kHz Crystal Oscillator (SOSC)
• External High-Frequency Oscillator Block:
– Three crystal/resonator modes
– Digital Clock Input mode
– 4x PLL with external sources
• Fail-Safe Clock Monitor:
– Allows for operational recovery if external clock stops
• Oscillator Start-up Timer (OST):
– Ensures stability of crystal oscillator sources
Programming/Debug Features
• In-Circuit Serial Programming™ (ICSP™) via Two Pins
• In-Circuit Debug (ICD) with Three Breakpoints via Two Pins
• Debug Integrated On-Chip
Table of Contents
Introduction.....................................................................................................................................................1
Features......................................................................................................................................................... 1
1. Packages................................................................................................................................................ 9
2. Pin Diagrams.........................................................................................................................................10
6. Register Legend....................................................................................................................................26
7. PIC18 CPU............................................................................................................................................27
8. Device Configuration.............................................................................................................................45
9. Memory Organization............................................................................................................................68
35. UART - Universal Asynchronous Receiver Transmitter with Protocol Support................................... 598
43. ADC - Analog-to-Digital Converter with Computation and Context Module........................................ 883
Legal Notice..............................................................................................................................................1126
Trademarks...............................................................................................................................................1126
1. Packages
Table 1-1. Packages
PIC18F26Q83 ● ● ● ●
PIC18F46Q83 ● ● ●
PIC18F56Q83 ● ●
2. Pin Diagrams
Figure 2-1.
28-Pin SPDIP
28-Pin SSOP
28-Pin SOIC
MCLR/VPP/RE3 1 28 RB7/ICSPDAT
RA0 2 27 RB6/ICSPCLK
RA1 3 26 RB5
RA2 4 25 RB4
RA3 5 24 RB3
RA4 6 23 RB2
RA5 7 22 RB1
VSS 8 21 RB0
RA7 9 20 VDD
RA6 10 19 VSS
RC0 11 18 RC7
RC1 12 17 RC6
RC2 13 16 RC5
RC3 14 15 RC4
Figure 2-2.
28-Pin VQFN
RE3/MCLR/VPP
RB7/ICSPDAT
RB6/ICSPCLK
RB5
RA1
RA0
RB4
28 27 26 25 24 23 22
RA2 1 21 RB3
RA3 2 20 RB2
RA4 3 19 RB1
RA5 4 18 RB0
VSS 5 17 VDD
RA7 6 16 VSS
RA6 7 15 RC7
8 9 10 11 12 13 14
RC4
RC6
RC0
RC1
RC2
RC3
RC5
Note: It is recommended that the exposed bottom pad be connected to VSS; however, it must not be the only VSS
connection to the device.
Figure 2-3.
40-Pin PDIP
MCLR/VPP/RE3 1 40 RB7/ICSPDAT
RA0 2 39 RB6/ICSPCLK
RA1 3 38 RB5
RA2 4 37 RB4
RA3 5 36 RB3
RA4 6 35 RB2
RA5 7 34 RB1
RE0 8 33 RB0
RE1 9 32 VDD
RE2 10 31 VSS
VDD 11 30 RD7
VSS 12 29 RD6
RA7 13 28 RD5
RA6 14 27 RD4
RC0 15 26 RC7
RC1 16 25 RC6
RC2 17 24 RC5
RC3 18 23 RC4
RD0 19 22 RD3
RD1 20 21 RD2
Figure 2-4.
40-Pin VQFN
RC5
RC4
RC6
RD3
RD2
RD1
RD0
RC3
RC2
RC1
40 39 38 37 36 35 34 33 32 31
RC7 1 30 RC0
RD4 2 29 RA6
RD5 3 28 RA7
RD6 4 27 VSS
RD7 5 26 VDD
VSS 6 25 RE2
VDD 7 24 RE1
RB0 8 23 RE0
RB1 9 22 RA5
RB2 10 21 RA4
11 12 13 14 15 16 17 18 19 20
RB3
RB4
RB5
ICSPCLK/RB6
ICSPDAT/RB7
VPP/MCLR/RE3
RA0
RA1
RA2
RA3
Note: It is recommended that the exposed bottom pad be connected to VSS; however, it must not be the only VSS
connection to the device.
Figure 2-5.
44-Pin TQFP
RC6
RC5
RD3
RD2
RD1
RD0
RC3
RC2
RC1
RC4
NC
44 43 42 41 40 39 38 37 36 35 34
RC7 1 33 NC
RD4 2 32 RC0
RD5 3 31 RA6
RD6 4 30 RA7
RD7 5 29 VSS
VSS 6 28 VDD
VDD 7 27 RE2
RB0 8 26 RE1
RB1 9 25 RE0
RB2 10 24 RA5
RB3 11 23 RA4
12 13 14 15 16 17 18 19 20 21 22
NC
NC
RB4
RB5
ICSPCLK/RB6
ICSPDAT/RB7
VPP/MCLR/RE3
RA0
RA1
RA2
Figure 2-6. RA3
48-Pin VQFN
RD3
RC6
RC5
RC4
RD2
RD1
RD0
RC3
RC2
RF3
RF1
RF2
48 47 46 45 44 43 42 41 40 39 38 37
RC7 1 36 RF0
RD4 2 35 RC1
RD5 3 34 RC0
RD6 4 33 RA6
RD7 5 32 RA7
VSS 6 31 VSS
VDD 7 30 VDD
RB0 8 29 RE2
RB1 9 28 RE1
RB2 10 27 RE0
RB3 11 26 RA5
RF4 12 25 RA4
13 14 15 16 17 18 19 20 21 22 23 24
RA1
RA0
RA2
RA3
RF7
ICSPCLK/RB6
RF6
RB4
RB5
ICSPDAT/RB7
VPP/MCLR/RE3
RF5
Note: It is recommended that the exposed bottom pad be connected to VSS; however, it must not be the only VSS
connection to the device.
Figure 2-7.
48-Pin TQFP
RC6
RC5
RC4
RD3
RD1
RC3
RD2
RD0
RC2
RF3
RF1
RF2
48 47 46 45 44 43 42 41 40 39 38 37
RC7 1 36 RF0
RD4 2 35 RC1
RD5 3 34 RC0
RD6 4 33 RA6
RD7 5 32 RA7
VSS 6 31 VSS
VDD 7 30 VDD
RB0 8 29 RE2
RB1 9 28 RE1
RB2 10 27 RE0
RB3 11 26 RA5
RF4 12 25 RA4
13 14 15 16 17 18 19 20 21 22 23 24
RA1
RA0
RA3
RA2
RF7
RF6
RB4
RB5
ICSPCLK/RB6
ICSPDAT/RB7
VPP/MCLR/RE3
RF5
SOIC, VQFN
SSOP
C1IN0- CLCIN0(1)
RA0 2 27 ANA0 — — — — — — — — — IOCA0 — — — TMS —
C2IN0- CLCIN4(1)
C1IN1- CLCIN1(1)
RA1 3 28 ANA1 — — — — — — — — — IOCA1 — — — — —
C2IN1- CLCIN5(1)
DAC1OUT1
C1IN0+
RA2 4 1 ANA2 VREF- (DAC) — — — — — — — — — IOCA2 — — BOOTA2 — —
C2IN0+
VREF- (ADC)
VREF+ (DAC)
RA3 5 2 ANA3 C1IN1+ — — — — — — — — MDCARL(1) IOCA3 — — — — —
VREF+ (ADC)
(1) IOCA4
RA4 6 3 ANA4 — — — T0CKI(1) — — — SS2(1) — CTS5(1) MDCARH — — BOOTA4 — —
CLKOUT
RA6 10 7 ANA6 — — — — — — — — — CTS3(1) — IOCA6 — — — —
OSC2
Datasheet
OSC1
RA7 9 6 ANA7 — — — — — — — — — RX3(1) — IOCA7 — — — —
CLKIN
C1IN3-
RB1 22 19 ANB1 — — — — CWG2(1) — — —(4) — — IOCB1 INT1(1) — — — —
C2IN3-
C1IN2-
RB3 24 21 ANB3 — — — — — — SCK2(1) — — — IOCB3 — CANRX(1) — TDO —
C2IN2-
PIC18F26/46/56Q83
ANB4
RB4 25 22 — — — T5G(1) — — — — — CTS4(1) — IOCB4 — — — — —
ADACT(1)
CLCIN3(1)
T6IN(1) PWM3ERS(1) RX2(1)
DS40002253C-page 14
T1CKI(1)
T3CKI(1)
RC0 11 8 ANC0 — — — — — — — — — — IOCC0 — — — — SOSCO
T3G(1)
SMT1WIN(1)
and its subsidiaries
© 2020-2022 Microchip Technology Inc.
...........continued
28-
Pin
28-
16-Bit PWM/
I/O(2) SPDIP, Pin A/D Reference Comparator ZCD Timers/SMT CWG CLC SPI I2C UART DSM IOC Interrupt CAN CRC on Boot JTAG Basic
CCP
rotatethispage90
SOIC, VQFN
SSOP
SOSCIN
RC1 12 9 ANC1 — — — SMT1SIG(1) CCP2(1) — — — — — — IOCC1 — — — —
SOSCI
PWMIN0(1)
RC2 13 10 ANC2 — — — T5CKI(1) — — — — — — IOCC2 — — — — —
CCP1(1)
RTS1
CWG1A
TX1
Datasheet
CWG1B
PWM11 DTR2
CWG1C CLC1OUT
PWM12 RTS2
CWG1D CLC2OUT SS1
PWM21 TX2
CWG2A CLC3OUT SCK1
PWM22 DTR3
ADGRDA C1OUT CWG2B CLC4OUT SDO1 SDA1
OUT(2) — — — — TMR0 PWM31 RTS3 DSM1 — — CANTX — — —
ADGRDB C2OUT CWG2C CLC5OUT SS2 SCL1
PWM32 TX3
CWG2D CLC6OUT SCK2
CCP1 DTR4
CWG3A CLC7OUT SDO2
CCP2 RTS4
CWG3B CLC8OUT
PIC18F26/46/56Q83
CCP3 TX4
CWG3C
DTR5
CWG3D
RTS5
Notes:
1. This is a PPS remappable input signal. The input function may be moved from the default location shown to one of several other PORTx pins. Refer to the peripheral input selection table for details on which PORT pins may be used for this signal.
DS40002253C-page 15
2. All output signals shown in this row are PPS remappable. These signals may be mapped to output onto one of several PORTx pin options as described in the peripheral output selection table.
3. This is a bidirectional signal. For normal module operation, the firmware needs to map this signal to the same pin in both the PPS input and PPS output registers.
4. These pins are configured for I2C logic levels; The SCLx/SDAx signals may be assigned to any of these pins. PPS assignments to the other pins (e.g., RB1) will operate, but input logic levels will be standard TTL/ST as selected by the INLVL register, instead of
the I2C specific or SMBus input buffer thresholds.
5. A 0.1 uF bypass capacitor to VSS is required on the VDD pin.
and its subsidiaries
© 2020-2022 Microchip Technology Inc.
48-
40- 40- 44- Pin 16-Bit CRC
Pin Pin Pin Timers/SM
I/O(2) A/D Reference Comparator ZCD PWM/ CWG CLC SPI I2C UART DSM IOC Interrupt CAN on JTAG Basic
TQFP / T
rotatethispage90
C1IN0- CLCIN0(1)
RA0 2 17 19 21 ANA0 — — — — — — — — — IOCA0 — — — TMS —
C2IN0- CLCIN4(1)
C1IN1- CLCIN1(1)
RA1 3 18 20 22 ANA1 — — — — — — — — — IOCA1 — — — — —
C2IN1- CLCIN5(1)
DAC1OUT1
VREF- C1IN0+
RA2 4 19 21 23 ANA2 (DAC) — — — — — — — — — IOCA2 — — BOOTA2 — —
C2IN0+
VREF-
(ADC)
VREF+
(DAC)
RA3 5 20 22 24 ANA3 C1IN1+ — — — — — — — — MDCARL(1) IOCA3 — — — — —
VREF+
(ADC)
(1) IOCA4
Datasheet
CLKOUT
RA6 14 29 31 33 ANA6 — — — — — — — — — CTS3(1) — IOCA6 — — — —
OSC2
OSC1
RA7 13 28 30 32 ANA7 — — — — — — — — — RX3(1) — IOCA7 — — — —
CLKIN
PIC18F26/46/56Q83
C1IN3-
RB1 34 9 9 9 ANB1 — — — — CWG2(1) — — —(4) — — IOCB1 INT1(1) — — — —
C2IN3-
C1IN2-
RB3 36 11 11 11 ANB3 — — — — — — SCK2(1) — — — IOCB3 — — — TDO —
C2IN2-
DS40002253C-page 16
ANB4
RB4 37 12 14 16 — — — T5G(1) — — — — — CTS4(1) — IOCB4 — — — — —
ADACT(1)
...........continued
48-
40- 40- 44- Pin 16-Bit CRC
Pin Pin Pin Timers/SM
I/O(2) A/D Reference Comparator ZCD PWM/ CWG CLC SPI I2C UART DSM IOC Interrupt CAN on JTAG Basic
TQFP / T
rotatethispage90
CLCIN3(1)
RB7 40 15 17 19 ANB7 DAC1OUT2 — — T6IN(1) PWM3ERS(1) — — — RX2(1) — IOCB7 — — — — ICSPDAT
CLCIN7(1)
T1CKI(1)
T3CKI(1)
RC0 15 30 32 34 ANC0 — — — — — — — — — — IOCC0 — — — — SOSCO
T3G(1)
SMT1WIN(1)
SOSCIN
RC1 16 31 35 35 ANC1 — — — SMT1SIG(1) CCP2(1) — — — — — — IOCC1 — — — —
SOSCI
PWMIN0(1)
RC2 17 32 36 40 ANC2 — — — T5CKI(1) — — — — — — IOCC2 — — — — —
CCP1(1)
PIC18F26/46/56Q83
RD6 29 4 4 4 AND6 — — — — — — — — — — — — — — — — —
RD7 30 5 5 5 AND7 — — — — — — — — — — — — — — — — —
RE0 8 23 25 27 ANE0 — — — — — — — — — — — — — — — — —
MCLR
RF0 — — — 36 ANF0 — — — — — — — — — — — — — — — — —
RF1 — — — 37 ANF1 — — — — — — — — — — — — — — — — —
RF2 — — — 38 ANF2 — — — — — — — — — — — — — — — —
RF3 — — — 39 ANF3 — — — — — — — — — — — — — — — —
RF4 — — — 12 ANF4 — — — — — — — — — — — — — — — —
RF5 — — — 13 ANF5 — — — — — — — — — — — — — — — —
and its subsidiaries
© 2020-2022 Microchip Technology Inc.
...........continued
48-
40- 40- 44- Pin 16-Bit CRC
Pin Pin Pin Timers/SM
I/O(2) A/D Reference Comparator ZCD PWM/ CWG CLC SPI I2C UART DSM IOC Interrupt CAN on JTAG Basic
TQFP / T
rotatethispage90
RF6 — — — 14 ANF6 — — — — — — — — — — — — — — — —
RF7 — — — 15 ANF7 — — — — — — — — — — — — — — — —
VSS 12, 31 6, 27 6, 29 6,31 — — — — — — — — — — — — — — — — — VSS
VDD(5) 11, 32 7, 26 7, 28 7, 30 — — — — — — — — — — — — — — — — — VDD(5)
DTR1
RTS1
CWG1A
TX1
CWG1B
PWM11 DTR2
CWG1C CLC1OUT
PWM12 RTS2
CWG1D CLC2OUT SS1
PWM21 TX2
CWG2A CLC3OUT SCK1
PWM22 DTR3
ADGRDA C1OUT CWG2B CLC4OUT SDO1 SDA1
OUT(2) — — TMR0 PWM31 RTS3 DSM1 — — — — — —
ADGRDB C2OUT CWG2C CLC5OUT SS2 SCL1
PWM32 TX3
CWG2D CLC6OUT SCK2
CCP1 DTR4
Datasheet
TX5
Notes:
PIC18F26/46/56Q83
1. This is a PPS remappable input signal. The input function may be moved from the default location shown to one of several other PORTx pins. Refer to the peripheral input selection table for details on which PORT pins may
be used for this signal.
2. All output signals shown in this row are PPS remappable. These signals may be mapped to output onto one of several PORTx pin options as described in the peripheral output selection table.
VDD C2
R1
VDD
VSS
R2
MCLR
C1
PIC® MCU
VSS
Key:
C1: 0.1 F, 20V ceramic (recommended)
R1: 10 kΩ (recommended)
R2: 100Ω to 470Ω (recommended)
C2: 0.1 F, 20V ceramic (required)
• Handling high-frequency noise: If the board is experiencing high-frequency noise (upward of tens of MHz),
add a second ceramic type capacitor in parallel to the above described decoupling capacitor. The value of the
second capacitor can be in the range of 0.01 μF to 0.001 μF. Place this second capacitor next to each primary
decoupling capacitor. In high-speed circuit designs, consider implementing a decade pair of capacitances as
close to the power and ground pins as possible (e.g., 0.1 μF in parallel with 0.001 μF).
• Maximizing performance: On the board layout from the power supply circuit, run the power and return traces to
the decoupling capacitors first, and then to the device pins. This ensures that the decoupling capacitors are first
in the power chain. Equally important is to keep the trace length between the capacitor and the power pins to a
minimum, thereby reducing PCB trace inductance.
R1
R2
MCLR
PIC® MCU
JP
C1
Notes:
1. R1 ≤ 10 kΩ is recommended. A suggested starting value is 10 kΩ. Ensure that the MCLR pin VIH and VIL
specifications are met.
2. R2 ≤ 470Ω will limit any current flowing into MCLR from the extended capacitor, C1, in the event of MCLR pin
breakdown, due to Electrostatic Discharge (ESD) or Electrical Overstress (EOS). Ensure that the MCLR pin
VIH and VIL specifications are met.
Pull-up resistors, series diodes and capacitors on the ICSPCLK and ICSPDAT pins are not recommended as they
can interfere with the programmer/debugger communications to the device. If such discrete components are an
application requirement, they need to be removed from the circuit during programming and debugging. Alternatively,
refer to the AC/DC characteristics and timing requirements information in the respective device Flash programming
specification for information on capacitive loading limits, and pin input voltage high (VIH) and input low (VIL)
requirements.
For device emulation, ensure that the “Communication Channel Select” (i.e., ICSPCLK/ICSPDAT pins), programmed
into the device, matches the physical connections for the ICSP to the Microchip debugger/emulator tool.
In planning the application’s routing and I/O assignments, ensure that adjacent PORT pins, and other signals in close
proximity to the oscillator, are benign (i.e., free of high frequencies, short rise and fall times, and other similar noise).
For additional information and design guidance on oscillator circuits, refer to these Microchip application notes,
available at the corporate website (www.microchip.com):
®
• AN826, “Crystal Oscillator Basics and Crystal Selection for rfPIC™ and PICmicro Devices”
®
• AN849, “Basic PICmicro Oscillator Design”
®
• AN943, “Practical PICmicro Oscillator Analysis and Design”
• AN949, “Making Your Oscillator Work”
BCF ADCON2,ADMD2
BCF ADCON2,ADMD1
BSF ADCON2,ADMD0
6. Register Legend
Table 6-1. Register Legend
Symbol Definition
R Readable bit
W Writable bit
HS Hardware settable bit
HC Hardware clearable bit
S Set only bit
C Clear only bit
U Unimplemented bit, read as ‘0’
7. PIC18 CPU
This family of devices contains a PIC18 8-bit CPU core based on the modified Harvard architecture. The PIC18 CPU
supports:
• System arbitration which decides memory access allocation depending on user priorities
• Vectored interrupt capability with automatic two-level deep context saving
• 127-level deep hardware stack with overflow and underflow Reset capabilities
• Support Direct, Indirect, and Relative Addressing modes
• 8x8 hardware multiplier
Figure 7-1. Family Block Diagram
Table Pointer
inc/dec logic
PCLATU PCLATH
Data Latch
PCU PCH PCL
Program Counter Data Memory
Address Latch
128-Level Stack
Address Latch Data Address
STKPTR
Program Memory
BSR FSR0 Access
FSR1 Bank
Data Latch
FSR2
inc/dec
Table Latch logic
Data Bus
Instruction Address
Instruction Bus Decode
Latch
BITOP W
ALU
selections default to the lowest priority configuration. If the same value is in two or more Priority registers, priority is
given to the higher-listed selection according to the following table.
Table 7-1. Default Priorities
Memory
Program Flash
CPU Access Scanner Data EEPROM
Memory
NVMCON
SFR/GRP
DMA 1 DMA 2 ....... DMA n
SRAM Data
Legend
Program Flash Memory Data
Data EEPROM Data
SFR/GPR Data
7.2.4 Peripheral 1 Priority > ISR Priority > Main Priority > Peripheral 2 Priority
In this case, the Peripheral 1 will stall the execution of the CPU. However, Peripheral 2 can access the memory in
cycles unused by Peripheral 1, ISR and the Main Routine.
Program Time
Cycles
Routine Multiply Method Memory
(Max) @ 64 MHz @ 40 MHz @ 10 MHz @ 4 MHz
(Words)
Without hardware multiply 13 69 4.3 μs 6.9 μs 27.6 μs 69 μs
8x8 unsigned
Hardware multiply 1 1 62.5 ns 100 ns 400 ns 1 μs
Without hardware multiply 33 91 5.7 μs 9.1 μs 36.4 μs 91 μs
8x8 signed
Hardware multiply 6 6 375 ns 600 ns 2.4 μs 6 μs
Without hardware multiply 21 242 15.1 μs 24.2 μs 96.8 μs 242 μs
16x16 unsigned
Hardware multiply 28 28 1.8 μs 2.8 μs 11.2 μs 28 μs
Without hardware multiply 52 254 15.9 μs 25.4 μs 102.6 μs 254 μs
16x16 signed
Hardware multiply 35 40 2.5 μs 4.0 μs 16.0 μs 40 μs
7.3.1 Operation
Example 7-3 shows the instruction sequence for an 8x8 unsigned multiplication. Only one instruction is required
when one of the arguments is already loaded in the WREG register. Example 7-4 shows the sequence to do an 8x8
signed multiplication. To account for the sign bits of the arguments, each argument’s Most Significant bit (MSb) is
tested and the appropriate subtractions are done.
MOVF ARG1, W ;
MOVF ARG1, W
MULWF ARG2 ; ARG1 * ARG2 -> PRODH:PRODL
BTFSC ARG2, SB ; Test Sign Bit
SUBWF PRODH, F ; PRODH = PRODH - ARG1
MOVF ARG2, W
BTFSC ARG1, SB ; Test Sign Bit
SUBWF PRODH, F ; PRODH = PRODH - ARG2
RES3: RES0 = ARG1H: ARG1L • ARG2H: ARG2L = ARG1H • ARG2H • 216 + ARG1H • ARG2L • 28
+ ARG1L • ARG2H • 28 + ARG1L • ARG2L
MOVF ARG1L, W
MULWF ARG2L ; ARG1L * ARG2L → PRODH:PRODL
MOVFF PRODH, RES1 ;
MOVFF PRODL, RES0 ;
;
MOVF ARG1H, W ;
MULWF ARG2H ; ARG1H * ARG2H → PRODH:PRODL
MOVFF PRODH, RES3 ;
MOVFF PRODL, RES2 ;
;
MOVF ARG1L, W
MULWF ARG2H ; ARG1L * ARG2H → PRODH:PRODL
MOVF PRODL, W ;
ADDWF RES1, F ; Add cross products
MOVF PRODH, W ;
ADDWFC RES2, F ;
CLRF WREG ;
ADDWFC RES3, F ;
;
MOVF ARG1H, W ;
MULWF ARG2L ; ARG1H * ARG2L → PRODH:PRODL
MOVF PRODL, W ;
ADDWF RES1, F ; Add cross products
MOVF PRODH, W ;
ADDWFC RES2, F ;
CLRF WREG ;
ADDWFC RES3, F ;
RES3: RES0 = ARG1H: ARG1L • ARG2H: ARG2L = ARG1H • ARG2H • 216 + ARG1H • ARG2L • 28
+ ARG1L • ARG2H • 28 + ARG1L • ARG2L + − 1 • ARG2H < 7 > • ARG1H: ARG1L • 216 +
− 1 • ARG1H < 7 > • ARG2H: ARG2L • 216
MOVF ARG1L, W
MULW ARG2L ; ARG1L * ARG2L → PRODH:PRODL
MOVF PRODH, RES1 ;
MOVFF PRODL, RES0 ;
;
MOVF ARG1H, W
MULWF ARG2H ; ARG1H * ARG2H → PRODH:PRODL
MOVFF PRODH, RES3 ;
MOVFF PRODL, RES2 ;
;
MOVF ARG1L, W
MULWF ARG2H ; ARG1L * ARG2H → PRODH:PRODL
MOVF PRODL, W ;
ADDWF RES1, F ; Add cross products
MOVF PRODH, W ;
ADDWFC RES2, F ;
CLRF WREG ;
ADDWFC RES3, F ;
;
MOVF ARG1H, W ;
MULWF ARG2L ; ARG1H * ARG2L → PRODH:PRODL
MOVF PRODL, W ;
ADDWF RES1, F ; Add cross products
MOVF PRODH, W ;
ADDWFC RES2, F ;
CLRF WREG ;
ADDWFC RES3, F ;
;
BTFSS ARG2H, 7 ; ARG2H:ARG2L neg?
BRA SIGN_ARG1 ; no, check ARG1
MOVF ARG1L, W ;
SUBWF RES2 ;
MOVF ARG1H, W ;
SUBWFB RES3
;
SIGN_ARG1:
BTFSS ARG1H, 7 ; ARG1H:ARG1L neg?
BRA CONT_CODE ; no, done
MOVF ARG2L, W ;
SUBWF RES2 ;
MOVF ARG2H, W ;
SUBWFB RES3
;
CONT_CODE:
:
Note: There are some instructions that take multiple cycles to execute. Refer to the “Instruction Set Summary”
section for details.
The CALL and GOTO instructions have the absolute program memory address embedded into the instruction. Since
instructions are always stored on word boundaries, the data contained in the instruction is a word address. The
word address is written to the corresponding bits of the Program Counter register, which accesses the desired byte
address in program memory. Instruction #2 in the example shows how the instruction GOTO 0006h is encoded in the
program memory. Program branch instructions, which encode a relative address offset, operate in the same manner.
The offset value stored in a branch instruction represents the number of single-word instructions that the PC will be
offset by.
Figure 7-4. Instructions in Program Memory
Word Address
LSB = 1 LSB = 0
Program Memory 000000h
Byte Locations 000002h
000004h
000006h
Instruction 1: MOVLW 055h 0Fh 55h 000008h
Instruction 2: GOTO 0006h EFh 03h 00000Ah
F0h 00h 00000Ch
Instruction 3: MOVFF 123h, 456h C1h 23h 00000Eh
F4h 56h 000010h
Instruction 4: MOVFFL 123h, 456h 00h 60h 000012h
F4h 8Ch 000014h
F4h 56h 000016h
000018h
00001Ah
Important: See the “PIC18 Instruction Execution and the Extended Instruction Set” section for
information on two-word instructions in the extended instruction set.
Important: The C and DC bits operate as the Borrow and Digit Borrow bits, respectively, in subtraction.
Important:
The contents of these registers need to be handled correctly to avoid erroneous code execution.
7.7.1 ISRPR
Name: ISRPR
Offset: 0x0BF
Bit 7 6 5 4 3 2 1 0
PR[2:0]
Access R/W R/W R/W
Reset 1 1 1
Value Description
111 System Arbiter Priority Level: 7 (Lowest Priority)
110 System Arbiter Priority Level: 6
101 System Arbiter Priority Level: 5
100 System Arbiter Priority Level: 4
011 System Arbiter Priority Level: 3
010 System Arbiter Priority Level: 2
001 System Arbiter Priority Level: 1
000 System Arbiter Priority Level: 0 (Highest Priority)
7.7.2 MAINPR
Name: MAINPR
Offset: 0x0BE
Bit 7 6 5 4 3 2 1 0
PR[2:0]
Access R/W R/W R/W
Reset 1 1 1
Value Description
111 System Arbiter Priority Level: 7 (Lowest Priority)
110 System Arbiter Priority Level: 6
101 System Arbiter Priority Level: 5
100 System Arbiter Priority Level: 4
011 System Arbiter Priority Level: 3
010 System Arbiter Priority Level: 2
001 System Arbiter Priority Level: 1
000 System Arbiter Priority Level: 0 (Highest Priority)
7.7.3 DMAxPR
Name: DMAxPR
Offset: 0x0B6,0x0B7,0x0B8,0x0B9,0x0BA,0x0BB,0x0BC,0x0BD
Bit 7 6 5 4 3 2 1 0
PR[2:0]
Access R/W R/W R/W
Reset 1 1 1
Value Description
111 System Arbiter Priority Level: 7 (Lowest Priority)
110 System Arbiter Priority Level: 6
101 System Arbiter Priority Level: 5
100 System Arbiter Priority Level: 4
011 System Arbiter Priority Level: 3
010 System Arbiter Priority Level: 2
001 System Arbiter Priority Level: 1
000 System Arbiter Priority Level: 0 (Highest Priority)
7.7.4 SCANPR
Name: SCANPR
Offset: 0x0B5
Bit 7 6 5 4 3 2 1 0
PR[2:0]
Access R/W R/W R/W
Reset 1 1 1
Value Description
111 System Arbiter Priority Level: 7 (Lowest Priority)
110 System Arbiter Priority Level: 6
101 System Arbiter Priority Level: 5
100 System Arbiter Priority Level: 4
011 System Arbiter Priority Level: 3
010 System Arbiter Priority Level: 2
001 System Arbiter Priority Level: 1
000 System Arbiter Priority Level: 0 (Highest Priority)
7.7.5 PRLOCK
Name: PRLOCK
Offset: 0x0B4
Bit 7 6 5 4 3 2 1 0
PRLOCKED
Access R/W
Reset 0
Important:
1. The PRLOCKED bit can only be set or cleared after the unlock sequence.
2. If the Configuration Bit PR1WAY = 1, the PRLOCKED bit cannot be cleared after it has been set. A
device Reset will clear the bit and allow one more set.
7.7.6 PROD
Name: PROD
Offset: 0x4F3
Timer Register
Product Register Pair
Bit 15 14 13 12 11 10 9 8
PROD[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
PROD[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• PRODH: Accesses the high byte PROD[15:8]
• PRODL: Accesses the low byte PROD[7:0]
7.7.7 STATUS
Name: STATUS
Offset: 0x4D8
STATUS Register
Bit 7 6 5 4 3 2 1 0
TO PD N OV Z DC C
Access R R R/W R/W R/W R/W R/W
Reset 1 1 0 0 0 0 0
Bit 6 – TO Time-Out
Reset States: POR/BOR = 1
All Other Resets = q
Value Description
1 Set at power-up or by execution of the CLRWDT or SLEEP instruction
0 A WDT time-out occurred
Bit 5 – PD Power-Down
Reset States: POR/BOR = 1
All Other Resets = q
Value Description
1 Set at power-up or by execution of the CLRWDT instruction
0 Cleared by execution of the SLEEP instruction
Bit 4 – N Negative
Used for signed arithmetic (two’s complement); indicates if the result is negative (ALU MSb = 1).
Reset States: POR/BOR = 0
All Other Resets = u
Value Description
1 The result is negative
0 The result is positive
Bit 3 – OV Overflow
Used for signed arithmetic (two’s complement); indicates an overflow of the 7-bit magnitude, which causes the sign
bit (bit 7) to change state.
Reset States: POR/BOR = 0
All Other Resets = u
Value Description
1 Overflow occurred for current signed arithmetic operation
0 No overflow occurred
Bit 2 – Z Zero
Reset States: POR/BOR = 0
All Other Resets = u
Value Description
1 The result of an arithmetic or logic operation is zero
0 The result of an arithmetic or logic operation is not zero
Notes:
1. For Borrow, the polarity is reversed. A subtraction is executed by adding the two’s complement of the second
operand.
2. For Rotate (RRCF, RLCF) instructions, this bit is loaded with either the high or low-order bit of the Source
register.
0x00
... Reserved
0xB3
0xB4 PRLOCK 7:0 PRLOCKED
0xB5 SCANPR 7:0 PR[2:0]
0xB6 DMA1PR 7:0 PR[2:0]
0xB7 DMA2PR 7:0 PR[2:0]
0xB8 DMA3PR 7:0 PR[2:0]
0xB9 DMA4PR 7:0 PR[2:0]
0xBA DMA5PR 7:0 PR[2:0]
0xBB DMA6PR 7:0 PR[2:0]
0xBC DMA7PR 7:0 PR[2:0]
0xBD DMA8PR 7:0 PR[2:0]
0xBE MAINPR 7:0 PR[2:0]
0xBF ISRPR 7:0 PR[2:0]
0xC0
... Reserved
0x0372
0x0373 STATUS_CSHAD 7:0 TO PD N OV Z DC C
0x0374 WREG_CSHAD 7:0 WREG[7:0]
0x0375 BSR_CSHAD 7:0 BSR[5:0]
0x0376 Reserved
0x0377 STATUS_SHAD 7:0 TO PD N OV Z DC C
0x0378 WREG_SHAD 7:0 WREG[7:0]
0x0379 BSR_SHAD 7:0 BSR[5:0]
0x037A Reserved
7:0 PCLATH[7:0]
0x037B PCLAT_SHAD
15:8 PCLATU[4:0]
7:0 FSRL[7:0]
0x037D FSR0_SHAD
15:8 FSRH[5:0]
7:0 FSRL[7:0]
0x037F FSR1_SHAD
15:8 FSRH[5:0]
7:0 FSRL[7:0]
0x0381 FSR2_SHAD
15:8 FSRH[5:0]
7:0 PROD[7:0]
0x0383 PROD_SHAD
15:8 PROD[15:8]
0x0385
... Reserved
0x04D7
0x04D8 STATUS 7:0 TO PD N OV Z DC C
0x04D9
... Reserved
0x04F2
7:0 PROD[7:0]
0x04F3 PROD
15:8 PROD[15:8]
8. Device Configuration
Important: The DEBUG Configuration bit is managed automatically by device development tools
including debuggers and programmers. For normal device operation, this bit needs to be maintained as a
‘1’.
8.3 User ID
32 words in the memory space (20 0000h - 20 003Fh) are designated as ID locations where the user can store
checksum or other code identification numbers. These locations are readable and writable during normal execution.
See the “User ID, Device ID and Configuration Settings Access, DIA and DCI” section for more information on
accessing these memory locations. For more information on checksum calculation, see the “PIC18FXXQ83 Family
Programming Specification” (DS-40002137).
8.5.1 CONFIG1
Name: CONFIG1
Offset: 30 0000h
Configuration Byte 1
Bit 7 6 5 4 3 2 1 0
RSTOSC[2:0] FEXTOSC[2:0]
Access R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1
8.5.2 CONFIG2
Name: CONFIG2
Offset: 30 0001h
Configuration Byte 2
Bit 7 6 5 4 3 2 1 0
FCMENS FCMENP FCMEN JTAGEN CSWEN PR1WAY CLKOUTEN
Access R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1
Bit 7 – FCMENS Fail-Safe Clock Monitor Enable for Secondary Crystal Oscillator Enable
Value Description
1 Fail-Safe Clock Monitor enabled for Secondary Crystal; Fail-Safe timer will set the FSCMS bit and
trigger OSFIF interrupt on secondary crystal failure
0 Fail-Safe Clock Monitor disabled for Secondary Crystal
Bit 6 – FCMENP Fail-Safe Clock Monitor Enable for Primary Crystal Oscillator
Value Description
1 Fail-Safe Clock Monitor enabled for Primary Crystal Oscillator; Fail-Safe timer will set FSCMP bit and
trigger OSFIF interrupt on primary crystal failure
0 Fail-Safe Clock Monitor disabled for Primary Crystal Oscillator
8.5.3 CONFIG3
Name: CONFIG3
Offset: 30 0002h
Configuration Byte 3
Bit 7 6 5 4 3 2 1 0
BOREN[1:0] LPBOREN IVT1WAY MVECEN PWRTS[1:0] MCLRE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 1 1 1 1 1 1
8.5.4 CONFIG4
Name: CONFIG4
Offset: 30 0003h
Configuration Byte 4
Bit 7 6 5 4 3 2 1 0
XINST LVP STVREN PPS1WAY ZCD BORV[1:0]
Access R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1
Note:
1. The higher voltage setting is recommended for an operation at or above 16 MHz.
8.5.5 CONFIG5
Name: CONFIG5
Offset: 30 0004h
Configuration Byte 5
Bit 7 6 5 4 3 2 1 0
WDTE[1:0] WDTCPS[4:0]
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 1 1 1 1 1
8.5.6 CONFIG6
Name: CONFIG6
Offset: 30 0005h
Configuration Byte 6
Bit 7 6 5 4 3 2 1 0
WDTCCS[2:0] WDTCWS[2:0]
Access R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1
WDTCON1[WINDOW] at POR
Software Control of Keyed Access
WDTCWS Window Delay Window Opening
Value WINDOW Required?
Percent of Time Percent of Time
111 111 n/a 100 Yes No
110 110 n/a 100
101 101 25 75
100 100 37.5 62.5
011 011 50 50 No Yes
010 010 62.5 37.5
001 001 75 25
000 000 87.5 12.5
8.5.7 CONFIG7
Name: CONFIG7
Offset: 30 0006h
Configuration Byte 7
Bit 7 6 5 4 3 2 1 0
DEBUG SAFEN BBEN BBSIZE[2:0]
Access R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1
Notes:
1. Once protection is enabled through ICSP™ or a self-write, it can only be reset through a Bulk Erase.
2. BBSIZE[2:0] bits can only be changed when BBEN = 1. Once BBEN = 0, BBSIZE[2:0] can only be changed
through a Bulk Erase.
8.5.8 CONFIG8
Name: CONFIG8
Offset: 30 0007h
Configuration Byte 8
Bit 7 6 5 4 3 2 1 0
WRTAPP WRTSAF WRTD WRTC WRTB
Access R/W R/W R/W R/W R/W
Reset 1 1 1 1 1
Notes:
1. Once protection is enabled through ICSP™ or a self-write, it can only be reset through a Bulk Erase.
2. Applicable only if SAFEN = 0.
3. Applicable only if BBEN = 0.
8.5.9 CONFIG9
Name: CONFIG9
Offset: 30 0008h
Configuration Byte 9
Bit 7 6 5 4 3 2 1 0
ODCON BPEN BOOTPINSEL[1:0]
Access R/W R/W R/W R/W
Reset 1 1 1 1
8.5.10 CONFIG10
Name: CONFIG10
Offset: 30 0009h
Configuration Byte 10
Bit 7 6 5 4 3 2 1 0
CP
Access R/W
Reset 1
Bit 0 – CP User Program Flash Memory and Data EEPROM Code Protection(1)
Value Description
1 User Program Flash Memory and Data EEPROM code protection are disabled
0 User Program Flash Memory and Data EEPROM code protection are enabled
Note:
1. Once this bit is enabled, it can only be reset through a Bulk Erase.
8.5.11 CONFIG11
Name: CONFIG11
Offset: 30 000Ah
Configuration Byte 11
Bit 7 6 5 4 3 2 1 0
BOOTPOR COE CFGSCEN DATSCEN SAFSCEN APPSCEN BOOTCOE BOOTSCEN
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 5 – CFGSCEN Non-Boot Block Area CRC Configuration Fuse Scan Enable
Value Description
1 Non-boot block area CRC scan/calculation will not include Configuration Fuse values in its calculation
0 Non-boot block area CRC scan/calculation will include all Configuration Fuse values except
CONFIG14H-CONFIG16L in its calculation
Bit 4 – DATSCEN Non-Boot Block Area CRC Data EEPROM Scan Enable
Value Description
1 Non-boot block area CRC scan/calculation will not include Data EEPROM values in its calculation
0 Non-boot block area CRC scan/calculation will include Data EEPROM values in its calculation
Bit 3 – SAFSCEN Non-Boot Block Area CRC SAF Area Scan Enable
Value Description
1 Non-boot block area CRC scan/calculation will not include SAF area of Flash memory in its calculation
if SAF area is enabled
0 Non-boot block area CRC scan/calculation will include SAF area of Flash memory in its calculation if
SAF area is enabled
Bit 2 – APPSCEN Non-Boot Block Area CRC Application Code Area Scan Enable
Value Description
1 Non-boot block area CRC scan/calculation will not include main application code area of Flash memory
in its calculations
0 Non-boot block area CRC scan/calculation will include main application code area of Flash memory in
its calculations
The Polynomial for the CRC of the boot block segment of memory
Note: The CRC-on-boot module uses a 32-bit polynomial, as such the polynomial configuration spans from
CONFIG12 to CONFIG15, with the MSB of CONFIG12 being the XOR of polynomial term X31 and the LSB of
CONFIG15 being the XOR of polynomial term X0.
Bit 31 30 29 28 27 26 25 24
BCRCPOL[31:24]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 23 22 21 20 19 18 17 16
BCRCPOL[23:16]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 15 14 13 12 11 10 9 8
BCRCPOL[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
BCRCPOL[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
The Seed for the CRC of the boot block segment of memory
Note: The CRC-on-boot module uses a 32-bit polynomial, as such the boot block seed spans from CONFIG16 to
CONFIG19, with the MSB of CONFIG16 being the MSB of the seed and the LSB of CONFIG19 being the LSB of the
seed.
Bit 31 30 29 28 27 26 25 24
BCRCSEED[31:24]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 23 22 21 20 19 18 17 16
BCRCSEED[23:16]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 15 14 13 12 11 10 9 8
BCRCSEED[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
BCRCSEED[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
The Expected Value for the CRC of the boot block segment of memory
Note: The CRC-on-boot module uses a 32-bit polynomial, as such the expected value spans from CONFIG20 to
CONFIG23, with the MSB of CONFIG20 being the MSB of the expected value, and the LSB of CONFIG23 being the
LSB of the expected value.
Bit 31 30 29 28 27 26 25 24
BCRCERES[31:24]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 23 22 21 20 19 18 17 16
BCRCERES[23:16]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 15 14 13 12 11 10 9 8
BCRCERES[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
BCRCERES[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
The Polynomial for the CRC of the non-boot block segments of memory
Note: The CRC-on-boot module uses a 32-bit polynomial, as such the polynomial configuration spans from
CONFIG24 to CONFIG27, with the MSB of CONFIG24 being the XOR of polynomial term X31 and the LSB of
CONFIG27 being the XOR of polynomial term X0.
Bit 31 30 29 28 27 26 25 24
CRCPOL[31:24]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 23 22 21 20 19 18 17 16
CRCPOL[23:16]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 15 14 13 12 11 10 9 8
CRCPOL[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
CRCPOL[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
The Seed for the CRC of the non-boot block segments of memory
Note: The CRC-on-boot module uses a 32-bit polynomial, as such the seed spans from CONFIG28 to CONFIG31,
with the MSB of CONFIG28 being the MSB of the seed and the LSB of CONFIG31 being the LSB of the seed.
Bit 31 30 29 28 27 26 25 24
CRCSEED[31:24]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 23 22 21 20 19 18 17 16
CRCSEED[23:16]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 15 14 13 12 11 10 9 8
CRCSEED[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
CRCSEED[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
The Expected Value for the CRC of the non-boot block segments of memory
Note: The CRC-on-boot module uses a 32-bit polynomial, as such the expected value spans from CONFIG32 to
CONFIG35, with the MSB of CONFIG32 being the MSB of the expected value, and the LSB of CONFIG35 being the
LSB of the expected value.
Bit 31 30 29 28 27 26 25 24
CRCERES[31:24]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 23 22 21 20 19 18 17 16
CRCERES[23:16]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 15 14 13 12 11 10 9 8
CRCERES[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
CRCERES[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
00
... Reserved
2FFFFF
300000 CONFIG1 7:0 RSTOSC[2:0] FEXTOSC[2:0]
300001 CONFIG2 7:0 FCMENS FCMENP FCMEN JTAGEN CSWEN PR1WAY CLKOUTEN
300002 CONFIG3 7:0 BOREN[1:0] LPBOREN IVT1WAY MVECEN PWRTS[1:0] MCLRE
300003 CONFIG4 7:0 XINST LVP STVREN PPS1WAY ZCD BORV[1:0]
300004 CONFIG5 7:0 WDTE[1:0] WDTCPS[4:0]
300005 CONFIG6 7:0 WDTCCS[2:0] WDTCWS[2:0]
300006 CONFIG7 7:0 DEBUG SAFEN BBEN BBSIZE[2:0]
300007 CONFIG8 7:0 WRTAPP WRTSAF WRTD WRTC WRTB
300008 CONFIG9 7:0 ODCON BPEN BOOTPINSEL[1:0]
300009 CONFIG10 7:0 CP
30000A30
CONFIG11 7:0 BOOTPOR COE CFGSCEN DATSCEN SAFSCEN APPSCEN BOOTCOE BOOTSCEN
000A
7:0 BCRCPOL[7:0]
30000B30 CRC Boot 15:8 BCRCPOL[15:8]
000B Polynomial 23:16 BCRCPOL[23:16]
31:24 BCRCPOL[31:24]
7:0 BCRCSEED[7:0]
30000F30 15:8 BCRCSEED[15:8]
CRC Boot Seed
000F 23:16 BCRCSEED[23:16]
31:24 BCRCSEED[31:24]
7:0 BCRCERES[7:0]
30001330 CRC Boot Expected 15:8 BCRCERES[15:8]
0013 Value 23:16 BCRCERES[23:16]
31:24 BCRCERES[31:24]
7:0 CRCPOL[7:0]
30001730 15:8 CRCPOL[15:8]
CRC Polynomial
0017 23:16 CRCPOL[23:16]
31:24 CRCPOL[31:24]
7:0 CRCSEED[7:0]
30001B30 15:8 CRCSEED[15:8]
CRC Seed
001B 23:16 CRCSEED[23:16]
31:24 CRCSEED[31:24]
7:0 CRCERES[7:0]
30001F30 CRC Expected 15:8 CRCERES[15:8]
001F Value 23:16 CRCERES[23:16]
31:24 CRCERES[31:24]
8.7.1 Device ID
Name: DEVICEID
Offset: 0x3FFFFE
Device ID Register
Bit 15 14 13 12 11 10 9 8
DEV[15:8]
Access R R R R R R R R
Reset q q q q q q q q
Bit 7 6 5 4 3 2 1 0
DEV[7:0]
Access R R R R R R R R
Reset q q q q q q q q
Device Device ID
PIC18F26Q83 A306h
PIC18F46Q83 A307h
PIC18F56Q83 A308h
8.7.2 Revision ID
Name: REVISIONID
Offset: 0x3FFFFC
Revision ID Register
Bit 15 14 13 12 11 10 9 8
1010[3:0] MJRREV[5:2]
Access R R R R R R R R
Reset 1 0 1 0 q q q q
Bit 7 6 5 4 3 2 1 0
MJRREV[1:0] MNRREV[5:0]
Access R R R R R R R R
Reset q q q q q q q q
Tip: For example, the REVISIONID register value for revision B1 will be 0xA041.
0x00
... Reserved
0x3FFFFB
7:0 MJRREV[1:0] MNRREV[5:0]
0x3FFFFC REVISIONID
15:8 1010[3:0] MJRREV[5:2]
7:0 DEV[7:0]
0x3FFFFE DEVICEID
15:8 DEV[15:8]
9. Memory Organization
There are three types of memory in PIC18 microcontroller devices:
• Program Memory
• Data RAM
• Data EEPROM
In Harvard architecture devices, the data and program memories use separate buses that allow for concurrent
access of the two memory spaces. The data EEPROM, for practical purposes, can be regarded as a peripheral
device, since it is addressed and accessed through a set of control registers.
Additional detailed information on the operation of the Program Flash Memory and data EEPROM memory is
provided in the “NVM - Nonvolatile Memory Module” section.
Rev. 40-000101G
4/20/2017
Device
Address
PIC18Fx6Q83 PIC18Fx7Q83
00 0000h
to
00 3FFFh
00 4000h Program Flash
to Memory
Program Flash
00 7FFFh (32 KW)(1)
Memory
00 8000h
(64 KW)(1)
to
00 FFFFh
01 0000h
to
01 FFFFh Not
02 0000h Present(2)
Not
to
Present(2)
1F FFFFh
20 0000h
to User IDs (32 Words)(3)
20 001Fh
20 0020h
to Reserved
2B FFFFh
2C 0000h
to Device Information Area (DIA)(3)(5)
2C 00FFh
2C 0100h
to Reserved
2F FFFFh
30 0000h
to Configuration Words (3)
30 0022h
30 0023h
to Reserved
37 FFFFh
38 0000h
to Data EEPROM (1024 Bytes)
38 03FFh
38 0400h
to Reserved
3B FFFFh
3C 0000h
to Device Configuration Information(3)(4)(5)
3C 000Ah
3C 000Bh
to Reserved
3F FFFBh
3F FFFCh
to Revision ID (1 Word)(3)(4)(5)
3F FFFDh
3F FFFEh
to Device ID (1 Word)(3)(4)(5)
3F FFFFh
Note 1: Storage Area Flash is implemented as the last 128 Words of User Flash, if enabled.
2: The addresses do not roll over. The region is read as ‘0’.
3: Not code-protected.
4: Hard-coded in silicon.
5: This region cannot be written by the user and it’s not affected by a Bulk Erase.
Important: If write-protected locations are written to, memory is not changed and the WRERR bit is set.
Partition(3)
Region Address BBEN = 1 BBEN = 1 BBEN = 0 BBEN = 0
SAFEN = 1 SAFEN = 0 SAFEN = 1 SAFEN = 0
00 0000h
....
Boot Block Boot Block
Last Boot Block
Memory Address
Notes:
1. Last Boot Block address is based on BBSIZE bits. Refer to the “Device Configuration” chapter for more
details.
2. For Last Program Memory address refer the table above.
3. Refer to the “Device Configuration” chapter for BBEN and SAFEN bit definitions.
4. Storage Area Flash is implemented as the last 128 Words of user Flash memory.
STKPTR<6:0>
Top-of-Stack Registers
0000010
TOSU TOSH TOSL
00h 1Ah 34h
0000011
The STKUNF bit is set when a stack pop returns a value of ‘0’. The STKUNF bit is cleared by software or by POR.
The action that takes place when the stack becomes full depends on the state of the Stack Overflow Reset Enable
(STVREN) Configuration bit.
If STVREN is set (default) and the stack has been popped enough times to unload the stack, the next pop will return
a value of ‘0’ to the PC, it will set the STKUNF bit and a Reset will be generated. This condition can be generated by
the RETURN, RETLW and RETFIE instructions.
If STVREN is cleared, the STKUNF bit will be set, but no Reset will occur.
Important: Returning a value of ‘0’ to the PC on an underflow has the effect of vectoring the program to
the Reset vector, where the stack conditions can be verified and appropriate actions can be taken. This is
not the same as a Reset, as the contents of the SFRs are not affected.
CALL SUB1, FAST ;STATUS, WREG, BSR SAVED IN FAST REGISTER STACK
•
•
SUB1:
•
•
RETURN, FAST ;RESTORE VALUES SAVED IN FAST REGISTER STACK
routine is the ADDWF PCL instruction. The next instruction executed will be one of the RETLW nn instructions that
returns the value ‘nn’ to the calling function.
The offset value (in WREG) specifies the number of bytes that the Program Counter will advance and must be
multiples of two (LSb = 0).
In this method, only one data byte may be stored in each instruction location and room on the return address stack is
required.
...........continued
Address Range Name of Region Standard Device Information
2C003Ch-2C003Fh Unassigned (2 Words)
Notes:
1. TSLR: Address 2C0024h-2C0029h store the measurements for the low range setting of the temperature
sensor at VDD = 3V, VREF+ = 2.048V from FVR1.
2. TSHR: Address 2C002Ah-2C002Fh store the measurements for the high range setting of the temperature
sensor at VDD = 3V, VREF+ = 2.048V from FVR1.
Important: For applications that require verified unique identification, contact the Microchip Technology
sales office to create a Serialized Quick Turn Programming option.
Important: Data is stored in this address range on receiving a request from the customer. The customer
may contact the local sales representative or Field Applications Engineer, and provide them the unique
identifier information that is required to be stored in this region.
the complete DCI table address and description. The DCI holds information about the device, which is useful for
programming and Bootloader applications.
The erase size is the minimum erasable unit in the PFM, expressed as rows. The total device Flash memory capacity
is (Erase size * Number of user-erasable pages).
Table 9-3. Device Configuration Information for PIC18-Q83 Devices
Value
Address Name Description Units
PIC18F26/46/56Q83 PIC18F27/47/57Q83
3C0000h-3C0001h ERSIZ Erase page size 128 128 Words
Number of write
3C0002h-3C0003h WLSIZ 0 0 Words
latches per row
Number of user-
3C0004h-3C0005h URSIZ 256 512 Pages
erasable pages
Data EEPROM
3C0006h-3C0007h EESIZ 1024 1024 Bytes
memory size
3C0008h-3C0009h PCNT Pin count 28/40(1)/48 28/40(1)/48 Pins
Note:
1. Pin count of 40 is also used for 44-pin part.
Important: The operation of some aspects of data memory are changed when the PIC18 extended
instruction set is enabled. See the PIC18 Instruction Execution and the Extended Instruction Set section
for more information.
The data memory in PIC18 devices is implemented as static RAM. The memory space is divided into as many as 64
banks with 256 bytes each. Figure 9-3 shows the data memory organization for all devices in the device family.
The data memory contains Special Function Registers (SFRs) and General Purpose Registers (GPRs). The SFRs
are used for control and status of the controller and peripheral functions, while GPRs are used for data storage and
scratchpad operations in the user’s application. Any read of an unimplemented location will read as ‘0’.
The value in the Bank Select Register (BSR) determines which bank is being accessed. The instruction set and
architecture allow operations across all banks. The entire data memory may be accessed by Direct, Indirect or
Indexed Addressing modes. Addressing modes are discussed later in this subsection.
To ensure that commonly used registers (SFRs and select GPRs) can be accessed in a single cycle, PIC18 devices
implement an Access Bank. This is a virtual 256-byte memory space that provides fast access to SFRs and the top
half of GPR Bank 5 without using the Bank Select Register. The Access Bank section provides a detailed description
of the Access RAM.
Bank 3
through
Bank 61
3E00h 00h
Bank 62
FFh
3F00h 00h
Bank 63
3FFFh FFh
Note 1: The Access RAM bit of the instruction can be used to force an override of the selected bank (BSR value) to
the registers of the Access Bank.
The Access Bank is used by core PIC18 instructions that include the Access RAM bit (the ‘a’ parameter in the
instruction). When ‘a’ is equal to ‘1’, the instruction uses the BSR and the 8-bit address included in the opcode for the
data memory address. When ‘a’ is ‘0’, the instruction ignores the BSR and uses the Access Bank address map.
Using this “forced” addressing allows the instruction to operate on a data address in a single cycle, without updating
the BSR first. Access RAM also allows for faster and more code efficient context saving and switching of variables.
The mapping of the Access Bank is slightly different when the extended instruction set is enabled (XINST
Configuration bit = 1). This is discussed in more detail in the Mapping the Access Bank in Indexed Liberal Offset
Mode section.
Important: The execution of some instructions in the core PIC18 instruction set are changed when the
PIC18 extended instruction set is enabled. See the Data Memory and the Extended Instruction Set section
for more information.
Information in the data memory space can be addressed in several ways. For most instructions, the Addressing
mode is fixed. Other instructions may use up to three modes, depending on which operands are used and whether or
not the extended instruction set is enabled.
The Addressing modes are:
• Inherent
• Literal
• Direct
• Indirect
An additional Addressing mode, Indexed Literal Offset, is available when the extended instruction set is enabled
(XINST Configuration bit = 1). Its operation is discussed in greater detail in the Indexed Addressing with Literal Offset
section.
Instructions without the ‘d’ argument have a destination that is implicit in the instruction; their destination is either the
target register being operated on or the W register.
Data Memory
0000h 00h
Using an instruction with one of the ADDWF, INDF1, 0 Bank 0
indirect addressing registers as the FFh
0100h 00h
operand.... Bank 1
FFh
0200h 00h
Bank 2
...uses the 14-bit address stored in FSR1H:FSR1L FFh
the FSR pair associated with that 0300h
register.... 7 0 7 0
Bank 3
x x 11 1 1 1 0 1 1 0 0 1 1 0 0
through
Bank 61
Operations on the FSRs with POSTDEC, POSTINC and PREINC affect the entire register pair; that is, rollovers of
the FSRnL register from FFh to 00h carry over to the FSRnH register. On the other hand, results of these operations
do not change the value of any flags in the STATUS register (e.g., Z, N, OV, etc.).
The PLUSW register can be used to implement a form of Indexed Addressing in the data memory space. By
manipulating the value in the W register, users can reach addresses that are fixed offsets from pointer addresses. In
some applications, this can be used to implement some powerful program control structure, such as software stacks,
inside of data memory.
Addressing mode; inherent and literal instructions do not change at all. Indirect addressing with FSR0 and FSR1 also
remain unchanged.
Figure 9-6. Comparing Addressing Options for Bit-Oriented and Byte-Oriented Instructions (Extended
Instruction Set Enabled)
EXAMPLE INSTRUCTION: ADDWF, f, d, a (Opcode: 0010 01da ffff ffff)
0000h
When ‘a’ = 0 and f ≥ 60h Bank 0 - 3
+
Note that in this mode, the
correct syntax is now:
FSR2H FSR2L
3FFFh
ADDWF [k], d Data Memory
where ‘k’ is the same as ‘f’.
0000h
When ‘a’ = 1 (all values of f) Bank 0 - 3
0400h
The instruction executes in
Direct mode (also known as Bank 4
Direct Long mode). ‘f’ is inter- 0460h
Access
preted as a location in one of
04FFh SFRs
the 63 banks of the data BSR
memory space. The bank is 0000 1010
designated by the Bank Bank 10
Select Register (BSR). The Bank 5-63
address can be in any 0010 01da ffff ffff
implemented bank in the data 3FFFh
memory space. Data Memory
Figure 9-7. Remapping the Access Bank with Indexed Literal Offset Addressing
0000h
Bank 0 - 3
EXAMPLE:
ADDWF, f, d, a 0400h
Remapping of the Access Bank applies only to operations using the Indexed Literal Offset mode. Operations that use
the BSR (Access RAM bit is ‘1’) will continue to use Direct Addressing as before.
9.7.1 PCL
Name: PCL
Offset: 0x4F9
Bit 7 6 5 4 3 2 1 0
PCL[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bits 7:0 – PCL[7:0] Provides direct read and write access to the Program Counter
9.7.2 PCLAT
Name: PCLAT
Offset: 0x4FA
Program Counter Latches
Holding register for bits [21:9] of the Program Counter (PC). Reads of the PCL register transfer the upper PC bits to
the PCLAT register. Writes to PCL register transfer the PCLAT value to the PC.
Bit 15 14 13 12 11 10 9 8
PCLATU[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
PCLATH[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
9.7.3 TOS
Name: TOS
Offset: 0x4FD
Top-of-Stack Register
Contents of the stack pointed to by the STKPTR register. This is the value that will be loaded into the Program
Counter upon a RETURN or RETFIE instruction.
Bit 23 22 21 20 19 18 17 16
TOS[20:16]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
TOS[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
TOS[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• TOSU: Accesses the upper byte TOS[20:16]
• TOSH: Accesses the high byte TOS[15:8]
• TOSL: Accesses the low byte TOS[7:0]
9.7.4 STKPTR
Name: STKPTR
Offset: 0x4FC
Bit 7 6 5 4 3 2 1 0
STKPTR[6:0]
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
9.7.5 WREG
Name: WREG
Offset: 0x4E8
Bit 7 6 5 4 3 2 1 0
WREG[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
9.7.6 INDF
Name: INDFx
Offset: 0x4EF,0x4E7,0x4DF
Indirect Data Register
This is a virtual register. The GPR/SFR register addressed by the FSRx register is the target for all operations
involving the INDFx register.
Bit 7 6 5 4 3 2 1 0
INDF[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
9.7.7 POSTDEC
Name: POSTDECx
Offset: 0x4ED,0x4E5,0x4DD
Indirect Data Register with post decrement
This is a virtual register. The GPR/SFR register addressed by the FSRx register is the target for all operations
involving the POSTDECx register. FSRx is decrememted after the read or write operation.
Bit 7 6 5 4 3 2 1 0
POSTDEC[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
9.7.8 POSTINC
Name: POSTINCx
Offset: 0x4EE,0x4E6,0x4DE
Indirect Data Register with post increment
This is a virtual register. The GPR/SFR register addressed by the FSRx register is the target for all operations
involving the POSTINCx register. FSRx is incremented after the read or write operation.
Bit 7 6 5 4 3 2 1 0
POSTINC[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
9.7.9 PREINC
Name: PREINCx
Offset: 0x4EC,0x4E4,0x4DC
Indirect Data Register with pre-increment
This is a virtual register. The GPR/SFR register addressed by the FSRx register plus 1 is the target for all operations
involving the PREINCx register. FSRx is incremented before the read or write operation.
Bit 7 6 5 4 3 2 1 0
PREINC[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
9.7.10 PLUSW
Name: PLUSWx
Offset: 0x4EB,0x4E3,0x4DB
Indirect Data Register with WREG offset
This is a virtual register. The GPR/SFR register addressed by the sum of the FSRx register plus the signed value of
the W register is the target for all operations involving the PLUSWx register.
Bit 7 6 5 4 3 2 1 0
PLUSW[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
9.7.11 FSR
Name: FSRx
Offset: 0x4E9,0x4E1,0x4D9
Indirect Address Register
The FSR value is the address of the data to which the INDF register points.
Bit 15 14 13 12 11 10 9 8
FSRH[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
FSRL[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
9.7.12 BSR
Name: BSR
Offset: 0x4E0
Bank Select Register
The BSR indicates the data memory bank of the GPR address.
Bit 7 6 5 4 3 2 1 0
BSR[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bits 5:0 – BSR[5:0] Most Significant bits of the data memory address
0x00
... Reserved
0x04D8
7:0 FSRL[7:0]
0x04D9 FSR2
15:8 FSRH[5:0]
0x04DB PLUSW2 7:0 PLUSW[7:0]
0x04DC PREINC2 7:0 PREINC[7:0]
0x04DD POSTDEC2 7:0 POSTDEC[7:0]
0x04DE POSTINC2 7:0 POSTINC[7:0]
0x04DF INDF2 7:0 INDF[7:0]
0x04E0 BSR 7:0 BSR[5:0]
7:0 FSRL[7:0]
0x04E1 FSR1
15:8 FSRH[5:0]
0x04E3 PLUSW1 7:0 PLUSW[7:0]
0x04E4 PREINC1 7:0 PREINC[7:0]
0x04E5 POSTDEC1 7:0 POSTDEC[7:0]
0x04E6 POSTINC1 7:0 POSTINC[7:0]
0x04E7 INDF1 7:0 INDF[7:0]
0x04E8 WREG 7:0 WREG[7:0]
7:0 FSRL[7:0]
0x04E9 FSR0
15:8 FSRH[5:0]
0x04EB PLUSW0 7:0 PLUSW[7:0]
0x04EC PREINC0 7:0 PREINC[7:0]
0x04ED POSTDEC0 7:0 POSTDEC[7:0]
0x04EE POSTINC0 7:0 POSTINC[7:0]
0x04EF INDF0 7:0 INDF[7:0]
0x04F0
... Reserved
0x04F8
0x04F9 PCL 7:0 PCL[7:0]
7:0 PCLATH[7:0]
0x04FA PCLAT
15:8 PCLATU[4:0]
0x04FC STKPTR 7:0 STKPTR[6:0]
7:0 TOS[7:0]
0x04FD TOS 15:8 TOS[15:8]
23:16 TOS[20:16]
10.1 Operations
NVM write operations are controlled by selecting the desired action with the NVMCMD bits and then starting the
operation by executing the unlock sequence. NVM read operations are started by setting the GO bit after setting the
read operation. Available NVM operations are shown in the following table.
Table 10-1. NVM Operations
...........continued
NVMCMD Unlock Operation DFM PFM Source/Destination WRERR INT
110 Yes Erase Page — page n/a Yes Yes
111 No Reserved (No Operation) — — — No No
Important: When the GO bit is set, writes operations are blocked on all NVM registers. The GO bit is
cleared by hardware when the operation is complete. The GO bit cannot be cleared by software.
NVMLOCK = 0x55;
NVMLOCK = 0xAA;
NVMCON0bits.GO = 1;
Important: To modify only a portion of a previously programmed page, the contents of the entire page
must be read and saved in the buffer RAM prior to the page erase. The Read Page operation is the
easiest way to do this. The page needs to be erased so that the new data can be written into the buffer
RAM to reprogram the page of PFM. However, any unprogrammed locations can be written using the
single word Write operation without first erasing the page.
Disable interrupts
(GIE = 0)
Enable interrupts
(GIE = 1)
Important:
• If a write or erase operation is terminated by an unexpected Reset, the WRERR bit will be set and the
user can check to decide whether a rewrite of the location(s) is needed.
• If a write or erase operation is attempted on a write-protected area, the WRERR bit will be set.
• If a write or erase operation is attempted on an invalid address location, the WRERR bit is set. (Refer
to the Program and Data Memory Map in the “Memory Organization” chapter for more information
on valid address locations.)
Important: Individual bytes of program memory may be modified, provided that the modification does
not attempt to change any NVM bit from a ‘0’ to a ‘1’. When modifying individual bytes with a page write
operation, it is necessary to load all buffer registers with either 0xFF or the existing contents of memory
before executing a page write operation. The fastest way to do this is by performing a page read operation.
In this device a PFM page is 128 words (256 bytes). This is the same size as one bank of general purpose RAM
(GPR). This area of GPR space is dedicated as a buffer area for NVM page operations. The buffer areas for each
device in the family are shown in the following table:
Table 10-2. NVM Buffer Banks
There are several ways to address the data in the GPR buffer space:
//–––––––––––––––––––––––––––––––––––––––––––––
while (NVMCON0bits.GO); // Wait for the write operation to complete
// Verify write operation success and call the recovery function if needed
if (NVMCON1bits.WRERR){
WRITE_FAULT_RECOVERY();
}
The steps necessary to change one or more words in PFM space are as follows:
1. Set the NVMADR registers to the target address.
2. Set the NVMCMD to ‘b010 (Page Read).
3. Set the GO bit to start the PFM read into the GPR buffer.
4. Monitor the GO bit or NVMIF interrupt flag to determine when the read has completed.
5. Make the desired changes to the GPR buffer data.
6. Set NVMCMD to ‘b110 (Page Erase).
7. Disable all interrupts.
8. Perform the unlock sequence as described in the Unlock Sequence section.
9. Set the GO bit to start the PFM page erase.
10. Monitor the GO bit or NVMIF interrupt flag to determine when the erase has completed.
11. Set NVMCMD to ‘b101 (Page Write).
12. Perform the unlock sequence.
13. Set the GO bit to start the PFM page write.
14. Monitor the GO bit or NVMIF interrupt flag to determine when the write has completed.
15. Interrupts can be enabled after the GO bit is clear.
16. Set the NVMCMD control bits to ‘b000.
Start
Verify Operation
Set GO bit
NVMDAT = No
RAM image ?
Yes Fail
Verify Operation
No
Last word ?
Yes
End
Verify Operation
10.3.9 User ID, Device ID, Configuration Settings Access, DIA and DCI
The NVMADR value determines which NVM address space is accessed. The User IDs and Configuration areas allow
read and write access, whereas Device and Revision IDs are limited to read-only.
Reading and writing User ID space is identical to reading and writing PFM space as described in the preceding
paragraphs.
Writing to the Configuration bits is performed in the same manner as writing to the Data Flash Memory (DFM).
Configuration settings are modified one byte at a time with the NVM Read and Write operations. When a Write
operation is performed on a Configuration byte, an erase byte is performed automatically before the new byte is
written. Any code protection settings that are not enabled will remain not enabled after the Write operation, unless the
new values enable them. However, any code protection settings that are enabled cannot be disabled by a self-write
of the configuration space. The user can modify the configuration space by the following steps:
1. Read the target Configuration byte by setting the NVMADR with the target address.
2. Retrieve the Configuration byte with the Read operation (NVMCMD = ‘b000).
3. Modify the Configuration byte in NVMDAT register.
4. Write the NVMDAT register to the Configuration byte using the Write operation (NVMCMD = ‘b011) and
unlock sequence.
TBLRD*+
TBLWT*+ TBLPTR is incremented after the read/write
TBLRD*-
TBLWT*- TBLPTR is decremented after the read/write
TBLRD+*
TBLWT+* TBLPTR is incremented before the read/write
Instruction: TBLRD*
Program Memory
(TBLPTR)
Instruction: TBLWT*
GPR Space
Buffer RAM
Program Memory
(TBLPTR[MSbs])
Note 1: During table writes the Table Pointer does not point directly to program memory. TBLPTRL
actually points to an address within the buffer registers. TBLPTRU:TBLPTRH points to program memory
where the entire buffer space will eventually be written with the NVM commands.
Table operations work with byte entities. Tables containing data, rather than program instructions, are not required
to be word-aligned. Therefore, a table can start and end at any byte address. If a table write is being used to write
executable code into program memory, program instructions will need to be word-aligned.
Note:
1. Refer to the “Memory Organization” chapter for more details about the size of the buffer registers block.
Instruction TABLAT
FETCH TBLRD
Register (IR) Read Register
Initiate Read
(GO = 1)
Each DFM write operation includes an implicit erase cycle for that byte. CPU execution continues in parallel and at
the completion of the write cycle, the GO bit is cleared in hardware and the NVM Interrupt Flag (NVMIF) bit is set.
The user can either enable the interrupt or poll the bit. NVMIF must be cleared by software.
The sequence of events for programming one byte of DFM is:
1. Set NVMADR registers with the target byte address.
2. Load NVMDATL register with desired byte.
3. Set the NVMCMD control bits to ‘b011 (Byte Write).
4. Disable all interrupts.
5. Perform the unlock sequence as described in the Unlock Sequence section.
6. Set the GO bit to start the DFM byte write.
7. Monitor the GO bit or NVMIF interrupt flag to determine when the write has been completed.
8. Interrupts can be enabled after the GO bit is cleared.
9. Set the NVMCMD control bits to ‘b000.
// Verify byte erase operation success and call the recovery function if needed
if (NVMCON1bits.WRERR){
ERASE_FAULT_RECOVERY();
}
10.5.1 NVMCON0
Name: NVMCON0
Offset: 0x040
Bit 7 6 5 4 3 2 1 0
GO
Access R/S/HC
Reset 0
10.5.2 NVMCON1
Name: NVMCON1
Offset: 0x041
Bit 7 6 5 4 3 2 1 0
WRERR NVMCMD[2:0]
Access R/C/HS R/W R/W R/W
Reset 0 0 0 0
10.5.3 NVMLOCK
Name: NVMLOCK
Offset: 0x042
Nonvolatile Memory Write Restriction Control Register
NVM write and erase operations require writing 0x55 then 0xAA to this register immediately before the operation
execution.
Bit 7 6 5 4 3 2 1 0
NVMLOCK[7:0]
Access WO WO WO WO WO WO WO WO
Reset 0 0 0 0 0 0 0 0
10.5.4 NVMADR
Name: NVMADR
Offset: 0x043
Bit 23 22 21 20 19 18 17 16
NVMADR[21:16]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
NVMADR[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
NVMADR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• NVMADRU: Accesses the upper byte NVMADR[21:16]
• NVMADRH: Accesses the high byte NVMADR[15:8]
• NVMADRL: Accesses the low byte NVMADR[7:0]
10.5.5 NVMDAT
Name: NVMDAT
Offset: 0x046
Bit 15 14 13 12 11 10 9 8
NVMDAT[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
NVMDAT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• NVMDATH: Accesses the high byte NVMDAT[15:8]
• NVMDATL: Accesses the low byte NVMDAT[7:0]
10.5.6 TBLPTR
Name: TBLPTR
Offset: 0x4F6
Bit 23 22 21 20 19 18 17 16
TBLPTR21 TBLPTR[20:16]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
TBLPTR[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
TBLPTR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• TBLPTRU: Accesses the upper byte TBLPTR[21:16]
• TBLPTRH: Accesses the high byte TBLPTR[15:8]
• TBLPTRL: Accesses the low byte TBLPTR[7:0]
10.5.7 TABLAT
Name: TABLAT
Offset: 0x4F5
Bit 7 6 5 4 3 2 1 0
TABLAT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bits 7:0 – TABLAT[7:0] The value of the NVM memory byte returned from the address contained in TBLPTR after a
TBLRD command, or the data written to the latch by a TBLWT command.
0x00
... Reserved
0x3F
0x40 NVMCON0 7:0 GO
0x41 NVMCON1 7:0 WRERR NVMCMD[2:0]
0x42 NVMLOCK 7:0 NVMLOCK[7:0]
7:0 NVMADR[7:0]
0x43 NVMADR 15:8 NVMADR[15:8]
23:16 NVMADR[21:16]
7:0 NVMDAT[7:0]
0x46 NVMDAT
15:8 NVMDAT[15:8]
0x48
... Reserved
0x04F4
0x04F5 TABLAT 7:0 TABLAT[7:0]
7:0 TBLPTR[7:0]
0x04F6 TBLPTR 15:8 TBLPTR[15:8]
23:16 TBLPTR21 TBLPTR[20:16]
11.1 Overview
The Vectored Interrupt Controller (VIC) module reduces the numerous peripheral interrupt request signals to a single
interrupt request signal to the CPU. This module includes the following major features:
• Interrupt Vector Table (IVT) with a unique vector for each interrupt source
• Fixed and ensured interrupt latency
• Programmable base address for IVT with lock
• Two user-selectable priority levels - High priority and low priority
• Two levels of context saving
• Interrupt state Status bits to indicate the current execution status of the CPU
The VIC module assembles all of the interrupt request signals and resolves the interrupts based on both a fixed
natural order priority (i.e., determined by the IVT), and a user-assigned priority (i.e., determined by the IPRx
registers), thereby eliminating scanning of interrupt sources.
Important: It is required that the user assign an even address to IVTBASE for correct operation.
Important: If for any reason the address of the ISR cannot be fetched from the vector table, it will cause
the system to reset and clear the Memory Execution Violation flag in the Power Control register. This can
occur due to any one of the following:
• The entry for the interrupt in the vector table lies outside the executable program memory area
• ISR pointed by the vector table lies outside the executable program memory area
; Disable Interrupts:
BCF INTCON0, GIE;
; Enable Interrupts
BSF INTCON0, GIE;
The user must follow the following sequence to set the IVTLOCKED bit.
; Disable Interrupts:
BCF INTCON0, GIE;
; Enable Interrupts
BSF INTCON0, GIE;
When the IVT1WAY Configuration bit is set, the IVTLOCKED bit can be cleared and set only once after a device
Reset. The unlock operation will have no effect after the lock sequence is used to set the IVTLOCKED bit. Unlocking
is inhibited until a system Reset occurs.
Important:
1. When a high-priority interrupt preempts a concurrent low-priority interrupt, GIEL may be cleared in
the high-priority Interrupt Service Routine. If GIEL is cleared, the low-priority interrupt will NOT be
serviced, even if it was originally requested. The corresponding interrupt flag needs to be cleared in
user code.
2. When a high-priority interrupt is requested while a low-priority Interrupt Service Routine is
executing, GIEL may be cleared in the high-priority Interrupt Service Routine. The pending low-
priority interrupt will resume, even if GIEL is cleared.
...........continued
Vector Interrupt
Vector Interrupt Number source
Number source
(cont.) (cont.)
0x8 INT0 0x48 U3RX
0x9 ZCD (Zero-Cross Detection) 0x49 U3TX
0xA AD (ADC Conversion Complete) 0x4A U3E
0xB ACT (Active Clock Tuning) 0x4B U3
0xC CM1 (Comparator) 0x4C —
0xD SMT1 (Signal Measurement Timer) 0x4D CLC4
0xE SMT1PRA 0x4E PWM4RINT
0xF SMT1PWA 0x4F PWM4GINT
0x10 ADT/ADCH1 (ADC Context 1) 0x50 INT2
0x11 ADCH2 (ADC Context 2) 0x51 CLC5
0x12 ADCH3 (ADC Context 3) 0x52 CWG2 (Complementary Waveform Generator)
0x13 ADCH4 (ADC Context 4) 0x53 NCO2
0x14 DMA1SCNT (Direct Memory Access) 0x54 DMA3SCNT
0x15 DMA1DCNT 0x55 DMA3DCNT
0x16 DMA1OR 0x56 DMA3OR
0x17 DMA1A 0x57 DMA3A
0x18 SPI1RX (Serial Peripheral Interface) 0x58 CCP3
0x19 SPI1TX 0x59 CLC6
0x1A SPI1 0x5A CWG3
0x1B TMR2 0x5B TMR4
0x1C TMR1 0x5C DMA4SCNT
0x1D TMR1G 0x5D DMA4DCNT
0x1E CCP1 (Capture/Compare/PWM) 0x5E DMA4OR
0x1F TMR0 0x5F DMA4A
0x20 U1RX 0x60 U4RX
0x21 U1TX 0x61 U4TX
0x22 U1E 0x62 U4E
0x23 U1 0x63 U4
0x24 CANRX (CAN receive) 0x64 DMA5SCNT
0x25 CANTX (CAN transmit) 0x65 DMA5DCNT
0x26 PWM1RINT 0x66 DMA5OR
0x27 PWM1GINT 0x67 DMA5A
0x28 SPI2RX 0x68 U5RX
0x29 SPI2TX 0x69 U5TX
0x2A SPI2 0x6A U5E
0x2B TU16B (Universal Timer 16B) 0x6B U5
0x2C TMR3 0x6C DMA6SCNT
0x2D TMR3G 0x6D DMA6DCNT
0x2E PWM2RINT 0x6E DMA6OR
0x2F PWM2GINT 0x6F DMA6A
0x30 INT1 0x70 —
0x31 CLC2 0x71 CLC7
0x32 CWG1 (Complementary Waveform Generator) 0x72 CM2
...........continued
Vector Interrupt
Vector Interrupt Number source
Number source
(cont.) (cont.)
0x33 NCO1 (Numerically Controlled Oscillator) 0x73 NCO3
0x34 DMA2SCNT 0x74 DMA7SCNT
0x35 DMA2DCNT 0x75 DMA7DCNT
0x36 DMA2OR 0x76 DMA7OR
0x37 DMA2A 0x77 DMA7A
0x38 I2C1RX 0x78 NVM
0x39 I2C1TX 0x79 CLC8
0x3A I2C1 0x7A CRC (Cyclic Redundancy Check)
0x3B I2C1E 0x7B TMR6
0x3C — 0x7C DMA8SCNT
0x3D CLC3 0x7D DMA8DCNT
0x3E PWM3RINT 0x7E DMA8OR
0x3F PWM3GINT 0x7F DMA8A
0x80 - 0x8F —
The natural order priority scheme goes from high-to-low with increasing vector numbers, with 0 being the highest
priority and decreasing from there.
For example, when two concurrently occurring interrupt sources that are both designated high priority, using the IPRx
register will be resolved using the natural order priority (i.e., the interrupt with a lower corresponding vector number
will preempt the interrupt with the higher vector number).
The ability for the user to assign every interrupt source to high- or low-priority levels means that the user program can
give an interrupt with a low natural priority, a higher overall priority level.
Important: The state of GIEH/L is not changed by the hardware when servicing an interrupt. The internal
state machine is used to keep track of execution states. These bits can be manipulated in the user code,
resulting in transferring execution to the main routine and ignoring existing interrupts.
Rev. 10-000265A
7/6/2016
MAIN
INTSTAT = 00
11.5.1 Serving a High- or Low-Priority Interrupt While the Main Routine Code Is Executing
When a high- or low-priority interrupt is requested while the main routine code is executing, the main routine
execution is halted and the ISR is addressed. Upon a return from the ISR (by executing the RETFIE instruction), the
main routine resumes execution.
Figure 11-2. Interrupt Execution: High/Low-Priority Interrupt While Executing Main Routine
Rev. 10-000267A
9/12/2016
RETFIE Executed
Main Code Main Code Executing Main Code Execution Halted Main Code Executing
Interrupt
Interrupt Interrupt
received cleared
If any other high-priority interrupts are pending and enabled, they are serviced before servicing the pending low-
priority interrupt. If no other high-priority interrupt requests are active, the low-priority interrupt is serviced.
Figure 11-3. Interrupt Execution: High-Priority Interrupt with a Low-Priority Interrupt Pending
Rev. 10-000267C
9/12/2016
Main Code Main routine Main Code Execution Halted Main routine
High Priority
Interrupt
High Interrupt High Interrupt
received cleared
Low Priority
Interrupt
Low Interrupt Low Interrupt
received cleared
Rev. 10-000267B
9/12/2016
Main Code Main routine Main Code Execution Halted Main routine
High Priority
Interrupt
High Interrupt High Interrupt
received cleared
Low Priority
Interrupt
Low Interrupt Low Interrupt
received cleared
Rev. 10-000267D
9/12/2016
Main Code Main routine Main Code Execution Halted Main routine
High Priority
Interrupt
High Interrupt High Interrupt
received cleared
Low Priority
Interrupt
Low Interrupt Low Interrupt
received cleared
Rev. 10-000266A
7/6/2016
MAIN
INTSTAT = 00
No Context Save/Restore
No Context HIGH LOW No Context
Save/Restore INTSTAT = 10 INTSTAT = 01 Save/Restore
No Context Save/Restore
1 2 3 4 5 6 7 8 9 10
System
Clock
Program
X X+2 X+2 0x82 0x218 0x21A 0x21C X+2 X+4 X+6
Counter
Instruction
Inst @ X(1) FNOP FNOP FNOP Inst @ 0x218 Inst @ 0x21A FNOP Inst @ X+2 Inst @ X+4
Register
BCF RETFIE
Interrupt
IVTBASE 0x80
Vector
1
Number
Program Memory
0x86
0x82
1 2 3 4 5 6 7 8 9 10 11
System
Clock
Program
Y Y+2 Y+2 Y+2 0x82 0x218 0x21A 0x21C Y+2 Y+4 Y+6
Counter
Instruction
Inst @ Y(1) Inst @ Y(1) FNOP FNOP FNOP Inst @ 0x218 Inst @ 0x21A FNOP Inst @ Y+2 Inst @ Y+4
Register
BCF RETFIE
Interrupt
IVTBASE 0x80
Vector
1
Number
Program Memory
0x86
0x82
1 2 3 4 5 6 7 8 9 10 11 12
System
Clock
Program
Z Z+2 Z+2 Z+2 Z+2 0x82 0x218 0x21A 0x21C Z+2 Z+4 Z+6
Counter
Instruction Inst @ Inst @
Inst @ Z(1) Inst @ Z(1) Inst @ Z(1) FNOP FNOP FNOP FNOP Inst @ Z+2 Inst @ Z+4
Register 0x218 0x21A
BCF RETFIE
Interrupt
IVTBASE 0x80
Vector
1
Number
Program Memory
0x86
0x82
1 2 3 4 5
Instruction
Clock
Program
X X+2 X+2 X+4 X+6
Counter
Instruction
Inst @ X(1) FNOP Inst @ X+2 Inst @ X+4
Register
Interrupt
Note: 1. Inst @ X clears the interrupt flag, Example BCF INTCON0, GIE.
Important: At a device Reset, the IPRx registers are initialized such that all user interrupt sources
are assigned to high priority.
2. Clear the Interrupt Flag Status bit associated with the peripheral in the associated PIRx STATUS register.
3. Enable the interrupt source by setting the interrupt enable control bit associated with the source in the
appropriate PIEx register.
4. If the vector table is used (MVECEN = 1), then set up the start address for the Interrupt Vector Table using
IVTBASE. See the Interrupt Vector Table Contents section for more details.
5. Once IVTBASE is written to, set the interrupt enable bits in INTCON0.
6. An example of setting up interrupts and ISRs using assembly and C can be found in Example 11-3 and
Example 11-4.
; Each ISR routine must have a predetermined origin otherwise there will be
; an assembly error because the address is not determined until link time
; which is too late to do the divide by 4 math on the address.
; Predetermined addresses must be evenly divisible by 4.
IntInit:
; Disable all interrupts
BCF INTCON0, GIE, ACCESS
; Enable interrupts
BANKSEL PIE0
BSF PIE0, SWIE
BSF PIE0, HLVDIE
BSF PIE0, OSFIE
; Enable interrupts
BSF INTCON0, GIEH, ACCESS
BSF INTCON0, GIEL, ACCESS
RETURN 1
// NOTE 1: If IVTBASE is changed from its default value of 0x000008, then the
// "base(...)" argument must be provided in the ISR. Otherwise the vector
// table will be placed at 0x0008 by default regardless of the IVTBASE value.
// NOTE 3: Multiple interrupts can be handled by the same ISR if they are
// specified in the "irq(...)" argument. Ex: irq(IRQ_SW, IRQ_HLVD)
When IPEN is also cleared, the interrupt priority feature is disabled and interrupts are compatible with PIC16
microcontroller midrange devices. All interrupts branch to address 0008h, since the interrupt priority is disabled.
11.13.1 INTCON0
Name: INTCON0
Offset: 0x4D6
Bit 7 6 5 4 3 2 1 0
GIE/GIEH GIEL IPEN INT2EDG INT1EDG INT0EDG
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 1 1 1
11.13.2 INTCON1
Name: INTCON1
Offset: 0x4D7
Bit 7 6 5 4 3 2 1 0
STAT[1:0]
Access R R
Reset 0 0
11.13.3 IVTBASE
Name: IVTBASE
Offset: 0x45D
Bit 23 22 21 20 19 18 17 16
IVTBASEU[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
IVTBASEH[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
IVTBASEL[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bits 20:16 – IVTBASEU[4:0] Interrupt Vector Table Base Address Most Significant 5 bits
Bits 15:8 – IVTBASEH[7:0] Interrupt Vector Table Base Address Middle 8 bits
Bits 7:0 – IVTBASEL[7:0] Interrupt Vector Table Base Address Least Significant 8 bits
11.13.4 IVTAD
Name: IVTAD
Offset: 0x45A
Bit 23 22 21 20 19 18 17 16
IVTADU[4:0]
Access R R R R R
Reset 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
IVTADH[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
IVTADL[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Bits 20:16 – IVTADU[4:0] Interrupt Vector Table Address Most Significant 5 bits
Bits 7:0 – IVTADL[7:0] Interrupt Vector Table Address Least Significant 8 bits
11.13.5 IVTLOCK
Name: IVTLOCK
Offset: 0x459
Bit 7 6 5 4 3 2 1 0
IVTLOCKED
Access R/W
Reset 0
Notes:
1. The IVTLOCKED bit can only be set or cleared after the unlock sequence in Example 11-1.
2. If IVT1WAY = 1, the IVTLOCKED bit cannot be cleared after it has been set.
11.13.6 SHADCON
Name: SHADCON
Offset: 0x376
Bit 7 6 5 4 3 2 1 0
SHADLO
Access R/W
Reset 0
11.13.7 PIE0
Name: PIE0
Offset: 0x49E
Bit 7 6 5 4 3 2 1 0
IOCIE CANIE CLC1IE TU16AIE CSWIE OSFIE HLVDIE SWINTIE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
11.13.8 PIE1
Name: PIE1
Offset: 0x49F
Bit 7 6 5 4 3 2 1 0
SMT1PWAIE SMT1PRAIE SMT1IE CM1IE ACTIE ADIE ZCDIE INT0IE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
11.13.9 PIE2
Name: PIE2
Offset: 0x4A0
Bit 7 6 5 4 3 2 1 0
DMA1AIE DMA1ORIE DMA1DCNTIE DMA1SCNTIE ADCH4IE ADCH3IE ADCH2IE ADCH1IE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
11.13.10 PIE3
Name: PIE3
Offset: 0x4A1
Bit 7 6 5 4 3 2 1 0
TMR0IE CCP1IE TMR1GIE TMR1IE TMR2IE SPI1IE SPI1TXIE SPI1RXIE
Access R/W R/W R/W R/W R/W R/W R/W R
Reset 0 0 0 0 0 0 0 0
11.13.11 PIE4
Name: PIE4
Offset: 0x4A2
Bit 7 6 5 4 3 2 1 0
PWM1IE PWM1PIE CANTIE CANRIE U1IE U1EIE U1TXIE U1RXIE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
11.13.12 PIE5
Name: PIE5
Offset: 0x4A3
Bit 7 6 5 4 3 2 1 0
PWM2IE PWM2PIE TMR3GIE TMR3IE TU16BIE SPI2IE SPI2TXIE SPI2RXIE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
11.13.13 PIE6
Name: PIE6
Offset: 0x4A4
Bit 7 6 5 4 3 2 1 0
DMA2AIE DMA2ORIE DMA2DCNTIE DMA2SCNTIE NCO1IE CWG1IE CLC2IE INT1IE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
11.13.14 PIE7
Name: PIE7
Offset: 0x4A5
Bit 7 6 5 4 3 2 1 0
PWM3IE PWM3PIE CLC3IE I2C1EIE I2C1IE I2C1TXIE I2C1RXIE
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
11.13.15 PIE8
Name: PIE8
Offset: 0x4A6
Bit 7 6 5 4 3 2 1 0
SCANIE CCP2IE TMR5GIE TMR5IE U2IE U2EIE U2TXIE U2RXIE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
11.13.16 PIE9
Name: PIE9
Offset: 0x4A7
Bit 7 6 5 4 3 2 1 0
PWM4IE PWM4PIE CLC4IE U3IE U3EIE U3TXIE U3RXIE
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
11.13.17 PIE10
Name: PIE10
Offset: 0x4A8
Bit 7 6 5 4 3 2 1 0
DMA3AIE DMA3ORIE DMA3DCNTIE DMA3SCNTIE NCO2IE CWG2IE CLC5IE INT2IE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
11.13.18 PIE11
Name: PIE11
Offset: 0x4A9
Bit 7 6 5 4 3 2 1 0
DMA4AIE DMA4ORIE DMA4DCNTIE DMA4SCNTIE TMR4IE CWG3IE CLC6IE CCP3IE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
11.13.19 PIE12
Name: PIE12
Offset: 0x4AA
Bit 7 6 5 4 3 2 1 0
DMA5AIE DMA5ORIE DMA5DCNTIE DMA5SCNTIE U4IE U4EIE U4TXIE U4RXIE
Access R/W R/W/HS R/W/HS R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
11.13.20 PIE13
Name: PIE13
Offset: 0x4AB
Bit 7 6 5 4 3 2 1 0
DMA6AIE DMA6ORIE DMA6DCNTIE DMA6SCNTIE U5IE U5EIE U5TXIE U5RXIE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
11.13.21 PIE14
Name: PIE14
Offset: 0x4AC
Bit 7 6 5 4 3 2 1 0
DMA7AIE DMA7ORIE DMA7DCNTIE DMA7SCNTIE NCO3IE CM2IE CLC7IE
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
11.13.22 PIE15
Name: PIE15
Offset: 0x4AD
Bit 7 6 5 4 3 2 1 0
DMA8AIE DMA8ORIE DMA8DCNTIE DMA8SCNTIE TMR6IE CRCIE CLC8IE NVMIE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
11.13.23 PIR0
Name: PIR0
Offset: 0x4AE
Bit 7 6 5 4 3 2 1 0
IOCIF CANIF CLC1IF TU16AIF CSWIF OSFIF HLVDIF SWIF
Access R R R/W/HS R R/W/HS R/W/HS R/W/HS R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate Interrupt Flag bits are clear
prior to enabling an interrupt.
2. IOCIF is a read-only bit. To clear the interrupt condition, all bits in the IOCxF registers must be cleared
3. The CSWIF interrupt will not wake the system from Sleep. The system will Sleep until another interrupt causes
the wake-up.
11.13.24 PIR1
Name: PIR1
Offset: 0x4AF
Bit 7 6 5 4 3 2 1 0
SMT1PWAIF SMT1PRAIF SMT1IF CM1IF ACTIF ADIF ZCDIF INT0IF
Access R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS
Reset 0 0 0 0 0 0 0 0
Notes:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
2. The external interrupt GPIO pin is selected by the INTxPPS register.
11.13.25 PIR2
Name: PIR2
Offset: 0x4B0
Bit 7 6 5 4 3 2 1 0
DMA1AIF DMA1ORIF DMA1DCNTIF DMA1SCNTIF ADCH4IF ADCH3IF ADCH2IF ADCH1IF
Access R/W/HS R/W/HS R/W/HS R/W/HS R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Note:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
11.13.26 PIR3
Name: PIR3
Offset: 0x4B1
Bit 7 6 5 4 3 2 1 0
TMR0IF CCP1IF TMR1GIF TMR1IF TMR2IF SPI1IF SPI1TXIF SPI1RXIF
Access R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R R R
Reset 0 0 0 0 0 0 0 0
Notes:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
2. SPI1IF is a read-only bit. To clear the interrupt condition, all bits in the SPI1INTF register must be cleared.
3. SPI1TXIF and SPI1RXIF are read-only bits and cannot be set/cleared by software.
11.13.27 PIR4
Name: PIR4
Offset: 0x4B2
Bit 7 6 5 4 3 2 1 0
PWM1IF PWM1PIF CANTIF CANRIF U1IF U1EIF U1TXIF U1RXIF
Access R R/W/HS R R R R R R
Reset 0 0 0 0 0 0 0 0
Notes:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
2. PWM1IF is a read-only bit. To clear the interrupt condition, all bits in the PWM1GIR register must be cleared
3. U1IF is a read-only bit. To clear the interrupt condition, all bits in the U1UIR register must be cleared
4. U1EIF is a read-only bit. To clear the interrupt condition, all bits in the U1ERR register must be cleared.
5. U1TXIF and U1RXIF are read-only bits and cannot be set/cleared by software.
11.13.28 PIR5
Name: PIR5
Offset: 0x4B3
Bit 7 6 5 4 3 2 1 0
PWM2IF PWM2PIF TMR3GIF TMR3IF TU16BIF SPI2IF SPI2TXIF SPI2RXIF
Access R R/W/HS R/W/HS R/W/HS R/W R R R
Reset 0 0 0 0 0 0 0 0
Notes:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
2. PWM2IF is a read-only bit. To clear the interrupt condition, all bits in the PWM2GIR register must be cleared.
3. SPI2IF is a read-only bit. To clear the interrupt condition, all bits in the SPI2INTF register must be cleared.
4. SPI2TXIF and SPI2RXIF are read-only bits and cannot be set/cleared by software.
11.13.29 PIR6
Name: PIR6
Offset: 0x4B4
Bit 7 6 5 4 3 2 1 0
DMA2AIF DMA2ORIF DMA2DCNTIF DMA2SCNTIF NCO1IF CWG1IF CLC2IF INT1IF
Access R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS
Reset 0 0 0 0 0 0 0 0
Note:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
11.13.30 PIR7
Name: PIR7
Offset: 0x4B5
Bit 7 6 5 4 3 2 1 0
PWM3IF PWM3PIF CLC3IF I2C1EIF I2C1IF I2C1TXIF I2C1RXIF
Access R R/W/HS R/W/HS R R R R
Reset 0 0 0 0 0 0 0
Notes:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
2. PWM3IF is a read-only bit. To clear the interrupt condition, all bits in the PWM3GIR register must be cleared.
3. I2C1EIF is a read-only bit. To clear the interrupt condition, all bits in the I2C1ERR register must be cleared.
4. I2C1IF is a read-only bit. To clear the interrupt condition, all bits in the I2C1PIR register must be cleared.
5. I2C1TXIF and I2C1RXIF are read-only bits. To clear the interrupt condition, the CLRBF bit in I2C1STAT1 must
be set.
11.13.31 PIR8
Name: PIR8
Offset: 0x4B6
Bit 7 6 5 4 3 2 1 0
SCANIF CCP2IF TMR5GIF TMR5IF U2IF U2EIF U2TXIF U2RXIF
Access R/W/HS R/W/HS R/W/HS R/W/HS R R R R
Reset 0 0 0 0 0 0 0 0
Notes:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
2. U2IF is a read-only bit. To clear the interrupt condition, all bits in the U2UIR register must be cleared.
3. U2EIF is a read-only bit. To clear the interrupt condition, all bits in the U2ERR register must be cleared.
4. U2TXIF and U2RXIF are read-only bits and cannot be set/cleared by software.
11.13.32 PIR9
Name: PIR9
Offset: 0x4B7
Bit 7 6 5 4 3 2 1 0
PWM4IF PWM4PIF CLC4IF U3IF U3EIF U3TXIF U3RXIF
Access R R/W R/W/HS R R R R
Reset 0 0 0 0 0 0 0
Notes:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
2. U3IF is a read-only bit. To clear the interrupt condition, all bits in the U3UIR register must be cleared
3. U3EIF is a read-only bit. To clear the interrupt condition, all bits in the U3ERR register must be cleared.
4. U3TXIF and U3RXIF are read-only bits and cannot be set/cleared by software.
11.13.33 PIR10
Name: PIR10
Offset: 0x4B8
Bit 7 6 5 4 3 2 1 0
DMA3AIF DMA3ORIF DMA3DCNTIF DMA3SCNTIF NCO2IF CWG2IF CLC5IF INT2IF
Access R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS
Reset 0 0 0 0 0 0 0 0
Note:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
11.13.34 PIR11
Name: PIR11
Offset: 0x4B9
Bit 7 6 5 4 3 2 1 0
DMA4AIF DMA4ORIF DMA4DCNTIF DMA4SCNTIF TMR4IF CWG3IF CLC6IF CCP3IF
Access R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS
Reset 0 0 0 0 0 0 0 0
Note:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
11.13.35 PIR12
Name: PIR12
Offset: 0x4BA
Bit 7 6 5 4 3 2 1 0
DMA5AIF DMA5ORIF DMA5DCNTIF DMA5SCNTIF U4IF U4EIF U4TXIF U4RXIF
Access R/W/HS R/W/HS R/W/HS R/W/HS R R R R
Reset 0 0 0 0 0 0 0 0
Notes:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
2. U4IF is a read-only bit. To clear the interrupt condition, all bits in the U4UIR register must be cleared.
3. U4EIF is a read-only bit. To clear the interrupt condition, all bits in the U4ERR register must be cleared.
4. U4TXIF and U4RXIF are read-only bits and cannot be set/cleared by software.
11.13.36 PIR13
Name: PIR13
Offset: 0x4BB
Bit 7 6 5 4 3 2 1 0
DMA6AIF DMA6ORIF DMA6DCNTIF DMA6SCNTIF U5IF U5EIF U5TXIF U5RXIF
Access R/W/HS R/W/HS R/W/HS R/W/HS R R R R
Reset 0 0 0 0 0 0 0 0
Notes:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
2. U5IF is a read-only bit. To clear the interrupt condition, all bits in the U5UIR register must be cleared.
3. U5EIF is a read-only bit. To clear the interrupt condition, all bits in the U5ERR register must be cleared.
4. U5TXIF and U5RXIF are read-only bits and cannot be set/cleared by software.
11.13.37 PIR14
Name: PIR14
Offset: 0x4BC
Bit 7 6 5 4 3 2 1 0
DMA7AIF DMA7ORIF DMA7DCNTIF DMA7SCNTIF NCO3IF CM2IF CLC7IF
Access R/W R/W R/W R/W R/W/HS R/W/HS R/W/HS
Reset 0 0 0 0 0 0 0
Note:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
11.13.38 PIR15
Name: PIR15
Offset: 0x4BD
Bit 7 6 5 4 3 2 1 0
DMA8AIF DMA8ORIF DMA8DCNTIF DMA8SCNTIF TMR6IF CRCIF CLC8IF NVMIF
Access R/W R/W R/W R/W R/W/HS R/W/HS R/W/HS R/W/HS
Reset 0 0 0 0 0 0 0 0
Note:
1. Interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit, or the global enable bit. User software needs to ensure the appropriate interrupt flag bits are clear
prior to enabling an interrupt.
11.13.39 IPR0
Name: IPR0
Offset: 0x362
Bit 7 6 5 4 3 2 1 0
IOCIP CANIP CLC1IP TU16AIP CSWIP OSFIP HLVDIP SWINTIP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 0 1 0 1 1 1 1
11.13.40 IPR1
Name: IPR1
Offset: 0x363
Bit 7 6 5 4 3 2 1 0
SMT1PWAIP SMT1PRAIP SMT1IP CM1IP ACTIP ADIP ZCDIP INT0IP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
11.13.41 IPR2
Name: IPR2
Offset: 0x364
Bit 7 6 5 4 3 2 1 0
DMA1AIP DMA1ORIP DMA1DCNTIP DMA1SCNTIP ADCH4IP ADCH3IP ADCH2IP ADCH1IP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 0 0 0 0
11.13.42 IPR3
Name: IPR3
Offset: 0x365
Bit 7 6 5 4 3 2 1 0
TMR0IP CCP1IP TMR1GIP TMR1IP TMR2IP SPI1IP SPI1TXIP SPI1RXIP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
11.13.43 IPR4
Name: IPR4
Offset: 0x366
Bit 7 6 5 4 3 2 1 0
PWM1IP PWM1PIP CANTIP CANRIP U1IP U1EIP U1TXIP U1RXIP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 0 0 1 1 1 1
11.13.44 IPR5
Name: IPR5
Offset: 0x367
Bit 7 6 5 4 3 2 1 0
PWM2IP PWM2PIP TMR3GIP TMR3IP TU16BIP SPI2IP SPI2TXIP SPI2RXIP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 0 1 1 1
11.13.45 IPR6
Name: IPR6
Offset: 0x368
Bit 7 6 5 4 3 2 1 0
DMA2AIP DMA2ORIP DMA2DCNTIP DMA2SCNTIP NCO1IP CWG1IP CLC2IP INT1IP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
11.13.46 IPR7
Name: IPR7
Offset: 0x369
Bit 7 6 5 4 3 2 1 0
PWM3IP PWM3PIP CLC3IP I2C1EIP I2C1IP I2C1TXIP I2C1RXIP
Access R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1
11.13.47 IPR8
Name: IPR8
Offset: 0x36A
Bit 7 6 5 4 3 2 1 0
SCANIP CCP2IP TMR5GIP TMR5IP U2IP U2EIP U2TXIP U2RXIP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
11.13.48 IPR9
Name: IPR9
Offset: 0x36B
Bit 7 6 5 4 3 2 1 0
PWM4IP PWM4PIP CLC4IP U3IP U3EIP U3TXIP U3RXIP
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 1 1 1 1 1
11.13.49 IPR10
Name: IPR10
Offset: 0x36C
Bit 7 6 5 4 3 2 1 0
DMA3AIP DMA3ORIP DMA3DCNTIP DMA3SCNTIP NCO2IP CWG2IP CLC5IP INT2IP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
11.13.50 IPR11
Name: IPR11
Offset: 0x36D
Bit 7 6 5 4 3 2 1 0
DMA4AIP DMA4ORIP DMA4DCNTIP DMA4SCNTIP TMR4IP CWG3IP CLC6IP CCP3IP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
11.13.51 IPR12
Name: IPR12
Offset: 0x36E
Bit 7 6 5 4 3 2 1 0
DMA5AIP DMA5ORIP DMA5DCNTIP DMA5SCNTIP U4IP U4EIP U4TXIP U4RXIP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
11.13.52 IPR13
Name: IPR13
Offset: 0x36F
Bit 7 6 5 4 3 2 1 0
DMA6AIP DMA6ORIP DMA6DCNTIP DMA6SCNTIP U5IP U5EIP U5TXIP U5RXIP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
11.13.53 IPR14
Name: IPR14
Offset: 0x370
Bit 7 6 5 4 3 2 1 0
DMA7AIP DMA7ORIP DMA7DCNTIP DMA7SCNTIP NCO3IP CM2IP CLC7IP
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 1 1 1
11.13.54 IPR15
Name: IPR15
Offset: 0x371
Bit 7 6 5 4 3 2 1 0
DMA8AIP DMA8ORIP DMA8DCNTIP DMA8SCNTIP TMR6IP CRCIP CLC8IP NVMIP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 1 1 1 1
0x00
... Reserved
0x0361
0x0362 IPR0 7:0 IOCIP CANIP CLC1IP TU16AIP CSWIP OSFIP HLVDIP SWINTIP
0x0363 IPR1 7:0 SMT1PWAIP SMT1PRAIP SMT1IP CM1IP ACTIP ADIP ZCDIP INT0IP
0x0364 IPR2 7:0 DMA1AIP DMA1ORIP DMA1DCNTIP DMA1SCNTIP ADCH4IP ADCH3IP ADCH2IP ADCH1IP
0x0365 IPR3 7:0 TMR0IP CCP1IP TMR1GIP TMR1IP TMR2IP SPI1IP SPI1TXIP SPI1RXIP
0x0366 IPR4 7:0 PWM1IP PWM1PIP CANTIP CANRIP U1IP U1EIP U1TXIP U1RXIP
0x0367 IPR5 7:0 PWM2IP PWM2PIP TMR3GIP TMR3IP TU16BIP SPI2IP SPI2TXIP SPI2RXIP
0x0368 IPR6 7:0 DMA2AIP DMA2ORIP DMA2DCNTIP DMA2SCNTIP NCO1IP CWG1IP CLC2IP INT1IP
0x0369 IPR7 7:0 PWM3IP PWM3PIP CLC3IP I2C1EIP I2C1IP I2C1TXIP I2C1RXIP
0x036A IPR8 7:0 SCANIP CCP2IP TMR5GIP TMR5IP U2IP U2EIP U2TXIP U2RXIP
0x036B IPR9 7:0 PWM4IP PWM4PIP CLC4IP U3IP U3EIP U3TXIP U3RXIP
0x036C IPR10 7:0 DMA3AIP DMA3ORIP DMA3DCNTIP DMA3SCNTIP NCO2IP CWG2IP CLC5IP INT2IP
0x036D IPR11 7:0 DMA4AIP DMA4ORIP DMA4DCNTIP DMA4SCNTIP TMR4IP CWG3IP CLC6IP CCP3IP
0x036E IPR12 7:0 DMA5AIP DMA5ORIP DMA5DCNTIP DMA5SCNTIP U4IP U4EIP U4TXIP U4RXIP
0x036F IPR13 7:0 DMA6AIP DMA6ORIP DMA6DCNTIP DMA6SCNTIP U5IP U5EIP U5TXIP U5RXIP
0x0370 IPR14 7:0 DMA7AIP DMA7ORIP DMA7DCNTIP DMA7SCNTIP NCO3IP CM2IP CLC7IP
0x0371 IPR15 7:0 DMA8AIP DMA8ORIP DMA8DCNTIP DMA8SCNTIP TMR6IP CRCIP CLC8IP NVMIP
0x0372
... Reserved
0x0375
0x0376 SHADCON 7:0 SHADLO
0x0377
... Reserved
0x0458
0x0459 IVTLOCK 7:0 IVTLOCKED
7:0 IVTADL[7:0]
0x045A IVTAD 15:8 IVTADH[7:0]
23:16 IVTADU[4:0]
7:0 IVTBASEL[7:0]
0x045D IVTBASE 15:8 IVTBASEH[7:0]
23:16 IVTBASEU[4:0]
0x0460
... Reserved
0x049D
0x049E PIE0 7:0 IOCIE CANIE CLC1IE TU16AIE CSWIE OSFIE HLVDIE SWINTIE
0x049F PIE1 7:0 SMT1PWAIE SMT1PRAIE SMT1IE CM1IE ACTIE ADIE ZCDIE INT0IE
0x04A0 PIE2 7:0 DMA1AIE DMA1ORIE DMA1DCNTIE DMA1SCNTIE ADCH4IE ADCH3IE ADCH2IE ADCH1IE
0x04A1 PIE3 7:0 TMR0IE CCP1IE TMR1GIE TMR1IE TMR2IE SPI1IE SPI1TXIE SPI1RXIE
0x04A2 PIE4 7:0 PWM1IE PWM1PIE CANTIE CANRIE U1IE U1EIE U1TXIE U1RXIE
0x04A3 PIE5 7:0 PWM2IE PWM2PIE TMR3GIE TMR3IE TU16BIE SPI2IE SPI2TXIE SPI2RXIE
0x04A4 PIE6 7:0 DMA2AIE DMA2ORIE DMA2DCNTIE DMA2SCNTIE NCO1IE CWG1IE CLC2IE INT1IE
0x04A5 PIE7 7:0 PWM3IE PWM3PIE CLC3IE I2C1EIE I2C1IE I2C1TXIE I2C1RXIE
0x04A6 PIE8 7:0 SCANIE CCP2IE TMR5GIE TMR5IE U2IE U2EIE U2TXIE U2RXIE
0x04A7 PIE9 7:0 PWM4IE PWM4PIE CLC4IE U3IE U3EIE U3TXIE U3RXIE
0x04A8 PIE10 7:0 DMA3AIE DMA3ORIE DMA3DCNTIE DMA3SCNTIE NCO2IE CWG2IE CLC5IE INT2IE
0x04A9 PIE11 7:0 DMA4AIE DMA4ORIE DMA4DCNTIE DMA4SCNTIE TMR4IE CWG3IE CLC6IE CCP3IE
0x04AA PIE12 7:0 DMA5AIE DMA5ORIE DMA5DCNTIE DMA5SCNTIE U4IE U4EIE U4TXIE U4RXIE
0x04AB PIE13 7:0 DMA6AIE DMA6ORIE DMA6DCNTIE DMA6SCNTIE U5IE U5EIE U5TXIE U5RXIE
0x04AC PIE14 7:0 DMA7AIE DMA7ORIE DMA7DCNTIE DMA7SCNTIE NCO3IE CM2IE CLC7IE
0x04AD PIE15 7:0 DMA8AIE DMA8ORIE DMA8DCNTIE DMA8SCNTIE TMR6IE CRCIE CLC8IE NVMIE
0x04AE PIR0 7:0 IOCIF CANIF CLC1IF TU16AIF CSWIF OSFIF HLVDIF SWIF
0x04AF PIR1 7:0 SMT1PWAIF SMT1PRAIF SMT1IF CM1IF ACTIF ADIF ZCDIF INT0IF
0x04B0 PIR2 7:0 DMA1AIF DMA1ORIF DMA1DCNTIF DMA1SCNTIF ADCH4IF ADCH3IF ADCH2IF ADCH1IF
0x04B1 PIR3 7:0 TMR0IF CCP1IF TMR1GIF TMR1IF TMR2IF SPI1IF SPI1TXIF SPI1RXIF
...........continued
0x04B2 PIR4 7:0 PWM1IF PWM1PIF CANTIF CANRIF U1IF U1EIF U1TXIF U1RXIF
0x04B3 PIR5 7:0 PWM2IF PWM2PIF TMR3GIF TMR3IF TU16BIF SPI2IF SPI2TXIF SPI2RXIF
0x04B4 PIR6 7:0 DMA2AIF DMA2ORIF DMA2DCNTIF DMA2SCNTIF NCO1IF CWG1IF CLC2IF INT1IF
0x04B5 PIR7 7:0 PWM3IF PWM3PIF CLC3IF I2C1EIF I2C1IF I2C1TXIF I2C1RXIF
0x04B6 PIR8 7:0 SCANIF CCP2IF TMR5GIF TMR5IF U2IF U2EIF U2TXIF U2RXIF
0x04B7 PIR9 7:0 PWM4IF PWM4PIF CLC4IF U3IF U3EIF U3TXIF U3RXIF
0x04B8 PIR10 7:0 DMA3AIF DMA3ORIF DMA3DCNTIF DMA3SCNTIF NCO2IF CWG2IF CLC5IF INT2IF
0x04B9 PIR11 7:0 DMA4AIF DMA4ORIF DMA4DCNTIF DMA4SCNTIF TMR4IF CWG3IF CLC6IF CCP3IF
0x04BA PIR12 7:0 DMA5AIF DMA5ORIF DMA5DCNTIF DMA5SCNTIF U4IF U4EIF U4TXIF U4RXIF
0x04BB PIR13 7:0 DMA6AIF DMA6ORIF DMA6DCNTIF DMA6SCNTIF U5IF U5EIF U5TXIF U5RXIF
0x04BC PIR14 7:0 DMA7AIF DMA7ORIF DMA7DCNTIF DMA7SCNTIF NCO3IF CM2IF CLC7IF
0x04BD PIR15 7:0 DMA8AIF DMA8ORIF DMA8DCNTIF DMA8SCNTIF TMR6IF CRCIF CLC8IF NVMIF
0x04BE
... Reserved
0x04D5
0x04D6 INTCON0 7:0 GIE/GIEH GIEL IPEN INT2EDG INT1EDG INT0EDG
0x04D7 INTCON1 7:0 STAT[1:0]
Note:
1. EXTOSC must meet the PLL specifications (see the data sheet Electrical Specifications).
If an external clock source is selected by the RSTOSC bits, the External Oscillator Mode Select (FEXTOSC)
Configuration bits must be used to select the External Clock mode. These modes include:
• ECL: External Clock Low Power mode
• ECM: External Clock Medium Power mode
• ECH: External Clock High Power mode
• LP: 32 kHz Low-Gain Crystal mode
PLLEN
CLKIN/OSC1 1
To Peripherals
0
External
Oscillator
(EXTOSC)
CLKOUT/OSC2 NDIV/
CDIV[4:0]
4x PLL NOSC/
COSC[2:0]
SOSCIN/SOSCI
Secondary 512
Oscillator 1001
(SOSC) 256
111 1000
128 Sleep
SOSCO 010 0111 CPU
64
100 0110
Post Divider
LFINTOSC 32
101 0101
31 kHz 16
110 0100 SYSCMD FOSC
Oscillator
8
Reserved 011 0011
4
Reserved 001 0010 Sleep
2
HFINTOSC Reserved 000 0001 Idle
1
0000
FRQ[3:0]
1,2,4,8,12,16,32,48,64
MHz
Oscillator LFINTOSC is used to
FSCM
monitor system clock
To Peripherals
MFINTOSC To Peripherals
To Peripherals
31.25 kHz and 500 kHz
Oscillator To Peripherals
signal. The internal oscillator block also features an RC oscillator which is dedicated to the Analog-to-Digital
Converter (ADC).
The oscillator module allows the system clock source or system clock frequency to be changed through clock
switching. Clock source selections are made via the New Oscillator Source Request (NOSC) bits. Once the clock
source has been selected, the clock source base frequency can be divided (post-scaled) via the New Divider
Selection Request (NDIV) bits.
The instruction clock (FOSC/4) can be routed to the OSC2/CLKOUT pin when the pin is not in use. The Clock Out
Enable (CLKOUTEN) Configuration bit controls the functionality of the CLKOUT signal. When CLKOUTEN is clear
(CLKOUTEN = 0), the CLKOUT signal is routed to the OSC2/CLKOUT pin. When CLKOUTEN is set (CLKOUTEN =
1), the OSC2/CLKOUT pin functions as an I/O pin.
12.1.1.1 EC Mode
The External Clock (EC) mode allows an externally generated logic level signal to be the system clock source. When
operating in EC mode, an external clock source is connected to the OSC1/CLKIN input pin. The OSC2/CLKOUT pin
is available as a general purpose I/O pin or as the CLKOUT signal pin.
EC mode provides three Power mode selections:
• Filename:
ECH: High PowerExternal
mode Clock (EC) Mode Operation.vsdx
• Title:
ECM: Medium Power mode
Last Edit: 2/7/2019
• First
ECL: Low Power mode
Used:
TheNotes:
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 PIC MCU design is fully static, stopping the
external clock input will have the effect of halting the device while leaving all data intact. Upon restarting the external
clock, the device will resume operation as if no time had elapsed.
The figure below shows the pin connections for EC mode.
Figure 12-2. External Clock (EC) Mode Operation
OSC1/CLKIN
Note:
1. Output depends on the setting of the CLKOUTEN Configuration bit.
The LP Oscillator mode selects the lowest gain setting of the internal inverter-amplifier, and consumes the least
Filename: Quartz Crystal Operation.vsdx
amount of current. LP mode is designed to drive 32.768 kHz tuning-fork type crystals (watch crystals), but can
Title:
operate
Last Edit: up to 100 kHz.
2/7/2019
First Used:
Notes:
The XT Oscillator mode selects the intermediate gain setting of the internal inverter-amplifier. Current consumption
is at a medium level when compared to the other two modes. XT mode is best suited to drive crystal and ceramic
resonators with a frequency range up to 4 MHz.
The HS Oscillator mode selects the highest gain setting of the internal inverter-amplifier, and consumes the most
current. This mode is best suited for crystal and ceramic resonators that require operating frequencies up to 20 MHz.
The figures below show typical circuits for quartz crystal and ceramic resonators.
Rev. Quart z Cry
PIC® MCU
OSC1/
C1 CLKIN
To internal
logic
Quartz
Crystal RF(2) Sleep
RS(1)
C2 OSC2/
CLKOUT
Notes:
1. A series resistor (RS) may be required for quartz crystals with low drive level.
2. The value of RF varies with the Oscillator mode selected (typically between 2 MΩ and 10 MΩ).
Rev. Ceramic
2/7/2
PIC® MCU
OSC1/
C1 CLKIN
To internal
logic
Resonator
Ceramic
RS(1)
C2 OSC2/
CLKOUT
Notes:
1. A series resistor (RS) may be required for ceramic resonators with low drive level.
2. The value of RF varies with the Oscillator mode selected (typically between 2 MΩ and 10 MΩ).
3. An additional parallel feedback resistor (RP) may be required for proper ceramic resonator operation.
12.1.1.4 4x PLL
The oscillator module contains a 4x Phase-Locked Loop (PLL) circuit that can be used with the external clock
sources to provide a system clock source. The input frequency for the PLL must fall within a specified range. See the
“PLL Specifications” table found in the “Electrical Specifications” chapter for more information.
The PLL can be enabled for use through one of two methods:
1. Program the RSTOSC Configuration bits to select the “EXTOSC with 4x PLL” option.
2. Write the NOSC bits to select the ”EXTOSC with 4x PLL” option.
PIC® MCU
C1 SOSCI
To internal
logic
32.768 kHz
Quartz RF Sleep
Crystal
Filename: External Clock (EC) Mode Operation.vsdx
Title:
Last Edit: 2/8/2019
First Used:C2 SOSCO
Notes:
32.768 kHz
external clock
source PIC® MCU
SOSCI
Important: The SOSC module must be disabled before changing Power modes. Changes to the Power
mode during operation may result in undefined oscillator behavior.
12.1.2.1 HFINTOSC
The High-Frequency Internal Oscillator (HFINTOSC) is a factory-calibrated, precision digitally-controlled internal
clock source that produces a wide range of stable clock frequencies. The HFINTOSC can be enabled through one of
the following methods:
• Program the RSTOSC Configuration bits to select the HFINTOSC upon device Reset or power-up
• Write to the New Oscillator Source Request (NOSC) bits to select the HFINTOSC during run time.
The HFINTOSC frequency is selected via the HFINTOSC Frequency Selection (FRQ) bits. Fine-tuning of the
HFINTOSC is done via the HFINTOSC Frequency Tuning (TUN) bits. The HFINTOSC output frequency can be
divided (post-scaled) via the New Divider Selection Request (NDIV) bits.
12.1.2.2 MFINTOSC
The Medium-Frequency Internal Oscillator (MFINTOSC) generates two constant clock outputs (500 kHz and 31.25
kHz). The MFINTOSC clock signals are created from the HFINTOSC using dynamic divider logic, which provides
constant MFINTOSC clock rates regardless of selected HFINTOSC frequency.
The MFINTOSC cannot be used as the system clock, but can be used as a clock source for certain peripherals, such
as a Timer.
12.1.2.3 LFINTOSC
The Low-Frequency Internal Oscillator (LFINTOSC) is a factory-calibrated 31 kHz internal clock source.
The LFINTOSC can be used as a system clock source, and may be used by certain peripheral modules as a clock
source. Additionally, the LFINTOSC provides a time base for the following:
• Power-up Timer (PWRT)
• Watchdog Timer (WDT)/Windowed Watchdog Timer (WWDT)
• Fail-Safe Clock Monitor (FSCM)
The LFINTOSC is enabled through one of the following methods:
• Program the RSTOSC Configuration bits to select LFINTOSC
• Write the NOSC bits to select LFINTOSC during run time
12.1.2.4 ADCRC
The Analog-to-Digital RC (ADCRC) oscillator is dedicated to the ADC module. This oscillator is also referred to as the
FRC clock. The ADCRC operates at a fixed frequency of approximately 600 kHz, and is used as a conversion clock
source. The ADCRC allows the ADC module to operate in Sleep mode, which can reduce system noise during the
ADC conversion. The ADCRC is automatically enabled when it is selected as the clock source for the ADC module,
or when selected as the clock source of any peripheral that may use it. The ADCRC may also be manually enabled
via the ADC Oscillator Enable (ADOEN) bit, thereby avoiding start-up delays when this source is used intermittently.
Important: The CSWIF interrupt does not wake the device from Sleep.
Notes:
1. EXTOSC is configured via the FEXTOSC Configuration bits.
2. HFINTOSC frequency is determined by the FRQ bits.
3. EXTOSC must meet the PLL specifications (see the data sheet Electrical Specifications).
12.2.3 CSWHOLD
When the system oscillator changes frequencies, peripherals using the system clock may be affected. For example,
if the I2C module is actively using the system clock as its Serial Clock (SCL) time base, changing the system
clock frequency will change the SCL frequency. The Clock Switch Hold (CSWHOLD) bit can be used to suspend a
requested clock switch. In this example, software can request a new clock source, use the CSWHOLD bit to suspend
the switch, wait for the I2C bus to become Idle, then reconfigure the SCL frequency based on the new clock source.
Once the I2C has been reconfigured, software can use CSWHOLD to complete the clock switch without causing any
issues with the I2C bus.
When CSWHOLD is set (CSWHOLD = 1), a write to NOSC and/or NDIV is accepted, but the clock switch is
suspended and does not automatically complete. While the switch is suspended, code execution continues using the
old (current) clock source. Module hardware will still enable the new oscillator selection and set the NOSCR bit. Once
the NOSCR bit is set, software will either:
• clear CSWHOLD so that the clock switch can complete, or
• copy the Current Oscillator Source Select (COSC) value into NOSC to abandon the clock switch.
When CSWHOLD is clear (CSWHOLD = 0), the clock switch will occur when the NOSCR bit is set. When NOSCR is
set, the CSWIF is also set, and if CSWIE is set, the generated interrupt will be serviced using the new oscillator.
OSC #1 OSC #2
NOSC written
Switch
ORDY complete
Cleared by
NOSCR hardware(2)
Cleared by
CSWIF software(1)
Cleared by
CSWHOLD software
Notes:
1. CSWIF is asserted coincident with NOSCR; interrupt is serviced at OSC#2 speed.
2. The assertion of NOSCR may not be seen by the user as it is only set for the duration of the switch.
PIC18F26/46/56Q83
OSC - Oscillator Module (With Fail-Safe Clock ...
OSC #1 OSC #2
NOSC written
Switch
ORDY complete
Cleared by
NOSCR hardware
New oscillator Cleared by
is ready software(1)
CSWIF
Cleared by
CSWHOLD software
Note:
1. CSWIF may be cleared before or after clearing CSWHOLD.
PIC18F26/46/56Q83
OSC - Oscillator Module (With Fail-Safe Clock ...
OSC #1
ORDY
Cleared by
NOSCR hardware
New oscillator Cleared by
is ready software(1)
CSWIF
Cleared by
CSWHOLD New oscillator
software
is ready, but
held while
New value
CSWHOLD = 1
written to
NOSC, old
clock switch
request is
abandoned
Note:
1. CSWIF may be cleared before or after rewriting NOSC; CSWIF is not automatically cleared.
Clock Monitor
Latch
S Q
FSCMEN
System Oscillator
(FOSC) R Q FOSC Failure
Detected
Primary External
Oscillator S Q
(EXTOSC)
FSCMENP
Secondary
External R Q EXTOSC Failure
Oscillator (SOSC) Detected
S Q
LFINTOSC ÷ 64 FSCMENS
31 kHz 484 Hz R Q
(~32 µs) (~2 ms) SOSC Failure
Detected
Sample Clock
the FSCMFEV bit will be set as well as the Oscillator Fail Interrupt Flag (OSFIF) of the PIR registers. Writing to
the primary and secondary external FSCM Fault Injection (FSCMPFI and FSCMSFI) bits will result in the respective
FSCM Fault Status (FSCMPEV and FSCMSEV) bits being set but the system clock will not switch. Additionally, the
Oscillator Fail Interrupt Flag (OSFIF) of the PIR registers will also be set.
Important: Software must clear the OSFIF bit before switching to the external oscillator. If the Fail-Safe
condition still exists, the OSFIF bit will be set again by module hardware.
Important: Active Clock Tuning requires the use of a 32.768 kHz external oscillator connected to the
SOSCI/SOSCO pins.
Active Clock Tuning is enabled via the Active Clock Tuning Enable (ACTEN) bit. When ACTEN is set (ACTEN =
1), the ACT module uses the SOSC time base to measure the HFINTOSC frequency, and uses the HFINTOSC
Frequency Tuning (TUN) bits to adjust the HFINTOSC frequency. When ACTEN is clear (ACTEN = 0), the ACT
feature is disabled, and user software can utilize the TUN bits to adjust the HFINTOSC frequency.
Important: When the ACT feature is enabled, the TUN bits are controlled directly through module
hardware and become read-only bits to user software. Writes to the TUN bits when the ACT feature is
enabled are ignored.
The figure below shows the Active Clock Tuning block diagram.
ACTEN
ACT clock
SOSC HFINTOSC
Active Clock
Tuning Block
ACT data SFR data
Software write
to OSCTUNE
ACTUD TUN[5:0]
ACTEN
ACTEN
set (ACTUD = 1), updates to OSCTUNE are suspended, although the module continues to operate. The last value
written to OSCTUNE is used for tuning, and the ACTLOCK bit is continually updated for each ACT cycle. When
ACTUD is clear (ACTUD = 0), the module updates OSCTUNE register every ACT cycle.
12.5.1 ACTCON
Name: ACTCON
Offset: 0x0AC
Bit 7 6 5 4 3 2 1 0
ACTEN ACTUD ACTLOCK ACTORS
Access R/W R/W R R
Reset 0 0 0 0
12.5.2 OSCCON1
Name: OSCCON1
Offset: 0x0AD
Bit 7 6 5 4 3 2 1 0
NOSC[2:0] NDIV[3:0]
Access R/W R/W R/W R/W R/W R/W R/W
Reset f f f q q q q
Notes:
1. The default value is determined by the RSTOSC Configuration bits. See the Reset Oscillator (RSTOSC)
selection table for the RSTOSC selections.
2. If NOSC is written with a reserved value, the operation is ignored and neither NOSC nor NDIV is written.
3. When CSWEN = 0, these bits are read-only and cannot be changed from the RSTOSC value.
12.5.3 OSCCON2
Name: OSCCON2
Offset: 0x0AE
Bit 7 6 5 4 3 2 1 0
COSC[2:0] CDIV[3:0]
Access R R R R R R R
Reset f f f f f f f
Note:
1. The RSTOSC value is the value present when user code execution begins. Refer to the RSTOSC
Configuration bits or the RSTOSC selection table for the Reset Oscillator selections.
12.5.4 OSCCON3
Name: OSCCON3
Offset: 0x0AF
Bit 7 6 5 4 3 2 1 0
CSWHOLD SOSCPWR ORDY NOSCR
Access R/W/HC R/W R R
Reset 0 1 0 0
Note:
1. If CSWHOLD = 0, the user may not see this bit set (NOSCR = 1). When the oscillator becomes ready, there
may be a delay of one instruction cycle before NOSCR is set. The clock switch occurs in the next instruction
cycle and NOSCR is cleared.
12.5.5 OSCTUNE
Name: OSCTUNE
Offset: 0x0B0
Bit 7 6 5 4 3 2 1 0
TUN[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
TUN Condition
01 1111 Maximum frequency
• •
• •
• •
00 0000 Center frequency. Oscillator is operating at the selected nominal frequency. (Default value)
• •
• •
• •
10 0000 Minimum frequency
12.5.6 OSCFRQ
Name: OSCFRQ
Offset: 0x0B1
Bit 7 6 5 4 3 2 1 0
FRQ[3:0]
Access R/W R/W R/W R/W
Reset 0 0 0 0
12.5.7 OSCSTAT
Name: OSCSTAT
Offset: 0x0B2
Bit 7 6 5 4 3 2 1 0
EXTOR HFOR MFOR LFOR SOR ADOR PLLR
Access R R R R R R R
Reset 0 0 0 0 0 0 0
12.5.8 OSCEN
Name: OSCEN
Offset: 0x0B3
Bit 7 6 5 4 3 2 1 0
EXTOEN HFOEN MFOEN LFOEN SOSCEN ADOEN PLLEN
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
Note:
1. This bit only controls external clock source supplied to the peripherals and has no effect on the system clock.
12.5.9 FSCMCON
Name: FSCMCON
Offset: 0x458
Bit 7 6 5 4 3 2 1 0
FSCMSFI FSCMSEV FSCMPFI FSCMPEV FSCMFFI FSCMFEV
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Notes:
1. This bit is used to demonstrate that FSCM can detect clock failure; the bit must be cleared for normal
operation.
2. This bit will not be cleared by hardware upon clock recovery; the bit must be cleared by the user.
0x00
... Reserved
0xAB
0xAC ACTCON 7:0 ACTEN ACTUD ACTLOCK ACTORS
0xAD OSCCON1 7:0 NOSC[2:0] NDIV[3:0]
0xAE OSCCON2 7:0 COSC[2:0] CDIV[3:0]
0xAF OSCCON3 7:0 CSWHOLD SOSCPWR ORDY NOSCR
0xB0 OSCTUNE 7:0 TUN[5:0]
0xB1 OSCFRQ 7:0 FRQ[3:0]
0xB2 OSCSTAT 7:0 EXTOR HFOR MFOR LFOR SOR ADOR PLLR
0xB3 OSCEN 7:0 EXTOEN HFOEN MFOEN LFOEN SOSCEN ADOEN PLLEN
0xB4
... Reserved
0x0457
0x0458 FSCMCON 7:0 FSCMSFI FSCMSEV FSCMPFI FSCMPEV FSCMFFI FSCMFEV
Accumulator
After n sums
Accumulator
After n sums
When the SHIFTM bit is not set, data will be shifted into the CRC, MSb first and the result will be big-endian. When
the SHIFTM bit is set, data will be shifted into the accumulator in the reversed order (LSb first) and the result will be
little-endian. The CRC module can be seeded with an initial value by setting the CRCOUT registers to the appropriate
value before beginning the CRC process.
Important: If TRIGEN = 1 and BURSTMD = 1, the user needs to ensure that the trigger source is active
for the scanner operation to complete.
5. Set the SCANLADR and SCANHADR registers with the beginning and ending locations in memory that are to
be scanned.
6. Select the priority level for the scanner module. (Refer to the “System Arbitration” and the “Priority Lock”
sections for more details.)
Note: The default priority levels of the system arbiter may need to be changed to ensure the scanner
operates as intended and that a memory access request is granted when it occurs.
7. Both EN and GO bits in the CRCCON0 register must be enabled to use the scanner. Setting the SGO bit will
start the scanner operation.
by clearing Configuration bits CFGSCEN, DATSCEN, SAFSCEN, APPSCEN and BOOTSCEN for the configuration
memory, EEPROM, SAF section, application section and boot section, respectively. Each memory segment is treated
slightly differently and can vary based on other configuration settings:
• The data EEPROM segment scans the entire data EEPROM memory of the device
• The configuration memory scans all configuration memory, except the four bytes for the non-boot CRC expected
value (as this would be self-referencing and cause issues in CRC calculation)
• The SAF area scans the Storage Area Flash region (the last 128 words of program memory) if the SAFEN
Configuration bit is cleared (Storage Area Flash enabled). If the Storage Area Flash is disabled, attempting to
scan this region will result in the CRC-on-boot indicating a mismatch.
• The boot area scans the region of program memory defined by the BBEN and BBSIZE Configuration bits. If the
BBEN bit is set (disabling boot area), attempting to scan this region will result in the CRC-on-boot indicating a
mismatch.
• The application area scans the remainder of program memory not specifically designated for the Boot Block or
the SAF
If a mismatch is not detected in a section (or if scanning of that section is disabled), the associated bit of BOOTREG
associated with that section (B0 for boot, B1 for non-boot) will be set. If all calculated CRC check values match their
expected values, the output pin of the CRC-on-boot module (if any is selected) will be either driven high or released
(depending on the ODCON Configuration bit) and user code will be executed beginning from the Reset vector.
13.13.1 CRCCON0
Name: CRCCON0
Offset: 0x357
Bit 7 6 5 4 3 2 1 0
EN GO BUSY ACCM SETUP[1:0] SHIFTM FULL
Access R/W R/W R R/W R/W R/W R
Reset 0 0 0 0 0 0 0
13.13.2 CRCCON1
Name: CRCCON1
Offset: 0x358
Bit 7 6 5 4 3 2 1 0
PLEN[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
13.13.3 CRCCON2
Name: CRCCON2
Offset: 0x359
Bit 7 6 5 4 3 2 1 0
DLEN[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
13.13.4 CRCDATA
Name: CRCDATA
Offset: 0x34F
Bit 31 30 29 28 27 26 25 24
CRCDATAT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
CRCDATAU[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
CRCDATAH[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
CRCDATAL[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
13.13.5 CRCOUT
Name: CRCOUT
Offset: 0x353
Bit 31 30 29 28 27 26 25 24
CRCOUTT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
CRCOUTU[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
CRCOUTH[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
CRCOUTL[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
13.13.6 CRCSHIFT
Name: CRCSHIFT
Offset: 0x353
Bit 31 30 29 28 27 26 25 24
CRCSHIFTT[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
CRCSHIFTU[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
CRCSHIFTH[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
CRCSHIFTL[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
13.13.7 CRCXOR
Name: CRCXOR
Offset: 0x353
Bit 31 30 29 28 27 26 25 24
CRCXORT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
CRCXORU[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
CRCXORH[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
CRCXORL[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
13.13.8 SCANCON0
Name: SCANCON0
Offset: 0x360
Bit 7 6 5 4 3 2 1 0
EN TRIGEN SGO MREG BURSTMD BUSY
Access R/W R/W R/W/HC R/W R/W R/W
Reset 0 0 0 1 0 0
Notes:
1. Setting EN = 0 does not affect any other register content.
2. Scanner trigger selection can be set using the SCANTRIG register.
3. This bit can be cleared in software. It is cleared in hardware when LADR > HADR (and a data cycle is not
occurring) or when CRCGO = 0.
4. The CRCEN and CRCGO bits must be set before setting the SGO bit.
5. See Table 13-2.
Table 13-2. Scanner Operating Modes
13.13.9 SCANLADR
Name: SCANLADR
Offset: 0x35A
Bit 23 22 21 20 19 18 17 16
SCANLADRU[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
SCANLADRH[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
SCANLADRL[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. Registers SCANLADRU/H/L form a 22-bit value, but are not guarded for atomic or asynchronous access;
registers may only be read or written while SGO = 0.
2. While SGO = 1, writing to this register is ignored.
13.13.10 SCANHADR
Name: SCANHADR
Offset: 0x35D
Bit 23 22 21 20 19 18 17 16
SCANHADRU[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1
Bit 15 14 13 12 11 10 9 8
SCANHADRH[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
SCANHADRL[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Notes:
1. Registers SCANHADRU/H/L form a 22-bit value but are not guarded for atomic or asynchronous access;
registers may only be read or written while SGO = 0.
2. While SGO = 1, writing to this register is ignored.
13.13.11 SCANTRIG
Name: SCANTRIG
Offset: 0x361
Bit 7 6 5 4 3 2 1 0
TSEL[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
Note:
1. The number of implemented bits varies by device.
13.13.12 BOOTREG
Name: BOOTREG
Offset: 0x038
Bit 7 6 5 4 3 2 1 0
BPOUT BOOTDONE B1 B0
Access R/W R/W R/W R/W
Reset 0 0 0 0
Bit 6 – BOOTDONE CRC-on-Boot on Previous Reset Status/ CRC-on-Bot on Next Reset Configuration
Value Description
1 CRC-on-Boot has run on previous Reset, run user code on next non-POR Reset
0 Run CRC-on-Boot on next non-POR Reset
0x00
... Reserved
0x37
0x38 BOOTREG 7:0 BPOUT BOOTDONE B1 B0
0x39
... Reserved
0x034E
7:0 CRCDATAL[7:0]
15:8 CRCDATAH[7:0]
0x034F CRCDATA
23:16 CRCDATAU[7:0]
31:24 CRCDATAT[7:0]
7:0 CRCOUTL[7:0]
15:8 CRCOUTH[7:0]
0x0353 CRCOUT
23:16 CRCOUTU[7:0]
31:24 CRCOUTT[7:0]
7:0 CRCSHIFTL[7:0]
15:8 CRCSHIFTH[7:0]
0x0353 CRCSHIFT
23:16 CRCSHIFTU[7:0]
31:24 CRCSHIFTT[7:0]
7:0 CRCXORL[7:0]
15:8 CRCXORH[7:0]
0x0353 CRCXOR
23:16 CRCXORU[7:0]
31:24 CRCXORT[7:0]
0x0357 CRCCON0 7:0 EN GO BUSY ACCM SETUP[1:0] SHIFTM FULL
0x0358 CRCCON1 7:0 PLEN[4:0]
0x0359 CRCCON2 7:0 DLEN[4:0]
7:0 SCANLADRL[7:0]
0x035A SCANLADR 15:8 SCANLADRH[7:0]
23:16 SCANLADRU[5:0]
7:0 SCANHADRL[7:0]
0x035D SCANHADR 15:8 SCANHADRH[7:0]
23:16 SCANHADRU[5:0]
0x0360 SCANCON0 7:0 EN TRIGEN SGO MREG BURSTMD BUSY
0x0361 SCANTRIG 7:0 TSEL[4:0]
14. Resets
There are multiple ways to reset the device:
• Power-on Reset (POR)
• Brown-out Reset (BOR)
• Low-Power Brown-out Reset (LPBOR)
• MCLR Reset
• WDT Reset
• RESET instruction
• Stack Overflow
• Stack Underflow
• Programming mode exit
• Memory Execution Violation Reset
• Main LDO Voltage Regulator Reset
• Configuration Memory Reset
A simplified block diagram of the On-Chip Reset Circuit is shown in the block diagram below.
Figure 14-1. Simplified Block Diagram of On-Chip Reset Circuit
Re v. 10 -00 00 06 G
RESET Instruction
Memory Violation
Main LDO Voltage Regulator
Configuration Memory
Stack Underflow
Stack Overflow
WWDT Time-out/
Window violation
Device
Reset
Power-on
Reset
VDD
Brown-out
Reset Power-up
Timer
LFINTOSC
2
LPBOR
PWRTS
Reset
Note:
1. See the BOR Operating Modes table for BOR active conditions.
...........continued
Instruction Execution upon:
BOREN SBOREN Device Mode BOR Mode
Release of POR Wake-up from Sleep
1 X Active Wait for release of BOR (BORRDY
01 Begins immediately
0 X Hibernate = 1)
Note:
1. In this specific case, “Release of POR” and “Wake-up from Sleep”, there is no BOR ready delay in start-up.
The BOR ready flag (BORRDY = 1) will be set before the CPU is ready to execute instructions because the
BOR circuit is forced on by the BOREN bits.
Figure 14-2. Brown-Out Situations
Rev. 30-000092A
4/12/2017
VDD
VBOR
Internal
Reset TPWRT(1)
VDD
VBOR
VDD
VBOR
Internal
Reset TPWRT(1)
Note:
1. TPWRT delay only if the Configuration bits enable the Power-up Timer.
Rev. 30-000091B
6/21/2017
Any Reset
BOR
BOR Event
REARM POR
Event To PCON
indicator bit
POR
LPBOR
POR Event
LPBOR Event
Reset
logic
Important: An internal Reset event (RESET instruction, BOR, WWDT, POR, STKOVF, STKUNF) does not
drive the MCLR pin low.
VDD
Internal POR
TPWRT
Power-up Timer
MCLR
TMCLR
Internal RESET
Oscillator Modes
External Crystal
TOST
Oscillator Start-up Timer
Oscillator
FOSC
Internal Oscillator
Oscillator
FOSC
CLKIN
FOSC
Program STATUS
Condition PCON0 Register PCON1 Register
Counter Register(1,2)
Power-on Reset 0 -110 0000 0011 110x ---- -111
...........continued
Program STATUS
Condition PCON0 Register PCON1 Register
Counter Register(1,2)
MCLR Reset during
0 -uuu uuuu uuuu 0uuu ---- -uuu
normal operation
MCLR Reset during
0 -10u uuuu uuuu 0uuu ---- -uuu
Sleep
WDT Time-out Reset 0 -0uu uuuu uuu0 uuuu ---- -uuu
Stack Underflow
0 -uuu uuuu u1uu uuuu ---- -uuu
Reset (STVREN = 1)
Data Protection
0 -uuu uuuu uuuu uuuu ---- -uu0
(Fuse Fault)
VREG or ULP Ready
0 -110 0000 0011 110u ---- -0u1
Fault
Memory Violation
0 -uuu uuuu uuuu uuuu ---- -u0u
Reset
14.13.1 BORCON
Name: BORCON
Offset: 0x049
Bit 7 6 5 4 3 2 1 0
SBOREN BORRDY
Access R/W R
Reset 1 q
14.13.2 PCON0
Name: PCON0
Offset: 0x4F0
Bit 7 6 5 4 3 2 1 0
STKOVF STKUNF WDTWV RWDT RMCLR RI POR BOR
Access R/W/HS R/W/HS R/W/HC R/W/HC R/W/HC R/W/HC R/W/HC R/W/HC
Reset 0 0 1 1 1 1 0 q
14.13.3 PCON1
Name: PCON1
Offset: 0x4F1
Bit 7 6 5 4 3 2 1 0
PORVDDIO3 PORVDDIO2 RVREG MEMV RCM
Access R/W/HC R/W/HC R/W/HC R/W/HC R/W/HC
Reset 1 1 1 0 q
0x00
... Reserved
0x48
0x49 BORCON 7:0 SBOREN BORRDY
0x4A
... Reserved
0x04EF
0x04F0 PCON0 7:0 STKOVF STKUNF WDTWV RWDT RMCLR RI POR BOR
0x04F1 PCON1 7:0 PORVDDIO3 PORVDDIO2 RVREG MEMV RCM
WWDT
Armed
WDT
Window
Violation
Window Closed
Window
Comparator
CLRWDT Sizes
WINDOW
RESET
..
. R
See
18-bit Prescale
WDTCON1
Counter
Register
E
..
.
CS
PS
R
5-bit Overflow
WDT Time-out
WDT Counter Latch
WDTE = b01
SEN
WDTE = b11
WDTE = b10
Sleep
CLRWDT Instruction
(or other WDT Reset)
Window Period
Time-out Event
Window Delay
(window violation can occur)
Conditions WWDT
WDTE = ‘b00
15.7.1 WDTCON0
Name: WDTCON0
Offset: 0x078
Bit 7 6 5 4 3 2 1 0
PS[4:0] SEN
Access R/W R/W R/W R/W R/W R/W
Reset q q q q q 0
Notes:
1. When the WDTCPS Configuration bits = ‘b11111, the Reset value (q) of WDTPS is ‘b01011. Otherwise, the
Reset value of WDTPS is equal to the WDTCPS in Configuration bits.
2. When the WDTCPS in Configuration bits ≠ ‘b11111, these bits are read-only.
15.7.2 WDTCON1
Name: WDTCON1
Offset: 0x079
Bit 7 6 5 4 3 2 1 0
CS[2:0] WINDOW[2:0]
Access R/W R/W R/W R/W R/W R/W
Reset q q q q q q
CS Clock Source
111-100 Reserved
011 EXTOSC
010 SOSC
001 MFINTOSC (31.25 kHz)
000 LFINTOSC (31 kHz)
Notes:
1. When the WDTCCS in Configuration bits = ‘0b111, the Reset value of WDTCS is ‘b000.
2. The Reset value (q) of WINDOW is determined by the value of WDTCWS in the Configuration bits.
3. When the WDTCCS in Configuration bits ≠ ‘b111, these bits are read-only.
4. When the WDTCWS in Configuration bits ≠ ‘b111, these bits are read-only.
15.7.3 WDTPSH
Name: WDTPSH
Offset: 0x07B
Bit 7 6 5 4 3 2 1 0
PSCNTH[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Note:
1. The 18-bit WDT prescaler value, PSCNT[17:0] includes the WDTPSL, WDTPSH and the lower bits of the
WDTTMR registers. PSCNT[17:0] is intended for debug operations and will be read during normal operation.
15.7.4 WDTPSL
Name: WDTPSL
Offset: 0x07A
Bit 7 6 5 4 3 2 1 0
PSCNTL[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Note:
1. The 18-bit WDT prescaler value, PSCNT[17:0] includes the WDTPSL, WDTPSH and the lower bits of the
WDTTMR registers. PSCNT[17:0] is intended for debug operations and will be read during normal operation.
15.7.5 WDTTMR
Name: WDTTMR
Offset: 0x07C
Bit 7 6 5 4 3 2 1 0
TMR[4:0] STATE PSCNT[17:16]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Note:
1. The 18-bit WDT prescaler value, PSCNT[17:0] includes the WDTPSL, WDTPSH and the lower bits of the
WDTTMR registers. PSCNT[17:0] is intended for debug operations and will not be read during normal
operation.
0x00
... Reserved
0x77
0x78 WDTCON0 7:0 PS[4:0] SEN
0x79 WDTCON1 7:0 CS[2:0] WINDOW[2:0]
0x7A WDTPSL 7:0 PSCNTL[7:0]
0x7B WDTPSH 7:0 PSCNTH[7:0]
0x7C WDTTMR 7:0 TMR[4:0] STATE PSCNT[17:16]
DMA1
Control Registers
Source Size
Program Flash
Memory
Destination Size
System Arbiter
.. Data EEPROM
..
. GPR/SFR
RAM Space
DMAn
Control Registers
Priority
Source Size
Destination Size
Depending on the priority of the DMA with respect to CPU execution (refer to the “Memory Access Scheme”
section in the “PIC18 CPU” chapter for more information), the DMA Controller can move data through two methods:
• Stalling the CPU execution until it has completed its transfers (DMA has higher priority over the CPU in this
mode of operation)
• Utilizing unused CPU cycles for DMA transfers (CPU has higher priority over the DMA in this mode of
operation). Unused CPU cycles are referred to as bubbles, which are instruction cycles available for use by the
DMA to perform read and write operations. In this way, the effective bandwidth for handling data is increased; at
the same time, DMA operations can proceed without causing a processor stall.
• Reading the source address memory and storing the value in the DMA Buffer register
• Writing the contents of the DMA Buffer register to the destination address memory
The XIP bit is a Status bit to indicate whether or not the data in the DMAnBUF register has been written to the
destination address. If the bit is set, then data is waiting to be written to the destination. If clear, it means that either
data has been written to the destination or that no source read has occurred.
The DMA has read access to PFM, Data EEPROM, and SFR/GPR space, and write access to SFR/GPR space.
Based on these memory access capabilities, the DMA can support the following memory transactions:
Table 16-1. DMA Memory Access
Important: Even though the DMA module has access to all memory and peripherals that are also
available to the CPU, it is recommended that the DMA does not access any register that is part of the
system arbitration. The DMA, as a system arbitration client must not be read or written by itself or by
another DMA instantiation.
The following sections discuss the various control interfaces required for DMA data transfers.
41FFh - 41DFh - 41BFh - 419Fh DMAnAIRQ_DMA7 417Fh DMAnSPTRH_DMA6 415Fh DMAnDPTRL_DMA5 413Fh DMAnSSAH_DMA3 411Fh DMAnDSAH_DMA2
41FEh - 41DEh - 41BEh - 419Eh DMAnCON1_DMA7 417Eh DMAnSPTRL_DMA6 415Eh DMAnDCNTH_DMA5 413Eh DMAnSSAL_DMA3 411Eh DMAnDSAL_DMA2
41FDh - 41DDh - 41BDh - 419Dh DMAnCON0_DMA7 417Dh DMAnSCNTH_DMA6 415Dh DMAnDCNTL_DMA5 413Dh DMAnSSZH_DMA3 411Dh DMAnDSZH_DMA2
41FCh - 41DCh - 41BCh - 419Ch DMAnSSAU_DMA7 417Ch DMAnSCNTL_DMA6 415Ch DMAnBUF_DMA5 413Ch DMAnSSZL_DMA3 411Ch DMAnDSZL_DMA2
41FBh TMR5H_M1 41DBh - 41BBh - 419Bh DMAnSSAH_DMA7 417Bh DMAnDSAH_DMA6 415Bh DMAnSIRQ_DMA4 413Bh DMAnSPTRU_DMA3 411Bh DMAnDPTRH_DMA2
41FAh TMR5L_M1 41DAh - 41BAh - 419Ah DMAnSSAL_DMA7 417Ah DMAnDSAL_DMA6 415Ah DMAnAIRQ_DMA4 413Ah DMAnSPTRH_DMA3 411Ah DMAnDPTRL_DMA2
41F9h TMR3H_M1 41D9h - 41B9h - 4199h DMAnSSZH_DMA7 4179h DMAnDSZH_DMA6 4159h DMAnCON1_DMA4 4139h DMAnSPTRL_DMA3 4119h DMAnDCNTH_DMA2
41F8h TMR3L_M1 41D8h - 41B8h - 4198h DMAnSSZL_DMA7 4178h DMAnDSZL_DMA6 4158h DMAnCON0_DMA4 4138h DMAnSCNTH_DMA3 4118h DMAnDCNTL_DMA2
41F7h TMR1H_M1 41D7h - 41B7h DMAnSIRQ_DMA8 4197h DMAnSPTRU_DMA7 4177h DMAnDPTRH_DMA6 4157h DMAnSSAU_DMA4 4137h DMAnSCNTL_DMA3 4117h DMAnBUF_DMA2
41F6h TMR1L_M1 41D6h - 41B6h DMAnAIRQ_DMA8 4196h DMAnSPTRH_DMA7 4176h DMAnDPTRL_DMA6 4156h DMAnSSAH_DMA4 4136h DMAnDSAH_DMA3 4116h DMAnSIRQ_DMA1
41F5h - 41D5h - 41B5h DMAnCON1_DMA8 4195h DMAnSPTRL_DMA7 4175h DMAnDCNTH_DMA6 4155h DMAnSSAL_DMA4 4135h DMAnDSAL_DMA3 4115h DMAnAIRQ_DMA1
41F4h - 41D4h - 41B4h DMAnCON0_DMA8 4194h DMAnSCNTH_DMA7 4174h DMAnDCNTL_DMA6 4154h DMAnSSZH_DMA4 4134h DMAnDSZH_DMA3 4114h DMAnCON1_DMA1
41F3h - 41D3h - 41B3h DMAnSSAU_DMA8 4193h DMAnSCNTL_DMA7 4173h DMAnBUF_DMA6 4153h DMAnSSZL_DMA4 4133h DMAnDSZL_DMA3 4113h DMAnCON0_DMA1
41F2h - 41D2h - 41B2h DMAnSSAH_DMA8 4192h DMAnDSAH_DMA7 4172h DMAnSIRQ_DMA5 4152h DMAnSPTRU_DMA4 4132h DMAnDPTRH_DMA3 4112h DMAnSSAU_DMA1
41F1h - 41D1h - 41B1h DMAnSSAL_DMA8 4191h DMAnDSAL_DMA7 4171h DMAnAIRQ_DMA5 4151h DMAnSPTRH_DMA4 4131h DMAnDPTRL_DMA3 4111h DMAnSSAH_DMA1
41F0h - 41D0h - 41B0h DMAnSSZH_DMA8 4190h DMAnDSZH_DMA7 4170h DMAnCON1_DMA5 4150h DMAnSPTRL_DMA4 4130h DMAnDCNTH_DMA3 4110h DMAnSSAL_DMA1
41EFh - 41CFh - 41AFh DMAnSSZL_DMA8 418Fh DMAnDSZL_DMA7 416Fh DMAnCON0_DMA5 414Fh DMAnSCNTH_DMA4 412Fh DMAnDCNTL_DMA3 410Fh DMAnSSZH_DMA1
41EEh - 41CEh - 41AEh DMAnSPTRU_DMA8 418Eh DMAnDPTRH_DMA7 416Eh DMAnSSAU_DMA5 414Eh DMAnSCNTL_DMA4 412Eh DMAnBUF_DMA3 410Eh DMAnSSZL_DMA1
41EDh - 41CDh - 41ADh DMAnSPTRH_DMA8 418Dh DMAnDPTRL_DMA7 416Dh DMAnSSAH_DMA5 414Dh DMAnDSAH_DMA4 412Dh DMAnSIRQ_DMA2 410Dh DMAnSPTRU_DMA1
41ECh - 41CCh - 41ACh DMAnSPTRL_DMA8 418Ch DMAnDCNTH_DMA7 416Ch DMAnSSAL_DMA5 414Ch DMAnDSAL_DMA4 412Ch DMAnAIRQ_DMA2 410Ch DMAnSPTRH_DMA1
41CBh - 41CBh - 41ABh DMAnSCNTH_DMA8 418Bh DMAnDCNTL_DMA7 416Bh DMAnSSZH_DMA5 414Bh DMAnDSZH_DMA4 412Bh DMAnCON1_DMA2 410Bh DMAnSPTRL_DMA1
41EAh - 41CAh - 41AAh DMAnSCNTL_DMA8 418Ah DMAnBUF_DMA7 416Ah DMAnSSZL_DMA5 414Ah DMAnDSZL_DMA4 412Ah DMAnCON0_DMA2 410Ah DMAnSCNTH_DMA1
41E9h - 41C9h - 41A9h DMAnDSAH_DMA8 4189h DMAnSIRQ_DMA6 4169h DMAnSPTRU_DMA5 4149h DMAnDPTRH_DMA4 4129h DMAnSSAU_DMA2 4109h DMAnSCNTL_DMA1
41E8h - 41C8h - 41A8h DMAnDSAL_DMA8 4188h DMAnAIRQ_DMA6 4168h DMAnSPTRH_DMA5 4148h DMAnDPTRL_DMA4 4128h DMAnSSAH_DMA2 4108h DMAnDSAH_DMA1
41E7h - 41C7h - 41A7h DMAnDSZH_DMA8 4187h DMAnCON1_DMA6 4167h DMAnSPTRL_DMA5 4147h DMAnDCNTH_DMA4 4127h DMAnSSAL_DMA2 4107h DMAnDSAL_DMA1
41E6h - 41C6h - 41A6h DMAnDSZL_DMA8 4186h DMAnCON0_DMA6 4166h DMAnSCNTH_DMA5 4146h DMAnDCNTL_DMA4 4126h DMAnSSZH_DMA2 4106h DMAnDSZH_DMA1
41E5h - 41C5h - 41A5h DMAnDPTRH_DMA8 4185h DMAnSSAU_DMA6 4165h DMAnSCNTL_DMA5 4145h DMAnBUF_DMA4 4125h DMAnSSZL_DMA2 4105h DMAnDSZL_DMA1
41E4h - 41C4h - 41A4h DMAnDPTRL_DMA8 4184h DMAnSSAH_DMA6 4164h DMAnDSAH_DMA5 4144h DMAnSIRQ_DMA3 4124h DMAnSPTRU_DMA2 4104h DMAnDPTRH_DMA1
41E3h IOCEF_M1 41C3h - 41A3h DMAnDCNTH_DMA8 4183h DMAnSSAL_DMA6 4163h DMAnDSAL_DMA5 4143h DMAnAIRQ_DMA3 4123h DMAnSPTRH_DMA2 4103h DMAnDPTRL_DMA1
41E2h IOCCF_M1 41C2h - 41A2h DMAnDCNTL_DMA8 4182h DMAnSSZH_DMA6 4162h DMAnDSZH_DMA5 4142h DMAnCON1_DMA3 4122h DMAnSPTRL_DMA2 4102h DMAnDCNTH_DMA1
41E1h IOCBF_M1 41C1h - 41A1h DMAnBUF_DMA8 4181h DMAnSSZL_DMA6 4161h DMAnDSZL_DMA5 4141h DMAnCON0_DMA3 4121h DMAnSCNTH_DMA2 4101h DMAnDCNTL_DMA1
41E0h IOCAF_M1 41C0h - 41A0h DMAnSIRQ_DMA7 4180h DMAnSPTRU_DMA6 4160h DMAnDPTRH_DMA5 4140h DMAnSSAU_DMA3 4120h DMAnSCNTL_DMA2 4100h DMAnBUF_DMA1
DMAnSSA DMAnDSA
DMAnSPTR DMAnDPTR
+1 +1
0 0
-1 -1
SMODE DMODE
The DMA can initiate data transfers from the PFM, Data EEPROM or SFR/GPR space. The SMR bits are used to
select the type of memory being pointed to by the Source Address Pointer. The SMR bits are required because the
PFM and SFR/GPR spaces have overlapping addresses that do not allow the specified address to uniquely define
the memory location to be accessed.
Important:
1. For proper memory read access to occur, the combination of address and space selection must be
valid.
2. The destination does not have space selection bits because it can only write to the SFR/GPR
space.
Important: Reading the DMAnSCNT or DMAnDCNT registers will never return zero. When either register
is decremented from ‘1’, it is immediately reloaded from the corresponding size register.
DMAnSSZ DMAnDSZ
DMAnSCNT DMAnDCNT
1 1
During the DMA operation after each transaction, Table 16-4 and Table 16-5 indicate how the Source/Destination
Pointer and Counter registers are modified.
The following sections discuss how to initiate and terminate DMA transfers.
Table 16-4. DMA Source Pointer/Counter During Operation
DMAnSCNT = DMAnSSZ
DMAnSCNT == 1
DMAnSPTR = DMAnSSA
DMAnDCNT = DMAnDSZ
DMAnDCNT == 1
DMAnDPTR = DMAnDSA
Important:
1. Software start can only occur when the EN bit is set.
2. If the CPU writes to the DGO bit while it is already set, there is no effect on the system, the DMA will
continue to operate normally.
Important: Reading the DMAnSCNT or DMAnDCNT registers will never return zero. When either register
is decremented from ‘1’, it is immediately reloaded from the corresponding size register.
Important: After the DMA message transfer is stopped, it requires an extra instruction cycle before the
Stop condition takes effect. Thus, after the Stop condition has occurred, a source read or a destination
write can occur depending on the source or destination bus availability.
Important: The SSTP and DSTP bits are independent functions and do not depend on each other. It is
possible for a message to be stopped by either counter at message end or both counters at message end.
8. Select the priority level for the DMA (see the “System Arbitration” section in the “PIC18 CPU” chapter) and
lock the priorities (see the “Priority Lock” section in the “PIC18 CPU” chapter).
9. Enable the DMA by setting the EN bit.
10. If using software control for data transfer, set the DGO bit, else this bit will be set by the hardware trigger.
Once the DMA is set up, Figure 16-5 describes the sequence of operation when the DMA uses hardware triggers and
utilizes the unused CPU cycles (bubble) for DMA transfers.
The following sections describe with visual reference the sequence of events for different configurations of the DMA
module.
Configure DMA
Module
EN = 1
DMA Source/
Destination Pointers/
Counters are loaded
SIRQEN = 1 & N
Trigger?
DGO = 1
N
Bubble?
Y
DMAnBUF = &DMAnSPTR
Source Read
XIP = 1
N
Bubble?
Y
&DMAnDPTR = DMABUF
Destination Write
XIP = 0
Y Reload
DMAxSCNTIF
DMAnSCNT = 0 DMAnSCNT & DGO = 0
=1
DMAnSPTR
N
Update Y
DMAnSSA, SIRQEN = 0 SSTP = 1
DMAnSCNT
Y Reload
DMAnDCNTIF
DMAnDCNT = 0 DMAnDCNT & DGO = 0
=1
DMAnDPTR
N
Y
Update AIRQEN = 0 DSTP = 1
DMAnDSA,
DMAnDCNT
N
N
DGO = 0
End Process
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Instruction
Clock
EN
SIRQEN
Source Hardware
Trigger
DGO
DMAnSCNT 4 3 2 1 4
DMAnDCNT 2 1 2 1 2
DMA STATE IDLE SR(1) DW(2) SR(1) DW(2) IDLE SR(1) DW(2) SR(1) DW(2) IDLE
DMAxSCNTIF
DMAxDCNTIF
Notes:
1. SR - Source Read
2. DW - Destination Write
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Instruction
Clock
EN
SIRQEN
Source Hardware
Trigger
DGO
DMAnSCNT 2 1 2 1 2
DMAnDCNT 4 3 2 1 4
DMA STATE IDLE SR(1) DW(2) SR(1) DW(2) IDLE SR(1) DW(2) SR(1) DW(2) IDLE
DMAxSCNTIF
DMAxDCNTIF
Notes:
1. SR - Source Read
2. DW - Destination Write
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
Instruction
Clock
EN
SIRQEN
Source
Hardware
Trigger
DGO
DMAnSPTR 0x100 0x101 0x100 0x101 0x100 0x101 0x100 0x101 0x100
DMAnDPTR 0x200 0x201 0x202 0x203 0x200 0x201 0x202 0x203 0x202
DMAnSCNT 2 1 2 1 2 1 2 1 2
DMAnDCNT 4 3 2 1 4 3 2 1 2
DMAxSCNTIF
DMAxDCNTIF
Notes:
1. SR - Source Read
2. DW - Destination Write
Instruction
Clock
EN
SIRQEN
Source Hardware
Trigger
DGO
DMAnSCNT 2 1 2 1 2
DMAnDCNT 10 9 8 7 6
DMA STATE IDLE SR(1) DW(2) SR(1) DW(2) IDLE SR(1) DW(2) SR(1) DW(2) IDLE
DMAxSCNTIF
DMAxDCNTIF
Notes:
1. SR - Source Read
2. DW - Destination Write
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Instruction
Clock
EN
SIRQEN
Source Hardware
Trigger
DGO
DMAnSCNT 2 1 2 1 2
DMAnDCNT 4 3 2 1 4
DMA STATE IDLE SR(1) DW(2) SR(1) DW(2) IDLE SR(1) DW(2) SR(1) DW(2) IDLE
DMAxSCNTIF
DMAxDCNTIF
DMAxORIF
DMAnCON1bits.SMA = 01
Notes:
1. SR - Source Read
2. DW - Destination Write
Instruction
Clock
EN
SIRQEN
AIRQEN
Source Hardware
Trigger
Abort Hardware
Trigger
DGO
DMAnSCNT 2 1 2 1 2
DMAnDCNT 10 9 2 1 10
DMA STATE IDLE SR(1) DW(2) SR(1) DW(2) IDLE SR(1) DW(2) SR(1) DW(2) IDLE
DMAxSCNTIF
DMAxDCNTIF
DMAxAIF
DMAnSSA 0x3EEF DMAnDSA 0x100
Notes:
1. SR - Source Read
2. DW - Destination Write
1 2 3 4 5 6 7 8 9 10 10 11 12
Instruction
Clock
EN
SIRQEN
AIRQEN
Source Hardware
Trigger
Abort Hardware
Trigger
DGO
DMAnSCNT 2 1 2
DMAnDCNT 10 9 8
DMAnCONbits.XIP
DMAxAIF
Notes:
1. SR - Source Read
2. DW - Destination Write
16.9 Reset
The DMA registers are set to the default state on any Reset. The registers are also reset to the default state when the
enable bit is cleared (EN = 0). User firmware needs to setup all the registers to resume DMA operation.
void initializeDMA(){
//Select DMA1 by setting DMASELECT register to 0x00
DMASELECT = 0x00;
//DMAnCON1 - DPTR remains, Source Memory Region PFM, SPTR increments, SSTP
DMAnCON1 = 0x0B;
//Source registers
//Source size
DMAnSSZH = 0x00;
DMAnSSZL = 0x0A;
//Source start address, 0x1000
DMAnSSAU = 0x00;
DMAnSSAH = 0x10;
DMAnSSAL = 0x00;
//Destination registers
//Destination size
DMAnDSZH = 0x00;
DMAnDSZL = 0x01;
//Destination start address,
DMAnDSA = &U1TXB;
//Start trigger source U1TX. Refer the datasheet for the correct code
DMAnSIRQ = 0xnn;
//Change arbiter priority if needed and perform lock operation
DMA1PR = 0x01; // Change the priority only if needed
PRLOCK = 0x55; // This sequence
PRLOCK = 0xAA; // is mandatory
PRLOCKbits.PRLOCKED = 1; // for DMA operation
//Enable the DMA & the trigger to start DMA transfer
DMAnCON0 = 0xC0;
}
16.13.1 DMASELECT
Name: DMASELECT
Offset: 0x0E8
DMA Instance Selection Register
Selects which DMA instance is accessed by the DMA registers
Bit 7 6 5 4 3 2 1 0
SLCT[2:0]
Access R/W R/W R/W
Reset 0 0 0
16.13.2 DMAnCON0
Name: DMAnCON0
Offset: 0x0FC
DMA Control Register 0
Bit 7 6 5 4 3 2 1 0
EN SIRQEN DGO AIRQEN XIP
Access R/W R/W/HC R/W/HS/HC R/W/HC R/HS/HC
Reset 0 0 0 0 0
16.13.3 DMAnCON1
Name: DMAnCON1
Offset: 0x0FD
Bit 7 6 5 4 3 2 1 0
DMODE[1:0] DSTP SMR[1:0] SMODE[1:0] SSTP
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
16.13.4 DMAnBUF
Name: DMAnBUF
Offset: 0x0E9
Bit 7 6 5 4 3 2 1 0
BUF[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
16.13.5 DMAnSSA
Name: DMAnSSA
Offset: 0x0F9
Bit 23 22 21 20 19 18 17 16
SSA[21:16]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
SSA[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
SSA[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names.
1. DMAnSSAU: Accesses the upper most byte [23:16].
2. DMAnSSAH: Accesses the high byte [15:8].
3. DMAnSSAL: Access the low byte [7:0].
16.13.6 DMAnSSZ
Name: DMAnSSZ
Offset: 0x0F7
Bit 15 14 13 12 11 10 9 8
SSZ[11:8]
Access R/W R/W R/W R/W
Reset 0 0 0 0
Bit 7 6 5 4 3 2 1 0
SSZ[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names.
1. DMAnSSZH: Accesses the high byte [15:8].
2. DMAnSSZL: Access the low byte [7:0].
16.13.7 DMAnSCNT
Name: DMAnSCNT
Offset: 0x0F2
Bit 15 14 13 12 11 10 9 8
SCNT[11:8]
Access R/W R/W R/W R/W
Reset 0 0 0 0
Bit 7 6 5 4 3 2 1 0
SCNT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names.
1. DMAnSCNTH: Accesses the high byte [15:8].
2. DMAnSCNTL: Access the low byte [7:0].
16.13.8 DMAnSPTR
Name: DMAnSPTR
Offset: 0x0F4
Bit 23 22 21 20 19 18 17 16
SPTR[21:16]
Access R R R R R R
Reset 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
SPTR[15:8]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
SPTR[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names.
1. DMAnSPTRU: Accesses the upper most byte [23:16].
2. DMAnSPTRH: Accesses the high byte [15:8].
3. DMAnSPTRL: Access the low byte [7:0].
16.13.9 DMAnDSA
Name: DMAnDSA
Offset: 0x0F0
Bit 15 14 13 12 11 10 9 8
DSA[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
DSA[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names.
1. DMAnDSAH: Accesses the high byte [15:8].
2. DMAnDSAL: Access the low byte [7:0].
16.13.10 DMAnDSZ
Name: DMAnDSZ
Offset: 0x0EE
Bit 15 14 13 12 11 10 9 8
DSZ[11:8]
Access R/W R/W R/W R/W
Reset 0 0 0 0
Bit 7 6 5 4 3 2 1 0
DSZ[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names.
1. DMAnDSZH: Accesses the high byte [15:8].
2. DMAnDSZL: Access the low byte [7:0].
16.13.11 DMAnDCNT
Name: DMAnDCNT
Offset: 0x0EA
Bit 15 14 13 12 11 10 9 8
DCNT[11:8]
Access R/W R/W R/W R/W
Reset 0 0 0 0
Bit 7 6 5 4 3 2 1 0
DCNT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names.
1. DMAnDCNTH: Accesses the high byte [15:8].
2. DMAnDCNTL: Access the low byte Destination Message Size bits [7:0].
16.13.12 DMAnDPTR
Name: DMAnDPTR
Offset: 0x0EC
Bit 15 14 13 12 11 10 9 8
DPTR[15:8]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
DPTR[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names.
1. DMAnDPTRH: Accesses the high byte [15:8].
2. DMAnDPTRL: Access the low byte [7:0].
16.13.13 DMAnSIRQ
Name: DMAnSIRQ
Offset: 0x0FF
Bit 7 6 5 4 3 2 1 0
SIRQ[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
...........continued
Vector Number Interrupt Source
Vector Number Interrupt Source (cont.) (cont.)
0x21 U1TX 0x6D DMA6DCNT
0x22 U1E 0x6E DMA6OR
0x23 U1 0x6F DMA6A
0x24 CANRX 0x70 -
0x25 CANTX 0x71 CLC7
0x26 PWM1RINT 0x72 CM2
0x27 PWM1GINT 0x73 NCO3
0x28 SPI2RX 0x74 DMA7SCNT
0x29 SPI2TX 0x75 DMA7DCNT
0x2A SPI2 0x76 DMA7OR
0x2B TU16B 0x77 DMA7ABRT
0x2C TMR3 0x78 NVM
0x2D TMR3G 0x79 CLC8
0x2E PWM2RINT 0x7A CRC (Cyclic Redundancy Check)
0x2F PWM2GINT 0x7B TMR6
0x30 INT1 0x7C DMA8SCNT
0x31 CLC2 0x7D DMA8DCNT
0x32 CWG1 (Complementary Waveform Generator) 0x7E DMA8OR
0x33 NCO1 (Numerically Controlled Oscillator) 0x7F DMA8ABRT
0x34 DMA2SCNT 0x80 TU16APR
0x35 DMA2DCNT 0x81 TU16ACAPT
0x36 DMA2OR 0x82 TU16AZERO
0x37 DMA2A 0x83 TU16BPR
0x38 I2C1RX 0x84 TU16BCAPT
0x39 I2C1TX 0x85 TU16BZERO
0x3A I2C1 0x86 -
0x3B I2C1E 0x87 -
0x3C - 0x88 -
0x3D CLC3 0x89 -
0x3E PWM3RINT 0x8A -
0x3F PWM3GINT 0x8B -
0x40 U2RX 0x8C -
0x41 U2TX 0x8D -
0x42 U2E 0x8E -
0x43 U2 0x8F -
0x44 TMR5 0x90 PWM1.S1P1 (PWM1 Parameter 1 of Slice 1)
0x45 TMR5G 0x91 PWM1.S1P2 (PWM1 Parameter 2 of Slice 1)
0x46 CCP2 0x92 PWM2S1P1
0x47 SCAN 0x93 PWM2S1P2
0x48 U3RX 0x94 PWM3S1P1
0x49 U3TX 0x95 PWM3S1P2
0x4A U3E 0x96 PWM4S1P1
0x4B U3 0x97 PWM4S1P2
16.13.14 DMAnAIRQ
Name: DMAnAIRQ
Offset: 0x0FE
Bit 7 6 5 4 3 2 1 0
AIRQ[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
0x00
... Reserved
0xE7
0xE8 DMASELECT 7:0 SLCT[2:0]
0xE9 DMAnBUF 7:0 BUF[7:0]
7:0 DCNT[7:0]
0xEA DMAnDCNT
15:8 DCNT[11:8]
7:0 DPTR[7:0]
0xEC DMAnDPTR
15:8 DPTR[15:8]
7:0 DSZ[7:0]
0xEE DMAnDSZ
15:8 DSZ[11:8]
7:0 DSA[7:0]
0xF0 DMAnDSA
15:8 DSA[15:8]
7:0 SCNT[7:0]
0xF2 DMAnSCNT
15:8 SCNT[11:8]
7:0 SPTR[7:0]
0xF4 DMAnSPTR 15:8 SPTR[15:8]
23:16 SPTR[21:16]
7:0 SSZ[7:0]
0xF7 DMAnSSZ
15:8 SSZ[11:8]
7:0 SSA[7:0]
0xF9 DMAnSSA 15:8 SSA[15:8]
23:16 SSA[21:16]
0xFC DMAnCON0 7:0 EN SIRQEN DGO AIRQEN XIP
0xFD DMAnCON1 7:0 DMODE[1:0] DSTP SMR[1:0] SMODE[1:0] SSTP
0xFE DMAnAIRQ 7:0 AIRQ[7:0]
0xFF DMAnSIRQ 7:0 SIRQ[7:0]
System
Clock
1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2
Instruction
3 3 3 3 3 3 3 3 3 3 3 3 3
Period
4 4 4 4 4 4 4 4 4 4 4 4 4
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
CPU Clock
Interrupt
(ROI = 1)
Notes:
1. Multicycle instructions are executed to completion before fetching 0x0004.
2. If the prefetched instruction clears GIE, the ISR will not occur, but DOZEN is still cleared and the CPU will
resume execution at full speed.
// Mainline operation
bool somethingToDo = FALSE;
void main() {
initializeSystem();
// DOZE = 64:1 (for example)
// ROI = 1;
GIE = 1; // enable interrupts
while (1) {
// If ADC completed, process data
if (somethingToDo) {
doSomething();
DOZEN = 1; // resume low-power
}
}
}
// Data interrupt handler
void interrupt() {
// DOZEN = 0 because ROI = 1
if (ADIF) {
somethingToDo = TRUE;
DOE = 0; // make main() go fast
ADIF = 0;
}
// else check other interrupts...
if (TMR0IF) {
timerTick++;
DOE = 1; // make main() go slow
TMR0IF = 0;
}
}
Note: User software can change the DOE bit in the ISR.
Important: Refer to individual chapters for more details on peripheral operation during Sleep.
Important: The first five events will cause a device Reset. The last event in the list is considered a
continuation of program execution. Fore more information about determining whether a device Reset or
wake-up event occurred, refer to the “Resets” chapter.
When the SLEEP instruction is being executed, the next instruction (PC + 2) is prefetched. For the device to wake up
through an interrupt event, the corresponding Interrupt Enable bit must be enabled in the PIEx register. Wake-up will
occur regardless of the state of the Global Interrupt Enable (GIE) bit. If the GIE bit is disabled, the device will continue
execution at the instruction after the SLEEP instruction. If the GIE bit is enabled, the device executes the instruction
after the SLEEP instruction and then call the Interrupt Service Routine (ISR).
Important: It is recommended to add a NOP as the immediate instruction after the SLEEP instruction.
The WDT is cleared when the device wakes up from Sleep, regardless of the source of wake-up. Upon a wake-from-
Sleep event, the core will wait for a combination of three conditions before beginning execution. The conditions are:
• PFM Ready
• System Clock Ready
• BOR Ready (unless BOR is disabled)
CLKIN(1)
Instruction Flo w
PC PC PC + 1 PC + 2 PC + 2 PC + 2 0004h 0005h
Instruction
Fetche d Inst(PC) = Slee p Inst(PC + 1) Inst(PC + 2) Inst(0x0004) Inst(0x0005)
Instruction Inst(PC - 1) Sleep Inst(PC + 1) Forced NOP Forced NOP Inst(0x0004)
Fetche d
Notes:
1. External clock - High, Medium, Low mode assumed.
2. CLKOUT is shown here for timing reference.
3. TOST = 1024 TOSC. This delay does not apply to EC and INTOSC Oscillator modes.
4. GIE = 1 assumed. In this case after wake-up, the processor calls the ISR at 0x0004. If GIE = 0, execution will
continue in-line.
• VREGPM = ‘b11; this mode is the similar to the Ultra-Low Power mode (VREGPM = ‘b10), and is
recommended ONLY for extended temperature ranges at or above 70℃.
Important:
1. Peripherals using FOSC will continue to operate while in Idle (but not in Sleep). Peripherals using
HFINTOSC:LFINTOSC will continue running in both Idle and Sleep.
2. When the Clock Out Enable (CLKOUTEN) Configuration bit is cleared, the CLKOUT pin will
continue operating while in Idle.
Important: The WWDT can bring the device out of Idle, in the same way it brings the device out of Sleep.
The DOZEN bit is not affected.
17.5.1 CPUDOZE
Name: CPUDOZE
Offset: 0x4F2
Bit 7 6 5 4 3 2 1 0
IDLEN DOZEN ROI DOE DOZE[2:0]
Access R/W R/W/HC/HS R/W R/W/HC/HS R/W R/W R/W
Reset 0 0 0 0 0 0 0
Bits 2:0 – DOZE[2:0] Ratio of CPU Instruction Cycles to Peripheral Instruction Cycles
Value Description
111 1:256
110 1:128
101 1:64
100 1:32
011 1:16
010 1:8
001 1:4
000 1:2
Note:
1. When ROI = 1 or DOE = 1.
17.5.2 VREGCON
Name: VREGCON
Offset: 0x048
Bit 7 6 5 4 3 2 1 0
PMSYS[1:0] VREGPM[1:0]
Access R R R/W R/W
Reset q q 1 0
0x00
... Reserved
0x47
0x48 VREGCON 7:0 PMSYS[1:0] VREGPM[1:0]
0x49
... Reserved
0x04F1
0x04F2 CPUDOZE 7:0 IDLEN DOZEN ROI DOE DOZE[2:0]
18.1 Overview
This module provides the ability to selectively enable or disable a peripheral. Disabling a peripheral places it in
its lowest possible Power state. The user can selectively disable unused modules to reduce the overall power
consumption.
Important: There will be no reads/writes to the module SFRs for at least two instruction cycles after it has
been re-enabled.
18.4.1 PMD0
Name: PMD0
Offset: 0x060
Bit 7 6 5 4 3 2 1 0
SYSCMD FVRMD HLVDMD CRCMD SCANMD CLKRMD IOCMD
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
Note:
1. Clearing the SYSCMD bit disables the system clock (FOSC) to peripherals, however peripherals clocked by
FOSC/4 are not affected.
18.4.2 PMD1
Name: PMD1
Offset: 0x061
Bit 7 6 5 4 3 2 1 0
SMT1MD TMR6MD TMR5MD TMR4MD TMR3MD TMR2MD TMR1MD TMR0MD
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
18.4.3 PMD2
Name: PMD2
Offset: 0x062
Bit 7 6 5 4 3 2 1 0
CANMD TU16BMD TU16AMD
Access R/W R/W R/W
Reset 0 0 0
18.4.4 PMD3
Name: PMD3
Offset: 0x063
Bit 7 6 5 4 3 2 1 0
ACTMD DAC1MD ADCMD C2MD C1MD ZCDMD
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Note:
1. Subject to the value of the ZCD Configuration bit.
18.4.5 PMD4
Name: PMD4
Offset: 0x064
Bit 7 6 5 4 3 2 1 0
CWG3MD CWG2MD CWG1MD DSM1MD NCO3MD NCO2MD NCO1MD
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
18.4.6 PMD5
Name: PMD5
Offset: 0x065
Bit 7 6 5 4 3 2 1 0
PWM4MD PWM3MD PWM2MD PWM1MD CCP3MD CCP2MD CCP1MD
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
18.4.7 PMD6
Name: PMD6
Offset: 0x066
Bit 7 6 5 4 3 2 1 0
U5MD U4MD U3MD U2MD U1MD SPI2MD SPI1MD I2C1MD
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
18.4.8 PMD7
Name: PMD7
Offset: 0x067
Bit 7 6 5 4 3 2 1 0
CLC8MD CLC7MD CLC6MD CLC5MD CLC4MD CLC3MD CLC2MD CLC1MD
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
18.4.9 PMD8
Name: PMD8
Offset: 0x068
Bit 7 6 5 4 3 2 1 0
DMA8MD DMA7MD DMA6MD DMA5MD DMA4MD DMA3MD DMA2MD DMA1MD
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
0x00
... Reserved
0x5F
0x60 PMD0 7:0 SYSCMD FVRMD HLVDMD CRCMD SCANMD CLKRMD IOCMD
0x61 PMD1 7:0 SMT1MD TMR6MD TMR5MD TMR4MD TMR3MD TMR2MD TMR1MD TMR0MD
0x62 PMD2 7:0 CANMD TU16BMD TU16AMD
0x63 PMD3 7:0 ACTMD DAC1MD ADCMD C2MD C1MD ZCDMD
0x64 PMD4 7:0 CWG3MD CWG2MD CWG1MD DSM1MD NCO3MD NCO2MD NCO1MD
0x65 PMD5 7:0 PWM4MD PWM3MD PWM2MD PWM1MD CCP3MD CCP2MD CCP1MD
0x66 PMD6 7:0 U5MD U4MD U3MD U2MD U1MD SPI2MD SPI1MD I2C1MD
0x67 PMD7 7:0 CLC8MD CLC7MD CLC6MD CLC5MD CLC4MD CLC3MD CLC2MD CLC1MD
0x68 PMD8 7:0 DMA8MD DMA7MD DMA6MD DMA5MD DMA4MD DMA3MD DMA2MD DMA1MD
19.1 Overview
Table 19-1. Port Availability per Device
Each port has eight registers to control the operation. These registers are:
• PORTx registers (reads the levels on the pins of the device)
• LATx registers (output latch)
• TRISx registers (data direction)
• ANSELx registers (analog select)
• WPUx registers (weak pull-up)
• INLVLx (input level control)
• SLRCONx registers (slew rate control)
• ODCONx registers (open-drain control)
In this section, the generic names such as PORTx, LATx, TRISx, etc. can be associated with PORTA, PORTB,
PORTC, etc., depending on availability per device.
A simplified model of a generic I/O port, without the interfaces to other peripherals, is shown in the following figure:
Figure 19-1. Generic I/O Port Operation
Re v. 10 -00 00 52 A
TRISx
D Q
Write LATx
Write PORTx VDD
CK
Data Register
Data bus
I/O pin
Read PORTx
To digital peripherals
ANSELx
To analog peripherals
VSS
BANKSEL PORTA ;
CLRF PORTA ;Clear PORTA
BANKSEL LATA ;
CLRF LATA ;Clear Data Latch
BANKSEL ANSELA ;
CLRF ANSELA ;Enable digital drivers
BANKSEL TRISA ;
MOVLW B'00111000' ;Set RA[5:3] as inputs
MOVWF TRISA ;and set others as outputs
Important: Most PORT pins share functions with device peripherals, both analog and digital. In general,
when a peripheral is enabled on a PORT pin, that pin cannot be used as a general purpose output;
however, the pin can still be read.
Important: As a general rule, output operations to a port must use the LAT register to avoid Read-
Modify-Write issues. For example, a bit set or clear operation reads the port, modifies the bit, and writes
the result back to the port. When two bit operations are executed in succession, output loading on the
changed bit may delay the change at the output in which case the bit will be misread in the second bit
operation and written to an unexpected level. The LAT registers are isolated from the port loading and
therefore changes are not delayed.
Important: The ANSELx bits default to the Analog mode after Reset. To use any pins as digital general
purpose or peripheral inputs, the corresponding ANSEL bits must be changed to ‘0’ by the user.
Important: Changing the input threshold selection must be performed while all peripheral modules are
disabled. Changing the threshold level during the time a module is active may inadvertently generate a
transition associated with an input pin, regardless of the actual voltage level on that pin.
rate limited. When a SLRCONx bit is cleared (SLRCONx = 0), The corresponding PORT pin drive slews at the
maximum rate possible.
Important: It is necessary to set open-drain control when using the pin for I2C.
Important: Any peripheral using the I2C pins reads the I2C input levels when enabled via RxyI2C.
Important: On a Power-on Reset (POR), the MCLR/VPP pin is enabled as a digital input-only if Master
Clear functionality is disabled.
The MCLR/VPP pin has an individually controlled internal weak pull-up. When set, the corresponding WPU bit
enables the pull-up. When the MCLR/VPP pin is configured as MCLR (MCLRE = 1 and, LVP = 0), or configured for
Low-Voltage Programming (MCLRE = x and LVP = 1), the pull-up is always enabled and the WPU bit has no effect.
19.14.1 PORTx
Name: PORTx
PORTx Register
Bit 7 6 5 4 3 2 1 0
Rx7 Rx6 Rx5 Rx4 Rx3 Rx2 Rx1 Rx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
Important:
• Writes to PORTx are actually written to the corresponding LATx register. Reads from PORTx register
return actual I/O pin values.
• The PORT bit associated with the MCLR pin is read-only and will read ‘1’ when the MCLR function is
enabled (LVP = 1 or (LVP = 0 and MCLRE = 1))
• Refer to the “Pin Allocation Table” for details about MCLR pin and pin availability per port
• Unimplemented bits will read back as ‘0’
19.14.2 LATx
Name: LATx
Bit 7 6 5 4 3 2 1 0
LATx7 LATx6 LATx5 LATx4 LATx3 LATx2 LATx1 LATx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
Important:
• Writes to LATx are equivalent to writes to the corresponding PORTx register. Reads from LATx
register return register values, not I/O pin values.
• Refer to the “Pin Allocation Table” for details about pin availability per port
• Unimplemented bits will read back as ‘0’
19.14.3 TRISx
Name: TRISx
Bit 7 6 5 4 3 2 1 0
TRISx7 TRISx6 TRISx5 TRISx4 TRISx3 TRISx2 TRISx1 TRISx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Important:
• The TRIS bit associated with the MCLR pin is read-only and the value is ‘1’
• Refer to the “Pin Allocation Table” for details about MCLR pin and pin availability per port
• Unimplemented bits will read back as ‘0’
19.14.4 ANSELx
Name: ANSELx
Bit 7 6 5 4 3 2 1 0
ANSELx7 ANSELx6 ANSELx5 ANSELx4 ANSELx3 ANSELx2 ANSELx1 ANSELx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Important:
• When setting a pin as an analog input, the corresponding TRIS bit must be set to Input mode to allow
external control of the voltage on the pin
• Refer to the “Pin Allocation Table” for details about pin availability per port
• Unimplemented bits will read back as ‘0’
19.14.5 WPUx
Name: WPUx
Bit 7 6 5 4 3 2 1 0
WPUx7 WPUx6 WPUx5 WPUx4 WPUx3 WPUx2 WPUx1 WPUx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Important:
• The weak pull-up device is automatically disabled if the pin is configured as an output, but this
register remains unchanged
• If MCLRE = 1, the weak pull-up on MCLR pin is always enabled and the corresponding WPU bit is
not affected
• Refer to the “Pin Allocation Table” for details about pin availability per port
• Unimplemented bits will read back as ‘0’
19.14.6 INLVLx
Name: INLVLx
Bit 7 6 5 4 3 2 1 0
INLVLx7 INLVLx6 INLVLx5 INLVLx4 INLVLx3 INLVLx2 INLVLx1 INLVLx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Important:
• Refer to the “Pin Allocation Table” for details about pin availability per port
• Unimplemented bits will read back as ‘0’
19.14.7 SLRCONx
Name: SLRCONx
Bit 7 6 5 4 3 2 1 0
SLRx7 SLRx6 SLRx5 SLRx4 SLRx3 SLRx2 SLRx1 SLRx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Important:
• Refer to the “Pin Allocation Table” for details about pin availability per port
• Unimplemented bits will read back as ‘0’
19.14.8 ODCONx
Name: ODCONx
Bit 7 6 5 4 3 2 1 0
ODCx7 ODCx6 ODCx5 ODCx4 ODCx3 ODCx2 ODCx1 ODCx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Important:
• Refer to the “Pin Allocation Table” for details about pin availability per port
• Unimplemented bits will read back as ‘0’
19.14.9 RxyI2C
Name: RxyI2C
Bit 7 6 5 4 3 2 1 0
SLEW[1:0] PU[1:0] TH[1:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Important:
• Refer to the “Pin Allocation Table” for details about pin availability per port
• Unimplemented bits will read back as ‘0’
0x00
... Reserved
0x0285
0x0286 RC4I2C 7:0 SLEW[1:0] PU[1:0] TH[1:0]
0x0287 RC3I2C 7:0 SLEW[1:0] PU[1:0] TH[1:0]
0x0288 RB2I2C 7:0 SLEW[1:0] PU[1:0] TH[1:0]
0x0289 RB1I2C 7:0 SLEW[1:0] PU[1:0] TH[1:0]
0x028A
... Reserved
0x03FF
0x0400 ANSELA 7:0 ANSELA7 ANSELA6 ANSELA5 ANSELA4 ANSELA3 ANSELA2 ANSELA1 ANSELA0
0x0401 WPUA 7:0 WPUA7 WPUA6 WPUA5 WPUA4 WPUA3 WPUA2 WPUA1 WPUA0
0x0402 ODCONA 7:0 ODCA7 ODCA6 ODCA5 ODCA4 ODCA3 ODCA2 ODCA1 ODCA0
0x0403 SLRCONA 7:0 SLRA7 SLRA6 SLRA5 SLRA4 SLRA3 SLRA2 SLRA1 SLRA0
0x0404 INLVLA 7:0 INLVLA7 INLVLA6 INLVLA5 INLVLA4 INLVLA3 INLVLA2 INLVLA1 INLVLA0
0x0405
... Reserved
0x0407
0x0408 ANSELB 7:0 ANSELB7 ANSELB6 ANSELB5 ANSELB4 ANSELB3 ANSELB2 ANSELB1 ANSELB0
0x0409 WPUB 7:0 WPUB7 WPUB6 WPUB5 WPUB4 WPUB3 WPUB2 WPUB1 WPUB0
0x040A ODCONB 7:0 ODCB7 ODCB6 ODCB5 ODCB4 ODCB3 ODCB2 ODCB1 ODCB0
0x040B SLRCONB 7:0 SLRB7 SLRB6 SLRB5 SLRB4 SLRB3 SLRB2 SLRB1 SLRB0
0x040C INLVLB 7:0 INLVLB7 INLVLB6 INLVLB5 INLVLB4 INLVLB3 INLVLB2 INLVLB1 INLVLB0
0x040D
... Reserved
0x040F
0x0410 ANSELC 7:0 ANSELC7 ANSELC6 ANSELC5 ANSELC4 ANSELC3 ANSELC2 ANSELC1 ANSELC0
0x0411 WPUC 7:0 WPUC7 WPUC6 WPUC5 WPUC4 WPUC3 WPUC2 WPUC1 WPUC0
0x0412 ODCONC 7:0 ODCC7 ODCC6 ODCC5 ODCC4 ODCC3 ODCC2 ODCC1 ODCC0
0x0413 SLRCONC 7:0 SLRC7 SLRC6 SLRC5 SLRC4 SLRC3 SLRC2 SLRC1 SLRC0
0x0414 INLVLC 7:0 INLVLC7 INLVLC6 INLVLC5 INLVLC4 INLVLC3 INLVLC2 INLVLC1 INLVLC0
0x0415
... Reserved
0x0417
0x0418 ANSELD 7:0 ANSELD7 ANSELD6 ANSELD5 ANSELD4 ANSELD3 ANSELD2 ANSELD1 ANSELD0
0x0419 WPUD 7:0 WPUD7 WPUD6 WPUD5 WPUD4 WPUD3 WPUD2 WPUD1 WPUD0
0x041A ODCOND 7:0 ODCD7 ODCD6 ODCD5 ODCD4 ODCD3 ODCD2 ODCD1 ODCD0
0x041B SLRCOND 7:0 SLRD7 SLRD6 SLRD5 SLRD4 SLRD3 SLRD2 SLRD1 SLRD0
0x041C INLVLD 7:0 INLVLD7 INLVLD6 INLVLD5 INLVLD4 INLVLD3 INLVLD2 INLVLD1 INLVLD0
0x041D
... Reserved
0x041F
0x0420 ANSELE 7:0 ANSELE2 ANSELE1 ANSELE0
0x0421 WPUE 7:0 WPUE3 WPUE2 WPUE1 WPUE0
0x0422 ODCONE 7:0 ODCE2 ODCE1 ODCE0
0x0423 SLRCONE 7:0 SLRE2 SLRE1 SLRE0
0x0424 INLVLE 7:0 INLVLE3 INLVLE2 INLVLE1 INLVLE0
0x0425
... Reserved
0x0427
0x0428 ANSELF 7:0 ANSELF7 ANSELF6 ANSELF5 ANSELF4 ANSELF3 ANSELF2 ANSELF1 ANSELF0
0x0429 WPUF 7:0 WPUF7 WPUF6 WPUF5 WPUF4 WPUF3 WPUF2 WPUF1 WPUF0
0x042A ODCONF 7:0 ODCF7 ODCF6 ODCF5 ODCF4 ODCF3 ODCF2 ODCF1 ODCF0
0x042B SLRCONF 7:0 SLRF7 SLRF6 SLRF5 SLRF4 SLRF3 SLRF2 SLRF1 SLRF0
0x042C INLVLF 7:0 INLVLF7 INLVLF6 INLVLF5 INLVLF4 INLVLF3 INLVLF2 INLVLF1 INLVLF0
...........continued
0x042D
... Reserved
0x04BD
0x04BE LATA 7:0 LATA7 LATA6 LATA5 LATA4 LATA3 LATA2 LATA1 LATA0
0x04BF LATB 7:0 LATB7 LATB6 LATB5 LATB4 LATB3 LATB2 LATB1 LATB0
0x04C0 LATC 7:0 LATC7 LATC6 LATC5 LATC4 LATC3 LATC2 LATC1 LATC0
0x04C1 LATD 7:0 LATD7 LATD6 LATD5 LATD4 LATD3 LATD2 LATD1 LATD0
0x04C2 LATE 7:0 LATE2 LATE1 LATE0
0x04C3 LATF 7:0 LATF7 LATF6 LATF5 LATF4 LATF3 LATF2 LATF1 LATF0
0x04C4
... Reserved
0x04C5
0x04C6 TRISA 7:0 TRISA7 TRISA6 TRISA5 TRISA4 TRISA3 TRISA2 TRISA1 TRISA0
0x04C7 TRISB 7:0 TRISB7 TRISB6 TRISB5 TRISB4 TRISB3 TRISB2 TRISB1 TRISB0
0x04C8 TRISC 7:0 TRISC7 TRISC6 TRISC5 TRISC4 TRISC3 TRISC2 TRISC1 TRISC0
0x04C9 TRISD 7:0 TRISD7 TRISD6 TRISD5 TRISD4 TRISD3 TRISD2 TRISD1 TRISD0
0x04CA TRISE 7:0 Reserved TRISE2 TRISE1 TRISE0
0x04CB TRISF 7:0 TRISF7 TRISF6 TRISF5 TRISF4 TRISF3 TRISF2 TRISF1 TRISF0
0x04CC
... Reserved
0x04CD
0x04CE PORTA 7:0 RA7 RA6 RA5 RA4 RA3 RA2 RA1 RA0
0x04CF PORTB 7:0 RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0
0x04D0 PORTC 7:0 RC7 RC6 RC5 RC4 RC3 RC2 RC1 RC0
0x04D1 PORTD 7:0 RD7 RD6 RD5 RD4 RD3 RD2 RD1 RD0
0x04D2 PORTE 7:0 RE3 RE2 RE1 RE0
0x04D3 PORTF 7:0 RF7 RF6 RF5 RF4 RF3 RF2 RF1 RF0
20.1 Overview
The pins denoted in the table below can be configured to operate as interrupt-on-change (IOC) pins for this device.
An interrupt can be generated by detecting a signal that has either a rising edge or a falling edge. Any individual
PORT pin, or combination of PORT pins, can be configured to generate an interrupt.
Table 20-1. IOC Pin Availability per Device
Important: If MCLRE = 1 or LVP = 1, the MCLR pin port functionality is disabled and IOC on that pin is
not available.
Positive
Edge
Detect
IOC
IOCAPx Flag
RAx Write to IOCAFx flag
Set/Reset
Logic
MOVLW 0xff
XORWF IOCAF, W
ANDWF IOCAF, F
20.7.1 IOCxF
Name: IOCxF
Bit 7 6 5 4 3 2 1 0
IOCxF7 IOCxF6 IOCxF5 IOCxF4 IOCxF3 IOCxF2 IOCxF1 IOCxF0
Access R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS
Reset 0 0 0 0 0 0 0 0
Important:
• If MCLRE = 1 or LVP = 1, the MCLR pin port functionality is disabled and IOC on that pin is not
available
• Refer to the “Pin Allocation Table” for details about pins with configurable IOC per port
20.7.2 IOCxN
Name: IOCxN
Bit 7 6 5 4 3 2 1 0
IOCxN7 IOCxN6 IOCxN5 IOCxN4 IOCxN3 IOCxN2 IOCxN1 IOCxN0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Important:
• If MCLRE = 1 or LVP = 1, the MCLR pin port functionality is disabled and IOC on that pin is not
available
• Refer to the “Pin Allocation Table” for details about pins with configurable IOC per port
20.7.3 IOCxP
Name: IOCxP
Bit 7 6 5 4 3 2 1 0
IOCxP7 IOCxP6 IOCxP5 IOCxP4 IOCxP3 IOCxP2 IOCxP1 IOCxP0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Important:
• If MCLRE = 1 or LVP = 1, the MCLR pin port functionality is disabled and IOC on that pin is not
available
• Refer to the “Pin Allocation Table” for details about pins with configurable IOC per port
0x00
... Reserved
0x0404
0x0405 IOCAP 7:0 IOCAP7 IOCAP6 IOCAP5 IOCAP4 IOCAP3 IOCAP2 IOCAP1 IOCAP0
0x0406 IOCAN 7:0 IOCAN7 IOCAN6 IOCAN5 IOCAN4 IOCAN3 IOCAN2 IOCAN1 IOCAN0
0x0407 IOCAF 7:0 IOCAF7 IOCAF6 IOCAF5 IOCAF4 IOCAF3 IOCAF2 IOCAF1 IOCAF0
0x0408
... Reserved
0x040C
0x040D IOCBP 7:0 IOCBP7 IOCBP6 IOCBP5 IOCBP4 IOCBP3 IOCBP2 IOCBP1 IOCBP0
0x040E IOCBN 7:0 IOCBN7 IOCBN6 IOCBN5 IOCBN4 IOCBN3 IOCBN2 IOCBN1 IOCBN0
0x040F IOCBF 7:0 IOCBF7 IOCBF6 IOCBF5 IOCBF4 IOCBF3 IOCBF2 IOCBF1 IOCBF0
0x0410
... Reserved
0x0414
0x0415 IOCCP 7:0 IOCCP7 IOCCP6 IOCCP5 IOCCP4 IOCCP3 IOCCP2 IOCCP1 IOCCP0
0x0416 IOCCN 7:0 IOCCN7 IOCCN6 IOCCN5 IOCCN4 IOCCN3 IOCCN2 IOCCN1 IOCCN0
0x0417 IOCCF 7:0 IOCCF7 IOCCF6 IOCCF5 IOCCF4 IOCCF3 IOCCF2 IOCCF1 IOCCF0
0x0418
... Reserved
0x0424
0x0425 IOCEP 7:0 IOCEP3
0x0426 IOCEN 7:0 IOCEN3
0x0427 IOCEF 7:0 IOCEF3
21.1 Overview
Filename: PPS Block Diagram.vsdx
Title:
The Peripheral Pin Select (PPS)
Last Edit: module connects peripheral inputs and outputs to the device I/O pins. Only digital
3/26/2019
signals areFirst
included
Used: in the selections.
Notes:
Important: All analog inputs and outputs remain fixed to their assigned pins and cannot be changed
through PPS.
Input and output selections are independent as shown in the figure below.
Figure 21-1. PPS Block Diagram
abcPPS
RA0PPS
RA0
Peripheral abc
RA0
Rxy
Peripheral xyz
Rxy
xyzPPS RxyPPS
Important: The notation “xxx” in the generic register name is a placeholder for the peripheral identifier.
For example, xxx = T0CKI for the T0CKIPPS register.
Multiple peripherals can operate from the same source simultaneously. Port reads always return the pin level
regardless of peripheral PPS selection. If a pin also has analog functions associated, the ANSEL bit for that pin must
be cleared to enable the digital input buffer.
...........continued
Default Pin Available Input Port
Register Reset
Peripheral PPS Input Register Selection at
Value at POR 28-Pin Devices 40-Pin Devices 48-Pin Devices
POR
ADC Conversion ADACTPPS RB4 'b001 100 — B C — B — D —— B — D — —
Trigger
SPI1 Clock SPI1SCKPPS RC3 'b010 011 — B C — B C — — — B C —— —
SPI1 Data SPI1SDIPPS RC4 'b010 100 — B C — B C — — — B C —— —
SPI1 Client Select SPI1SSPPS RA5 'b000 101 A — C A — — D — A —— D — —
SPI2 Clock SPI2SCKPPS RB3 'b001 011 — B C — B — D — — B — D — —
SPI2 Data SPI2SDIPPS RB2 'b001 010 — B C — B — D — — B — D — —
SPI2 Client Select SPI2SSPPS RA4 'b000 100 A — C A — — D — A —— D — —
I2C1 Clock I2C1SCLPPS(1) RC3 'b010 011 — B C — B C — — — B C —— —
I2C1 Data I2C1SDAPPS(1) RC4 'b010 100 — B C — B C — — — B C —— —
UART1 Receive U1RXPPS RC7 'b010 111 — B C — B C — — —— C —— F
UART1 Clear to Send U1CTSPPS RC6 'b010 110 — B C — B C — — —— C —— F
UART2 Receive U2RXPPS RB7 'b001 111 — B C — B — D — — B — D — —
UART2 Clear to Send U2CTSPPS RB6 'b001 110 — B C — B — D — — B — D — —
UART3 Receive U3RXPPS RA7 'b000 111 A B — A B — — — A ———— F
UART3 Clear to Send U3CTSPPS RA6 'b000 110 A B — A B — — — A ———— F
UART4 Receive U4RXPPS RB5 'b001 101 — B C — B — D — — B — D — —
UART4 Clear to Send U4CTSPPS RB4 'b001 100 — B C — B — D — — B — D — —
UART5 Receive U5RXPPS RA5 'b000 101 A — C A — C — — A ———— F
UART5 Clear to Send U5CTSPPS RA4 'b000 100 A — C A — C — — A ———— F
CAN Receive CANRXPPS RB3 'b001 011 — B C — B — D — — B — D — —
Note:
1. Bidirectional pin. The corresponding output must select the same pin.
Important: The notation ‘Rxy’ is a placeholder for the pin identifier. The ‘x’ holds the place of the PORT
letter and the ‘y’ holds the place of the bit number. For example, Rxy = RA0 for the RA0PPS register.
The table below shows the output codes for each peripheral, as well as the available Port selections.
Table 21-2. PPS Output Selection Table
Available Output Ports
RxyPPS Output Source
28-Pin Devices 40-Pin Devices 48-Pin Devices
0x46 CANTX — B C — B — D — — B — D — —
0x45 ADGRDB A — C A — C — — A — — — — F
0x44 ADGRDA A — C A — C — — A — — — — F
0x43 DSM1 A — C A — — D — A — — D — —
0x42 CLKR — B C — B C — — — B — — E —
...........continued
Available Output Ports
RxyPPS Output Source
28-Pin Devices 40-Pin Devices 48-Pin Devices
0x41 NCO3 — B C — B — — E — B — — E —
0x40 NCO2 — B C — B — D — — B — D — —
0x3F NCO1 A — C A — — D — A — — D — —
0x3E - 0x3C Reserved — — — — — — — — — — — — — —
0x3B TU16B — B C — B — D — — B — D — —
0x3A TU16A — B C — B C — — — — C — — F
0x39 TMR0 — B C — B C — — — — C — — F
0x38 I2C1 SDA(1) — B C — B C — — — B C — — —
0x37 I2C1 SCL(1) — B C — B C — — — B C — — —
0x36 SPI2 SS A — C A — — D — A — — D — —
0x35 SPI2 SDO — B C — B — D — — B — D — —
0x34 SPI2 SCK — B C — B — D — — B — D — —
0x33 SPI1 SS A — C A — — D — A — — D — —
0x32 SPI1 SDO — B C — B C — — — B C — — —
0x31 SPI1 SCK — B C — B C — — — B C — — —
0x30 C2OUT A — C A — — — E A — — — E —
0x2F C1OUT A — C A — — D — A — — D — —
0x2E UART5 RTS — B C — B C — — — — C — — F
0x2D UART5 TXDE — B C — B C — — — — C — — F
0x2C UART5 TX — B C — B C — — — — C — — F
0x2B UART4 RTS A B — A — — D — A — — D — —
0x2A UART4 TXDE A B — A — — D — A — — D — —
0x29 UART4 TX A B — A — — D — A — — D — —
0x28 UART3 RTS A B — A B — — — A — — — — F
0x27 UART3 TXDE A B — A B — — — A — — — — F
0x26 UART3 TX A B — A B — — — A — — — — F
0x25 UART2 RTS — B C — B — D — — B — D — —
0x24 UART2 TXDE — B C — B — D — — B — D — —
0x23 UART2 TX — B C — B — D — — B — D — —
0x22 UART1 RTS — B C — B C — — — — C — — F
0x21 UART1 TXDE — B C — B C — — — — C — — F
0x20 UART1 TX — B C — B C — — — — C — — F
0x1F PWM4S1P2_OUT A — C A — — D — A — — D — —
0x1E PWM4S1P1_OUT A — C A — C — — — — C — — F
0x1D PWM3S1P2_OUT — B C — B — D — — B — D — —
0x1C PWM3S1P1_OUT — B C — B — D — — B — D — —
0x1B PWM2S1P2_OUT — B C — B — D — — B — D — —
0x1A PWM2S1P1_OUT — B C — B — D — — B — D — —
0x19 PWM1S1P2_OUT — B C — B C — — — — C — — F
0x18 PWM1S1P1_OUT — B C — B C — — — — C — — F
0x17 CCP3 — B C — B — D — — B — D — —
0x16 CCP2 — B C — B C — — — — C — — F
0x15 CCP1 — B C — B C — — — — C — — F
0x14 CWG3D A — C A — — D — A — — D — —
0x13 CWG3C A — C A — — D — A — — D — —
...........continued
Available Output Ports
RxyPPS Output Source
28-Pin Devices 40-Pin Devices 48-Pin Devices
0x12 CWG3B A — C A — — — E A — — — E —
0x11 CWG3A — B C — B C — — — B C — — —
0x10 CWG2D — B C — B — D — — B — D — —
0x0F CWG2C — B C — B — D — — B — D — —
0x0E CWG2B — B C — B — D — — B — D — —
0x0D CWG2A — B C — B C — — — B C — — —
0x0C CWG1D — B C — B — D — — B — D — —
0x0B CWG1C — B C — B — D — — B — D — —
0x0A CWG1B — B C — B — D — — B — D — —
0x09 CWG1A — B C — B C — — — B C — — —
0x08 CLC8OUT — B C — B — D — — B — D — —
0x07 CLC7OUT — B C — B — D — — B — D — —
0x06 CLC6OUT A — C A — C — — A — — — — F
0x05 CLC5OUT A — C A — C — — A — — — — F
0x04 CLC4OUT — B C — B — D — — B — D — —
0x03 CLC3OUT — B C — B — D — — B — D — —
0x02 CLC2OUT A — C A — C — — A — — — — F
0x01 CLC1OUT A — C A — C — — A — — — — F
0x00 LATxy A B C A B C D E A B C D E F
Note:
1. Bidirectional pin. The corresponding input must select the same pin.
Important: The I2C default pins and a limited number of other alternate pins are I2C and SMBus
compatible. SDA and SCL signals can be routed to any pin; however, pins without I2C compatibility will
operate at standard TTL/ST logic levels as selected by the port’s INLVL register.
Important: The PPSLOCKED bit is clear by default (PPSLOCKED = 0), which allows the PPS selection
registers to be modified without an unlock sequence.
PPS selection registers are locked when the PPSLOCKED bit is set (PPSLOCKED = 1). Setting the PPSLOCKED bit
requires a specific lock sequence as shown in the examples below in both C and assembly languages.
PPS selection registers are unlocked when the PPSLOCKED bit is clear (PPSLOCKED = 0). Clearing the
PPSLOCKED bit requires a specific unlock sequence as shown in the examples below in both C and assembly
languages.
Important: All interrupts must be disabled before starting the lock/unlock sequence to ensure proper
execution.
; suspend interrupts
BCF INTCON0,GIE
BANKSEL PPSLOCK
; required sequence, next 5 instructions
MOVLW 0x55
MOVWF PPSLOCK
MOVLW 0xAA
MOVWF PPSLOCK
; Set PPSLOCKED bit
BSF PPSLOCK,PPSLOCKED
; restore interrupts
BSF INTCON0,GIE
; suspend interrupts
BCF INTCON0,GIE
BANKSEL PPSLOCK
; required sequence, next 5 instructions
MOVLW 0x55
MOVWF PPSLOCK
MOVLW 0xAA
MOVWF PPSLOCK
; Clear PPSLOCKED bit
BCF PPSLOCK,PPSLOCKED
; restore interrupts
BSF INTCON0,GIE
21.8.1 xxxPPS
Name: xxxPPS
Bit 7 6 5 4 3 2 1 0
PORT[2:0] PIN[2:0]
Access R/W R/W R/W R/W R/W R/W
Reset m m m m m m
Notes:
1. The Reset value ‘m’ is determined by device default locations for that input.
2. Refer to the “Pin Allocation Table” for details about available pins per port.
21.8.2 RxyPPS
Name: RxyPPS
Bit 7 6 5 4 3 2 1 0
RxyPPS[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
21.8.3 PPSLOCK
Name: PPSLOCK
Bit 7 6 5 4 3 2 1 0
PPSLOCKED
Access R/W
Reset 0
0x00
... Reserved
0x01FF
0x0200 PPSLOCK 7:0 PPSLOCKED
0x0201 RA0PPS 7:0 RA0PPS[6:0]
0x0202 RA1PPS 7:0 RA1PPS[6:0]
0x0203 RA2PPS 7:0 RA2PPS[6:0]
0x0204 RA3PPS 7:0 RA3PPS[6:0]
0x0205 RA4PPS 7:0 RA4PPS[6:0]
0x0206 RA5PPS 7:0 RA5PPS[6:0]
0x0207 RA6PPS 7:0 RA6PPS[6:0]
0x0208 RA7PPS 7:0 RA7PPS[6:0]
0x0209 RB0PPS 7:0 RB0PPS[6:0]
0x020A RB1PPS 7:0 RB1PPS[6:0]
0x020B RB2PPS 7:0 RB2PPS[6:0]
0x020C RB3PPS 7:0 RB3PPS[6:0]
0x020D RB4PPS 7:0 RB4PPS[6:0]
0x020E RB5PPS 7:0 RB5PPS[6:0]
0x020F RB6PPS 7:0 RB6PPS[6:0]
0x0210 RB7PPS 7:0 RB7PPS[6:0]
0x0211 RC0PPS 7:0 RC0PPS[6:0]
0x0212 RC1PPS 7:0 RC1PPS[6:0]
0x0213 RC2PPS 7:0 RC2PPS[6:0]
0x0214 RC3PPS 7:0 RC3PPS[6:0]
0x0215 RC4PPS 7:0 RC4PPS[6:0]
0x0216 RC5PPS 7:0 RC5PPS[6:0]
0x0217 RC6PPS 7:0 RC6PPS[6:0]
0x0218 RC7PPS 7:0 RC7PPS[6:0]
0x0219 RD0PPS 7:0 RD0PPS[6:0]
0x021A RD1PPS 7:0 RD1PPS[6:0]
0x021B RD2PPS 7:0 RD2PPS[6:0]
0x021C RD3PPS 7:0 RD3PPS[6:0]
0x021D RD4PPS 7:0 RD4PPS[6:0]
0x021E RD5PPS 7:0 RD5PPS[6:0]
0x021F RD6PPS 7:0 RD6PPS[6:0]
0x0220 RD7PPS 7:0 RD7PPS[6:0]
0x0221 RE0PPS 7:0 RE0PPS[6:0]
0x0222 RE1PPS 7:0 RE1PPS[6:0]
0x0223 RE2PPS 7:0 RE2PPS[6:0]
0x0224
... Reserved
0x0228
0x0229 RF0PPS 7:0 RF0PPS[6:0]
0x022A RF1PPS 7:0 RF1PPS[6:0]
0x022B RF2PPS 7:0 RF2PPS[6:0]
0x022C RF3PPS 7:0 RF3PPS[6:0]
0x022D RF4PPS 7:0 RF4PPS[6:0]
0x022E RF5PPS 7:0 RF5PPS[6:0]
0x022F RF6PPS 7:0 RF6PPS[6:0]
0x0230 RF7PPS 7:0 RF7PPS[6:0]
0x0231
... Reserved
0x023C
0x023D CANRXPPS 7:0 PORT[2:0] PIN[2:0]
0x023E INT0PPS 7:0 PORT PIN[2:0]
0x023F INT1PPS 7:0 PORT[1:0] PIN[2:0]
...........continued
...........continued
21.9.1 CANRXPPS
Name: CANRXPPS
Offset: 0x23D
Bit 7 6 5 4 3 2 1 0
PORT[2:0] PIN[2:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
OUT
D Q
CLCxOUT
Q1
LCx_in[0]
LCx_in[1] CLCx_out
to Peripherals
LCx_in[2]
Input Data Selection Gates(1)
. lcx g1
EN
RxyPPS
. lcx g2
lcx g3
Logic
Function
(2)
lcxq
PPS CLCx
. lcx g4
POL TRIS
MODE Interrupt
LCx_in[n-2]
LCx_in[n-1] det
LCx_in[n]
INTP
set bit
INTN CLCxIF
Interrupt
det
Notes:
1. See Figure 22-2 for input data selection and gating.
2. See Figure 22-3 for programmable logic functions.
Depending on the number of bits implemented in the CLCnSELy registers, there can be as many as 256 sources
available as inputs to the configurable logic. Four multiplexers are used to independently select these inputs to pass
on to the next stage as indicated on the left side of the following diagram.
Data inputs in the figure are identified by a generic numbered input name.
Data Selection
d1T G1D1N
d1N G1D2T
LCx_in[n]
D1S G1D2N lcxg1
G1D3N
d2T
d2N G1D4T
LCx_in[n]
G1D4N
D2S
LCx_in[0]
Data GATE 2
d3T lcxg2
LCx_in[n]
D3S
Data GATE 3
LCx_in[0]
lcxg3
d4N
Data GATE 4
LCx_in[n]
lcxg4
D4S
(Same as Data GATE 1)
Note: are
Note: All controls All undefined
controls are undefined at power up
at power-up.
The CLC Input Selection table correlates the generic input name to the actual signal for each CLC module. The table
column labeled ‘DyS Value’ indicates the MUX selection code for the selected data input. DyS is an abbreviation for
the MUX select input codes, D1S through D4S, where ‘y’ is the gate number.
It is possible (but not recommended) to select both the true and negated values of an input. When this is done, the
gate output is ‘0’, regardless of the other inputs, but may emit logic glitches (transient-induced pulses). If the output of
the channel must be ‘0’ or ‘1’, the recommended method is to set all gate bits to ‘0’ and use the gate polarity bit to set
the desired level.
Data gating is configured with the logic gate select registers as follows:
• Gate 1: CLCnGLS0
• Gate 2: CLCnGLS1
• Gate 3: CLCnGLS2
• Gate 4: CLCnGLS3
Note: Register number suffixes are different than the gate numbers because other variations of this module have
multiple gate selections in the same register.
Data gating is indicated in the right side of Figure 22-2. Only one gate is shown in detail. The remaining three gates
are configured identically, except when the data enables correspond to the enables for that gate.
AND-OR OR-XOR
lcxg1 lcxg1
lcxg2 lcxg2
lcxq lcxq
lcxg3 lcxg3
lcxg4 lcxg4
lcxg1 lcxg1
S Q lcxq
lcxg2
lcxg2
lcxq
lcxg3
lcxg3
R
lcxg4 lcxg4
lcxg1 R
lcxg1 R
lcxg3 lcxg3
5. Enable the chosen inputs through the four gates using the CLCnGLS0 through CLCnGLS3 registers.
6. Select the gate output polarities with the GyPOL bits.
7. Select the desired logic function with the MODE bits.
8. Select the desired polarity of the logic output with the POL bit (this step may be combined with the previous
gate output polarity step).
9. If driving a device pin, configure the associated pin PPS control register and also clear the TRIS bit
corresponding to that output.
10. Configure the interrupts (optional). See the CLC Interrupts section.
11. Enable the CLC by setting the EN bit.
22.8.1 CLCSELECT
Name: CLCSELECT
Offset: 0x0D5
CLC Instance Selection Register
Selects which CLC instance is accessed by the CLC registers
Bit 7 6 5 4 3 2 1 0
SLCT[2:0]
Access R/W R/W R/W
Reset 0 0 0
22.8.2 CLCnCON
Name: CLCnCON
Offset: 0x0D6
Bit 7 6 5 4 3 2 1 0
EN OUT INTP INTN MODE[2:0]
Access R/W R R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
Bit 5 – OUT Logic cell output data, after LCPOL. Sampled from CLCxOUT.
Bit 4 – INTP Configurable Logic Cell Positive Edge Going Interrupt Enable
Value Description
1 CLCxIF will be set when a rising edge occurs on CLCxOUT
0 Rising edges on CLCxOUT have no effect on CLCxIF
Bit 3 – INTN Configurable Logic Cell Negative Edge Going Interrupt Enable
Value Description
1 CLCxIF will be set when a falling edge occurs on CLCxOUT
0 Falling edges on CLCxOUT have no effect on CLCxIF
22.8.3 CLCnPOL
Name: CLCnPOL
Offset: 0x0D7
Bit 7 6 5 4 3 2 1 0
POL G4POL G3POL G2POL G1POL
Access R/W R/W R/W R/W R/W
Reset 0 x x x x
22.8.4 CLCnSEL0
Name: CLCnSEL0
Offset: 0x0D8
Bit 7 6 5 4 3 2 1 0
D1S[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
22.8.5 CLCnSEL1
Name: CLCnSEL1
Offset: 0x0D9
Bit 7 6 5 4 3 2 1 0
D2S[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
22.8.6 CLCnSEL2
Name: CLCnSEL2
Offset: 0x0DA
Bit 7 6 5 4 3 2 1 0
D3S[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
22.8.7 CLCnSEL3
Name: CLCnSEL3
Offset: 0x0DB
Bit 7 6 5 4 3 2 1 0
D4S[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
22.8.8 CLCnGLS0
Name: CLCnGLS0
Offset: 0x0DC
Bit 7 6 5 4 3 2 1 0
G1D4T G1D4N G1D3T G1D3N G1D2T G1D2N G1D1T G1D1N
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
22.8.9 CLCnGLS1
Name: CLCnGLS1
Offset: 0x0DD
Bit 7 6 5 4 3 2 1 0
G2D4T G2D4N G2D3T G2D3N G2D2T G2D2N G2D1T G2D1N
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
22.8.10 CLCnGLS2
Name: CLCnGLS2
Offset: 0x0DE
Bit 7 6 5 4 3 2 1 0
G3D4T G3D4N G3D3T G3D3N G3D2T G3D2N G3D1T G3D1N
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
22.8.11 CLCnGLS3
Name: CLCnGLS3
Offset: 0x0DF
Bit 7 6 5 4 3 2 1 0
G4D4T G4D4N G4D3T G4D3N G4D2T G4D2N G4D1T G4D1N
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
22.8.12 CLCDATA
Name: CLCDATA
Offset: 0x0D4
CLC Data Output Register
Mirror copy of CLC outputs
Bit 7 6 5 4 3 2 1 0
CLC8OUT CLC7OUT CLC6OUT CLC5OUT CLC4OUT CLC3OUT CLC2OUT CLC1OUT
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
0x00
... Reserved
0xD3
0xD4 CLCDATA 7:0 CLC8OUT CLC7OUT CLC6OUT CLC5OUT CLC4OUT CLC3OUT CLC2OUT CLC1OUT
0xD5 CLCSELECT 7:0 SLCT[2:0]
0xD6 CLCnCON 7:0 EN OUT INTP INTN MODE[2:0]
0xD7 CLCnPOL 7:0 POL G4POL G3POL G2POL G1POL
0xD8 CLCnSEL0 7:0 D1S[7:0]
0xD9 CLCnSEL1 7:0 D2S[7:0]
0xDA CLCnSEL2 7:0 D3S[7:0]
0xDB CLCnSEL3 7:0 D4S[7:0]
0xDC CLCnGLS0 7:0 G1D4T G1D4N G1D3T G1D3N G1D2T G1D2N G1D1T G1D1N
0xDD CLCnGLS1 7:0 G2D4T G2D4N G2D3T G2D3N G2D2T G2D2N G2D1T G2D1N
0xDE CLCnGLS2 7:0 G3D4T G3D4N G3D3T G3D3N G3D2T G3D2N G3D1T G3D1N
0xDF CLCnGLS3 7:0 G4D4T G4D4N G4D3T G4D3N G4D2T G4D2N G4D1T G4D1N
DIV
EN Counter Reset
128
111
EN 000
CLK
P1 P2
CLKRCLK
EN
CLKR Output
DIV = 001
DC = 10
Duty Cycle
(50%)
Important: The DC value at Reset is 10. This makes the default duty cycle 50% and not 0%.
Important: Clock dividers and clock duty cycles can be changed while the module is enabled but doing
so may cause glitches to occur on the output. To avoid possible glitches, clock dividers and clock duty
cycles will be changed only when the EN bit is clear.
23.5.1 CLKRCON
Name: CLKRCON
Offset: 0x039
Bit 7 6 5 4 3 2 1 0
EN DC[1:0] DIV[2:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 1 0 0 0 0
Note:
1. Bits are valid for DIV ≥ 001. For DIV = 000, duty cycle is fixed at 50%.
23.5.2 CLKRCLK
Name: CLKRCLK
Offset: 0x03A
Bit 7 6 5 4 3 2 1 0
CLK[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
0x00
... Reserved
0x38
0x39 CLKRCON 7:0 EN DC[1:0] DIV[2:0]
0x3A CLKRCLK 7:0 CLK[4:0]
T0CKIPPS CK Q RxyPPS
T0CS
8-bit TMR0 Body Diagram (T016BIT = 0) 16-bit TMR0 Body Diagram (T016BIT = 1)
Read TMR0L
COMPARATOR OUT
Write TMR0L
T0_match 8
8
TMR0H
Timer 0 High
Byte
Latch 8
Enable
TMR0H
8
Internal Data Bus
Timer0 Configuration:
• Timer0 mode = 16-bit
• Clock Source = FOSC/4 (250 kHz)
• Synchronous operation
• Prescaler = 1:1
• Postscaler = 1:2 (T0OUTPS = 1)
In this case, the TMR0_out toggles every two rollovers of TMR0H:TMR0L.
i.e., (0xFFFF)*2*(1/250 kHz) = 524.28 ms
24.5.1 T0CON0
Name: T0CON0
Offset: 0x31A
Bit 7 6 5 4 3 2 1 0
EN OUT MD16 OUTPS[3:0]
Access R/W R R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
24.5.2 T0CON1
Name: T0CON1
Offset: 0x31B
Bit 7 6 5 4 3 2 1 0
CS[2:0] ASYNC CKPS[3:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Value Description
111 CLC1_OUT
110 SOSC
101 MFINTOSC (500 kHz)
100 LFINTOSC
011 HFINTOSC
010 FOSC/4
001 Pin selected by T0CKIPPS (Inverted)
000 Pin selected by T0CKIPPS (Noninverted)
24.5.3 TMR0H
Name: TMR0H
Offset: 0x319
Bit 7 6 5 4 3 2 1 0
TMR0H[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
24.5.4 TMR0L
Name: TMR0L
Offset: 0x318
Bit 7 6 5 4 3 2 1 0
TMR0L[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
0x00
... Reserved
0x0317
0x0318 TMR0L 7:0 TMR0L[7:0]
0x0319 TMR0H 7:0 TMR0H[7:0]
0x031A T0CON0 7:0 EN OUT MD16 OUTPS[3:0]
0x031B T0CON1 7:0 CS[2:0] ASYNC CKPS[3:0]
Important: References to the module Timer1 apply to all the odd numbered timers on this device.
TxGATE
4
TxGPPS
GSPM
PPS 00 00
1
0 Single Pulse D Q GVAL
NOTE (5) 0
11 11
1 Acq. Control
Q1
D Q
GPOL GGO/DONE
CK Q
ON Interrupt
set bit
R
GTM det TMRxGIF
GE
set flag bit
TMRxIF
ON
EN
(2) To Comparators (6)
TMRx
Tx_overflow Synchronized Clock Input
TMRxH TMRxL Q D 0
1
TxCLK
SYNC
TxCLK
4
TxCKIPPS
(1)
PPS 0000
Prescaler
Synchronize(3)
1,2,4,8
(4)
Note det
111 1
2
Fosc/2
CKPS Internal Sleep
Clock Input
Notes:
1. This signal comes from the pin selected by Timer1 PPS register.
2. TMRx register increments on rising edge.
3. Synchronize does not operate while in Sleep.
4. See TxCLK for clock source selections.
5. See TxGATE for gate source selections.
6. Synchronized comparator output must not be used in conjunction with synchronized input clock.
ON GE Timer1 Operation
1 1 Count enabled
1 0 Always on
0 1 Off
0 0 Off
Important: In Counter mode, a falling edge must be registered by the counter prior to the first
incrementing rising edge after any one or more of the following conditions:
• Timer1 enabled after POR
• Write to TMRxH or TMRxL
• Timer1 is disabled
• Timer1 is disabled (ON = 0) when TxCKI is high, then Timer1 is enabled (ON = 1) when TxCKI is low.
Refer to the figure below.
TxCKI = 1
When TMRx
Enabled
TxCKI = 0
When TMRx
Enabled
Notes:
1. Arrows indicate counter increments.
2. In Counter mode, a falling edge must be registered by the counter prior to the first incrementing rising edge of
the clock.
Important: The oscillator requires a start-up and stabilization time before use. Thus, the SOSCEN bit of
the OSCEN register must be set and a suitable delay observed prior to enabling Timer1. A software check
can be performed to confirm if the secondary oscillator is enabled and ready to use. This is done by polling
the secondary oscillator ready Status bit. Refer to the “OSC - Oscillator Module (with Fail-Safe Clock
Monitor)” chapter for more details.
single instance in time (refer to Figure 25-3 for more details). In contrast, when not in 16-bit mode, the user must read
each register separately and determine if the values have become invalid due to a rollover that may have occurred
between the read operations.
When a write request of the TMRxL register is requested, the TMRxH buffer register is simultaneously updated with
the contents of the TMRxH register. The value of TMRxH must be preloaded into the TMRxH buffer register prior to
the write request for the TMRxL register. This provides the user with the ability to write all 16 bits to the TMRx register
at the same time. Any requests to write to TMRxH directly does not clear the Timer1 prescaler value. The prescaler
value is only cleared through write requests to the TMRxL register.
Figure 25-3. Timer1 16-Bit Read/Write Mode Block Diagram
From
TMRx
Circuitr y
Read TMRxL
Write TMRxL
8
8
TMRxH
8
8
Inte rnal Da ta Bus
TMRxGE
TxGPOL
TxG_IN
TxCKI
TxGVAL
Timer1
Important: Enabling Toggle mode at the same time as changing the gate polarity may result in
indeterminate operation.
TMRxGE
TxGPOL
TxGTM
TxTxG_IN
TxCKI
TxGVAL
Timer1
TMRxGE
TxGPOL
TxGSPM
Cleared by hardware on
TxGGO/ Set by software falling edge of TxGVAL
DONE
Counting enabled on
rising edge of TxG
TxG_IN
TxCKI
TxGVAL
TIMER1
Cleared by
TMRxGIF Cleared by software Set by hardware on software
falling edge of TxGVAL
Clearing the GSPM bit will also clear the GGO/DONE bit. See the figure below for timing details. Enabling the Toggle
mode and the Single Pulse mode simultaneously will permit both sections to work together. This allows the cycle
times on the Timer1 gate source to be measured. See the figure below for timing details.
Figure 25-7. Timer1 Gate Single Pulse and Toggle Combined Mode
TMRxGE
TxGPOL
TxGSPM
TxGTM
Cleared by hardware on
TxGGO/ Set by software falling edge of TxGVAL
DONE
Counting enabled on
rising edge of TxG
TxG_IN
TxCKI
TxGVAL
TIMER1
Important: The TMRx register and the TMRxIF bit must be cleared before enabling interrupts.
...........continued
Peripheral Bit Name Prefix
Timer 5 T5
25.13.1 TxCON
Name: TxCON
Offset: 0x31E,0x32A,0x336
Bit 7 6 5 4 3 2 1 0
CKPS[1:0] SYNC RD16 ON
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
Bit 0 – ON Timer On
Reset States: POR/BOR = 0
All Other Resets = u
Value Description
1 Enables Timer
0 Disables Timer
25.13.2 TxGCON
Name: TxGCON
Offset: 0x31F,0x32B,0x337
Bit 7 6 5 4 3 2 1 0
GE GPOL GTM GSPM GGO/DONE GVAL
Access R/W R/W R/W R/W R/W R
Reset 0 0 0 0 0 x
25.13.3 TxCLK
Name: TxCLK
Offset: 0x321,0x32D,0x339
Bit 7 6 5 4 3 2 1 0
CS[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
25.13.4 TxGATE
Name: TxGATE
Offset: 0x320,0x32C,0x338
Bit 7 6 5 4 3 2 1 0
GSS[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
...........continued
GSS Gate Source
Timer1 Timer3 Timer5
000001 TMR0_OUT
000000 Pin selected by T1GPPS Pin selected by T3GPPS Pin selected by T5GPPS
25.13.5 TMRx
Name: TMRx
Offset: 0x31C,0x328,0x334
Timer Register
Bit 15 14 13 12 11 10 9 8
TMRx[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
TMRx[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• TMRxH: Accesses the high byte TMRx[15:8]
• TMRxL: Accesses the low byte TMRx[7:0]
0x00
... Reserved
0x031B
7:0 TMR1[7:0]
0x031C TMR1
15:8 TMR1[15:8]
0x031E T1CON 7:0 CKPS[1:0] SYNC RD16 ON
0x031F T1GCON 7:0 GE GPOL GTM GSPM GGO/DONE GVAL
0x0320 T1GATE 7:0 GSS[5:0]
0x0321 T1CLK 7:0 CS[4:0]
0x0322
... Reserved
0x0327
7:0 TMR3[7:0]
0x0328 TMR3
15:8 TMR3[15:8]
0x032A T3CON 7:0 CKPS[1:0] SYNC RD16 ON
0x032B T3GCON 7:0 GE GPOL GTM GSPM GGO/DONE GVAL
0x032C T3GATE 7:0 GSS[5:0]
0x032D T3CLK 7:0 CS[4:0]
0x032E
... Reserved
0x0333
7:0 TMR5[7:0]
0x0334 TMR5
15:8 TMR5[15:8]
0x0336 T5CON 7:0 CKPS[1:0] SYNC RD16 ON
0x0337 T5GCON 7:0 GE GPOL GTM GSPM GGO/DONE GVAL
0x0338 T5GATE 7:0 GSS[5:0]
0x0339 T5CLK 7:0 CS[4:0]
Important: References to module Timer2 apply to all the even numbered timers on this device (Timer2,
Timer4, etc.).
Figure 26-1. Timer2 with Hardware Limit Timer (HLT) Block Diagram
RSEL
TxINPPS Rev. 10-000168D
4/29/2019
TxIN PPS
MODE MODE[3]
External
TMRx_ers Edge Detector reset
Reset
Sources(2) Level Detector CCP_pset(1)
Mode Control
(2 clock Sync)
Sync
(2 Clocks)
1
TxPR OUTPS
ON 0
CSYNC
Notes:
1. Signal to the CCP peripheral for PWM pulse trigger in PWM mode.
2. See RSEL for external Reset sources.
3. See CS for clock source selections.
CKPS ‘b010
TxPR 1
OUTPS ‘b0001
TMRx_clk
TxTMR 0 1 0 1 0 1 0
TMRx_postscaled
Notes: 1. Setting the interrupt flag is synchronized with the instruction clock.
Synchronization may take as many as two instruction cycles.
2. Cleared by software.
...........continued
MODE Output Timer Control
Mode Operation Operation
[4:3] [2:0] Start Reset Stop
000 Reserved
Rising edge start ON = 1 and
001 — ON = 0
(Figure 26-11) TMRx_ers ↑
or
Monostable Edge-Triggered Start ON = 1 and
010 Next clock after
Falling edge start TMRx_ers ↓ —
(Note 1)
TxTMR = TxPR
ON = 1 and
011 Any edge start — (Note 3)
10 TMRx_ers ↕
Reserved 100 Reserved
Reserved 101 Reserved
High-level start and ON = 1 and
110 Level-Triggered Start Low-level Reset (Figure 26-12) TMRx_ers = 1 TMRx_ers = 0 ON = 0 or
and Held in Reset
One Shot
Low-level start and ON = 1 and
Hardware Reset (Note 2)
111 High-level Reset TMRx_ers = 0 TMRx_ers = 1
Notes:
1. If ON = 0, then an edge is required to restart the timer after ON = 1.
2. When T2TMR = T2PR, the next clock clears ON and stops T2TMR at 00h.
3. When T2TMR = T2PR, the next clock stops T2TMR at 00h but does not clear ON.
TMRx_clk
ON
TxPR 5
TxTMR 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
TMRx_clk
TMRx_ers
TxPR 5
TxTMR 0 1 2 3 4 5 0 1 2 3 4 5 0 1
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Rev. 10-000197C
3/6/2019
TMRx_clk
TxPR 5
ON
TMRx_ers
TxTMR 0 1 2 0 1 2 3 4 5 0 1 2 3 4 5 0 1
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by
the CPU to set or clear the ON bit of TxCON. CPU execution is asynchronous
to the timer clock input.
TMRx_clk
TxPR 5
ON
TMRx_ers
TxTMR 0 1 2 0 1 2 3 4 5 0 0 1 2 3 4 5 0
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
TMRx_clk
TxPR 5
ON
TxTMR 0 1 2 3 4 5 0 1 2 3 4 5 0
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU
to set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
TMRx_clk
TxPR 5
ON
TMRx_ers
TxTMR 0 1 2 3 4 5 0 1 2
CCP_pset
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
TMRx_clk
TxPR 5
ON
TMRx_ers
TxTMR 0 1 2 3 4 5 0 1 2 0 1 2 3 4 5 0
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
26.8.8 Level Reset, Edge Triggered Hardware Limit One Shot Modes
In Level Triggered One Shot mode, the timer count is reset on the external signal level and starts counting on the
rising/falling edge of the transition from Reset level to the active level while the ON bit is set. Reset levels are
selected as follows:
• Low Reset level (MODE = ‘b01110)
• High Reset level (MODE = ‘b01111)
When the timer count matches the TxPR period count, the timer is reset and the ON bit is cleared. When the ON bit
is cleared by either a TxPR match or by software control, a new external signal edge is required after the ON bit is set
to start the counter.
When Level-Triggered Reset One Shot mode is used in conjunction with the CCP PWM operation, the PWM drive
goes active with the external signal edge that starts the timer. The PWM drive goes inactive when the timer count
equals the CCPRx pulse-width count. The PWM drive does not go active when the timer count clears at the TxPR
period count match.
Figure 26-10. Low Level Reset, Edge Triggered Hardware Limit One Shot Mode Timing Diagram (MODE =
‘b01110)
Rev. 10-000 202C
3/6/201 9
TMRx_clk
TxPR 5
ON
TMRx_ers
TxTMR 0 1 2 3 4 5 0 1 0 1 2 3 4 5 0
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
Figure 26-11. Rising Edge Triggered Monostable Mode Timing Diagram (MODE = ‘b10001)
Rev. 10-000203B
3/6/2019
TMRx_clk
TxPR 5
ON
TMRx_ers
TxTMR 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
TMRx_clk
TxPR 5
(1)
Instruction BSF BSF BCF BSF
ON
TMRx_ers
TxTMR 0 1 2 3 4 5 0 1 2 3 0 1 2 3 4 5 0
TMRx_postscaled
PWM Duty
D3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
Important: References to module Timer2 apply to all the even numbered timers on this device (Timer2,
Timer4, etc.).
26.10.1 TxTMR
Name: TxTMR
Offset: 0x322,0x32E,0x33A
Timer Counter Register
Bit 7 6 5 4 3 2 1 0
TxTMR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
26.10.2 TxPR
Name: TxPR
Offset: 0x323,0x32F,0x33B
Timer Period Register
Bit 7 6 5 4 3 2 1 0
TxPR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
26.10.3 TxCON
Name: TxCON
Offset: 0x324,0x330,0x33C
Timerx Control Register
Bit 7 6 5 4 3 2 1 0
ON CKPS[2:0] OUTPS[3:0]
Access R/W/HC R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Note:
1. In certain modes, the ON bit will be auto-cleared by hardware. See Table 26-1.
26.10.4 TxHLT
Name: TxHLT
Offset: 0x325,0x331,0x33D
Bit 7 6 5 4 3 2 1 0
PSYNC CPOL CSYNC MODE[4:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. Setting this bit ensures that reading TxTMR will return a valid data value.
2. When this bit is ‘1’, the Timer cannot operate in Sleep mode.
3. CKPOL must not be changed while ON = 1.
4. Setting this bit ensures glitch-free operation when the ON is enabled or disabled.
5. When this bit is set, then the timer operation will be delayed by two input clocks after the ON bit is set.
6. Unless otherwise indicated, all modes start upon ON = 1 and stop upon ON = 0 (stops occur without affecting
the value of TxTMR).
7. When TxTMR = TxPR, the next clock clears TxTMR, regardless of the operating mode.
26.10.5 TxCLKCON
Name: TxCLKCON
Offset: 0x326,0x332,0x33E
Bit 7 6 5 4 3 2 1 0
CS[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
26.10.6 TxRST
Name: TxRST
Offset: 0x327,0x333,0x33F
Timer External Reset Signal Selection Register
Bit 7 6 5 4 3 2 1 0
RSEL[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
...........continued
Reset Source
RSEL
TMR2 TMR4 TMR6
000011 TMR6_Postscaler_OUT TMR6_Postscaler_OUT Reserved
000010 TMR4_Postscaler_OUT Reserved TMR4_Postscaler_OUT
000001 Reserved TMR2_Postscaler_OUT TMR2_Postscaler_OUT
000000 Pin selected by T2INPPS Pin selected by T4INPPS Pin selected by T6INPPS
0x00
... Reserved
0x0321
0x0322 T2TMR 7:0 T2TMR[7:0]
0x0323 T2PR 7:0 T2PR[7:0]
0x0324 T2CON 7:0 ON CKPS[2:0] OUTPS[3:0]
0x0325 T2HLT 7:0 PSYNC CPOL CSYNC MODE[4:0]
0x0326 T2CLKCON 7:0 CS[4:0]
0x0327 T2RST 7:0 RSEL[5:0]
0x0328
... Reserved
0x032D
0x032E T4TMR 7:0 T4TMR[7:0]
0x032F T4PR 7:0 T4PR[7:0]
0x0330 T4CON 7:0 ON CKPS[2:0] OUTPS[3:0]
0x0331 T4HLT 7:0 PSYNC CPOL CSYNC MODE[4:0]
0x0332 T4CLKCON 7:0 CS[4:0]
0x0333 T4RST 7:0 RSEL[5:0]
0x0334
... Reserved
0x0339
0x033A T6TMR 7:0 T6TMR[7:0]
0x033B T6PR 7:0 T6PR[7:0]
0x033C T6CON 7:0 ON CKPS[2:0] OUTPS[3:0]
0x033D T6HLT 7:0 PSYNC CPOL CSYNC MODE[4:0]
0x033E T6CLKCON 7:0 CS[4:0]
0x033F T6RST 7:0 RSEL[5:0]
Period Latch
Set SMTxPRAIF
SMT_window SMT
Clock SMTxPR
Sync
Circuit
Control Set SMTxIF
Logic Comparator
SMT_signal SMT
Clock
Sync
Circuit
24-bit
Reset SMTxCPR
Buffer
CSEL
See See
SMTxSIG SMT_signal SMTxWIN SMT_window
Register Register
SSEL WSEL
...........continued
MODE Mode of Operation Synchronous Operation
1010 Windowed Counter No
1001 Gated Counter No
1000 Counter No
0111 Capture Yes
0110 Time of Flight Measurement Yes
0101 Gated Windowed Measurement Yes
0100 Windowed Measurement Yes
0011 High and Low Time Measurement Yes
0010 Period and Duty Cycle Measurement Yes
0001 Gated Timer Yes
0000 Timer Yes
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxPR 11
SMTxTMR 0 1 2 3 4 5 6 7 8 9 10 11 0 1 2 3 4 5 6 7 8 9
SMTxIF
SMTx_signal
SMTx_signalsync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxPR 0xFFFFFF
SMTxTMR 0 1 2 3 4 5 6 7
SMTxCPW 5 7
SMTxPWAIF
SMTx_signal
SMTx_signalsync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxPR 0xFFFFFF
SMTxTMR 0 1 2 3 4 5
SMTxCPW 5
SMTxPWAIF
SMTx_signal
SMTx_signalsync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxTMR 0 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5
SMTxCPW 5 2
SMTxCPR 11
SMTxPWAIF
SMTxPRAIF
Figure 27-7. Period and Duty Cycle, Single Acquisition Mode Timing Diagram
Rev. 10-000178A
11/15/2018
SMTx_signal
SMTx_signalsync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxTMR 0 1 2 3 4 5 6 7 8 9 10 11 1
SMTxCPW 5
SMTxCPR 11
SMTxPWAIF
SMTxPRAIF
SMTx_signal
SMTx_signalsync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxTMR 0 1 2 3 4 5 1 2 3 4 5 6 1 2 1 2 3
SMTxCPW 5 2
SMTxCPR 6
SMTxPWAIF
SMTxPRAIF
Figure 27-9. High and Low Measurement Mode, Single Acquisition Timing Diagram
Rev. 10-000179A
11/15/2018
SMTx_signal
SMTx_signalsync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxTMR 0 1 2 3 4 5 1 2 3 4 5 6
SMTxCPW 5
SMTxCPR 6
SMTxPWAIF
SMTxPRAIF
SMTxWIN
SMTxWIN_sync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxTMR 0 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 1 2 3 4
SMTxCPR 12 8
SMTxPRAIF
SMTxWIN
SMTxWIN_sync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxTMR 0 1 2 3 4 5 6 7 8 9 10 11 12
SMTxCPR 12
SMTxPRAIF
SMTxWIN
SMTxWIN_sync
SMTx_signal
SMTx_signalsync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxTMR 0 1 2 3 4 5 6 0 1 2 3 0
SMTxCPR 6 3
SMTxPRAIF
Figure 27-13. Gated Windowed Measurement Mode, Single Acquisition Timing Diagram
Rev. 10-000183A
11/15/2018
SMTxWIN
SMTxWIN_sync
SMTx_signal
SMTx_signalsync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxTMR 0 1 2 3 4 5 6
SMTxCPR 6
SMTxPRAIF
SMTxWIN
SMTxWIN_sync
SMTx_signal
SMTx_signalsync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxTMR 0 1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 11 12 13 1 2
SMTxCPW 13
SMTxCPR 4
SMTxPWAIF
SMTxPRAIF
SMTxWIN
SMTxWIN_sync
SMTx_signal
SMTx_signalsync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxTMR 0 1 2 3 4 5
SMTxCPW
SMTxCPR 4
SMTxPWAIF
SMTxPRAIF
SMTxWIN
SMTxWIN_sync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxTMR 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
SMTxCPW 3 19 32
SMTxCPR 2 18 31
SMTxPWAIF
SMTxPRAIF
SMTxWIN
SMTxWIN_sync
SMTx Clock
SMTxEN
SMTxGO
SMTxGO_sync
SMTxTMR 0 1 2 3
SMTxCPW 3
SMTxCPR 2
SMTxPWAIF
SMTxPRAIF
SMTxWIN
SMTx_signal
SMTxEN
SMTxGO
SMTxTMR 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
SMTxCPW 12 25
SMTxWIN
SMTx_signal
SMTxEN
SMTxGO
SMTxTMR 0 1 2 3 4 5 6 7 8 9 10 11 12 13
SMTxCPW 8 13
SMTxPWAIF
SMTxWIN
SMTx_signal
SMTxEN
SMTxGO
SMTxTMR 0 1 2 3 4 5 6 7 8
SMTxCPW 8
SMTxPWAIF
SMTxWIN
SMTx_signal
SMTxEN
SMTxGO
SMTxTMR 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5
SMTxCPW 9 5
SMTxCPR 16
SMTxPWAIF
SMTxPRAIF
SMTxWIN
SMTx_signal
SMTxEN
SMTxGO
SMTxTMR 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
SMTxCPW 9
SMTxCPR 16
SMTxPWAIF
SMTxPRAIF
27.1.7 Interrupts
The SMT has three interrupts located in one of the PIR registers:
• Pulse-Width Acquisition Interrupt (SMTxPWAIF): Interrupt triggers when the SMTxCPW register is updated
with the SMTxTMR register value.
• Period Acquisition Interrupt (SMTxPRAIF): Interrupt triggers when the SMTxCPR register is updated with the
SMTxTMR register value.
• Counter Period Match Interrupt (SMTxIF): Interrupt triggers when the SMTxTMR register equals the SMTxPR
register.
Each of the above interrupts can be enabled/disabled using the corresponding bits in the PIE register.
27.2.1 SMTxCON0
Name: SMTxCON0
Offset: 0x030C
Bit 7 6 5 4 3 2 1 0
EN STP WPOL SPOL CPOL PS[1:0]
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
27.2.2 SMTxCON1
Name: SMTxCON1
Offset: 0x030D
Bit 7 6 5 4 3 2 1 0
GO REPEAT MODE[3:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
27.2.3 SMTxSTAT
Name: SMTxSTAT
Offset: 0x030E
Bit 7 6 5 4 3 2 1 0
CPRUP CPWUP RST TS WS AS
Access R/W/HC R/W/HC R/W R R R
Reset 0 0 0 0 0 0
27.2.4 SMTxCLK
Name: SMTxCLK
Offset: 0x030F
Bit 7 6 5 4 3 2 1 0
CSEL[3:0]
Access R/W R/W R/W R/W
Reset 0 0 0 0
27.2.5 SMTxWIN
Name: SMTxWIN
Offset: 0x0311
Bit 7 6 5 4 3 2 1 0
WSEL[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
...........continued
WSEL Value Window Source Active in Sleep
000011 SOSC Yes
000010 MFINTOSC (32 kHz) Yes
000001 LFINTOSC Yes
000000 SMT1WINPPS No
27.2.6 SMTxSIG
Name: SMTxSIG
Offset: 0x0310
Bit 7 6 5 4 3 2 1 0
SSEL[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
...........continued
SSEL Value Source
000001 TMR0_OUT
000000 SMT1SIGPPS
27.2.7 SMTxTMR
Name: SMTxTMR
Offset: 0x0300
Bit 23 22 21 20 19 18 17 16
TMR[23:16]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
TMR[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
TMR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• SMTxTMRU: Accesses the upper byte TMR[23:16]
• SMTxTMRH: Accesses the high byte TMR[15:8]
• SMTxTMRL: Accesses the low byte TMR[7:0]
27.2.8 SMTxCPR
Name: SMTxCPR
Offset: 0x0303
Bit 23 22 21 20 19 18 17 16
CPR[23:16]
Access R R R R R R R R
Reset x x x x x x x x
Bit 15 14 13 12 11 10 9 8
CPR[15:8]
Access R R R R R R R R
Reset x x x x x x x x
Bit 7 6 5 4 3 2 1 0
CPR[7:0]
Access R R R R R R R R
Reset x x x x x x x x
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• SMTxCPRU: Accesses the upper byte CPR[23:16]
• SMTxCPRH: Accesses the high byte CPR[15:8]
• SMTxCPRL: Accesses the low byte CPR[7:0]
27.2.9 SMTxCPW
Name: SMTxCPW
Offset: 0x0306
Bit 23 22 21 20 19 18 17 16
CPW[23:16]
Access R R R R R R R R
Reset x x x x x x x x
Bit 15 14 13 12 11 10 9 8
CPW[15:8]
Access R R R R R R R R
Reset x x x x x x x x
Bit 7 6 5 4 3 2 1 0
CPW[7:0]
Access R R R R R R R R
Reset x x x x x x x x
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• SMTxCPWU: Accesses the upper byte CPW[23:16]
• SMTxCPWH: Accesses the high byte CPW[15:8]
• SMTxCPWL: Accesses the low byte CPW[7:0]
27.2.10 SMTxPR
Name: SMTxPR
Offset: 0x0309
Bit 23 22 21 20 19 18 17 16
PR[23:16]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 15 14 13 12 11 10 9 8
PR[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
PR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bits 23:0 – PR[23:0] The SMTxTMR Value at Which the SMTxTMR Resets to Zero
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• SMTxPRU: Accesses the upper byte PR[23:16]
• SMTxPRH: Accesses the high byte PR[15:8]
• SMTxPRL: Accesses the low byte PR[7:0]
0x00
... Reserved
0x02FF
7:0 TMR[7:0]
0x0300 SMT1TMR 15:8 TMR[15:8]
23:16 TMR[23:16]
7:0 CPR[7:0]
0x0303 SMT1CPR 15:8 CPR[15:8]
23:16 CPR[23:16]
7:0 CPW[7:0]
0x0306 SMT1CPW 15:8 CPW[15:8]
23:16 CPW[23:16]
7:0 PR[7:0]
0x0309 SMT1PR 15:8 PR[15:8]
23:16 PR[23:16]
0x030C SMT1CON0 7:0 EN STP WPOL SPOL CPOL PS[1:0]
0x030D SMT1CON1 7:0 GO REPEAT MODE[3:0]
0x030E SMT1STAT 7:0 CPRUP CPWUP RST TS WS AS
0x030F SMT1CLK 7:0 CSEL[3:0]
0x0310 SMT1SIG 7:0 SSEL[5:0]
0x0311 SMT1WIN 7:0 WSEL[5:0]
Timer Clock
Selections
timer clock
TUxyCLK Prescaler Block
CPOL
Prescaler Register
External Input TUxyPS
Sources
TUxyERS prescaled clock
RUN
CLR
START reset
Counter Block
ers
STOP Edge Detection reset
RESET Edge/Level Polarity start run/stop count_en Counter Register
S Q
EPOL Synchronization TUxyTMR
CSYNC stop
R
zero
Datasheet
RDSEL
PIC18F26/46/56Q83
1
OPOL
OM
Period Register
TUxyPR
DS40002253C-page 469
Module
off
Enable (Double Buffered)
OSEN Disable
PRIF
ON CIF Interrupt TUxyIF
Interrupt Trigger
ZIF Enable To PIRx
Counter PRIFDMA
Prescaler DMA Trigger CIFDMA
ZIFDMA
PIC18F26/46/56Q83
UTMR - Universal Timer Module
Important: Due to the inherent uncertainty of reading or writing a 16-bit timer with an 8-bit bus and
operating from an asynchronous clock source, it is recommended that read/write of the timer registers use
the CAPT and the CLR commands. Refer to the Timer Counter and Capture Registers section for more
information.
ON
RUN
(processor
domain) sync into sync into
timer domain processor domain
(timer
domain)
STOP
set CIF
Note:
1. Not to scale; clocks are not shown.
ON
RUN
(processor
domain) sync into sync into
timer domain processor domain
(timer
domain)
STOP
set CIF
Note:
1. Not to scale; clocks are not shown.
Clearing the CSYNC bit will disable the synchronization logic. When CSYNC = 0, ERS asynchronously gates the
clock and/or resets the timer, according to Start, Reset and Stop options. It is possible that the timer clock may
transition at the same time that the ON bit is set by the user or an ERS event occurs or a CLR or CAPT command is
passed (a clock collision), which may cause unpredictable results to the counter value. Setting CSYNC = 1 removes
this uncertainty.
Important: Using an external clock synchronizer, like the CLC or the comparator sync logic, can allow
synchronous applications with CSYNC = 0, but clock rate limitations may apply at the device level.
The ON bit must be set for all counting operations. With START = ‘b00 (no ERS Start), setting ON will start the timer
as though a Start condition occurred. With START > ‘b00 (ERS edge/level-triggers Start), setting ON prepares the
timer for an ERS Start condition and enables the ERS detection logic.
ON will return to ‘0’ when a hardware Stop condition occurs or when written by software, except as noted in the One
Shot Mode section. Figure 28-4 and Figure 28-5 below show timing examples for One Shot mode with CSYNC = 1
and CSYNC = 0, respectively.
(1)
ON
(2)
RUN
TUCLK
Fosc/4
TUxyTMR 0 (3) 1 2 3 4 = PR 0 1
TUxyCR 3 1
CAPT
ERS
PR Match
TMR = PR
Timer Out
(Pulse)
Timer Out
(Level)
ZIF (4)
PRIF (4)
Timer Setup:
START = None (ON = 1) RESET = At PR Match STOP = Rising ERS Edge
CSYNC = Sync OSEN = Enabled
PR = 4 (Period of 5) PS = 2 (Prescaler of 3)
Note:
1. The ON bit is set in the software and cleared by hardware upon Stop (One Shot mode).
2. The RUN trace illustrates the actual RUN SFR bit and not the internal Timer Clock domain
run/stop signal.
3. Ensure that TUxyTMR counter is reset to zero by setting CLR command.
4. Cleared by software.
(1)
ON
(2)
RUN
TUCLK
Fosc/4
TUxyTMR 0 (3) 1 2 3 4 = PR 0 1
TUxyCR 2 1
CAPT
ERS
PR Match
TMR = PR
Timer Out
(Pulse)
Timer Out
(Level)
ZIF (4)
PRIF (4)
Timer Setup:
START = None (ON = 1) RESET = At PR Match STOP = Rising ERS Edge
CSYNC = Async OSEN = Enabled
PR = 4 (Period of 5) PS = 2 (Prescaler of 3)
Note:
1. The ON bit is set in the software and cleared by hardware upon Stop (One Shot mode).
2. The RUN trace illustrates the actual RUN SFR bit and not the internal Timer Clock domain
run/stop signal.
3. Ensure that TUxyTMR counter is reset to zero by setting CLR command.
4. Cleared by software.
erroneous values. This can occur when the counter/timer is operating from an asynchronous clock source or when
the read happens coincidentally with the rollover of the bottom 8 bits of the TUxyTMR counter register.
Clearing the RDSEL bit directs all counter/timer reads through the TUxyCR capture register. The TUxyCR capture
register is functionally a read-only register and is loaded directly from the counter/timer in response to either of the
following three conditions:
1. Setting the CAPT command bit.
2. When a stop event is generated.
3. In the event of an ERS rising edge (or falling edge based on EPOL bit selection) if the Stop condition is set to
none. See Stop Event for more details on Stop condition.
It is recommended that any read of the timer, when it is running, utilizes the CAPT command bit with the RDSEL bit
clear. Asserting the CAPT bit will cause synchronous transfer of the timer value to the TUxyCR capture register. The
CAPT bit remains set until the capture is complete. The TUxyCR capture register can then be read by the processor
without any data corruption. See Figure 28-6 for an example of the CAPT bit operation.
Figure 28-6. CAPT Bit Operation
TUxyTMR 0 1 PR 0 PR 0
TUxyCR 42 141
(2)
RUN
PR Match
TMR = PR
Timer Out (3) (3)
(Pulse)
CAPT
Timer Setup:
START = None (ON = 1) RESET = At PR Match STOP = None
CSYNC = Sync
Note:
1. Cross-domain clock synchronization applies as required but is not highlighted.
2. The RUN trace illustrates the internal Timer Clock domain run/stop signal. Clock sync delays
apply before the value appears in the RUN SFR bit.
3. The uncertainty of the output is due to the prescaler setting.
4. Cleared by software.
In the event of an ERS rising capture, the TUxyCR capture register must be read before the event of a second ERS
rising or the data captured will be overwritten by the second rising event.
The TUxyTMR counter register can be written when the RDSEL bit is set, provided that the ON bit is clear.
Attempting to write to the TUxyTMR counter register with the ON bit set can result in corrupted data. If the intention is
to clear the counter, the CLR command bit needs to be used instead of writing zeros. Asserting the CLR bit clears the
TUxyTMR counter register, even if the ON bit is set. The CLR bit remains set until the counter is reset.
The CAPT and CLR command bits are subject to synchronization delays which is dependent on the settings of
CSYNC and ON bits, as shown in Table 28-2.
Table 28-2. Behavior of CAPT and CLR Commands with Respect to ON and CSYNC Bits
0 (Timer Stopped) 1 Synchronization delay of three timer clock cycles applies. The desired
action is delayed until timer clock resumes.
0 (Timer Stopped) 0 No synchronization delay applies. Desired action is performed immediately.
Important:
1. Reading and writing the TUxyTMR counter register when the timer is running (ON = 1) is not
recommended. The TUxyTMR counter register needs to be read or written to only when the timer is
stopped (ON = 0) to prevent data corruption.
2. The TUxyTMR register, like many othe registers in the module, remains unchanged after a non-
POR/BOR system Reset. It is recommended to always clear this register at the start of program
execution to avoid counting from an unknown value.
3. Setting the CLR bit does not reset the TUxyCR capture register.
4. The TUxyTMR register needs to not be written as a means to change the effective period. If the
intention is to change the timer period, the TUxyPR period register needs to be changed instead.
See Timer Period Register for more details on how to change the timer period while the timer is
running.
5. When software sets a CLR or CAPT command bit, the bit value of ‘1’ is indicated in the SFR
immediately, to indicate that the over-and-back clock synchronization is not complete. However, a
sufficiently high timer clock frequency might complete the cross-domain synchronization within one
instruction cycle and the bit value would always appear to be ‘0’.
6. Setting CLR or CAPT command bits to ‘0’ has no effect.
7. The timer starts counting by incrementing the TUxyTMR value to the next valid counter value. For
instance, if the counter is in Reset state (TUxyTMR = 0), then the timer starts counting from 1. If
the TUxyTMR = PR and RESET = at PR Match, then the timer will start counting by resetting the
counter to zero first.
Important:
1. Writing to MSBs after arming the load can lead to corrupted operation.
2. Reading the TUxyPR period register returns the most-recently written value, not necessarily the
current effective PR value.
Important:
1. Actions involving ERS require the ON bit to be set and a running clock.
2. The EPOL bit must not be changed when ON = 1. Changing EPOL will spontaneously cause an
edge event and can cause timer output to flip.
START STOP
RESET EPOL
Clock Rising
Rising Sync
Edge
Detect
ERS
D Q Either
Signal
Clock Level-1
Sync
Timer Clock
Selections
TUxyCLK To Prescaler
CPOL timer clock
Important:
1. The value of the TUxyTMR counter and TUxyCR capture registers are not affected when the ON bit
is clear, unless they are changed explicitly by the user.
2. Clock synchronization may apply, in which case, actions performed may or may not have immediate
effect.
3. The ON bit, like many other bits in the module, remains unchanged after a non-POR/BOR system
Reset. It is recommended to clear the ON bit at the start of program execution to avoid starting the
system with a running timer.
Important:
1. In the event of a level-triggered Start/Reset, the active level must be asserted for at least one timer
clock period to ensure proper sampling. If the duration of the asserted level is less than one timer
clock, there is a possibility of the level trigger being missed and not sampled by the timer module.
3. At a start event: The counter/timer resets at the first clock of the counter/timer start and/or when the TUxyTMR
counter register is equal to the TUxyPR period register. The number of cycles needed to reach PR match is
extended by one. If the Start condition is ERS = 1 (or ERS = 0, based on EPOL selection), the Reset will only
apply to the leading ERS edge. See Figure 28-11 for an example of Reset at a Start event.(2)
4. At period match: The counter/timer resets when TUxyTMR counter register is equal to the TUxyPR period
register.
Important:
1. If the counter is already zero, a Reset event will not trigger ZIF interrupt.
2. When prescaler > 0, then any ERS or Start-based Reset event that occurs during a PR match
period will reset the timer counter and prescaler counter immediately, and the pulse output will not
occur. If the Reset event collides with the pulse output (regardless of prescaler setting), then the
pulse output will occur naturally and the counter will reset at the next prescaler counter naturally.
3. In the event of a level-triggered Start/Reset, the active level must be asserted for at least one timer
clock period to ensure proper sampling. If the duration of the asserted level is less than one timer
clock, there is a possibility of the level trigger being missed and not sampled by the timer module.
ERS
RESET
(4)
RUN
Timer Setup:
START = Rising ERS Edge RESET = At Start+PR Match STOP = Rising ERS Edge
CSYNC = Sync
Note:
1. Cross-domain clock synchronization applies as required but is not highlighted.
2. A coincident Start/Stop condition that starts the counter does not cause either a capture
or CIF to be set.
3. A synchronous edge-triggered Start/Stop condition is one timer clock cycle wide internally.
4. The RUN trace illustrates the internal Timer Clock domain run/stop signal. Clock sync delays
apply before the value appears in the RUN SFR bit.
5. The uncertainty of the output is due to the prescaler setting.
6. Timer Out (Level) rises along with ERS when START = Rising/Either ERS Edge.
7. Cleared by software.
TUxyTMR 0 1 33 0 1 PR 0 142 0
TUxyCR 33 142
PW < PR PW > PR
ERS
ON (2)
RUN (3)
RESET
PRIF (5)
Timer Setup:
START = None (ON = 1) RESET = ERS Level-0+PR Match STOP = Either ERS Edge
CSYNC = Sync OSEN = Enabled
Note:
1. Cross-domain clock synchronization applies as required but is not highlighted.
2. The ON bit is set in the software and cleared by hardware upon Stop (One Shot mode).
3. The RUN trace illustrates the internal Timer Clock domain run/stop signal. Clock sync
delays apply before the value appears in the RUN SFR bit.
4. The uncertainty of the output is due to the prescaler setting.
5. Cleared by software.
ERS
(3)
RUN
PR Match
TMR = PR
Timer Out (4)
(Pulse)
Timer Out (5) (6) (5)
(Level)
CAPT
ZIF (7)
PRIF (7)
Timer Setup:
START = Rising ERS Edge RESET = None STOP = Either ERS Edge
CSYNC = Sync
Note:
1. Cross-domain clock synchronization applies as required but is not highlighted.
2. TOP represents the maximum counter value.
3. The RUN trace illustrates the internal Timer Clock domain run/stop signal. Clock sync delays
apply before the value appears in the RUN SFR bit.
4. The uncertainty of the output is due to the prescaler setting.
5. Timer Out (Level) rises along with ERS when START = Rising/Either ERS Edge.
6. Timer Out (Level) falls synchronous to the timer clock.
7. Cleared by software.
TUxyTMR 0 1 42 0 PR 0 0 0 PR 0
TUxyCR PR PR
(2)
RUN
PR Match
TMR = PR
Timer Out (3) (3)
(Pulse)
Timer Out
(Level)
PRIF (4)
CIF (4)
Timer Setup:
START = ERS Level-1 RESET = At Start+PR Match STOP = At PR Match
CSYNC = Sync
Note:
1. Cross-domain clock synchronization applies as required but is not highlighted.
2. The RUN trace illustrates the internal Timer Clock domain run/stop signal. Clock sync delays
apply before the value appears in the RUN SFR bit.
3. The uncertainty of the output is due to the prescaler setting.
4. Cleared by software.
Important:
1. In the event of coincidental start and stop events, and RUN = 0; the start event takes precedence,
timer capture and CIF interrupt are blocked, and OSEN is ignored. See Figure 28-8 for a
coincidental start and stop event at ERS rising edge. If RUN = 1, then the stop event is ignored, but
will still cause a capture.
2. If Reset and Stop are coincident, the captured value is the value prior to the Reset and the counter
will stop at zero.
3. After stopping, the start edge detector needs up to 3 timer clock periods to resume, and any
overlapping stop events may be ignored in that interval.
4. If the counter is not running (no start has occurred), a stop event will have no side effects, such as
capturing data.
Important:
1. This bit is relevant when RESET = ‘b00 (No hardware Reset) and counter equals PR.
2. The effect of Limit mode is to prevent the counter from exceeding PR value. Reset and CLR events
are not prevented from clearing the counter.
Important: In One Shot mode, a Stop condition clears the ON bit, even if it coincides with another Start
event. If a Stop event occurs prior to Start, that Stop condition does not clear ON bit.
TUxyTMR 0(2) 1 2 PR 0 1 2 PR 0 1 2
TUxyCR PR PR
(3)
ON
(4)
RUN
PR Match
TMR = PR
Timer Out (5) (5)
(Pulse)
Timer Setup:
START = None (ON = 1) RESET = At PR Match STOP = At PR Match
CSYNC = Sync OSEN = Enabled
Note:
1. Cross-domain clock synchronization applies as required but is not highlighted.
2. Ensure that TUxyTMR counter is reset to zero by setting CLR command.
3. The ON bit is set in the software and cleared by hardware upon Stop (One Shot mode).
4. The RUN trace illustrates the internal Timer Clock domain run/stop signal. Clock sync
delays apply before the value appears in the RUN SFR bit.
5. The uncertainty of the output is due to the prescaler setting.
6. Cleared by software.
Important:
1. The RUN bit is held at zero if a Start has occurred (the counter is “running”), but ERS is holding the
counter at the value zero when RESET = ‘b01 (level-triggered).
2. The RUN status bit lags the internal Run/Stop state by two to three instruction cycles. If Start and
Stop occur rapidly in succession, the RUN bit may not be set at all.
and cleared to indicate the timer has stopped. The output remains set through all Reset conditions, except when ERS
is holding the timer/counter in a Reset state (RESET = ‘b11, level ERS Reset).
When the OM bit is cleared, the timer output is pulsed high at every period match (pulse output). The duration of the
pulse is one single primary clock period at the end of the counter match period, regardless of the prescaler. This is
demonstrated in Figure 28-4 and Figure 28-5 where the pulse output occurs only during the last timer clock period
during the PR match.
The polarity of the output (pulsed or level) is controlled by the OPOL bit in the TUxyCON0 register. When OPOL is
set, the output will either pulse low or be held low when timer output is active. When OPOL is cleared, the output will
be either pulse high or be held high when timer output is active. The OPOL bit will control the output polarity of the
module even when the module is disabled (ON = 0).
Important:
1. When START = ‘b01 or ‘b10 (edge-triggered), the level output is asserted as soon as the qualified
ERS edge is registered without any synchronization delays (even when CSYNC = 1).
2. When LIMIT = 1, the pulse output will assert as indicated and will remain asserted until the counter
changes from PR.
3. The OPOL bit does not affect the polarity of the RUN SFR bit.
Important:
1. The interrupts need not be enabled with their associated enable bits to be used as triggers for DMA
transfer.
2. The interrupts must be enabled for the TUxyIF flag to be set in the PIRx register as shown in Figure
28-13.
PR Match PRIE
Interrupt
Logic PRIF
PRIFDMA
CIFDMA
Zero ZIE
Interrupt
Logic ZIF
ZIFDMA
Timer Clock
Clock Enable
Gate Logic Counter
TUxyERS TUxyCONz Control and Match Capture
TUxyHLT Period
TUxyPS Carry Enable Registers
Timer Output
Interrupt and
DMA Triggers
Timer Chain Out
Main
TUCHAIN
Secondary
Timer Chain In
Timer Clock
N/C
Clock Enable
N/C
Gate Logic Counter
TUxyERS TUxyCONz Control and Match Capture
N/C
TUxyHLT Period
TUxyPS Registers
Logic
Disconnected N/C
Note:
1. This is a conceptual diagram only.
2. Control registers, state machine, prescaler and input ERS and clock for
Secondary module is not used. Rather they are derived from the Main
module.
28.9.1 TUxyCON0
Name: TUxyCON0
Bit 7 6 5 4 3 2 1 0
ON CPOL OM OPOL RDSEL PRIE ZIE CIE
Access R/W/HC R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. The selected clock will be enabled when this bit is set and a Start condition has occurred.
2. When this bit is set and CSYNC = 1, it takes three timer clocks to synchronize. When this bit is cleared and
CSYNC = 1, the selected clock source (especially external clock sources) must supply at least three additional
clocks to resolve internal states. During this time, if the timer is already running, any stop/Reset related ERS
events that get processed will continue to affect the Run state of the timer. If CSYNC = 0, the ON bit clears
immediately and the timer stops immediately.
3. This bit is not clock synchronized, and needs to only be changed while ON = 0.
4. The purpose of this control is to select the active edge when using externally-clocked Counter mode.
5. This bit controls the output even when ON = 0.
6. This bit is shadowed when the module is frozen during debugging and restored when the module resumes
operation.
7. Capture or stop events load the TUxyCR capture register, regardless of this bit’s setting.
8. The effect of writing to TUxyCR with RDSEL = 0 is not defined.
9. The interrupt flags will be set even if the corresponding interrupt is disabled.
10. The PRIF interrupt will not occur if the user writes the PR value to the TUxyTMR counter register directly.
11. The CIF interrupt trigger requires a running timer.
12. This register is not available when the module is chained and operated as a Secondary module.
28.9.2 TUxyCON1
Name: TUxyCON1
Bit 7 6 5 4 3 2 1 0
RUN OSEN CLR LIMIT CAPT PRIF ZIF CIF
Access R R/W R/S/HC R/W R/S/HC R/W/HS R/W/HS R/W/HS
Reset 0 0 0 0 0 0 0 0
Notes:
1. Clock synchronization delays apply.
2. This bit is held at zero if a Start has occurred (the counter is “running”), but ERS is holding the counter at the
value zero when RESET = ‘b01 (level-triggered).
3. The clearing of the ON bit in One Shot mode is subject to clock synchronization delays. Refer to sections
Synchronous vs. Asynchronous Operation and One Shot Mode for details.
4. This bit is not clock synchronized, and needs to only be changed while ON = 0.
5. This bit is subject to clock synchronization delays. See Timer Counter and Capture Registers for details.
6. If the counter is disabled (ON = 0) or if the module is frozen during debugging, then the timer clock has been
disabled; the effect of setting CLR or CAPT command bits depends on the clock synchronization setting. If
CSYNC = 0, the corresponding action is performed immediately. If CSYNC = 1, the corresponding action is
delayed until the clock resumes (even in Frozen state while debugging). See also Timer Counter and Capture
Registers.
7. A capture event can also be triggered by other means. See Timer Counter and Capture Registers for details.
8. If the CAPT command is near-coincident with a Stop event, the captured value may represent the first event
that occurs.
9. The captured value is read by setting RDSEL = 0 and reading TUxyCR.
10. This bit may be set by software to invoke an interrupt or DMA operation.
11. The interrupt flags will be set even if the corresponding interrupt is disabled.
12. The PRIF interrupt will not occur if the user writes the PR value to the TUxyTMR counter register directly.
13. The CIF interrupt trigger requires a running timer.
14. This register is not available when the module is chained and operated as a Secondary module.
28.9.3 TUxyHLT
Name: TUxyHLT
Bit 7 6 5 4 3 2 1 0
EPOL CSYNC START[1:0] RESET[1:0] STOP[1:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 1 0 0 0 0 0 0
Notes:
1. This bit is Reset to ‘1’.
2. If CSYNC = 0, the ERS and ON edges must occur sufficiently further away from the clock edge to be
registered into the timer domain. If the ERS and/or ON edges occur too close to the clock edge, it may result in
a Race condition and the ERS/ON edges may be missed.
3. The TUxyCLK clock source is enabled when ON = 1 regardless of the Start event.
4. If EPOL = 1, then timer Start/Reset/Stop conditions happen at the alternate level/edge, respectively.
5. When the timer is running, any subsequent Start condition is ignored. If RESET = ‘b10 (Reset at first clock
after starting), the timer resets at every Start condition, even when the actual start event is being ignored.
6. If START = ‘b11 (level triggered at ERS = 1), RESET = ‘b10 (Reset at first clock after starting) applies only
at the Off-On transition of the timer’s Run state.
7. If RESET = ‘b10 (level-triggered), the RUN bit is held at ‘0’.
8. A Reset or Stop event reloads the PR register as described in Timer Period Register.
9. Actions involving ERS require ON = 1 and a running clock.
10. Software can always set ON = 0 to stop the counter.
11. If OSEN = 1, a Stop event will clear ON.
12. This register is not clock synchronized and needs to only be written when ON = 0.
13. This register is not available when the module is chained and operated as a Secondary module.
28.9.4 TUxyPS
Name: TUxyPS
Bit 7 6 5 4 3 2 1 0
PS[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. This register needs to only be written when ON = 0.
2. This register is not available when the module is chained and operated as a Secondary module.
3. The internal prescaler counter (not the TUxyPS register) is reset by any Stop or Reset event, and upon any
write to the TUxyPS and TUxyTMR registers. This allows the next timer interval to be full-length.
Name: TU16yTMR
Offset: 0x38B,0x397
Timer Counter Register for 16-bit version of UTMR module. This register can only be addressed when RDSEL = 1.
Bit 15 14 13 12 11 10 9 8
TMR[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
TMR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. Writing to this register will change the raw counter value directly. The user must handle the operation correctly
to avoid data corruption. There is no safeguard for atomic access. Reading or writing a running counter is not
recommended. This register must only be accessed while clocking is disabled.
2. The individual bytes in this multibyte register can be accessed with the following register names:
– TUxyTMRH: Accesses the high byte TUxyTMR[15:8]
– TUxyTMRL: Accesses the low byte TUxyTMR[7:0]
Name: TU16yCR
Offset: 0x38B,0x397
Timer Capture Register for 16-bit version of UTMR module. This register can only be addressed when RDSEL = 0.
Bit 15 14 13 12 11 10 9 8
CR[15:8]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
CR[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Notes:
1. Writing to this register is not recommended and may result in unexplained behavior.
2. The captured value is updated at Stop or when software sets CAPT = 1, regardless of the RDSEL value. Refer
to Timer Counter and Capture Registers for details.
3. The individual bytes in this multibyte register can be accessed with the following register names:
– TUxyCRH: Accesses the high byte TUxyCR[15:8]
– TUxyCRL: Accesses the low byte TUxyCR[7:0]
Name: TU16yPR
Offset: 0x38D,0x399
Bit 15 14 13 12 11 10 9 8
PR[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
PR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Notes:
1. This register is double-buffered; effective PR value is loaded as defined by Timer Period Register.
2. Data written to higher bytes is buffered; data written to LSB is also buffered and arms the effective PR value to
be loaded at the next Reset or CLR event.
3. Reading this register returns the data most-recently written, not necessarily the current PR setting.
4. The individual bytes in this multibyte register can be accessed with the following register names:
– TUxyPRH: Accesses the high byte TUxyPR[15:8]
– TUxyPRL: Accesses the low byte TUxyPR[7:0]
28.9.8 TUxyCLK
Name: TUxyCLK
Bit 7 6 5 4 3 2 1 0
CLK[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
Note:
1. This register is not available when the module is chained and operated as a Secondary module.
28.9.9 TUxyERS
Name: TUxyERS
Bit 7 6 5 4 3 2 1 0
ERS[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
...........continued
External Reset Source Connection
ERS
TU16A TU16B
000111 PWM2S1P2_OUT
000110 PWM2S1P1_OUT
000101 PWM1S1P2_OUT
000100 PWM1S1P1_OUT
000011 TU16B_OUT Reserved
000010 Reserved TU16A_OUT
000001 TUIN1PPS
000000 TUIN0PPS
Note:
1. TUxyPRL_Write,TUxyTMRL_Read and TUxyCRL_Read are event triggers occurring when the indicated SFR
is accessed.
Note:
1. This register is not available when the module is chained and operated as a Secondary module.
28.9.10 TUCHAIN
Name: TUCHAIN
Offset: 0x3BB
Bit 7 6 5 4 3 2 1 0
CH16AB
Access R/W
Reset x
TU16ATMR, TU16ACR and TU16APR form the Least Significant bits of the counter, capture and
period values, respectively.
0 Timers TU16A and TU16B operate as independent 16-bit timers
Note: When chained, TUxyCON0, TUxyCON1, TUxyHLT, TUxyPS, TUxyCLK and TUxyERS of the Secondary
module are undefined. Refer to the Chaining Counter Timers section for details.
0x00
... Reserved
0x0386
0x0387 TU16ACON0 7:0 ON CPOL OM OPOL RDSEL PRIE ZIE CIE
0x0388 TU16ACON1 7:0 RUN OSEN CLR LIMIT CAPT PRIF ZIF CIF
0x0389 TU16AHLT 7:0 EPOL CSYNC START[1:0] RESET[1:0] STOP[1:0]
0x038A TU16APS 7:0 PS[7:0]
7:0 TMR[7:0]
0x038B TU16ATMR
15:8 TMR[15:8]
7:0 CR[7:0]
0x038B TU16ACR
15:8 CR[15:8]
7:0 PR[7:0]
0x038D TU16APR
15:8 PR[15:8]
0x038F TU16ACLK 7:0 CLK[4:0]
0x0390 TU16AERS 7:0 ERS[5:0]
0x0391
... Reserved
0x0392
0x0393 TU16BCON0 7:0 ON CPOL OM OPOL RDSEL PRIE ZIE CIE
0x0394 TU16BCON1 7:0 RUN OSEN CLR LIMIT CAPT PRIF ZIF CIF
0x0395 TU16BHLT 7:0 EPOL CSYNC START[1:0] RESET[1:0] STOP[1:0]
0x0396 TU16BPS 7:0 PS[7:0]
7:0 TMR[7:0]
0x0397 TU16BTMR
15:8 TMR[15:8]
7:0 CR[7:0]
0x0397 TU16BCR
15:8 CR[15:8]
7:0 PR[7:0]
0x0399 TU16BPR
15:8 PR[15:8]
0x039B TU16BCLK 7:0 CLK[4:0]
0x039C TU16BERS 7:0 ERS[5:0]
0x039D
... Reserved
0x03BA
0x03BB TUCHAIN 7:0 CH16AB
Important: In devices with more than one CCP module, it is very important to pay close attention to
the register names used. Throughout this section, the prefix “CCPx” is used as a generic replacement for
specific numbering. A number placed where the “x” is in the prefix is used to distinguish between separate
modules. For example, CCP1CON and CCP2CON control the same operational aspects of two completely
different CCP modules.
The assignment of a particular timer to a module is selected as shown in the “Capture, Compare, and PWM Timers
Selection” chapter. All of the modules may be active at once and may share the same timer resource if they are
configured to operate in the same mode (Capture/Compare or PWM) at the same time.
Important: If an event occurs during a 2-byte read, the high and low-byte data will be from different
events. It is recommended while reading the CCPRx register pair to either disable the module or read the
register pair twice for data integrity.
CCPRx
16
Capture Trigger Sources set CCPxIF
See CCPxCAP register Prescaler and
1,4,16 Edge Detect
16
CCPx PPS
MODE TMR1
CCPxPPS
Important: If the CCPx pin is configured as an output, a write to the port can cause a capture event.
Important: Clocking Timer1 from the system clock (FOSC) must not be used in Capture mode. For
Capture mode to recognize the trigger event on the CCPx pin, Timer1 must be clocked from the instruction
clock (FOSC/4) or from an external clock source.
MODE
Auto-conversion Trigger
CCPRx
RxyPPS
TMR1
TRIS
Important: Clearing the CCPxCON register will force the CCPx compare output latch to the default low
level. This is not the PORT I/O data latch.
Important: Clocking Timer1 from the system clock (FOSC) must not be used in Compare mode. For
Compare mode to recognize the trigger event on the CCPx pin, Timer1 must be clocked from the
instruction clock (FOSC/4) or from an external clock source.
PWM resolution defines the maximum number of steps that can be present in a single PWM period. A higher
resolution allows for more precise control of the power applied to the load.
The term duty cycle describes the proportion of the ON time to the OFF time and is expressed in percentages, where
0% is fully OFF and 100% is fully ON. A lower duty cycle corresponds to less power applied and a higher duty cycle
corresponds to more power applied. The figure below shows a typical waveform of the PWM signal.
Figure 29-3. CCP PWM Output Signal
Period
Pulse Width
TMR2 = PR2
TMR2 = CCPRx
TMR2 = 0
CCPRxH CCPRxL
CCPx_out
to peripherals
set CCPIF
10-bit Latch(2)
(Not accessible by user)
S RxyPPS
TMR2 Module TRIS Control
R
TMR2 (1)
ERS logic
Comparator CCPx_pset
PR2
Notes: 1. An 8-bit timer is concatenated with two bits generated by Fosc or two bits of the internal prescaler
to create 10-bit time base.
2. The alignment of the 10 bits from the CCPR register is determined by the CCPxFMT bit.
Important: The corresponding TRIS bit must be cleared to enable the PWM output on the CCPx pin.
Important: To send a complete duty cycle and period on the first PWM output, the above
steps must be included in the setup sequence. If it is not critical to start with a complete PWM
signal on the first output, then step 6 may be ignored.
Important: The Timer postscaler (see the “Timer2 Interrupt” section) is not used in the determination of
the PWM frequency.
The CCPRx register is used to double buffer the PWM duty cycle. This double buffering is essential for glitchless
PWM operation.
The 8-bit timer T2TMR register is concatenated with either the 2-bit internal system clock (FOSC), or two bits of the
prescaler, to create the 10-bit time base. The system clock is used if the Timer2 prescaler is set to 1:1.
When the 10-bit time base matches the CCPRx register, then the CCPx pin is cleared (see Figure 29-4).
Important: If the pulse-width value is greater than the period, the assigned PWM pin(s) will remain
unchanged.
PWM Frequency 1.22 kHz 4.88 kHz 19.53 kHz 78.12 kHz 156.3 kHz 208.3 kHz
Timer Prescale 16 4 1 1 1 1
T2PR Value 0xFF 0xFF 0xFF 0x3F 0x1F 0x17
PWM Frequency 1.22 kHz 4.90 kHz 19.61 kHz 76.92 kHz 153.85 kHz 200.0 kHz
Timer Prescale 16 4 1 1 1 1
T2PR Value 0x65 0x65 0x65 0x19 0x0C 0x09
29.5.1 CCPxCON
Name: CCPxCON
Offset: 0x342,0x346,0x34A
Bit 7 6 5 4 3 2 1 0
EN OUT FMT MODE[3:0]
Access R/W R R/W R/W R/W R/W R/W
Reset 0 x 0 0 0 0 0
Notes:
1. The set and clear operations of the Compare mode are reset by setting MODE = ‘b0000 or EN = 0.
2. When MODE = ‘b0001 or ‘b1011, then the timer associated with the CCP module is cleared. TMR1 is the
default selection for the CCP module, so it is used for indication purposes only.
29.5.2 CCPxCAP
Name: CCPxCAP
Offset: 0x343,0x347,0x34B
Capture Trigger Input Selection Register
Bit 7 6 5 4 3 2 1 0
CTS[3:0]
Access R/W R/W R/W R/W
Reset 0 0 0 0
29.5.3 CCPRx
Name: CCPRx
Offset: 0x340,0x344,0x348
Capture/Compare/Pulse-Width Register
Bit 15 14 13 12 11 10 9 8
CCPR[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
Bit 7 6 5 4 3 2 1 0
CCPR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• When MODE = Capture or Compare
– CCPRxH: Accesses the high byte CCPR[15:8]
– CCPRxL: Accesses the low byte CCPR[7:0]
• When MODE = PWM and FMT = 0
– CCPRx[15:10]: Not used
– CCPRxH[1:0]: Accesses the two Most Significant bits CCPR[9:8]
– CCPRxL: Accesses the eight Least Significant bits CCPR[7:0]
• When MODE = PWM and FMT = 1
– CCPRxH: Accesses the eight Most Significant bits CCPR[9:2]
– CCPRxL[7:6]: Accesses the two Least Significant bits CCPR[1:0]
– CCPRx[5:0]: Not used
0x00
... Reserved
0x033F
7:0 CCPR[7:0]
0x0340 CCPR1
15:8 CCPR[15:8]
0x0342 CCP1CON 7:0 EN OUT FMT MODE[3:0]
0x0343 CCP1CAP 7:0 CTS[3:0]
7:0 CCPR[7:0]
0x0344 CCPR2
15:8 CCPR[15:8]
0x0346 CCP2CON 7:0 EN OUT FMT MODE[3:0]
0x0347 CCP2CAP 7:0 CTS[3:0]
7:0 CCPR[7:0]
0x0348 CCPR3
15:8 CCPR[15:8]
0x034A CCP3CON 7:0 EN OUT FMT MODE[3:0]
0x034B CCP3CAP 7:0 CTS[3:0]
30.1.1 CCPTMRS0
Name: CCPTMRS0
Offset: 0x34C
Bit 7 6 5 4 3 2 1 0
C3TSEL[1:0] C2TSEL[1:0] C1TSEL[1:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 1 0 1 0 1
0x00
... Reserved
0x034B
0x034C CCPTMRS0 7:0 C3TSEL[1:0] C2TSEL[1:0] C1TSEL[1:0]
P1 Buffer
Duty Cycle
Reset
PR Buffer
PWMx_SaP1_out
Q
Set
Set
PWMxCLK PWMx_SaP2_out
Q
Reset
Duty Cycle
P2 Buffer
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP1IF
PWMxPIF
PWMxIF
P1 Buffer
Duty Cycle
Set
PR Buffer
PWMx_SaP1_out
Q
Reset
PWMx_clk
Clock Prescale Timer
Period
Event
Sources
Reset
PWMxCLK PWMx_SaP2_out
Q
Set
Duty Cycle
P2 Buffer
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP2IF
The parameter register specifies the number of PWM clock periods that the output goes Active before the period
center. The output goes inactive the same number of prescaled PWM clock periods after the period center. Block and
timing diagrams follow.
Figure 31-5. Center-Aligned Block Diagram
P1 Buffer
Duty Cycle
Reset
PR Buffer PWMx_SaP1_out
Q
Set
PWMx_clk
Clock Prescale Timer
Period
Event
Sources
Set
PWMxCLK
PWMx_SaP2_out
Q
Reset
Duty Cycle
P2 Buffer
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP2IF
P1 Buffer
=
PR Buffer
Set
PWMx_SaP1_out
Q
PWMxCLK
=
P2 Buffer
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP1IF
PWMxPIF
P1 Buffer
=
Pulse
PWMx_SaP1_out
Q
PR Buffer
PWMx_clk
Clock Prescale Timer
Period PWMx_SaP2_out
Sources
Event Q
Pulse
PWMxCLK
=
P2 Buffer
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP1IF
PWMxPIF
P1 Buffer
=
Toggle
PWMx_SaP1_out
Q
PR Buffer
PWMx_clk
Clock Prescale Timer
Period PWMx_SaP2_out
Sources
Event Q
Toggle
PWMxCLK
=
P2 Buffer
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP1IF
PWMxPIF
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP1IF
SaP2IF
Reset by software
Note: MODE = ‘b000, PR = 5, P1 = 4, P2 = 2, PPEN = 1.
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP2IF
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 0 0 0 1
PWMx_ers
SaP1_out
SaP2_out
Note: PR = 5, P1 = 4, P2 = 2.
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 0 0 1 2 3 4 5
PWMx_ers
SaP1_out
SaP2_out
Note: PR = 5, P1 = 4, P2 = 2.
Important: No changes are allowed after the LD bit is set until after the LD bit is cleared by hardware.
Unexpected behavior may result if the LD bit is cleared by software.
31.7 Interrupts
Each PWM instance has a period interrupt and interrupts associated with the mode and parameter settings.
31.9.1 PWMxERS
Name: PWMxERS
Offset: 0x460,0x46F,0x47E,0x48D
PWMx External Reset Source
Bit 7 6 5 4 3 2 1 0
ERS[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
31.9.2 PWMxCLK
Name: PWMxCLK
Offset: 0x461,0x470,0x47F,0x48E
PWMx Clock Source
Bit 7 6 5 4 3 2 1 0
CLK[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
31.9.3 PWMxLDS
Name: PWMxLDS
Offset: 0x462,0x471,0x480,0x48F
PWMx Auto-load Trigger Source Select Register
Bit 7 6 5 4 3 2 1 0
LDS[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
31.9.4 PWMxPR
Name: PWMxPR
Offset: 0x463,0x472,0x481,0x490
PWMx Period Register
Determines the PWMx period
Bit 15 14 13 12 11 10 9 8
PR[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
PR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• PWMxPRH: Accesses the high byte PR[15:8]
• PWMxPRL: Accesses the low byte PR[7:0]
31.9.5 PWMxCPRE
Name: PWMxCPRE
Offset: 0x465,0x474,0x483,0x492
PWMx Clock Prescaler Register
Bit 7 6 5 4 3 2 1 0
CPRE[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
31.9.6 PWMxPIPOS
Name: PWMxPIPOS
Offset: 0x466,0x475,0x484,0x493
PWMx Period Interrupt Postscaler Register
Bit 7 6 5 4 3 2 1 0
PIPOS[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
31.9.7 PWMxGIR
Name: PWMxGIR
Offset: 0x467,0x476,0x485,0x494
PWMx Interrupt Register
Bit 7 6 5 4 3 2 1 0
S1P2 S1P1
Access R/W/HS R/W/HS
Reset 0 0
31.9.8 PWMxGIE
Name: PWMxGIE
Offset: 0x468,0x477,0x486,0x495
PWMx Interrupt Enable Register
Bit 7 6 5 4 3 2 1 0
S1P2 S1P1
Access R/W R/W
Reset 0 0
31.9.9 PWMxCON
Name: PWMxCON
Offset: 0x469,0x478,0x487,0x496
PWM Control Register
Bit 7 6 5 4 3 2 1 0
EN LD ERSPOL ERSNOW
Access R/W R/W/HC R/W R/W
Reset 0 0 0 0
31.9.10 PWMxSaCFG
Name: PWMxSaCFG
PWM Slice “a” Configuration Register(1)
Bit 7 6 5 4 3 2 1 0
POL2 POL1 PPEN MODE[2:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bits 2:0 – MODE[2:0] PWM Module Slice “a” Operating Mode Select
Selects operating mode for both PWMx_SaP1_out and PWMx_SaP2_out
Value Description
11x Reserved. Outputs go to Reset state.
101 Compare mode: Toggle PWMx_SaP1_out and PWMx_SaP2_out on PWM timer match with
corresponding parameter register
100 Compare mode: Set PWMx_SaP1_out and PWMx_SaP2_out high on PWM timer match with
corresponding parameter register
011 Variable Aligned mode
010 Center-Aligned mode
001 Right Aligned mode
000 Left Aligned mode
Note:
1. Changes to this register must be done only when the EN bit is cleared.
31.9.11 PWMxSaP1
Name: PWMxSaP1
PWM Slice “a” Parameter 1 Register
Determines the active period of slice “a”, parameter 1 output
Bit 15 14 13 12 11 10 9 8
P1[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
P1[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• PWMxSaP1H: Accesses the high byte P1[15:8]
• PWMxSaP1L: Accesses the low byte P1[7:0]
31.9.12 PWMxSaP2
Name: PWMxSaP2
PWM Slice “a” Parameter 2 Register
Determines the active period of slice “a”, parameter 2 output
Bit 15 14 13 12 11 10 9 8
P2[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
P2[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• PWMxSaP2H: Accesses the high byte P2[15:8]
• PWMxSaP2L: Accesses the low byte P2[7:0]
31.9.13 PWMLOAD
Name: PWMLOAD
Offset: 0x49C
Mirror copies of all PWMxLD bits
Bit 7 6 5 4 3 2 1 0
MPWM4LD MPWM3LD MPWM2LD MPWM1LD
Access R/W R/W R/W R/W
Reset 0 0 0 0
31.9.14 PWMEN
Name: PWMEN
Offset: 0x49D
Mirror copies of all PWMxEN bits
Bit 7 6 5 4 3 2 1 0
MPWM4EN MPWM3EN MPWM2EN MPWM1EN
Access R/W R/W R/W R/W
Reset 0 0 0 0
0x00
... Reserved
0x045F
0x0460 PWM1ERS 7:0 ERS[4:0]
0x0461 PWM1CLK 7:0 CLK[4:0]
0x0462 PWM1LDS 7:0 LDS[4:0]
7:0 PR[7:0]
0x0463 PWM1PR
15:8 PR[15:8]
0x0465 PWM1CPRE 7:0 CPRE[7:0]
0x0466 PWM1PIPOS 7:0 PIPOS[7:0]
0x0467 PWM1GIR 7:0 S1P2 S1P1
0x0468 PWM1GIE 7:0 S1P2 S1P1
0x0469 PWM1CON 7:0 EN LD ERSPOL ERSNOW
0x046A PWM1S1CFG 7:0 POL2 POL1 PPEN MODE[2:0]
7:0 P1[7:0]
0x046B PWM1S1P1
15:8 P1[15:8]
7:0 P2[7:0]
0x046D PWM1S1P2
15:8 P2[15:8]
0x046F PWM2ERS 7:0 ERS[4:0]
0x0470 PWM2CLK 7:0 CLK[4:0]
0x0471 PWM2LDS 7:0 LDS[4:0]
7:0 PR[7:0]
0x0472 PWM2PR
15:8 PR[15:8]
0x0474 PWM2CPRE 7:0 CPRE[7:0]
0x0475 PWM2PIPOS 7:0 PIPOS[7:0]
0x0476 PWM2GIR 7:0 S1P2 S1P1
0x0477 PWM2GIE 7:0 S1P2 S1P1
0x0478 PWM2CON 7:0 EN LD ERSPOL ERSNOW
0x0479 PWM2S1CFG 7:0 POL2 POL1 PPEN MODE[2:0]
7:0 P1[7:0]
0x047A PWM2S1P1
15:8 P1[15:8]
7:0 P2[7:0]
0x047C PWM2S1P2
15:8 P2[15:8]
0x047E PWM3ERS 7:0 ERS[4:0]
0x047F PWM3CLK 7:0 CLK[4:0]
0x0480 PWM3LDS 7:0 LDS[4:0]
7:0 PR[7:0]
0x0481 PWM3PR
15:8 PR[15:8]
0x0483 PWM3CPRE 7:0 CPRE[7:0]
0x0484 PWM3PIPOS 7:0 PIPOS[7:0]
0x0485 PWM3GIR 7:0 S1P2 S1P1
0x0486 PWM3GIE 7:0 S1P2 S1P1
0x0487 PWM3CON 7:0 EN LD ERSPOL ERSNOW
0x0488 PWM3S1CFG 7:0 POL2 POL1 PPEN MODE[2:0]
7:0 P1[7:0]
0x0489 PWM3S1P1
15:8 P1[15:8]
7:0 P2[7:0]
0x048B PWM3S1P2
15:8 P2[15:8]
0x048D PWM4ERS 7:0 ERS[4:0]
0x048E PWM4CLK 7:0 CLK[4:0]
0x048F PWM4LDS 7:0 LDS[4:0]
7:0 PR[7:0]
0x0490 PWM4PR
15:8 PR[15:8]
0x0492 PWM4CPRE 7:0 CPRE[7:0]
0x0493 PWM4PIPOS 7:0 PIPOS[7:0]
0x0494 PWM4GIR 7:0 S1P2 S1P1
...........continued
Important: Except as noted for Full Bridge mode, mode changes must only be performed while EN = 0.
CWGx_clock
CWGxA
CWGxC
Rising event dead band Rising event dead band
Falling event dead band Falling event dead band
CWGxB
CWGxD
CWGx_data
Figure 32-2. Simplified CWG Block Diagram (Half Bridge Mode, MODE = ‘b100)
LSAC Re v. 10 -00 02 09 D
1/29 /20 19
1
11
0
10
High-Z
01
LSBD
E LSAC
EN 1 11
0 10
High-Z 01
00
1
0 CWGxC
POLC
Auto-shutdown source S Q
(CWGxAS1 register) LSBD
R
REN 1 11
SHUTDO WN = 0 0 10
High-Z 01
00
1
0 CWG1D
POLD
SHUTDO WN
FREEZE
D Q
CWG Data
CWGx clock
CWGxA
CWGxB
Figure 32-4. Simplified CWG Block Diagram (Push-Pull Mode, MODE = ‘b101)
LSAC Re v. 10 -00 02 10 D
1/29 /20 19
1 11
0 10
High-Z 01
00
1
CWG Data CWG Data A
0 CWGxA
POLA
LSBD
D Q
Q
1 11
0 10
High-Z 01
CWG Data B 00
1
CWG Data Input CWG 0 CWGxB
POLB
Data
D Q
LSAC
E
1 11
EN 0 10
High-Z 01
00
1
0 CWGxC
POLC
Auto-shutdown source S Q
(CWGxAS1 register)
R LSBD
REN
1 11
SHUTDO WN = 0
0 10
High-Z 01
00
1
0 CWGxD
POLD
SHUTDO WN
FREEZE
D Q
CWG Data
FET QA QC
FET
Driver Driver
CWG1A
CWG1B LOAD
CWG1D QB QD
Figure 32-6. Simplified CWG Block Diagram (Forward and Reverse Full Bridge Modes)
LSAC
MODE = ‘b011: Reverse
1 11
Rising Dead-Band Block 0 10
CWG Clock clock
signal out High-Z 01
signal in 00
CWG 1
CWG Data A
Data
0 CWGA
POLA
MODE[0] D Q
CWG Q LSBD
Data
cwg data 1 11
signal in 0 10
signal out
CWG Clock clock High-Z 01
Falling Dead-Band Block 00
1
CWG Data Input CWG Data B
CWG Data
0 CWGxB
POLB
D Q
E LSAC
1 11
EN
0 10
High-Z 01
00
CWG Data C
1
0 CWGxC
POLC
Auto-shutdown source S Q
(CWGxAS1 register)
R LSBD
REN
1 11
SHUTDO WN = 0
0 10
High-Z 01
00
CWG Data D
1
0 CWGxD
POLD
SHUTDO WN
FREEZE
D Q
CWG Data
In Forward Full Bridge mode (MODE = ‘b010), CWGxA is driven to its Active state, CWGxB and CWGxC are driven
to their Inactive state, and CWGxD is modulated by the input signal, as shown in Figure 32-7.
In Reverse Full Bridge mode (MODE = ‘b011), CWGxC is driven to its Active state, CWGxA and CWGxD are driven
to their Inactive states, and CWGxB is modulated by the input signal, as shown in Figure 32-7.
In Full Bridge mode, the dead-band period is used when there is a switch from forward to reverse or vice versa.
This dead-band control is described in the Dead-Band Control section, with additional details in the Rising Edge and
Reverse Dead Band and Falling Edge and Forward Dead Band sections. Steering modes are not used with either of
the Full Bridge modes.
Figure 32-7. Example of Full-Bridge Output
Rev. 30-000099A
Forward
4/14/2017
Mode
Period
CWGxA (2)
CWGxB (2)
CWGxC (2)
Pulse Width
CWGxD (2)
(1) (1)
Reverse
Mode
Period
CWGxA (2)
Pulse Width
CWGxB (2)
CWGxC (2)
CWGxD (2)
(1) (1)
Notes:
1. A rising CWG data input creates a rising event on the modulated output.
2. Output signals shown as active-high; all POLy bits are clear.
Figure 32-8. Example of PWM Direction Change at Near 100% Duty Cycle
Rev. 30-000100A
4/14/2017
t1
Forward Period Reverse Period
CWGxA
CWGxC
CWGxD
Pulse Width
TON
External Switch C
TOFF
External Switch D
CWG Data A 1
1
POLA 0 CWGxA
0
OVRA
STRA LSBD
1 11
0 10
CWG
CWG Data Data High-Z 01
Input
00
D Q CWG Data B
1
E 1
POLB 0 CWGxB
0
OVRB
EN STRB LSAC
1 11
0 10
High-Z 01
00
CWG Data C 1
Auto-shutdown source
S Q 1
(CWGxAS1 register) POLC 0 CWGxC
R 0
OVRC
1 11
0 10
High-Z 01
00
CWG Data D 1
1
POLD 0 CWGxD
0
OVRD
SHUTDO WN
STRD
FREEZE
D Q
CWG Data
Important: Only the STRx bits are synchronized; the OVRx bits are not synchronized.
CWGx clock
CWG Data
CWGxA
CWGxB
CWG Data
STRA
CWGxA
cwg_clock
CWG Data
CWGxA
CWGxB
Dead band is always initiated on the edge of the input source signal. A count of zero indicates that no dead band is
present.
If the input source signal reverses polarity before the dead-band count is completed, then no signal will be seen on
the respective output.
The CWGxDBR register value is double-buffered. When EN = 0, the buffer is loaded when CWGxDBR is written.
When EN = 1, the buffer will be loaded at the rising edge following the first falling edge of the CWG Data, after the LD
bit is set.
cwg_clock
CWG Data
CWGxA
CWGxB
The CWGxDBF register value is double-buffered. When EN = 0, the buffer is loaded when CWGxDBF is written.
When EN = 1, the buffer will be loaded at the rising edge following the first falling edge of the data input after the LD
bit is set.
1
TDEAD − BAND_MAX = • DBx + 1
FCWG_CLOCK
1
T JITTER =
FCWG_CLOCK
32.10 Auto-Shutdown
Auto-shutdown is a method to immediately override the CWG output levels with specific overrides that allow for safe
shutdown of the circuit. The Shutdown state can be either cleared automatically or held until cleared by software. The
auto-shutdown circuit is illustrated in the following figure.
Figure 32-14. CWG Shutdown Block Diagram
Write 1 to Re v. 10 -00 01 72 F
2/8/20 19
SHUTDOWN bit
Auto-shutdown source
(CWGxAS1 register)
SHUTDOWN S
S Q
D Q CWG_shutdown
REN FREEZE
R
Write 0 to
SHUTDOWN bit
CWG_data CK
32.10.1 Shutdown
The Shutdown state can be entered by either of the following two methods:
• Software Generated
• External Input
Important: Shutdown inputs are level sensitive, not edge sensitive. The Shutdown state cannot be
cleared, except by disabling auto-shutdown, as long as the shutdown input level persists.
Important: The SHUTDOWN bit cannot be cleared in software if the Auto-Shutdown condition is still
present.
Figure 32-15. Shutdown Functionality, Auto-Restart Disabled (REN = 0, LSAC = ‘b01, LSBD = ‘b01)
Rev. 30-000105A
4/14/2017
CWG Input
Shutdown Source
SHUTDOWN
CWGxA
CWGxC Tri-State (No Pulse)
32.11.2 Auto-Restart
When the REN bit is set (REN = 1), the CWG module will restart from the Shutdown state automatically.
Once all Auto-Shutdown conditions are removed, the hardware will automatically clear the SHUTDOWN bit. Once
SHUTDOWN is cleared, the CWG module will resume operation upon the first rising edge of the CWG data input.
Important: The SHUTDOWN bit cannot be cleared in software if the Auto-Shutdown condition is still
present.
Figure 32-16. Shutdown Functionality, Auto-Restart Enabled (REN = 1, LSAC = ‘b01, LSBD = ‘b01)
Rev. 30-000106A
4/14/2017
CWG Input
Shutdown Source
SHUTDOWN
32.14.1 CWGxCON0
Name: CWGxCON0
Offset: 0x3C0,0x3C9,0x3D2
Bit 7 6 5 4 3 2 1 0
EN LD MODE[2:0]
Access R/W R/W/HC R/W R/W R/W
Reset 0 0 0 0 0
Note:
1. This bit can only be set after EN = 1; it cannot be set in the same cycle when EN is set.
32.14.2 CWGxCON1
Name: CWGxCON1
Offset: 0x3C1,0x3CA,0x3D3
Bit 7 6 5 4 3 2 1 0
IN POLD POLC POLB POLA
Access R R/W R/W R/W R/W
Reset x 0 0 0 0
32.14.3 CWGxCLK
Name: CWGxCLK
Offset: 0x3BC,0x3C5,0x3CE
Bit 7 6 5 4 3 2 1 0
CS
Access R/W
Reset 0
32.14.4 CWGxISM
Name: CWGxISM
Offset: 0x3BD,0x3C6,0x3CF
Bit 7 6 5 4 3 2 1 0
ISM[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
32.14.5 CWGxSTR
Name: CWGxSTR
Offset: 0x3C4,0x3CD,0x3D6
Bit 7 6 5 4 3 2 1 0
OVRD OVRC OVRB OVRA STRD STRC STRB STRA
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. The bits in this register apply only when MODE = ‘b00x (CWGxCON0, Steering modes).
2. This bit is double-buffered when MODE = ‘b001.
32.14.6 CWGxAS0
Name: CWGxAS0
Offset: 0x3C2,0x3CB,0x3D4
Bit 7 6 5 4 3 2 1 0
SHUTDOWN REN LSBD[1:0] LSAC[1:0]
Access R/W/HS/HC R/W R/W R/W R/W R/W
Reset 0 0 0 1 0 1
Notes:
1. This bit may be written while EN = 0, to place the outputs into the shutdown configuration.
2. The outputs will remain in Auto-Shutdown state until the next rising edge of the CWG data input after this bit is
cleared.
32.14.7 CWGxAS1
Name: CWGxAS1
Offset: 0x3C3,0x3CC,0x3D5
Bit 7 6 5 4 3 2 1 0
AS7E AS6E AS5E AS4E AS3E AS2E AS1E AS0E
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. This bit may be written while EN = 0, to place the outputs into the shutdown configuration.
2. The outputs will remain in Auto-Shutdown state until the next rising edge of the CWG data input after this bit is
cleared.
32.14.8 CWGxDBR
Name: CWGxDBR
Offset: 0x3BE,0x3C7,0x3D0
Bit 7 6 5 4 3 2 1 0
DBR[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset x x x x x x
32.14.9 CWGxDBF
Name: CWGxDBF
Offset: 0x3BF,0x3C8,0x3D1
Bit 7 6 5 4 3 2 1 0
DBF[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset x x x x x x
0x00
... Reserved
0x03BB
0x03BC CWG1CLK 7:0 CS
0x03BD CWG1ISM 7:0 ISM[4:0]
0x03BE CWG1DBR 7:0 DBR[5:0]
0x03BF CWG1DBF 7:0 DBF[5:0]
0x03C0 CWG1CON0 7:0 EN LD MODE[2:0]
0x03C1 CWG1CON1 7:0 IN POLD POLC POLB POLA
0x03C2 CWG1AS0 7:0 SHUTDOWN REN LSBD[1:0] LSAC[1:0]
0x03C3 CWG1AS1 7:0 AS7E AS6E AS5E AS4E AS3E AS2E AS1E AS0E
0x03C4 CWG1STR 7:0 OVRD OVRC OVRB OVRA STRD STRC STRB STRA
0x03C5 CWG2CLK 7:0 CS
0x03C6 CWG2ISM 7:0 ISM[4:0]
0x03C7 CWG2DBR 7:0 DBR[5:0]
0x03C8 CWG2DBF 7:0 DBF[5:0]
0x03C9 CWG2CON0 7:0 EN LD MODE[2:0]
0x03CA CWG2CON1 7:0 IN POLD POLC POLB POLA
0x03CB CWG2AS0 7:0 SHUTDOWN REN LSBD[1:0] LSAC[1:0]
0x03CC CWG2AS1 7:0 AS7E AS6E AS5E AS4E AS3E AS2E AS1E AS0E
0x03CD CWG2STR 7:0 OVRD OVRC OVRB OVRA STRD STRC STRB STRA
0x03CE CWG3CLK 7:0 CS
0x03CF CWG3ISM 7:0 ISM[4:0]
0x03D0 CWG3DBR 7:0 DBR[5:0]
0x03D1 CWG3DBF 7:0 DBF[5:0]
0x03D2 CWG3CON0 7:0 EN LD MODE[2:0]
0x03D3 CWG3CON1 7:0 IN POLD POLC POLB POLA
0x03D4 CWG3AS0 7:0 SHUTDOWN REN LSBD[1:0] LSAC[1:0]
0x03D5 CWG3AS1 7:0 AS7E AS6E AS5E AS4E AS3E AS2E AS1E AS0E
0x03D6 CWG3STR 7:0 OVRD OVRC OVRB OVRA STRD STRC STRB STRA
NCOxINC
20
(1)
INCxBUF
20 20
NCO_overflow Adder
NCOx Cloc k 20
Sources
NCOx_clk
NCOxACC
See
NCOxCLK 20
Register
NCO_interrupt Set NCOxIF
Fixed Duty
Cycle Mode
Circuitry
TRIS control
CKS D Q D Q 0
NCOx_out
PPS
_ 1
Q NCOxOUT
RxyPPS
PFM POL
To Peripherals
EN S Q
OUT bit in
_ Synchronizer NCOxCO N
Ripple Register
R Q
Counter
Pulse
R Frequency
Mode Circuitry
PWS
Note 1: The increment registers are double-buffered to allow for value changes to be made without first disabling
the NCO module. The full increment value is loaded into the buffer registers on the second rising edge of the
NCOx_clk signal that occurs immediately after a write to the NCOxINCL register. The buffers are not user-
accessible and are shown here for reference.
33.1.2 Accumulator
The accumulator is a 20-bit register. Read and write access to the accumulator is available through three registers:
• NCOxACCL
• NCOxACCH
• NCOxACCU
33.1.3 Adder
The NCO adder is a full adder, which operates synchronously from the source clock. The addition of the previous
result and the increment value replaces the accumulator value on the rising edge of each input clock.
NCOx
Clock
Source
NCOx
Increment 4000h 4000h 4000h
Value
NCOx
Accumulator 00000h 04000h 08000h FC000h 00000h 04000h 08000h FC000h 00000h 04000h 08000h
Value
NCO_overflow
NCO_interrupt
NCOx Output
FDC Mode
NCOx Output
PF Mode
NCOxPWS =
000
NCOx Output
PF Mode
NCOxPWS =
001
Important: When the selected pulse width is greater than the accumulator overflow time frame, then the
NCO output does not toggle.
The level of the Active and Inactive states is determined by the POL bit.
PF mode is selected by setting the PFM bit.
33.5 Interrupts
When the accumulator overflows, the NCO Interrupt Flag bit, NCOxIF, in the associated PIR register is set. To enable
interrupt service on this event, the following bits must be set:
• EN bit
• NCOxIE bit in the associated PIE register
• Peripheral and Global Interrupt Enable bits
The interrupt must be cleared by software by clearing the NCOxIF bit in the Interrupt Service Routine.
33.8.1 NCOxCON
Name: NCOxCON
Offset: 0x446,0x44E,0x456
NCO Control Register
Bit 7 6 5 4 3 2 1 0
EN OUT POL PFM
Access R/W R R/W R/W
Reset 0 0 0 0
33.8.2 NCOxCLK
Name: NCOxCLK
Offset: 0x447,0x44F,0x457
NCO Input Clock Control Register
Bit 7 6 5 4 3 2 1 0
PWS[2:0] CKS[4:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
...........continued
CKS Clock Source
Active in Sleep
Value NCO1 NCO2 NC03
00000 FOSC No
Note:
1. PWS applies only when operating in Pulse Frequency mode.
33.8.3 NCOxACC
Name: NCOxACC
Offset: 0x440,0x448,0x450
Bit 23 22 21 20 19 18 17 16
ACC[19:16]
Access R/W R/W R/W R/W
Reset 0 0 0 0
Bit 15 14 13 12 11 10 9 8
ACC[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
ACC[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– NCOxACCU: Accesses the upper byte ACC[23:16]
– NCOxACCH: Accesses the high byte ACC[15:8]
– NCOxACCL: Accesses the low byte ACC[7:0].
2. The accumulator spans registers NCOxACCU:NCOxACCH:NCOxACCL. The 24 bits are reserved, but not
all are used. This register updates in real-time, asynchronously to the CPU; there is no provision to ensure
atomic access to this 24-bit space using an 8-bit bus. Writing to this register while the module is operating will
produce undefined results.
33.8.4 NCOxINC
Name: NCOxINC
Offset: 0x443,0x44B,0x453
Bit 23 22 21 20 19 18 17 16
INC[19:16]
Access R/W R/W R/W R/W
Reset 0 0 0 0
Bit 15 14 13 12 11 10 9 8
INC[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
INC[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 1
Bits 19:0 – INC[19:0] Value by which the NCOxACC is increased by each NCO clock
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– NCOxINCU: Accesses the upper byte INC[19:16]
– NCOxINCH: Accesses the high byte INC[15:8]
– NCOxINCL: Accesses the low byte INC[7:0].
2. The logical increment spans NCOxINCU:NCOxINCH:NCOxINCL.
3. NCOxINC is double-buffered as INCBUF:
– INCBUF is updated on the next falling edge of NCOxCLK after writing to NCOxINCL
– NCOxINCU and NCOxINCH will be written prior to writing NCOxINCL.
0x00
... Reserved
0x043F
7:0 ACC[7:0]
0x0440 NCO1ACC 15:8 ACC[15:8]
23:16 ACC[19:16]
7:0 INC[7:0]
0x0443 NCO1INC 15:8 INC[15:8]
23:16 INC[19:16]
0x0446 NCO1CON 7:0 EN OUT POL PFM
0x0447 NCO1CLK 7:0 PWS[2:0] CKS[4:0]
7:0 ACC[7:0]
0x0448 NCO2ACC 15:8 ACC[15:8]
23:16 ACC[19:16]
7:0 INC[7:0]
0x044B NCO2INC 15:8 INC[15:8]
23:16 INC[19:16]
0x044E NCO2CON 7:0 EN OUT POL PFM
0x044F NCO2CLK 7:0 PWS[2:0] CKS[4:0]
7:0 ACC[7:0]
0x0450 NCO3ACC 15:8 ACC[15:8]
23:16 ACC[19:16]
7:0 INC[7:0]
0x0453 NCO3INC 15:8 INC[15:8]
23:16 INC[19:16]
0x0456 NCO3CON 7:0 EN OUT POL PFM
0x0457 NCO3CLK 7:0 PWS[2:0] CKS[4:0]
CH
See
CARH
MDxCARH
Register
CHPOL D
SYNC
Q
1
MS
0
CHSYNC
RxyPPS
See MOD
MDxSRC DSM_out
PPS
Register
OPOL
CL
D
SYNC
Q
1
0
See
CARL
MDxCARL
Register CLSYNC
CLPOL
carrier_low
carrier_high
Modula tor
DSM_out
CHSYNC = 1
CLSYNC = 0
DSM_out
CHSYNC = 1
CLSYNC = 1
DSM_out
CHSYNC = 0
CLSYNC = 0
DSM_out
CHSYNC = 0
CLSYNC = 1
carrier_high
carrier_low
Modula tor
DSM_out
carrier_high
carrier_low
Modula tor
DSM_out
Acti ve Carrier
carrier_high both carrier_low carrier_high both carrier_low
State
carrier_high
carrier_low
Modula tor
DSM_out
carrier_high
carrier_low
Acti ve Carrier
carrier_high carrier_low carrier_high CL
State
34.9.1 MDxCON0
Name: MDxCON0
Offset: 0x6A
Bit 7 6 5 4 3 2 1 0
EN OUT OPOL BIT
Access R/W R/W R/W R/W
Reset 0 0 0 0
Notes:
1. The modulated output frequency can be greater and asynchronous from the clock that updates this register bit.
The bit value may not be valid for higher speed modulator or carrier signals.
2. MDBIT must be selected as the modulation source in the MDxSRC register for this operation.
34.9.2 MDxCON1
Name: MDxCON1
Offset: 0x6B
Bit 7 6 5 4 3 2 1 0
CHPOL CHSYNC CLPOL CLSYNC
Access R/W R/W R/W R/W
Reset 0 0 0 0
Note:
1. Narrowed carrier pulse widths or spurs may occur in the signal stream if the carrier is not synchronized.
34.9.3 MDxCARH
Name: MDxCARH
Offset: 0x6E
Bit 7 6 5 4 3 2 1 0
CH[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
CH Connection
11111-10111 Reserved
10110 CLC8_OUT
10101 CLC7_OUT
10100 CLC6_OUT
10011 CLC5_OUT
10010 CLC4_OUT
10001 CLC3_OUT
10000 CLC2_OUT
01111 CLC1_OUT
01110 NCO3_OUT
01101 NCO2_OUT
01100 NCO1_OUT
01011 PWM4S1P1_OUT
01010 PWM3S1P1_OUT
01001 PWM2S1P1_OUT
01000 PWM1S1P1_OUT
00111 CCP3_OUT
00110 CCP2_OUT
00101 CCP1_OUT
00100 CLKREF_OUT
00011 EXTOSC
00010 HFINTOSC
00001 FOSC (System Clock)
00000 Pin selected by MDCARHPPS
34.9.4 MDxCARL
Name: MDxCARL
Offset: 0x6D
Bit 7 6 5 4 3 2 1 0
CL[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
CL Connection
11111-10111 Reserved
10110 CLC8_OUT
10101 CLC7_OUT
10100 CLC6_OUT
10011 CLC5_OUT
10010 CLC4_OUT
10001 CLC3_OUT
10000 CLC2_OUT
01111 CLC1_OUT
01110 NCO3_OUT
01101 NCO2_OUT
01100 NCO1_OUT
01011 PWM4S1P2_OUT
01010 PWM3S1P2_OUT
01001 PWM2S1P2_OUT
01000 PWM1S1P2_OUT
00111 CCP3_OUT
00110 CCP2_OUT
00101 CCP1_OUT
00100 CLKREF_OUT
00011 EXTOSC
00010 HFINTOSC
00001 FOSC (System Clock)
00000 Pin selected by MDCARLPPS
34.9.5 MDxSRC
Name: MDxSRC
Offset: 0x6C
Bit 7 6 5 4 3 2 1 0
MS[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
MS Connection
111111-100000 Reserved
100000 SPI2_SDO
011111 SPI1_SDO
011110 UART5_TX
011101 UART4_TX
011100 UART3_TX
011011 UART2_TX
011010 UART1_TX
011001 CLC8_OUT
011000 CLC7_OUT
010111 CLC6_OUT
010110 CLC5_OUT
010101 CLC4_OUT
010100 CLC3_OUT
010011 CLC2_OUT
010010 CLC1_OUT
010001 CMP2_OUT
010000 CMP1_OUT
001111 NCO3_OUT
001110 NCO2_OUT
001101 NCO1_OUT
001100 PWM4S1P2_OUT
001011 PWM4S1P1_OUT
001010 PWM3S1P2_OUT
001001 PWM3S1P1_OUT
001000 PWM2S1P2_OUT
000111 PWM2S1P1_OUT
000110 PWM1S1P2_OUT
000101 PWM1S1P1_OUT
000100 CCP3_OUT
000011 CCP2_OUT
000010 CCP1_OUT
000001 MDBIT
000000 Pin selected by MDSRCPPS
0x00
... Reserved
0x69
0x6A MD1CON0 7:0 EN OUT OPOL BIT
0x6B MD1CON1 7:0 CHPOL CHSYNC CLPOL CLSYNC
0x6C MD1SRC 7:0 MS[5:0]
0x6D MD1CARL 7:0 CL[4:0]
0x6E MD1CARH 7:0 CH[4:0]
8
UxTXIE
FIFO Interrupt
(if equipped) UxTXB register UxTXIF
8
+ UxTXCHK RxyPPS
TXEN
MSb LSb TX pin
Mode
(8) 0 PPS
Control
Transmit Shift Register (TSR)
TX_out
+1 Multiplier x4 x16
BRGS 1 0
UxBRGH UxBRGL
RXFOIF RXIDL
RXEN
RXPPS
MSb RSR Register LSb
RX pin
Pin Buffer Mode Data
PPS Stop (8) 7 1 0 Start
and Control Recovery
UxRXIF Interrupt
UxRXIE
Important: The UxTXIF Transmitter Interrupt flag is set when the TXEN Enable bit is set and the UxTXB
register can accept data.
Important: The TSR is not mapped in data memory, so it is not available to the user.
Rev. 10-000115B
Word 1
9/1/2017
Write to UxTXB
BRG Output
(Shift Clock)
Rev. 10-000116B
Write to UxTXB
BRG Output
(Shift Clock)
TX pin Start bit bit 0 bit 1 bit 7/8 Stop bit Start bit bit 0
Setting the RXEN bit enables the receiver circuitry of the UART. Setting the MODE bits configures the UART for the
desired Asynchronous mode. Setting the ON bit enables the UART. The TRIS bit corresponding to the selected RX
I/O pin must be set to configure the pin as an input.
Important: If the RX function is on an analog pin, the corresponding ANSEL bit must be cleared for the
receiver to function.
The UxRXIF Interrupt Flag bit will be set when it is not suppressed and there is an unread character in the FIFO,
regardless of the state of interrupt enable bits. Reading the UxRXB register will transfer the top character out of the
FIFO and reduce the FIFO contents by one. The UxRXIF Interrupt Flag bit is read-only and therefore cannot be set or
cleared by software.
Important: When PERIE is set, the UxRXIF interrupts are suppressed by PERIF = 1.
RXIDL
Read UxRXB
UxRXIF
(Interrupt flag)
RXFOIF Flag
Cleared by software
Note: This timing diagram shows three bytes appearing on the RX input. The UxRXB is not read before the third
word is received, causing the RXFOIF (FIFO overrun) bit to be set. STPMD = 0, STP = 00.
The controller transmits commands and the receiver receives them. There are no Error conditions or retransmit
mechanisms.
DMX, or DMX512A, consists of a “universe” of 512 channels. This means that one controller can output up to 512
bytes on a single DMX link. Each piece of equipment on the line is programmed to listen to a consecutive sequence
of one or more of these bytes.
For example, a fog machine connected to one of the universes may be programmed to receive one byte, starting at
byte number 10, and a lighting unit may be programmed to receive four bytes starting at byte number 22.
Rev. 10-000329A
Start Start 9/5/2017
Software sends the Start Code and the ‘n’ data bytes by writing the UxTXB register with each byte to be sent in the
desired order. A UxTXIF value of ‘1’ indicates when the UxTXB is ready to accept the next byte.
The internal byte counter is not accessible to software. Software needs to keep track of the number of bytes written to
UxTXB to ensure that no more and no less than ‘n’ bytes are sent because the DMX state machine will automatically
insert a Break and reset its internal counter after ‘n’ bytes are written. One way to ensure synchronization between
hardware and software is to toggle TXEN after the last byte of the universe is completely free of the transmit shift
register, as indicated by the TXMTIF bit.
• TXEN = 0
• RXEN = 1
• RXPOL = 0
• UxP2 = number of first byte to receive
• UxP3 = number of last byte to receive
• UxBRG = value to achieve 250K baud rate
• STP = 10 for two Stop bits
• ON = 1
• UxRXPPS = code for desired input pin
• Input pin ANSEL bit = 0
When configured as a DMX Receiver, the UART listens for a Break character that is at least 23 bit periods wide. If
the Break is shorter than 23 bit times, the Break is ignored and the DMX state machine remains in Idle mode. Upon
receiving the Break, the DMX counters will be reset to align with the incoming data stream. Immediately after the
Break, the UART will see the “Mark after Break” (MAB). This space is ignored by the UART. The Start Code follows
the MAB and will always be stored in the receive FIFO.
After the Start Code, the first through the 512th byte will be received, but not all of them are stored in the receive
FIFO. The UART ignores all received bytes until the ones of interest are received. This is done using the UxP2 and
UxP3 registers. The UxP2 register holds the value of the byte number to start the receive process. The byte counter
starts at ‘0’ for the first byte after the Start Code. For example, to receive four bytes starting at the 10th byte after the
Start Code, write 009h (9 decimal) to UxP2H:L and 00Ch (12 decimal) to UxP3H:L. The receive FIFO depth is limited,
therefore the bytes must be retrieved by reading UxRXB as they come in to avoid a receive FIFO Overrun condition.
Typically, two Stop bits are inserted between bytes. If either Stop bit is detected as a ‘0’, the framing error for that
byte will be set.
Since the DMX sequence always starts with a Break, the software can verify that it is in sync with the sequence by
monitoring the RXBKIF flag to ensure that the next byte received after the RXBKIF flag is processed as the Start
Code and subsequent bytes are processed as the expected data.
When a client receives data, the checksum is accumulated on each byte as it is received using the same algorithm
as the sending process. The last byte, which is the inverted checksum value calculated by the sending process, is
added to the locally calculated checksum by the UART. The check passes when the result is all ‘1’s, otherwise the
check fails and the CERIF bit is set.
Two methods for computing the checksum are available: legacy and enhanced. The legacy checksum includes
only the data bytes. The enhanced checksum includes the PID and the data. The C0EN control bit determines the
checksum method. Setting C0EN to ‘1’ selects the enhanced method. Software must select the appropriate method
before the Start bit of the checksum byte is received.
Important: The TXEN bit must be set before the Host process is received and remain set while in LIN
mode whether or not the Client process is a transmitter.
The Host process is started by writing the PID to the UxP1L register when UxP2 is ‘0’ and the UART is Idle. The
UxTXIF will not be set in this case. Only the six Least Significant bits of UxP1L are used in the PID transmission.
The two Most Significant bits of the transmitted PID are PID parity bits. PID[6] is the exclusive-or of PID bits 0, 1, 2
and 4. PID[7] is the inverse of the exclusive-or of PID bits 1, 3, 4 and 5.
The UART hardware calculates and inserts these bits in the serial stream.
Writing UxP1L automatically clears the UxTXCHK and UxRXCHK registers and generates the Break, the delimiter bit,
the Sync character (55h), and the PID transmission portion of the transaction. The data portion of the transaction that
follows, if there is one, is a Client process. See the LIN Client Mode section for more details of that process. The
host receives its own PID if RXEN is set. Software performs the Client process corresponding to the PID that was
sent and received. Attempting to write UxP1L before an active Host process is complete will not succeed. Instead,
the TXWRE bit will be set.
The protocol is inherently half-duplex. Communication over the bus occurs in the form of forward and backward
frames. Wait times between the frames are defined in the standard to prevent collision between the frames.
A Control Device transmission is termed as the forward frame. In the DALI 2.0 standard, a forward frame can be two
or three bytes in length. The two-byte forward frame is used for communication between Control Device and Control
Gear whereas the three-byte forward frame is used for communication between Control Devices on the bus. The first
byte in the forward frame is the control byte and is followed by either one or two data bytes. The transaction begins
when the Control Device starts a transmission. Unlike other protocols, each byte in the frame is transmitted MSb first.
Typical frame timing is shown below.
Figure 35-7. DALI Frame Timing
Rev. 10-000331A
Control Control 9/5/2017
UxTXIF
(Transmit Buffer
Reg Empty Flag) bit
TXMTIF (Transmit
Shift Reg Empty
Flag) bit
During the communication between two Control Devices, three bytes are required to be transmitted. In this case, the
software must write the third byte to UxTXB as soon as UxTXIF goes true and before the output shifter becomes
empty. This ensures that the three bytes of the forward frame are transmitted back-to-back without any interruption.
All Control Gear on the bus receive the forward frame. If the forward frame requires a reply to be sent, one of the
Control Gear may respond with a single byte, called the backward frame. The 2.0 standard requires the Control Gear
to begin transmission of the backward frame between 5.5 ms to 10.5 ms (~14 to 22 half-bit times) after reception of
the forward frame. Once the backward frame is received by the Control Device, it is required to wait a minimum of 2.4
ms (~6 half-bit times). After this wait time, the Control Device is free to transmit another forward frame. Refer to the
figure below.
Figure 35-8. DALI Forward/Backward Frame Timing
Rev. 10-000332A
9/7/2017
Backward
Gear TX Frame
backward wait period
A Start bit is used to indicate the start of the forward and backward frames. When ABDEN = 0, the receiver bit rate
is determined by the BRG register. When ABDEN = 1, the first bit synchronizes the receiver with the transmitter and
sets the receiver bit rate. The low period of the Start bit is measured and is used as the timing reference for all data
bits in the forward and backward frames. The ABDOVF bit is set if the Start bit low period causes the measurement
counter to overflow. All the bits following the Start bit are data bits. The bit stream terminates when no transition is
detected in the middle of a bit period. Refer to the figure below.
Rev. 10-000330A
9/5/2017
The forward and backward frames are terminated by two Idle bit periods or Stop bits. Normally, these start in the first
bit period of a byte. If both Stop bits are valid, the byte reception is terminated.
If either of the Stop bits is invalid, the frame is tagged as invalid by saving it as a null byte and setting the framing
error in the receive FIFO.
A framing error also occurs when no transition is detected on the bus in the middle of a bit period when the byte
reception is not complete. In such a scenario, the byte will be saved with the FERIF bit set.
To replace or delete any pending forward frame data, the TXBE bit needs to be set to flush the shift register and
transmit buffer. A new control byte can then be written to the UxTXB register. The control byte will be held in the
buffer and sent at the beginning of the next forward frame following the UxP1 wait time.
In Control Device mode, PERIF is set when a forward frame is received. This helps the software to determine
whether the received byte is part of a forward frame from a Control Device (either from the Control Device under
consideration or from another Control Device on the bus) or a backward frame from a Control Gear.
35.7 Polarity
Receive and transmit polarity is user selectable and affects all modes of operation.
The idle level is programmable with the TXPOL and RXPOL polarity control bits. Both control bits default to ‘0’, which
selects a high idle level for transmit and receive. The low level Idle state is selected by setting the control bit to ‘1’.
TXPOL controls the TX idle level. RXPOL controls the RX idle level.
In all modes, except DALI, the transmitter is Idle for the number of Stop bit periods between each consecutively
transmitted word. In DALI, the Stop bits are generated after the last bit in the transmitted data stream.
The input is checked for the idle level in the middle of the first Stop bit, when receive verify on first is selected, as well
as in the middle of the second Stop bit, when verify on both is selected. If any Stop bit verification indicates a nonidle
level, the framing error FERIF bit is set for the received word.
byte is stored in the receive FIFO. When STP = 10, the store operation is performed in the middle of the second Stop
bit, otherwise, it is performed in the middle of the first Stop bit.
The FERIF and PERIF interrupts are not delayed with STPMD. When STPMD is set, the preferred indicator for
reversing transceiver direction is the UxRXIF interrupt because it is delayed whereas the others are not.
The flow control method is selected with the FLO bits. Flow control is disabled when both bits are cleared.
UART 1 UART 2
RX TX
RTS CTS
TX RX
CTS RTS
The UART receiving data asserts the RTS output low when the input FIFO is empty. When a character is received,
the RTS output goes high until the UxRXB is read to free up both FIFO locations.
When the CTS input goes high after a byte has started to transmit, the transmission will complete normally. The
receiver accommodates this by accepting the character in the second FIFO location even when the CTS input is high.
Rev. 10-000334A
9/6/2017
UART
SN75176 Vcc
RX R 4k7
RE A
TXDE
DE B
TX D 4k7
Gnd
CTS(1)
The other method adjusts the value of the Baud Rate Generator. This can be done automatically with the Auto-Baud
Detect feature (see the Auto-Baud Detect section). There may not be fine enough resolution when adjusting the Baud
Rate Generator to compensate for a gradual change of the peripheral clock frequency.
Writing a new value to UxBRG causes the BRG timer to be reset (or cleared). This ensures that the BRG does not
wait for a timer overflow before outputting the new baud rate.
If the system clock is changed during an active receive operation, a receive error or data loss may result. To avoid
this problem, check the status of the RXIDL bit to make sure that the receive operation is Idle before changing the
system clock. The following table contains formulas for determining the baud rate.
Table 35-2. Baud Rate Formulas
The following example provides a sample calculation for determining the baud rate and baud rate error.
UxBRG = 16000000 − 1
16 × 9600
UxBRG = 103.17 ≃ 103
16000000
CalculatedBaudrate =
16 × 103 + 1
CalculatedBaudrate = 9615
Rev. 10-000120B
9/6/2017
RX pin start bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7
BRG Clock
RXIDL
Cleared by
ABDIF software
(Interrupt Flag) bit
RXIDL indicates that the sync input is active. RXIDL will go low on the first falling edge and go high on the fifth rising
edge.
The BRG auto-baud clock is determined by the BRGS bit, as shown in the following table.
Table 35-3. BRG Counter Clock Rates
During ABD, the internal BRG register is used as a 16-bit counter. However, the UxBRG registers retain the previous
BRG value until the auto-baud process is successfully completed. While calibrating the baud rate period, the internal
BRG register is clocked at 1/8th the BRG base clock rate. The resulting byte measurement is the average bit time
when clocked at full speed and is transferred to the UxBRG registers when complete.
Important:
1. When both the WUE and ABDEN bits are set, the auto-baud detection will occur on the byte
following the Break character (see the Auto Wake-on-Break section).
2. It is up to the user to verify the incoming character baud rate is within the range of the selected BRG
clock source. Some combinations of oscillator frequency and UART baud rates are not possible.
q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4
FOSC
RX line
WUIF
Cleared by software
Note 1: The UART remains in Idle while the WUE bit is set.
Rev. 10-000327B
9/6/2017
q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4
FOSC
RX line
WUIF
Cleared by software
Note 1: The UART remains in Idle while the WUE bit is set.
To generate an interrupt on a wake-up event, all the following bits must be set:
• The UxIE bit in the PIEx register
• Global interrupt enables
The WUE bit is automatically cleared by the transition to the Idle state on the RX line at the end of the Break. This
signals to the user that the Break event is over. At this point, the UART module is in Idle mode, waiting to receive the
next character.
SENDB is disabled in the LIN and DMX modes because those modes generate the Break sequence automatically.
The SENDB bit is automatically reset by hardware after the Break Stop bit is complete.
The TXMTIF bit indicates when the transmit operation is Active or Idle, just as it does during normal transmission.
The following figure illustrates the Break sequence.
Figure 35-15. Send-Break Sequence
Write 9/6/2017
Write to UxTXB
BRG Output
(Shift Clock)
Sync
TX pin Start bit bit 0 bit 1 bit 11 Stop bit start
UxTXIF Break
(Transmit Buffer
Reg Empty Flag) bit
TXMTIF (Transmit
Shift Reg Empty
Flag) bit
SENDB
Auto cleared
(send break
control bit)
...........continued
Peripheral Bit Name Prefix
UART3 (limited features) U3
UART4 (limited features) U4
UART5 (limited features) U5
35.20.1 UxCON0
Name: UxCON0
Offset: 0x2AB,0x2BE,0x2D1,0x2E4,0x2F7
Bit 7 6 5 4 3 2 1 0
BRGS ABDEN TXEN RXEN MODE[3:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. Changing the UART MODE while ON = 1 may cause unexpected results.
2. Clearing TXEN or RXEN will not clear the corresponding buffers. Use TXBE or RXBE to clear the buffers.
3. ABDEN is read-only when MODE > ‘b0111.
4. Full-featured UARTs only.
35.20.2 UxCON1
Name: UxCON1
Offset: 0x2AC,0x2BF,0x2D2,0x2E5,0x2F8
Bit 7 6 5 4 3 2 1 0
ON WUE RXBIMD BRKOVR SENDB
Access R/W R/W/HC R/W R/W R/W/HC
Reset 0 0 0 0 0
Note:
1. This bit is read-only in LIN, DMX and DALI modes.
35.20.3 UxCON2
Name: UxCON2
Bit 7 6 5 4 3 2 1 0
RUNOVF RXPOL STP[1:0] C0EN TXPOL FLO[1:0]
Access R/W R/W/HC R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. All modes transmit selected number of Stop bits.
2. Full-featured UARTs only.
35.20.4 UxERRIR
Name: UxERRIR
Bit 7 6 5 4 3 2 1 0
TXMTIF PERIF ABDOVF CERIF FERIF RXBKIF RXFOIF TXCIF
Access R/S/C R/W/HC R/W/S R/W/S R/S/C R/W/S R/W/S R/W/S
Reset 1 0 0 0 0 0 0 0
Value Description
1 Transmitted word is not equal to the word received during transmission
0 Transmitted word equals the word received during transmission
Note:
1. Full-featured UARTs only.
35.20.5 UxERRIE
Name: UxERRIE
Bit 7 6 5 4 3 2 1 0
TXMTIE PERIE ABDOVE CERIE FERIE RXBKIE RXFOIE TXCIE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Note:
1. Full-featured UARTs only.
35.20.6 UxUIR
Name: UxUIR
Offset: 0x2B1,0x2C4,0x2D7,0x2EA,0x2FD
Bit 7 6 5 4 3 2 1 0
WUIF ABDIF ABDIE
Access R/W/S R/W/S R/W
Reset 0 0 0
35.20.7 UxFIFO
Name: UxFIFO
Offset: 0x2B0,0x2C3,0x2D6,0x2E9,0x2FC
Bit 7 6 5 4 3 2 1 0
TXWRE STPMD TXBE TXBF RXIDL XON RXBE RXBF
Access R/W/S R/W R/W/S/C R/S/C R/S/C S/C R/W/S/C R/S/C
Reset 0 0 1 0 1 1 1 0
Value Description
0 Receive buffer is not full
Note:
1. The BSF instruction will not be used to set RXBE because doing so will clear a byte pending in the transmit
shift register when the UxTXB register is empty. Instead, use the MOVWF instruction with a ‘0’ in the TXBE bit
location.
35.20.8 UxBRG
Name: UxBRG
Offset: 0x2AE,0x2C1,0x2D4,0x2E7,0x2FA
Bit 15 14 13 12 11 10 9 8
BRG[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
BRG[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– UxBRGH: Accesses the high byte BRG[15:8]
– UxBRGL: Accesses the low byte BRG[7:0]
2. The UxBRG registers will only be written when ON = 0.
3. Maximum BRG value when MODE = ‘100x and BRGS = 1 is 0x7FFE.
4. Maximum BRG value when MODE = ‘100x and BRGS = 0 is 0x1FFE.
35.20.9 UxRXB
Name: UxRXB
Offset: 0x2A1,0x2B4,0x2C7,0x2DA,0x2ED
Bit 7 6 5 4 3 2 1 0
RXB[7:0]
Access R R R R R R R R
Reset x x x x x x x x
35.20.10 UxTXB
Name: UxTXB
Offset: 0x2A3,0x2B6,0x2C9,0x2DC,0x2EF
Bit 7 6 5 4 3 2 1 0
TXB[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
35.20.11 UxP1
Name: UxP1
UART Parameter 1
Bit 15 14 13 12 11 10 9 8
P1[8]
Access R/W
Reset 0
Bit 7 6 5 4 3 2 1 0
P1[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• UxP1H: Accesses the high byte P1[8]
• UxP1L: Accesses the low byte P1[7:0]
35.20.12 UxP2
Name: UxP2
UART Parameter 2
Bit 15 14 13 12 11 10 9 8
P2[8]
Access R/W
Reset 0
Bit 7 6 5 4 3 2 1 0
P2[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• UxP2H: Accesses the high byte P2[8]
• UxP2L: Accesses the low byte P2[7:0]
35.20.13 UxP3
Name: UxP3
UART Parameter 3
Bit 15 14 13 12 11 10 9 8
P3[8]
Access R/W
Reset 0
Bit 7 6 5 4 3 2 1 0
P3[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• UxP3H: Accesses the high byte P3[8]
• UxP3L: Accesses the low byte P3[7:0]
35.20.14 UxTXCHK
Name: UxTXCHK
Offset: 0x2A4,0x2B7
Bit 7 6 5 4 3 2 1 0
TXCHK[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
35.20.15 UxRXCHK
Name: UxRXCHK
Offset: 0x2A2, 0x2B5
Bit 7 6 5 4 3 2 1 0
RXCHK[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
00 U2ERRIE 7:0 TXMTIE PERIE ABDOVE CERIE FERIE RXBKIE RXFOIE TXCIE
0x01
... Reserved
0x02A0
0x02A1 U1RXB 7:0 RXB[7:0]
0x02A2 U1RXCHK 7:0 RXCHK[7:0]
0x02A3 U1TXB 7:0 TXB[7:0]
0x02A4 U1TXCHK 7:0 TXCHK[7:0]
7:0 P1[7:0]
0x02A5 U1P1
15:8 P1[8]
7:0 P2[7:0]
0x02A7 U1P2
15:8 P2[8]
7:0 P3[7:0]
0x02A9 U1P3
15:8 P3[8]
0x02AB U1CON0 7:0 BRGS ABDEN TXEN RXEN MODE[3:0]
0x02AC U1CON1 7:0 ON WUE RXBIMD BRKOVR SENDB
0x02AD U1CON2 7:0 RUNOVF RXPOL STP[1:0] C0EN TXPOL FLO[1:0]
7:0 BRG[7:0]
0x02AE U1BRG
15:8 BRG[15:8]
0x02B0 U1FIFO 7:0 TXWRE STPMD TXBE TXBF RXIDL XON RXBE RXBF
0x02B1 U1UIR 7:0 WUIF ABDIF ABDIE
0x02B2 U1ERRIR 7:0 TXMTIF PERIF ABDOVF CERIF FERIF RXBKIF RXFOIF TXCIF
0x02B3 U1ERRIE 7:0 TXMTIE PERIE ABDOVE CERIE FERIE RXBKIE RXFOIE TXCIE
0x02B4 U2RXB 7:0 RXB[7:0]
0x02B5 U2RXCHK 7:0 RXCHK[7:0]
0x02B6 U2TXB 7:0 TXB[7:0]
0x02B7 U2TXCHK 7:0 TXCHK[7:0]
7:0 P1[7:0]
0x02B8 U2P1
15:8 P1[8]
7:0 P2[7:0]
0x02BA U2P2
15:8 P2[8]
7:0 P3[7:0]
0x02BC U2P3
15:8 P3[8]
0x02BE U2CON0 7:0 BRGS ABDEN TXEN RXEN MODE[3:0]
0x02BF U2CON1 7:0 ON WUE RXBIMD BRKOVR SENDB
0x02C0 U2CON2 7:0 RUNOVF RXPOL STP[1:0] C0EN TXPOL FLO[1:0]
7:0 BRG[7:0]
0x02C1 U2BRG
15:8 BRG[15:8]
0x02C3 U2FIFO 7:0 TXWRE STPMD TXBE TXBF RXIDL XON RXBE RXBF
0x02C4 U2UIR 7:0 WUIF ABDIF ABDIE
0x02C5 U2ERRIR 7:0 TXMTIF PERIF ABDOVF CERIF FERIF RXBKIF RXFOIF TXCIF
0x02C6 U2ERRIE 7:0 TXMTIE PERIE ABDOVE CERIE FERIE RXBKIE RXFOIE TXCIE
0x02C7 U3RXB 7:0 RXB[7:0]
0x02C8 Reserved
0x02C9 U3TXB 7:0 TXB[7:0]
0x02CA Reserved
7:0 P1[7:0]
0x02CB U3P1
15:8
7:0 P2[7:0]
0x02CD U3P2
15:8
7:0 P3[7:0]
0x02CF U3P3
15:8
0x02D1 U3CON0 7:0 BRGS ABDEN TXEN RXEN MODE[3:0]
0x02D2 U3CON1 7:0 ON WUE RXBIMD BRKOVR SENDB
0x02D3 U3CON2 7:0 RUNOVF RXPOL STP[1:0] TXPOL FLO[1:0]
...........continued
7:0 BRG[7:0]
0x02D4 U3BRG
15:8 BRG[15:8]
0x02D6 U3FIFO 7:0 TXWRE STPMD TXBE TXBF RXIDL XON RXBE RXBF
0x02D7 U3UIR 7:0 WUIF ABDIF ABDIE
0x02D8 U3ERRIR 7:0 TXMTIF PERIF ABDOVF CERIF FERIF RXBKIF RXFOIF
0x02D9 U3ERRIE 7:0 TXMTIE PERIE ABDOVE CERIE FERIE RXBKIE RXFOIE
0x02DA U4RXB 7:0 RXB[7:0]
0x02DB Reserved
0x02DC U4TXB 7:0 TXB[7:0]
0x02DD Reserved
7:0 P1[7:0]
0x02DE U4P1
15:8
7:0 P2[7:0]
0x02E0 U4P2
15:8
7:0 P3[7:0]
0x02E2 U4P3
15:8
0x02E4 U4CON0 7:0 BRGS ABDEN TXEN RXEN MODE[3:0]
0x02E5 U4CON1 7:0 ON WUE RXBIMD BRKOVR SENDB
0x02E6 U4CON2 7:0 RUNOVF RXPOL STP[1:0] TXPOL FLO[1:0]
7:0 BRG[7:0]
0x02E7 U4BRG
15:8 BRG[15:8]
0x02E9 U4FIFO 7:0 TXWRE STPMD TXBE TXBF RXIDL XON RXBE RXBF
0x02EA U4UIR 7:0 WUIF ABDIF ABDIE
0x02EB U4ERRIR 7:0 TXMTIF PERIF ABDOVF CERIF FERIF RXBKIF RXFOIF
0x02EC U4ERRIE 7:0 TXMTIE PERIE ABDOVE CERIE FERIE RXBKIE RXFOIE
0x02ED U5RXB 7:0 RXB[7:0]
0x02EE Reserved
0x02EF U5TXB 7:0 TXB[7:0]
0x02F0 Reserved
7:0 P1[7:0]
0x02F1 U5P1
15:8
7:0 P2[7:0]
0x02F3 U5P2
15:8
7:0 P3[7:0]
0x02F5 U5P3
15:8
0x02F7 U5CON0 7:0 BRGS ABDEN TXEN RXEN MODE[3:0]
0x02F8 U5CON1 7:0 ON WUE RXBIMD BRKOVR SENDB
0x02F9 U5CON2 7:0 RUNOVF RXPOL STP[1:0] TXPOL FLO[1:0]
7:0 BRG[7:0]
0x02FA U5BRG
15:8 BRG[15:8]
0x02FC U5FIFO 7:0 TXWRE STPMD TXBE TXBF RXIDL XON RXBE RXBF
0x02FD U5UIR 7:0 WUIF ABDIF ABDIE
0x02FE U5ERRIR 7:0 TXMTIF PERIF ABDOVF CERIF FERIF RXBKIF RXFOIF
0x02FF U5ERRIE 7:0 TXMTIE PERIE ABDOVE CERIE FERIE RXBKIE RXFOIE
Data bus
Rev. 10-000076B
11/2/2018
Read Write
8 8
SDI 8 8
SSP
SSET CKP
SPI Control Module
and Transfer Counter
1 1 SS_out
See SCK Generator 1 0 RxyPPS
SPIxCLK
Register 0
SSP
SSET
SPIxBAUD MST
CLKSEL
SCK_in
SPIxSCKPPS
CKP
Note: 1. If the transmit FIFO is empty and TXR = 1, the previous value of the receive shift register will be sent to the transmit serializer.
The SPI transmit output (SDO_out) is available to the remappable PPS SDO pin and internally to the select
peripherals.
The SPI bus typically operates with a single host device and one or more client devices. When multiple client devices
are used, an independent Client Select connection is required from the host device to each client device.
The host selects only one client at a time. Most client devices have tri-state outputs so their output signal appears
disconnected from the bus when they are not selected.
Transmissions typically involve Shift registers, eight bits in size, one in the host and one in the client. With either
the host or the client device, data is always shifted out one bit at a time, with the Most Significant bit (MSb) shifted
out first. At the same time, a new bit is shifted into the device. Unlike older Microchip devices, the SPI module on
this device contains one register for incoming data and another register for outgoing data. Both registers also have
multibyte FIFO buffers and allow for DMA bus connections.
The figure below shows a typical connection between two devices configured as host and client devices.
Figure 36-2. SPI Host/Client Connection with FIFOs
Rev. 10-000080C
1/11/2019
(Note 1) (Note 1)
Notes: 1. In some modes, if the Transmit FIFO is empty, the most recently received byte of data will be transmitted.
2. This diagram assumes that the LSBF bit is cleared (communications are MSb-first). When LSBF is
set, the communications will be LSb-first.
Data is shifted out of the transmit FIFO on the programmed clock edge and into the receive Shift register on the
opposite edge of the clock.
The host device transmits information on its SDO output pin which is connected to, and received by, the client’s SDI
input pin. The client device transmits information on its SDO output pin, which is connected to, and received by, the
host’s SDI input pin.
The host device sends out the clock signal. Both the host and the client devices need to be configured for the same
clock phase and clock polarity.
During each SPI clock cycle, a full-duplex data transmission occurs. This means that while the host device is sending
out the MSb from its output register (on its SDO pin) and the client device is reading this bit and saving it as the LSb
of its input register. The client device is also sending out the MSb from its Shift register (on its SDO pin) and the host
device is reading this bit and saving it as the LSb of its input register.
After eight bits have been shifted out, the host and client have exchanged register values and stored the incoming
data into the receiver FIFOs.
If there is more data to exchange, the registers are loaded with new data and the process repeats.
Whether the data is meaningful or not (dummy data) depends on the application software. This leads to three
scenarios for data transmission:
• Host sends useful data and client sends dummy data
• Host sends useful data and client sends useful data
• Host sends dummy data and client sends useful data
In this SPI module, dummy data may be sent without software involvement. Dummy transmit data is automatically
handled by clearing the TXR bit and receive data is ignored by clearing the RXR bit. See Table 36-1 as well as Host
Mode and Client Mode for further TXR/RXR setting details.
This SPI module can send transmissions of any number of bits, and can send information in segments of varying size
(from 1-8 bits in width). As such, transmissions may involve any number of clock cycles, depending on the amount of
data to be transmitted.
When there is no more data to be transmitted, the host stops sending the clock signal and deselects the client. Every
client device connected to the bus that has not been selected through its Client Select line disregards the clock and
transmission signals and does not transmit out any data of its own.
Important:
1. The BUSY bit is subject to synchronization delay of up to two instruction cycles. The user must
wait for it to set after loading the transmit buffer (SPIxTXB register) before using it to determine the
status of the SPI module.
2. It is also not recommended to read SPIxTCNT while the BUSY bit is set, as the value in the
registers may not be a reliable indicator of the transfer counter. Use the TCZIF bit to accurately
determine that the transfer counter has reached zero.
Important: The transmit and receive FIFO occupancy refer to the number of bytes that are currently
being stored in each FIFO. These values are used in this chapter to illustrate the function of these FIFOs
and are not directly accessible through software.
The SPIxRXB register addresses the receive FIFO and is read-only. Reading from this register will read from the
first FIFO location that was written to by hardware and decrease the receive FIFO occupancy. If the FIFO is empty,
reading from this register will instead return a value of ’0’ and set the RXRE (Receive Buffer Read Error) bit. The
RXRE bit must then be cleared in software to properly reflect the status of the read error. When the receive FIFO is
full, the RXBF bit will be set.
The SPIxTXB register addresses the transmit FIFO and is write-only. Writing to the register will write to the first empty
FIFO location and increase the occupancy. If the FIFO is full, writing to this register will not affect the data and will set
the TXWE bit. When the transmit FIFO is empty, the TXBE bit will be set.
More details on enabling and disabling the receive and transmit functions is summarized in Table 36-1 and Client
Mode Transmit Options.
Important:
In all Client modes and when BMODE = 1 in Host modes, the transfer counter will still decrement as
transfers occur and can be used to count the number of messages sent/received, control SS_out, and
trigger TCZIF. Also, when BMODE = 1, the SPIxTWIDTH register can be used in Host and Client modes
to determine the size of messages sent and received by the SPI, even if the transfer counter is not being
actively used to control the number of messages being sent/received by the SPI module.
Important:
With BMODE = 1, it is possible for the transfer counter (SPIxTCNT) to decrement below zero, although
when in Host Receive Only mode, transfer clocks will cease when the transfer counter reaches zero.
TXR = 1 TXR = 0
Software Write to
Note 2
SPIxTCNT
SPIxTCNT 0 5 4 3 2 1 0
Software Write To
TXR
TXR
Software Write to
RXR
RXR
SCK_out Note 3
SRMTIF
TCZIF Note 2
Software Write
to SPIxTXB
TXFIFO 0 1 2 1 2 1 2 1 0 1 0
Occupancy
SPIxTIF
Software Read
from SPIxRXB
RXFIFO 0 1 0 1 0 1 0 1 0 1 0
Occupancy
SPIxRIF
When BMODE = 0, the transfer counter (SPIxTCNT) must also be written to before transfers will occur. Transfers will
cease when the transfer counter reaches ‘0’. For example, if SPIxTXB is written twice and then SPIxTCNTL is written
with ‘3’, the transfer will start with the SPIxTCNTL write. The two bytes in the TXFIFO will be sent after which the
transfer will suspend until the third and last byte is written to SPIxTXB.
Software Write
to TXR
TXR
Software Write
to RXR
RXR
SCK_out
SRMTIF Note 3
BCZIF
When BMODE = 0, the transfer counter (SPIxTCNT) must also be written to before transfers will occur, and transfers
will cease when the transfer counter reaches ‘0’.
For example, if SPIxTXB is written twice and then SPIxTCNTL is written with ‘3’, the transfer will start with the
SPIxTCNTL write. The two bytes in the TXFIFO will be sent after which the transfer will suspend until the third and
last byte is written to SPIxTXB.
Important: When operating in Receive Only mode and the size of every SPI transaction is less than 8
bits, it is recommended to operate in BMODE = 1 mode. The size of the packet can be configured using
the SPIxTWIDTH register.
Software Write to
TxCNTL
SPIxTXCNT 0 -1 -2 3 2 1 0
Software Write to
TXR
TXR
Software Write
to RXR
RXR
SCK_out
SRMTIF Note 2
TCZIF
Software Write
to SPIxTXB
TXFIFO 0 1 2 1 0
Occupancy
Software Read
from SPIxRXB
RXFIFO 0 1 0 1 0 1 0
Occupancy
SPIxRIF
SPIEN
baud_clock
Software Write to
SPIxTCNTL
Transfer 1 0
Counter
SS_out
SCK_out
SDO_bit_number 7 6 5 4 3 2 1 0
Notes: 1. SDO bit number illustrates the transmitted bit number, and is not intended to imply SDO_out tristate operation.
2. Assumes SPIxTXB holds data when SPIxTCNTL is written.
Rev. 10-000276A
11/6/2018
MST = 1,CKE = 0, SMP = 0
SCK A I A I A I A I A I A I A I A I
SDO Previous bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 CKP = 0
SCK A I A I A I A I A I A I A I A I
SDO Previous bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 CKP = 1
Rev. 10-000315A
SCK A I A I A I A I A I A I A I A I
SDO bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 next CKP = 0
tx_buf
input sample clock write
A I A I A I A I A I A I A I A I
SCK
SDO bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 next CKP = 1
tx_buf
input sample clock write
Rev. 10-000277A
11/6/2018
SCK A I A I A I A I A I A I A I A I
SDO previous bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 CKP = 0
SCK A I A I A I A I A I A I A I A I
SDO previous bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 CKP = 1
Rev. 10-000278A
11/6/2018
SCK I A I A I A I A I A I A I A I A
SDO bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 CKP = 0
SCK I A I A I A I A I A I A I A I A
SDO bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 CKP = 1
(either due to the host not clocking the SCK line or the SS being false), the SDO pin will be driven to the value of
the LAT bit associated with the SDO pin. When the SPI module is active, its output is determined by both TXR and
whether there is data in the transmit FIFO.
When the TRIS bit associated with the SDO pin is set, the pin will only have an output level driven to it when TXR = 1
and the Client Select input is true. In all other cases, the pin will be tri-stated.
Table 36-3. Client Mode Transmit
SS_in
SCK_in Note 1
SOSIF Note 2
EOSIF
Transfer Counter 0 -1 -2 3 2 1 0
Receiver process
SPIxRIF
Software
Read from
SPIxRXB
Notes: 1. This delay is exaggerated for illustration, and can be as short as1/2 bit period.
2. If the device is sleeping, SOSIF will wake it up for interrupt service.
3. Setting SPIxTCNTL is optional in this example, otherwise it will count -3, -4, -5, and TCZIF will not occur.
The Client Select for the SPI module is controlled by the SSET bit. When SSET is cleared (its default state), the
Client Select will act as described above. When the bit is set, the SPI module will behave as if the SS input is always
in its Active state.
Important:
When SSET is set, the effective SS_in signal is always active. Hence, the SSFLT bit may be disregarded.
SCK SCK
SPI Host SDOx SDIx SPI Client
SDIx SDOx #1
SSxOUT/GPIO SSxIN
SCK
SDIx SPI Client
SDOx #2
SSxIN
SCK
SDIx SPI Client
SDOx #3
SSxIN
SCK SCK(in)
SPI Host SDOx SDIx SPI Client
SDIx #1
SSxIN
SSxOUT/GPIO
SCK(out) SDOx
SCK(in) SDIx
SPI Client
SSxIN #2
SCK(out) SDOx
SCK(in) SDIx
SDOx
SS_in
SCK
SDO_bit_number 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
SRMTIF
SOSIF
Note 3
TCZIF
EOSIF Note 3
Important:
The TCZIF flag only indicates that the transfer counter has decremented from one to zero, and may not
indicate that the entire data transfer process is complete. Either poll the BUSY bit and wait for it to be
cleared or use the Shift Register Empty Interrupt (SRMTIF) to determine when a data transfer is fully
complete.
36.7.1 SPIxCON0
Name: SPIxCON0
Offset: 0x084,0x091
Bit 7 6 5 4 3 2 1 0
EN LSBF MST BMODE
Access R/W R/W R/W R/W
Reset 0 0 0 0
Note:
1. Do not change this bit when EN = 1.
36.7.2 SPIxCON1
Name: SPIxCON1
Offset: 0x085,0x092
Bit 7 6 5 4 3 2 1 0
SMP CKE CKP FST SSP SDIP SDOP
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 1 0 0
36.7.3 SPIxCON2
Name: SPIxCON2
Offset: 0x086,0x093
SPI Control Register 2(3)
Bit 7 6 5 4 3 2 1 0
BUSY SSFLT SSET TXR RXR
Access R R R/W R/W R/W
Reset 0 0 0 0 0
Notes:
1. The BUSY bit is subject to synchronization delay of up to two instruction cycles. The user must wait after
loading the transmit buffer (the SPIxTXB register) before using it to determine the status of the SPI module.
2. See the Host Mode TXR/RXR Settings table as well as the Host Mode and Client Mode sections for more
details pertaining to TXR and RXR function.
3. This register will not be written to while a transfer is in progress (the BUSY bit is set).
36.7.4 SPIxCLK
Name: SPIxCLK
Offset: 0x08C,0x099
Bit 7 6 5 4 3 2 1 0
CLKSEL[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
CLK Selection
10111-11111 Reserved
10110 CLC8_OUT
10101 CLC7_OUT
10100 CLC6_OUT
10011 CLC5_OUT
10010 CLC4_OUT
10001 CLC3_OUT
10000 CLC2_OUT
01111 CLC1_OUT
01110 SMT1_OUT
01001-01111 Reserved
01110 TU16B_OUT
01101 TU16A_OUT
01000 TMR6_Postscaler_OUT
00111 TMR4_Postscaler_OUT
00110 TMR2_Postscaler_OUT
00101 TMR0_OUT
00100 Clock Reference Output
00011 EXTOSC
00010 MFINTOSC (500 kHz)
00001 HFINTOSC
00000 FOSC (System Clock)
36.7.5 SPIxBAUD
Name: SPIxBAUD
Offset: 0x089,0x096
Bit 7 6 5 4 3 2 1 0
BAUD[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
36.7.6 SPIxTCNT
Name: SPIxTCNT
Offset: 0x082,0x08F
Bit 15 14 13 12 11 10 9 8
TCNTH[2:0]
Access R/W R/W R/W
Reset 0 0 0
Bit 7 6 5 4 3 2 1 0
TCNTL[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
36.7.7 SPIxTWIDTH
Name: SPIxTWIDTH
Offset: 0x088,0x095
Bit 7 6 5 4 3 2 1 0
TWIDTH[2:0]
Access R/W R/W R/W
Reset 0 0 0
Bits 2:0 – TWIDTH[2:0] SPI Transfer Count Byte Width or three LSbs of the Transfer Bit Count
Value Condition Description
n BMODE = 0 Bits 2-0 of the transfer bit count
n BMODE = 1 Number of bits in each transfer byte count. Bits = n (when n > 0) or 8 (when n = 0).
36.7.8 SPIxSTATUS
Name: SPIxSTATUS
Offset: 0x087,0x094
Bit 7 6 5 4 3 2 1 0
TXWE TXBE RXRE CLB RXBF
Access R/C/HS R R/C/HS S R
Reset 0 1 0 0 0
36.7.9 SPIxRXB
Name: SPIxRXB
Offset: 0x080,0x08D
Bit 7 6 5 4 3 2 1 0
RXB[7:0]
Access R R R R R R R R
Reset x x x x x x x x
36.7.10 SPIxTXB
Name: SPIxTXB
Offset: 0x081,0x08E
Bit 7 6 5 4 3 2 1 0
TXB[7:0]
Access W W W W W W W W
Reset x x x x x x x x
36.7.11 SPIxINTE
Name: SPIxINTE
Offset: 0x08B,0x098
Bit 7 6 5 4 3 2 1 0
SRMTIE TCZIE SOSIE EOSIE RXOIE TXUIE
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
36.7.12 SPIxINTF
Name: SPIxINTF
Offset: 0x08A,0x097
Bit 7 6 5 4 3 2 1 0
SRMTIF TCZIF SOSIF EOSIF RXOIF TXUIF
Access R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS
Reset 0 0 0 0 0 0
0x00
... Reserved
0x7F
0x80 SPI1RXB 7:0 RXB[7:0]
0x81 SPI1TXB 7:0 TXB[7:0]
7:0 TCNTL[7:0]
0x82 SPI1TCNT
15:8 TCNTH[2:0]
0x84 SPI1CON0 7:0 EN LSBF MST BMODE
0x85 SPI1CON1 7:0 SMP CKE CKP FST SSP SDIP SDOP
0x86 SPI1CON2 7:0 BUSY SSFLT SSET TXR RXR
0x87 SPI1STATUS 7:0 TXWE TXBE RXRE CLB RXBF
0x88 SPI1TWIDTH 7:0 TWIDTH[2:0]
0x89 SPI1BAUD 7:0 BAUD[7:0]
0x8A SPI1INTF 7:0 SRMTIF TCZIF SOSIF EOSIF RXOIF TXUIF
0x8B SPI1INTE 7:0 SRMTIE TCZIE SOSIE EOSIE RXOIE TXUIE
0x8C SPI1CLK 7:0 CLKSEL[4:0]
0x8D SPI2RXB 7:0 RXB[7:0]
0x8E SPI2TXB 7:0 TXB[7:0]
7:0 TCNTL[7:0]
0x8F SPI2TCNT
15:8 TCNTH[2:0]
0x91 SPI2CON0 7:0 EN LSBF MST BMODE
0x92 SPI2CON1 7:0 SMP CKE CKP FST SSP SDIP SDOP
0x93 SPI2CON2 7:0 BUSY SSFLT SSET TXR RXR
0x94 SPI2STATUS 7:0 TXWE TXBE RXRE CLB RXBF
0x95 SPI2TWIDTH 7:0 TWIDTH[2:0]
0x96 SPI2BAUD 7:0 BAUD[7:0]
0x97 SPI2INTF 7:0 SRMTIF TCZIF SOSIF EOSIF RXOIF TXUIF
0x98 SPI2INTE 7:0 SRMTIE TCZIE SOSIE EOSIE RXOIE TXUIE
0x99 SPI2CLK 7:0 CLKSEL[4:0]
ABD
(See I2CxCON2
I2CxADR0/1/2/3 Register)
SDAHT
TH I2CxADB0/1 (See I2CxCON2 Register)
Address compare
(See RxyI2C Register) SDA
(out)
TX Shift
RX Shift RxyPPS
I2CxSDAPPS Register
Register
SDA
(in)
CLK I2CxADB0/1 Transmit
Receive Buffer
ABD Buffer
I2CxRXB
See (See I2CxCON2 I2CxTXB
I2CxCLK Register)
Register
I2C Control Unit
SCL
See
I2CxBTO Host (out)
Register Module RxyPPS
SCL BTO
(in) Client
Module
I2CxSCLPPS
Interrupt
TH I2CxPIR
Controller
(See RxyI2C Register)
• Start condition
• Restart condition
• Stop condition
• Address match
• Data Write
• Acknowledge Status
• NACK detection
• Data Byte Count
• Bus Collision
• Bus Time-out
– Clock Stretching for:
• RX buffer full
• TX buffer empty
• Incoming address match
• Data Write
• Acknowledge Status
– Bus Collision Detection with Arbitration
– Bus Time-out Detection
• Selectable clock sources
• Clock prescaler
– Selectable Serial Data (SDA) Hold Time
– Dedicated I2C Pad (I/O) Control
• Standard GPIO or I2C-specific slew rate control
• Selectable I2C pull-up levels
• I2C-specific, SMBus 2.0/3.0, or standard GPIO input threshold level selections
– Integrated Direct Memory Access (DMA) support
– Remappable pin locations using Peripheral Pin Select (PPS)
Term Definition
Host The device that initiates a transfer, generates the clock signal and terminates a transfer
Client The device addressed by the host
Multi-Host A bus containing more than one host device that can initiate communication
Transmitter The device that shifts data out onto the bus
Receiver The device that shifts data in from the bus
Arbitration Procedure that ensures only one host at a time controls the bus
Synchronization Procedure that synchronizes the clock signal between two or more devices on the bus
Idle The state in which no activity occurs on the bus and both bus lines are at a high logic level
Active The state in which one or more devices are communicating on the bus
Matching Address The address byte received by a client that matches the value that is stored in the
I2CxADR0/1/2/3 registers
Addressed Client Client device that has received a matching address and is actively being clocked by a host
device
Write Request Host transmits an address with the R/W bit clear indicating that it wishes to transmit data to a
client device
Read Request Host transmits an address with the R/W bit set indicating that it wishes to receive data from a
client device
Clock Stretching The action in which a device holds the SCL line low to stall communication
Bus Collision Occurs when the module samples the SDA line and returns a low state while expecting a high
state
Bus Time-out Occurs whenever communication stalls for a period longer than acceptable
Receive Buffer
SDA
Shift Register SCK Transmit Buffer
I2C Client 1
Transmit Buffer
SCK
Receive Buffer
I2C Host
SDA
Shift Register
I2C Client 2
– Standard GPIO input thresholds (controlled by the Input Level Control (INLVLx) registers)
• Slew rate limiting:
– I2C-specific slew rate limiting
– Standard GPIO slew rate (controlled by the Slew Rate Control (SLRCONx) registers)
• 2
I C pull-ups:
– Programmable ten or two times the current of the standard internal pull-up
– Standard GPIO pull-up (controlled by the Weak Pull-Up Control (WPUx) registers)
Important: The pin locations for SDA and SCL are remappable through the Peripheral Pin Select (PPS)
registers. If new pin locations for SDA and SCL are desired, user software must configure the INLVLx,
SLRCONx, ODCONx, and TRISx registers for each new pin location. The RxyI2C registers cannot be
used since they are dedicated to the default pin locations. Additionally, the internal pull-ups for non-I2C
pins are not strong enough to drive the pins; therefore, external pull-up resistors must be used.
Filename: SDA Hold Time.vsdx
Title:
Last Edit: 11/15/2018
37.3.2.1 First
SDA HoldUsed:
Time
Notes:
SDA hold time refers to the amount of time between the low threshold region of the falling edge of SCL (VIL ≤ 0.3
VDD) and either the low threshold region of the rising edge of SDA (VIL ≤ 0.3 VDD) or the high threshold region of the
falling edge of SDA (VIH ≥ 0.7 VDD) (see Figure 37-3). If the SCL fall time is long or close to the maximum allowable
time set by the I2C Specification, data may be sampled in the undefined Logic state between the 70% and 30%
region of the falling SCL edge, leading to data corruption. The I2C module offers selectable SDA hold times, which
can be useful to ensure valid data transfers at various bus data rates and capacitance loads.
Figure 37-3. SDA Hold Time
SDA Hold
SDA
Time
Start
Condition
SDA
SCL
Important: The ACKCNT bit is only used when the I2CxCNT register is zero, otherwise the ACKDT bit is
used for ACK/NACK sequences.
In Host Write or Client Read modes, the Acknowledge Status (ACKSTAT) bit holds the result of the Acknowledge
sequence transmitted by the receiving device. The ACKSTAT bit is cleared when the receiver sends an ACK, and is
set when the receiver does not Acknowledge (NACK).
The Acknowledge Time Status (ACKT) bit indicates whether or not the bus is in an Acknowledge sequence. The
ACKT bit is set during an ACK/NACK sequence on the 8th falling edge of SCL, and is cleared on the 9th rising edge
of SCL, indicating that the bus is not in an ACK/NACK sequence.
Certain conditions will cause a NACK sequence to be sent automatically. A NACK sequence is generated by module
hardware when any of the following bits are set:
• Transmit Write Error Status (TXWE)
• Transmit Underflow Status (TXU)
• Receive Read Error Status (RXRE)
• Receive Overflow Status (RXO)
Filename: Acknowledge Sequence.vsdx
Title:
Last Edit: Important:
1/8/2019 Once a NACK is detected on the bus, all subsequent Acknowledge sequences will consist of
First Used:
Notes: a NACK until all Error conditions are cleared.
SCL SCL
Important: In 10-bit Client mode, a Restart is required for the host to read data out of the client,
regardless of which data transfer format is used – host read-only or combined. For example, if the host
wishes to perform a bulk read, it will transmit the client’s 10-bit address with the R/W bit clear.
Restart
Condition
SDA
SCL
SCL
SDA Stop
Condition
The Bus Time-Out Clock Source Selection (BTOC) bits select the time-out clock source. If an oscillator is selected as
the time-out clock source, such as the LFINTOSC, the time-out clock base period is approximately 1 ms. If a timer is
selected as the time-out clock source, the timer can be configured to produce a variety of time periods.
Remember: The SMBus protocol dictates a 25 ms time-out for client devices and a 35 ms time-out for
host devices.
The Time-Out Time Selection (TOTIME) bits and the Time-Out Prescaler Extension Enable (TOBY32) bit are used to
determine the time-out period. The value written into TOTIME multiplies the base time-out clock period. For example,
if a value of ‘35’ is written into the TOTIME bits, and the LFINTOSC is selected as the time-out clock source, the
time-out period is approximately 35 ms (35 x 1 ms). If the TOBY32 bit is set (TOBY32 = 1), the time-out period
determined by the TOTIME bits is multiplied by 32. If TOBY32 is clear (TOBY32 = 0), the time-out period determined
by the TOTIME bits is used as the time-out period.
The examples below illustrate possible time-out configurations.
The Time-Out Recovery Selection (TOREC) bit determines how the module will respond to a bus time-out. When
a bus time-out occurs and TOREC is set (TOREC = 1), the I2C module is reset and module hardware sets the
Bus Time-Out Interrupt Flag (BTOIF). If the Bus Time-Out Interrupt Enable (BTOIE) is also set, an interrupt will be
generated. If a bus time-out occurs and TOREC is clear (TOREC = 0), the BTOIF bit is set, but the module is not
reset.
If the module is configured in Client mode with TOREC set (TOREC = 1), and a bus time-out event occurs
(regardless of the state of the Client Mode Active (SMA) bit), the module is immediately reset, the SMA and Client
Clock Stretching (CSTR) bits are cleared, and the Bus Time-Out Interrupt Flag (BTOIF) bit is set.
If the module is configured in Client mode with TOREC clear (TOREC = 0), and a bus time-out event occurs
(regardless of the state of the Client Mode Active (SMA) bit), the BTOIF bit is set, but user software must reset the
module.
If the module is configured in Host mode with TOREC set (TOREC = 1), and the bus time-out event occurs while the
Host is active (Host Mode Active (MMA) = 1), the Host Data Ready (MDR) bit is cleared, the module will immediately
attempt to transmit a Stop condition, and sets the BTOIF bit. Stop condition generation may be delayed if a client
device is stretching the clock, but will resume once the clock is released, or if the client holding the bus also has a
time-out event occur.
Filename:
The MMA bit is only cleared after the Stop condition has been generated.
Host Mode BTO Event Example .vsdx
Title:
If the module is configured
Last Edit: 1/9/2019
in Host mode with TOREC clear (TOREC = 0), and the bus time-out event occurs while
theFirst
Host is active (Host Mode Active (MMA) = 1), the MDR bit is cleared and the BTOIF bit is set, but user software
Used:
Notes:
must initiate the Stop condition by setting the P bit.
The figure below shows an example of a Bus Time-Out event when the module is operating in Host mode.
Figure 37-8. Host Mode Bus Time-Out Example
Host waits
SDA D0 for ACK/NACK Stop detected
PCIF = 1
I2CxTXIF = 1
TXBE = 1
SCL 8
Enable Timer2 Host attempts to issue Stop ,
but must wait until SCL = 1
T2_Postscaled_out BTOIF = 1
Software
clears BTOIF,
TMR2IF
T2TMR_T2PR_Match TMR2IF = 1
• In Host mode, the desired client address is transmitted from the I2CxTXB register.
• In Client mode, a matching received address is loaded into the I2CxRXB register.
Table 37-1. Address Buffer Direction
Important: A transmit underflow can only occur when clock stretching is disabled (Clock Stretching
Disable (CSD) bit = 1). Clock stretching prevents transmit underflows because the clock is stretched after
the 8th falling SCL edge, and is only released upon the write of new data into I2CxTXB.
Important: A receive overflow can only occur when clock stretching is disabled. Clock stretching
prevents receive overflows because the receive shift register cannot receive any more data until user
software or the DMA reads I2CxRXB and the SCL line is released.
Hardware reads
RXBF = 1 Client
releases SCL
SCL 1 2 3 4 5 6 7 8
Clock
stretched
SDA D7 D6 D5 D4 D3 D2 D1 D0
Software reads
I2CxRXB Hardware
RXBF clears RXBF
Hardware sets
CSTR = 1 Hardware
CSTR clears CSTR
In Client Transmit mode, clock stretching prevents transmit underflows. When I2CxTXB is empty (TXBE = 1) and the
I2CxCNT register is nonzero (I2CxCNT != 0), client hardware stretches the clock and sets CSTR upon the 8th falling
SCL edge. Once the client has loaded new data into I2CxTXB, client hardware automatically clears CSTR to release
the SCL line and allow further communication (see Figure 37-10).
Software loads
I2CxTXB Hardware
TXBE clears TXBE
Important: In 10-bit Client Addressing mode, clock stretching occurs only after the client receives a
matching low address byte, or a matching high address byte with the R/W bit = 1 (Host read) while the
Client Mode Active (SMA) bit is set (SMA = 1). Clock stretching does not occur after the client receives a
matching high address byte with the R/W bit = 0 (Host write).
The Data Write Interrupt and Hold Enable feature provides an interrupt event and stretches the SCL signal after
the client receives a data byte. This feature is enabled by setting the Data Write Interrupt and Hold Enable (WRIE)
bit. When enabled (WRIE = 1), module hardware sets both the CSTR bit and the Data Write Interrupt Flag (WRIF)
bit and stretches the SCL line after the 8th falling edge of SCL. Once the client has read the new data, software
determines whether to send an ACK or a NACK back to the host device. Client software must clear both the CSTR
and WRIF bits to resume communication.
The Acknowledge Status Time Interrupt and Hold Enable feature generates an interrupt event and stretches the SCL
line after the acknowledgement phase of a transaction. This feature is enabled by setting the Acknowledge Status
Time Interrupt and Hold Enable (ACKTIE) bit. When enabled (ACKTIE = 1), module hardware sets the CSTR bit
and the Acknowledge Status Time Interrupt Flag (ACKTIF) bit and stretches the clock after the 9th falling edge of
SCL for all address, read, or write operations. Client software must clear both the ACKTIF and CSTR bits to resume
communication.
Important: The I2CxCNT register will not decrement past a zero value.
When a byte transfer causes the I2CxCNT register to decrement to ‘0’, the Byte Count Interrupt Flag (CNTIF) bit
is set, and if the Byte Count Interrupt Enable (CNTIE) is set, the general purpose I2C Interrupt Flag (I2CxIF) bit of
the Peripheral Interrupt Registers (PIR) is also set. If the I2C Interrupt Enable (I2CxIE) bit of the Peripheral Interrupt
Enable (PIE) registers is set, module hardware will generate an interrupt event.
Important: The I2CxIF bit is read-only and can only be cleared by clearing all the interrupt flag bits of the
I2CxPIR register.
The I2CxCNT register can be read at any time, but it is recommended that a double read is performed to ensure a
valid count value.
The I2CxCNT register can be written to; however, care is required to prevent register corruption. If the I2CxCNT
register is written to during the 8th falling SCL edge of a reception, or during the 9th falling SCL edge of a
transmission, the register value may be corrupted. In Client mode, I2CxCNT can be safely written to any time the
clock is not being stretched (CSTR = 0), or after a Stop condition has been received (Stop Condition Interrupt Flag
(PCIF) = 1). In Host mode, I2CxCNT can be safely written to any time the Host Data Ready (MDR) or Bus Free
(BFRE) bits are set. If the I2C packet is longer than 65,536 bytes, the I2CxCNT register can be updated mid-message
to prevent the count from reaching zero; however, the preventative measures listed above must be followed.
When in either Client Read or Host Write mode and the I2CxCNT value is nonzero (I2CxCNT != 0), the value of the
ACKDT bit is used as the acknowledgement response. When I2CxCNT reaches zero (I2CxCNT = 0), the value of the
Acknowledge End of Count (ACKCNT) bit is used for the acknowledgement response.
In Host read or write operations, when the I2CxCNT register is clear (I2CxCNT = 0) and the Restart Enable (RSEN)
bit is clear, host hardware automatically generates a Stop condition upon the 9th falling edge of SCL. When I2CxCNT
is clear (I2CxCNT = 0) and RSEN is set (RSEN = 1), host hardware will stretch the clock while it waits for the Start
(S) bit to be set (S = 1). When the Start bit has been set, module hardware transmits a Restart condition followed by
the address of the client it wishes to communicate with.
Important: When using the auto-load feature in any Transmit mode (Client, Host, Multi-Host), the first
of the two bytes following the address is the I2CxCNT register’s high byte, followed by the I2CxCNT
register’s low byte. If the order of these two bytes is switched, the value loaded into the I2CxCNT register
will not be correct.
In Host Reception mode, the first two bytes received from the client are loaded into both I2CxCNT and I2CxRXB.
The value of the Acknowledge Data (ACKDT) bit is used as the host’s acknowledgement response to prevent a false
NACK from being generated before the I2CxCNT register is updated with the new count value.
In Client Reception mode, the first two bytes received after a receiving a matching 7-bit or 10-bit address are loaded
into both I2CxCNT and I2CxRXB, and the value of the ACKDT bit is used as the client’s acknowledgement response.
In Client Transmit mode, the first two bytes loaded into I2CxTXB following the reception of a matching 7-bit or 10-bit
address are transferred into both I2CxCNT and the transmit shift register.
Important: It is not necessary to preload the I2CxCNT register when using the auto-load feature. If no
value is loaded by the 9th falling SCL edge following an address transmission or reception, the Byte Count
Interrupt Flag (CNTIF) will be set by module hardware, and must be cleared by software to prevent an
interrupt event before I2CxCNT is updated. Alternatively, I2CxCNT can be preloaded with a nonzero value
to prevent the CNTIF from being set. In this case, the preloaded value will be overwritten once the new
count value has been loaded into I2CxCNT.
host, hardware sets the I2CxRXIF bit, which triggers the DMA to read I2CxRXB. Once the DMA has read I2CxRXB,
I2CxRXIF is cleared by hardware and the DMA waits for the next occurrence of I2CxRXIF being set.
37.3.14 Interrupts
The I2C module offers several interrupt features designed to assist with communication functions. The interrupt
hardware contains four high-level interrupts and several condition-specific interrupts.
Important: I2CxTXIF can only be set when either the Client Mode Active (SMA) or Host Mode Active
(MMA) bits are set, and the I2CxCNT register is nonzero (I2CxCNT != 0). The SMA bit is only set after
an address has been successfully acknowledged by a client device, which prevents false interrupts from
being triggered on address reception. The MMA bit is set once the host completes the transmission of a
Start condition.
The I2C Receive Interrupt Flag (I2CxRXIF) bit is set when the receive shift register has loaded new data into the
receive buffer, I2CxRXB. When new data is loaded into I2CxRXB, the Receive Buffer Full Status (RXBF) bit is set
(RXBF = 1), which also sets I2CxRXIF. If the I2C Receive Interrupt Enable (I2CxRXIE) bit is set, an interrupt event
will occur when the I2CxRXIF bit becomes set. Reading data from I2CxRXB, or setting the CLRBF bit, will clear the
interrupt condition. The I2CxRXIF bit is also used by the DMA as a trigger source.
Important: I2CxRXIF can only be set when either the Client Mode Active (SMA) or Host Mode Active
(MMA) bits are set.
The I2C Interrupt Flag (I2CxIF) is the general purpose interrupt. I2CxIF is set whenever any of the interrupt flag bits
contained in the I2C Peripheral Interrupt (I2CxPIR) Register and the associated interrupt enable bits contained in
the I2C Peripheral Interrupt Enable (I2CxPIE) Register are set. If I2CxIF becomes set while the I2C Interrupt Enable
(I2CxIE) bit is set, an interrupt event will occur. I2CxIF is cleared by module hardware when all enabled interrupt flag
bits in I2CxPIR are clear.
The I2C Error Interrupt Flag (I2CxEIF) is set whenever any of the interrupt flag bits contained in the I2C Error
(I2CxERR) Register and their associated interrupt enable bits are set. If I2CxEIF becomes set while the I2C Error
Interrupt Enable (I2CxEIE) bit is set, an interrupt event will occur. I2CxEIF is cleared by hardware when all enabled
error interrupt flag bits in the I2CxERR register are clear.
Important: The I2CxEIF bit is read-only, and is only cleared by hardware after all enabled I2CxERR error
flags have been cleared.
7-bit address
R/W
I2CxRSR (receive shift register) 1 1 0 0 1 0 0 X
Bits ignored
Bits compared X X (masked)
In 10-bit Address mode, I2CxADR0 and I2CxADR1, and I2CxADR2 and I2CxADR3 are combined to create two 10-bit
addresses. I2CxADR0 and I2CxADR2 hold the lower eight bits of the address, while I2CxADR1 and I2CxADR3 hold
the upper two bits of the address, the R/W bit, and the five-digit ‘11110’ code assigned to the five Most Significant
bits of the high address byte.
Important: The ‘11110’ code is specified by the I2C Specification, but is not supported by Microchip. It is
up to the user to ensure the correct bit values are loaded into the address high byte. If a host device has
included the five-digit code in the address it intends to transmit, the client must also include those bits in
client address.
The upper received address byte is compared to the values in I2CxADR1 and I2CxADR3. If a match occurs, the
address is stored in either I2CxADB1 (when ABD = 0) or in I2CxRXB (when ABD = 1), and the value of the R/W bit
is transferred into the R bit. The lower received address byte is compared to the values in I2CxADR0 and I2CxADR2,
and if a match occurs, the address is stored in either I2CxADB0 (when ABD = 0) or in I2CxRXB (when ABD = 1).
In 10-bit Address with Masking mode, I2CxADR0 and I2CxADR1 are combined to form the 10-bit address, while
I2CxADR2 and I2CxADR3 are combined to form the 10-bit mask. The upper received address byte is compared to
the masked value in I2CxADR1. If a match occurs, the address is stored in either I2CxADB1 (when ABD = 0) or in
I2CxRXB (when ABD = 1), and the value of the R/W bit is transferred into the R bit. The lower received address byte
is compared to the value in I2CxADR0, and if a match occurs, the address is stored in either I2CxADB0 (when ABD =
0) or in I2CxRXB (when ABD = 1).
Start (S)
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
– The Address Interrupt Flag (ADRIF) bit is set. If the Address Interrupt and Hold Enable (ADRIE) bit
is set, and the Clock Stretching Disable (CSD) bit is clear, hardware sets the Client Clock Stretching
(CSTR) bit and the generic I2CxIF bit. This allows time for the client to read either I2CxADB0 or I2CxRXB
and selectively ACK/NACK based on the received address. When the client has finished processing the
address, software must clear CSTR to resume operation.
– The matching received address is loaded into either the I2CxADB0 register or into the I2CxRXB register
as determined by the Address Buffer Disable (ABD) bit. When ABD is clear (ABD = 0), the matching
address is copied to I2CxADB0. When ABD is set (ABD = 1), the matching address is copied to
I2CxRXB, which also sets the Receive Buffer Full Status (RXBF) bit and the I2C Receive Interrupt Flag
(I2CxRXIF) bit. I2CxRXIF is a read-only bit, and must be cleared by either reading I2CxRXB or by setting
the Clear Buffer (CLRBF) bit (CLRBF = 1).
If no address match occurs, the module remains Idle.
4. If the Transmit Buffer Empty Status (TXBE) bit is set (TXBE = 1), I2CxCNT has a nonzero value (I2CxCNT !=
0), and the I2C Transmit Interrupt Flag (I2CxTXIF) is set (I2CxTXIF = 1), client hardware sets CSTR, stretches
the clock (when CSD = 0), and waits for software to load I2CxTXB with data. I2CxTXB must be loaded to clear
I2CxTXIF. Once data is loaded into I2CxTXB, hardware automatically clears CSTR to resume communication.
5. The host device transmits the 9th clock pulse, and client hardware transfers the value of the ACKDT bit onto
the SDA line. If there are pending errors, such as a receive overflow (RXO = 1), client hardware automatically
generates a NACK condition. NACKIF is set, and the module goes Idle.
6. Upon the 9th falling SCL edge, the data byte in I2CxTXB is transferred to the transmit shift register, and
I2CxCNT is decremented by one. Additionally, the Acknowledge Status Time Interrupt Flag (ACKTIF) bit is set.
If the Acknowledge Status Time Interrupt and Hold Enable (ACKTIE) bit is also set, the generic I2CxIF is set,
and if client hardware generated an ACK, the CSTR bit is also set and the clock is stretched (when CSD = 0).
If a NACK was generated, the CSTR bit remains unchanged. Once complete, software must clear CSTR and
ACKTIF to release the clock and continue operation.
7. If the client generated an ACK and I2CxCNT is nonzero, host hardware transmits eight clock pulses, and client
hardware begins to shift the data byte out of the shift register starting with the Most Significant bit (MSb).
8. After the 8th falling edge of SCL, client hardware checks the status of TXBE and I2CxCNT. If TXBE is set and
I2CxCNT has a nonzero count value, hardware sets CSTR and the clock is stretched (when CSD = 0) until
software loads I2CxTXB with new data. Once I2CxTXB has been loaded, hardware clears TXBE, I2CxTXIF,
and CSTR to resume communication.
9. Once the host hardware clocks in all eight data bits, it transmits the 9th clock pulse along with the ACK/
NACK response back to the client. Client hardware copies the ACK/NACK value to the Acknowledge Status
(ACKSTAT) bit and sets ACKTIF. If ACKTIE is also set, client hardware sets the generic I2CxIF bit and CSTR,
and stretches the clock (when CSD = 0). Software must clear CSTR to resume operation.
10. After the 9th falling edge of SCL, data currently loaded in I2CxTXB is transferred to the transmit shift register,
setting both TXBE and I2CxTXIF. I2CxCNT is decremented by one. If I2CxCNT is zero (I2CxCNT = 0), CNTIF
is set.
11. If I2CxCNT is nonzero and the host issued an ACK on the last byte (ACKSTAT = 0), the host transmits eight
clock pulses, and client hardware begins to shift data out of the shift register.
12. Repeat steps 8 – 11 until the host has received all the requested data (I2CxCNT = 0). Once all data has been
received, the host issues a NACK, followed by either a Stop or Restart condition. Once the NACK has been
received by the client, hardware sets NACKIF and clears SMA. If the NACK Detect Interrupt Enable (NACKIE)
bit is also set, the generic I2C Error Interrupt Flag (I2CxEIF) is set. If the host issued a Stop condition, client
hardware sets the Stop Condition Interrupt Flag (PCIF). If the host issued a Restart condition, client hardware
sets the Restart Condition Interrupt Flag (RSCIF). If the associated interrupt enable bits are also set, the
generic I2CxIF is also set.
Important: I2CxEIF is read-only, and is cleared by hardware when all enable interrupt flag bits in
I2CxERR are cleared.
Figure 37-13. 7-Bit Client Mode Transmission (No Clock Stretching) rotatethispage90
5HY,&6ODYH
$&. 1$&.
IURP IURP
5: host)
6WDUW host) 6WRS +DUGZDUHVHWV
3&,)
6'$ $ $ $ $ $ $ $ ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
6&/
+DUGZDUHVHWV +DUGZDUHFOHDUV
60$ 60$ 60$
+DUGZDUHFRSLHV
5:YDOXHWR5ELW
5
Datasheet
+DUGZDUHFOHDUV'ELW
ODVWE\WHZDVDGGUHVV
' +DUGZDUHVHWV'ELW
PIC18F26/46/56Q83
Host¶V$&.FRSLHG Host¶V1$&.
WR$&.67$7 FRSLHGWR$&.67$7
$&.67$7
%HIRUH6WDUWVRIWZDUH 'DWDE\WHWUDQVIHUUHGWRVKLIWUHJLVWHU
ORDGVGDWDLQWR,&[7;% ,&[7;,)127VHW
DS40002253C-page 699
7;%(
,&[7;,)VHW 6RIWZDUHORDGVGDWDLQWR
GDWDE\WHWUDQVIHUUHGWRVKLIWUHJLVWHU ,&[7;%FOHDULQJ,&[7;,)
and its subsidiaries
© 2020-2022 Microchip Technology Inc.
$&.
1$&.
5: IURP IURP 6WRS
6WDUW
host) host)
6'$ $ $ $ $ $ $ $ ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
6&/ 2 3 4 5 6
+DUGZDUHVHWV 6RIWZDUHFOHDUV
&675 &675 &675
Datasheet
Host¶V$&.FRSLHG Host¶V1$&.
WR$&.67$7 FRSLHGWR$&.67$7
$&.67$7
PIC18F26/46/56Q83
'DWDE\WHWUDQVIHUUHGWRVKLIWUHJLVWHU
%HIRUH6WDUWVRIWZDUH ,&[7;,)127VHW
ORDGVGDWDLQWR,&[7;%
7;%(
,&[7;,)VHW 6RIWZDUHORDGVGDWDLQWR
GDWDE\WHWUDQVIHUUHGWRVKLIWUHJLVWHU ,&[7;%FOHDULQJ,&[7;,)
DS40002253C-page 700
and its subsidiaries
© 2020-2022 Microchip Technology Inc.
SDA A7 A6 A5 A4 A3 A2 A1 0 D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Matching received
I2CxRXIF set,
address loaded Software reads
data byte
into I2CxADB0 I2CxRXB, clearing
transferred to
RXBF I2CxRXB I2CxRXIF
Hardware sets
PIC18F26/46/56Q83
CNTIF
I2CxRXB and determine the state of the ACKDT bit that is transmitted back to the host. Once the client
determines the Acknowledgement response, software clears CSTR to allow further communication.
9. Host hardware transmits the 9th clock pulse. If there are pending errors, such as receive buffer overflow, client
hardware automatically generates a NACK condition, sets NACKIF, and the module goes Idle. If I2CxCNT is
nonzero (I2CxCNT != 0), client hardware transmits the value of ACKDT as the acknowledgement response to
the host. It is up to software to configure ACKDT appropriately. In most cases, the ACKDT bit must be clear
(ACKDT = 0) so that the host receives an ACK response (logic low level on SDA during the 9th clock pulse).
If I2CxCNT is zero (I2CxCNT = 0), client hardware transmits the value of the Acknowledge End of Count
(ACKCNT) bit as the Acknowledgement response, rather than the value of ACKDT. It is up to software to
configure ACKCNT appropriately. In most cases, ACKCNT must be set (ACKCNT = 1), which represents
a NACK condition. When host hardware detects a NACK on the bus, it will generate a Stop condition. If
ACKCNT is clear (ACKCNT = 0), an ACK will be issued, and host hardware will not issue a Stop condition.
10. Upon the 9th falling edge of SCL, the ACKTIF bit is set. If ACKTIE is also set, the generic I2CxIF is set,
and if CSD is clear, client hardware sets CSTR and stretches the clock. This allows time for software to read
I2CxRXB. Once complete, software must clear both CSTR and ACKTIF to release the clock and continue
communication.
11. Repeat steps 6 -10 until the host has transmitted all the data (I2CxCNT = 0), or until the host issues a Stop or
Restart condition.
Figure 37-16. 7-Bit Client Mode Reception (No Clock Stretching) rotatethispage90
SDA A7 A6 A5 A4 A3 A2 A1 0 D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Hardware sets
Matching received NACKIF
I2CxRXIF set,
address loaded Software reads
data byte
into I2CxADB0 I2CxRXB, clearing
transferred to
RXBF I2CxRXB I2CxRXIF
Hardware copies
Hardware clears D
bit, last byte was
PIC18F26/46/56Q83
D address Hardware sets D
bit, last byte was Hardware sets
data CNTIF
SDA A7 A6 A5 A4 A3 A2 A1 0 D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Matching received
address loaded into
I2CxADB0
ADRIF
CSTR
I2CxRXIF set,
Software reads
data byte
PIC18F26/46/56Q83
I2CxCNT 0x02 0x01 0x00
Hardware sets
CNTIF
DS40002253C-page 705
CNTIF
and its subsidiaries
© 2020-2022 Microchip Technology Inc.
SDA A7 A6 A5 A4 A3 A2 A1 0 D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Matching received
I2CxRXIF set,
address loaded Software reads
data byte
into I2CxADB0 I2CxRXB, clearing
transferred to
RXBF I2CxRXB I2CxRXIF
Hardware sets
PIC18F26/46/56Q83
CNTIF
ACKDT value
Start R/W copied to SDA ACKCNT value Stop
copied to SDA
SDA A7 A6 A5 A4 A3 A2 A1 0 D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Matching received
address loaded
into I2CxADB0
WRIF
Hardware sets Software clears
CSTR and WRIF CSTR and WRIF
Datasheet
CSTR
I2CxRXIF set,
data byte Software reads
PIC18F26/46/56Q83
I2CxCNT 0x02 0x01 0x00
Hardware sets
CNTIF
DS40002253C-page 707
CNTIF
PIC18F26/46/56Q83
I2C - Inter-Integrated Circuit Module
Important: Regardless of whether the Address Interrupt and Hold Enable (ADRIE) bit is set, clock
stretching does not occur when the R/W bit is clear in 10-bit Addressing modes.
4. The host device transmits the 9th clock pulse, and client hardware transfers the value of the ACKDT bit
onto the SDA line. If there are pending errors, such as a receive buffer overflow (RXO = 1), client hardware
generates a NACK and the module goes Idle.
5. The host device transmits the low address byte. If the client is configured in 10-bit Addressing mode
(no masking), the received low address byte is compared to the values in I2CxADR0 and I2CxADR2. In
10-bit Addressing with Masking mode, the received low address byte is compared to the masked value of
I2CxADR0.
If a match occurs:
– The Client Mode Active (SMA) bit is set by module hardware.
– ADRIF is set. If ADRIE is set, and the Clock Stretching Disable (CSD) bit is clear, hardware sets the
Client Clock Stretching (CSTR) bit and the generic I2CxIF bit. This allows time for the client to read either
I2CxADB0 or I2CxRXB and selectively ACK/NACK based on the received address. When the client has
finished processing the address, software must clear CSTR to resume operation.
– The matching received address is loaded into either the I2CxADB0 register or into the I2CxRXB register
as determined by the ABD bit. When ABD is clear (ABD = 0), the matching address is copied to
I2CxADB0. When ABD is set (ABD = 1), the matching address is copied to I2CxRXB, which also sets
RXBF and I2CxRXIF. I2CxRXIF is a read-only bit, and must be cleared by either reading I2CxRXB or by
setting the Clear Buffer (CLRBF) bit (CLRBF = 1).
If no match occurs, the module goes Idle.
6. The host device transmits the 9th clock pulse, and client hardware transfers the value of the ACKDT bit
onto the SDA line. If there are pending errors, such as a receive buffer overflow (RXO = 1), client hardware
generates a NACK and the module goes Idle.
7. After the 9th falling edge of SCL, the Acknowledge Status Time Interrupt Flag (ACKTIF) bit is set. If the
Acknowledge Time Interrupt and Hold Enable (ACKTIE) bit is also set, the generic I2CxIF is set, and if client
hardware generated an ACK, the CSTR bit is also set and the clock is stretched (when CSD = 0). If a NACK
was generated, the CSTR bit remains unchanged. Once completed, software must clear CSTR and ACKTIF to
release the clock and resume operation.
8. Host hardware issues a Restart condition (cannot be a Start condition), and once the client detects the
Restart, hardware sets the Restart Condition Interrupt Flag (RSCIF). If the Restart Condition Interrupt Enable
(RSCIE) bit is also set, the generic I2CxIF is also set.
9. Host hardware transmits the client’s high address byte with R/W set.
If the received high address byte matches:
– The R/W bit value is copied to the R bit.
– The SMA bit is set.
– The D bit is cleared, indicating the last byte as an address.
– ADRIF is set. If ADRIE is set, and the CSD bit is clear, hardware sets CSTR and the generic I2CxIF bit.
This allows time for the client to read either I2CxADB1 or I2CxRXB and selectively ACK/NACK based on
the received address. When the client has finished processing the address, software must clear CSTR to
resume operation.
– The matching received address is loaded into either the I2CxADB1 register or into the I2CxRXB register
as determined by the ABD bit. When ABD is clear (ABD = 0), the matching address is copied to
I2CxADB1. When ABD is set (ABD = 1), the matching address is copied to I2CxRXB, which also sets
RXBF and I2CxRXIF. I2CxRXIF is a read-only bit, and must be cleared by either reading I2CxRXB or by
setting CLRBF (CLRBF = 1).
If the address does not match, the module goes Idle.
10. If the Transmit Buffer Empty Status (TXBE) bit is set (TXBE = 1), I2CxCNT has a nonzero value (I2CxCNT !=
0), and the I2C Transmit Interrupt Flag (I2CxTXIF) is set (I2CxTXIF = 1), client hardware sets CSTR, stretches
the clock (when CSD = 0), and waits for software to load I2CxTXB with data. I2CxTXB must be loaded to clear
I2CxTXIF. Once data is loaded into I2CxTXB, hardware automatically clears CSTR to resume communication.
11. The host device transmits the 9th clock pulse, and client hardware transfers the value of the ACKDT bit onto
the SDA line. If there are pending errors, such as a receive overflow (RXO = 1), client hardware automatically
generates a NACK condition. NACKIF is set, and the module goes Idle.
12. Upon the 9th falling SCL edge, the data byte in I2CxTXB is transferred to the transmit shift register, and
I2CxCNT is decremented by one. Additionally, the ACKTIF bit is set. If the ACKTIE bit is also set, the generic
I2CxIF is set, and if client hardware generated an ACK, the CSTR bit is also set and the clock is stretched
(when CSD = 0). If a NACK was generated, the CSTR bit remains unchanged. Once complete, software must
clear CSTR and ACKTIF to release the clock and continue operation.
13. If the client generated an ACK and I2CxCNT is nonzero, host hardware transmits eight clock pulses, and client
hardware begins to shift the data byte out of the shift register starting with the Most Significant bit (MSb).
14. After the 8th falling edge of SCL, client hardware checks the status of TXBE and I2CxCNT. If TXBE is set and
I2CxCNT has a nonzero count value, hardware sets CSTR and the clock is stretched (when CSD = 0) until
software loads I2CxTXB with new data. Once I2CxTXB has been loaded, hardware clears CSTR to resume
communication.
15. Once the host hardware clocks in all eight data bits, it transmits the 9th clock pulse along with the ACK/
NACK response back to the client. Client hardware copies the ACK/NACK value to the Acknowledge Status
(ACKSTAT) bit and sets ACKTIF. If ACKTIE is also set, client hardware sets the generic I2CxIF bit and CSTR,
and stretches the clock (when CSD = 0). Software must clear CSTR to resume operation.
16. After the 9th falling edge of SCL, data currently loaded in I2CxTXB is transferred to the transmit shift register,
setting both TXBE and I2CxTXIF. I2CxCNT is decremented by one. If I2CxCNT is zero (I2CxCNT = 0), CNTIF
is set.
17. If I2CxCNT is nonzero and the host issued an ACK on the last byte (ACKSTAT = 0), the host transmits eight
clock pulses, and client hardware begins to shift data out of the shift register.
18. Repeat Steps 13-17 until the host has received all the requested data (I2CxCNT = 0). Once all data is
received, host hardware transmits a NACK condition, followed by either a Stop or Restart condition. Once the
NACK has been received by the client, hardware sets NACKIF and clears SMA. If the NACK Detect Interrupt
Enable (NACKIE) bit is also set, the generic I2C Error Interrupt Flag (I2CxEIF) is set. If the host issued a Stop
condition, client hardware sets the Stop Condition Interrupt Flag (PCIF). If the host issued a Restart condition,
client hardware sets the Restart Condition Interrupt Flag (RSCIF) bit. If the associated interrupt enable bits are
also set, the generic I2CxIF is also set.
NACK
R/W Restart R/W (from Stop
ACK (from client)
host )
SDA 1 1 1 1 0 A9 A8 0 A7 A6 A5 A4 A3 A2 A1 A0 1 1 1 1 0 A9 A8 1 D7 D6 D5 D4 D3 D2 D1 D0
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Hardware clears D
D bit for address bytes
Hardware sets D
PIC18F26/46/56Q83
Host's NACK
copied to
ACKSTAT ACKSTAT
of SCL. This allows time for the client to read I2CxRXB, which clears RXBF and I2CxRXIF, and prevents
a receive buffer overflow. Once I2CxRXB has been read, RXBF and I2CxRXIF are cleared, and hardware
releases SCL.
10. Host hardware transmits the 8th bit of the current data byte into the client receive shift register. Client
hardware then transfers the complete byte into I2CxRXB on the 8th falling edge of SCL, and sets the following
bits:
– I2CxRXIF
– I2CxIF
– Data Write Interrupt Flag (WRIF)
– Data (D)
– RXBF
I2CxCNT is decremented by one. If the Data Write Interrupt and Hold Enable (WRIE) bit is set (WRIE =
1), hardware sets CSTR (when CSD = 0) and stretches the clock, allowing time for client software to read
I2CxRXB and determine the state of the ACKDT bit that is transmitted back to the host. Once the client
determines the Acknowledgement response, software clears CSTR to allow further communication.
11. Upon the 9th falling edge of SCL, the ACKTIF bit is set. If ACKTIE is also set, the generic I2CxIF is set,
and if CSD is clear, client hardware sets CSTR and stretches the clock. This allows time for software to read
I2CxRXB. Once complete, software must clear both CSTR and ACKTIF to release the clock and continue
communication.
12. Repeat Steps 8 – 11 until the host has transmitted all the data (I2CxCNT = 0), or until the host issues a Stop or
Restart condition.
SDA 1 1 1 1 0 A9 A8 0 A7 A6 A5 A4 A3 A2 A1 A0 D7 D6 D5 D4 D3 D2 D1 D0
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Hardware sets
Matching received Matching received I2CxRXIF set, NACKIF
High address loaded Low address loaded data byte
into I2CxADB1 into I2CxADB0 transferred to
RXBF I2CxRXB
Hardware copies
R R/W value to R bit
PIC18F26/46/56Q83
I2CxCNT 0x01 0x00
DS40002253C-page 714
PIC18F26/46/56Q83
I2C - Inter-Integrated Circuit Module
S
T
S A6 A5 A4 A3 A2 A1 A0 1 A D7 D6 D5 D4 D3 D2 D1 D0 N O
P
Figure 37-24. 7-Bit Host Read Diagram (from a specific memory/register location)
S
R T
S A6 A5 A4 A3 A2 A1 A0 0 A RA7 RA6 RA5 RA4 RA3 RA2 RA1 RA0 A A6 A5 A4 A3 A2 A1 A0 1 A D7 D6 D5 D4 D3 D2 D1 D0 N O
S P
Restart
Address R/W condition Address R/W
high byte high byte
S
R T
S 1 1 1 1 0 A9 A8 0 A A7 A6 A5 A4 A3 A2 A1 A0 A 1 1 1 1 0 A9 A8 1 A D7 D6 D5 D4 D3 D2 D1 D0 N O
S P
S A6 A5 A4 A3 A2 A1 A0 0 A D7 D6 D5 D4 D3 D2 D1 D0 N
T
O
P
Figure 37-27. 7-Bit Host Write Diagram (to a specific memory/register location)
S
T
S A6 A5 A4 A3 A2 A1 A0 0 A RA7RA6RA5 RA4 RA3RA2 RA1RA0 A D7 D6 D5 D4 D3 D2 D1 D0 N O
P
Address R/W
high byte
S
T
S 1 1 1 1 0 A9 A8 0 A A7 A6 A5 A4 A3 A2 A1 A0 A D7 D6 D5 D4 D3 D2 D1 D0 N O
P
PIC18F26/46/56Q83
I2C - Inter-Integrated Circuit Module
CLK[4:0]
11111
10111 I2CxBAUD FME
10110
FPRECLK = FSCL
. 1
. I2CxCLK
. (BAUD + 1) 0
00010
00001
00000
I2CxCLK contains several clock source selections. The clock source selections typically include variants of the
system clock and timer resources.
Important: When using a timer as the clock source, the timer must also be configured. Additionally,
when using the HFINTOSC as a clock source, it is important to understand that the HFINTOSC frequency
selected by the OSCFRQ register is used as the clock source. The clock divider selected by the NDIV bits
is not used. For example, if OSCFRQ selects 4 MHz as the HFINTOSC clock frequency, and the NDIV
bits select a divide by four scaling factor, the I2C Clock Frequency will be 4 MHz and not 1 MHz since the
divider is ignored.
I2CxBAUD is used to determine the prescaler (clock divider) for the I2CxCLK source.
The FME bit acts as a secondary divider to the prescaled clock source.
When FME is clear (FME = 0), one SCL period (TSCL) is equal to five clock periods of the prescaled I2CxCLK source.
In other words, the prescaled I2CxCLK source is divided by five. For example, if the HFINTOSC (set to 4 MHz) clock
source is selected, I2CxBAUD is loaded with a value of ‘7’, and the FME bit is clear, the actual SCL frequency is 100
kHz (see the equation below).
Equation 37-1. SCL Frequency (FME = 0)
Example:
• I2CxCLK: HFINTOSC (4 MHz)
• I2CxBAUD: 7
• FME: FME = 0
fI2CxCLK
4 MHz
BAUD + 1 8
fSCL = = = 100 kHz
FME 5
When FME is clear, host hardware uses the first prescaled I2CxCLK source period to drive SCL low (see Figure
37-30). During the second period, hardware verifies that SCL is in fact low. During the third period, hardware releases
SCL, allowing it to float high. Host hardware then uses the fourth and fifth periods to sample SCL to verify that SCL
is high. If a client is holding SCL low (clock stretch) during the fourth and/or fifth period, host hardware samples each
successive prescaled I2CxCLK period until a high level is detected on SCL. Once the high level is detected, host
hardware samples SCL during the next two I2CxCLK periods to verify that SCL is high.
I2C
Prescaled
Clock 1 2 3 4 5 1 2 3 4 5 1 2
TSCL TSCL
SCL
Host samples
Host samples SCL to SCL to ensure Host samples SCL to Host samples Host must
ensure SCL is low ensure SCL is low SCL for high detect SCL
SCL is high
high twice
When FME is set (FME = 1), one SCL period (TSCL) is equal to four clock periods of the prescaled I2CxCLK source.
In other words, the prescaled I2CxCLK source is divided by four. Using the example from above, if the HFINTOSC
(4 MHz) clock source is selected, I2CxBAUD is loaded with a value of ‘7’, and the FME bit is set, the actual SCL
frequency is 125 kHz (see the equation below).
Equation 37-2. SCL Frequency (FME = 1)
Example:
• I2CxCLK: HFINTOSC (4 MHz)
• I2CxBAUD: 7
• FME: FME = 1
fI2CxCLK
4 MHz
BAUD + 1 8
fSCL = = = 125 kHz
FME 4
Filename: FME = 1.vsdx
WhenTitle:
FME is set, host hardware uses the first prescaled I2CxCLK source period to drive SCL low (see Figure
Last Edit: 7/30/2019
37-31).
FirstDuring
Used: the second prescaled period, hardware verifies that SCL is in fact low. During the third period,
hardware releases SCL, allowing it to float high. Host hardware then uses the fourth period to sample SCL to verify
Notes:
that SCL is high. If a client is holding SCL low (clock stretch) during the fourth period, host hardware samples each
successive prescaled I2CxCLK period until a high level is detected on SCL. Once the high level is detected, host
hardware samples SCL during the next period to verify that SCL is high.
Figure 37-31. SCL Timing (FME = 1) Rev. FME = 1.v s
7/30/2019
I2C
Prescaled
Clock 1 2 3 4 1 2 3 4 1 2 3 4
TSCL TSCL TSCL
SCL
Host samples SCL to Host samples Host samples SCL to Host samples SCL Host must
ensure SCL is low SCL to ensure SCL is low for high detect SCL
ensure SCL is high
high
BFRE = 1
SCIF = 1
Start condition
Write to START (S) bit asserted
tHD:DAT(2)
SDA
SCL tHD:STA(1)
BFRET = 00
(8 - I2C Clock Pulses)
Completion of Start
If ABD = 0: Hardware loads I2C Shift
register from I2CxADB0/1
If ABD = 1: Hardware loads I2C Shift
register with I2CxTXB
Important:
1. See the device data sheet for Start condition hold time parameters.
2. SDA hold times are configured via the SDAHT bits.
SDA D1 D0 ACK
ACK Complete
SCL 7 8 9
Software/DMA
I2CxCNT = 1 reads I2CxRXB,
Filename: NACK Sequence Timing.vsdx
RXBF
Title:
I2CxRXIF = 1 clearing I2CxRXIF
Last Edit: 1/10/2019 and RXBF
First Used:
Notes:
I2CxCLK 4 1 2 3 4 1 2 3 4 1
SDA D1 D0 NACK
NACK Complete
SCL 7 8 9
CNTIF = 1
I2CxCNT = 0
I2CxRXIF = 1 Software/DMA
RXBF
reads I2CxRXB,
clearing I2CxRXIF
and RXBF
I2CxCLK 4 1 2 3 4 1 2 3 4 1
Begin NACK
sequence
Once the Restart condition is detected on the bus, the Restart Condition Interrupt Flag (RSCIF) is set by hardware,
and if the Restart Condition Interrupt Enable (RSCIE) bit is set, the generic I2CxIF is also set.
Figure 37-35. Restart Condition Timing
Hardware Completion of
Write to Start (S) samples SDA Repeated Start
bit
SDA
I2CxCLK 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2
Repeated Start
Host releases Host releases condition detected
SDA SCL RSCIF = 1
Important:
1. See the device data sheet for Restart condition setup times.
Important: At least one SCL low period must appear before a Stop condition is valid. If the SDA line
transitions low, then high again, while SCL is high, the Stop condition is ignored, and a Start condition will
be detected by the receiver.
Stop detected
Stop condition PCIF = 1
begins
TSU:STO(2)
SDA D0 NACK
THD:STO(2)
TSCL/2(1)
SCL 8 9
NACK SEQUENCE
I2CxCLK 1 2 3 4 1 2 3 4 1 2 3 4 1 2
Important:
1. At least one SCL low period must appear before a Stop is valid.
2. See the device data sheet Electrical Specifications for Stop condition setup and hold times.
4. If upon the 8th falling edge of SCL, I2CxTXB is empty (Transmit Buffer Empty Status (TXBE) = 1), I2CxCNT is
nonzero (I2CxCNT != 0), and the Clock Stretching Disable (CSD) bit is clear (CSD = 0):
– The I2C Transmit Interrupt Flag (I2CxTXIF) is set. If the I2C Transmit Interrupt Enable (I2CxTXIE) bit is
also set, the generic I2CxIF is also set.
– The Host Data Request (MDR) bit is set, and the clock is stretched, allowing time for software to load
I2CxTXB with new data. Once I2CxTXB has been written, hardware releases SCL and clears MDR.
5. Hardware transmits the 9th clock pulse and waits for an ACK/NACK response from the client. If the host
receives an ACK, module hardware transfers the data from I2CxTXB into the transmit shift register, and
I2CxCNT is decremented by one. If the host receives a NACK, hardware will attempt to issue a Stop condition.
If the clock is currently being stretched by a client, the host must wait until the bus is free before issuing the
Stop.
6. Host hardware checks I2CxCNT for a zero value. If I2CxCNT is zero:
a. If ABD is clear (ABD = 0), host hardware issues a Stop condition, or sets MDR if the Restart Enable
(RSEN) bit is set and waits for software to set the Start bit to issue a Restart condition. CNTIF is set.
b. If ABD is set (ABD = 1), host hardware issues a Stop condition, or sets MDR if RSEN is set and waits for
software to load I2CxTXB with a new client address. CNTIF is set.
7. Host hardware transmits the data byte.
8. If upon the 8th falling edge of SCL I2CxTXB is empty (TXBE = 1), I2CxCNT is nonzero (I2CxCNT != 0), and
CSD is clear (CSD = 0):
– I2CxTXIF is set. If the I2CxTXIE bit is also set, the generic I2CxIF is also set.
– The MDR bit is set, and the clock is stretched, allowing time for software to load I2CxTXB with new data.
Once I2CxTXB has been written, hardware releases SCL and clears MDR.
If TXBE is set (TXBE = 1) and I2CxCNT is zero (I2CxCNT = 0):
– I2CxTXIF is NOT set.
– CNTIF is set.
– Host hardware issues a Stop condition, setting PCIF.
9. Repeat Steps 5 – 8 until all data has been transmitted.
SDA A7 A6 A5 A4 A3 A2 A1 0 D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
7-bit address
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Hardware clears
MMA
MMA Hardware sets MMA
on detection of Start
Hardware sets
CNTIF;
RSTEN = 0, so
Client's ACK copied host issues
Datasheet
PIC18F26/46/56Q83
loads data into I2CxTXB
TXBE
I2CxTXIF set, Software loads data into
data byte transferred to shift register I2CxTXB, clearing I2CxTXIF
DS40002253C-page 725
PIC18F26/46/56Q83
I2C - Inter-Integrated Circuit Module
SDA A7 A6 A5 A4 A3 A2 A1 1 D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Hardware clears
MMA
MMA Hardware sets MMA
on detection of Start
Hardware sets
CNTIF;
RSTEN = 0, so
Host's ACK host issues
Datasheet
PIC18F26/46/56Q83
I2CxCNT 0x02 0x01 0x00
High address
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Hardware clears
MMA Hardware sets MMA
on detection of Start
MMA
Hardware sets
CNTIF;
RSTEN = 0, so
Client's ACK copied
host issues
ACKSTAT
Datasheet
to ACKSTAT
Stop
PIC18F26/46/56Q83
Before Start, software
TXBE loads data into I2CxTXB Data byte transferred to shift register,
I2CxTXIF NOT set
DS40002253C-page 730
PIC18F26/46/56Q83
I2C - Inter-Integrated Circuit Module
14. If previous data is currently in I2CxRXB (RXBF = 1) when the first seven bits are received by the receive shift
register, hardware sets MDR, and the clock is stretched after the 7th falling edge of SCL. This allows software
to read I2CxRXB, which clears the RXBF bit, and prevents a receive buffer overflow. Once the RXBF bit is
cleared, hardware releases SCL.
15. Host hardware clocks in the 8th bit of the data byte into the receive shift register, then transfers the complete
byte into I2CxRXB, which sets the I2CxRXIF and RXBF bits. If I2CxRXIE is also set, hardware sets the
generic I2CxIF bit. I2CxCNT is decremented by one.
16. Hardware checks I2CxCNT for a zero value.
If I2CxCNT is nonzero (I2CxCNT != 0), hardware transmits the value of the Acknowledge Data (ACKDT) bit as
the acknowledgement response to the client. It is up to user software to properly configure ACKDT. In most
cases, ACKDT must be clear (ACKDT = 0), which indicates an ACK response.
If I2CxCNT is zero (I2CxCNT = 0), hardware transmits the value of the Acknowledge End of Count (ACKCNT)
bit as the acknowledgement response to the client. CNTIF is set, and host hardware either issues a Stop
condition or a Restart condition. It is up to user software to properly configure ACKCNT. In most cases,
ACKCNT must be set (ACKCNT = 1), which indicates a NACK response. When hardware detects a NACK on
the bus, it automatically issues a Stop condition. If a NACK is not detected, the Stop will not be generated,
which may lead to a stalled Bus condition.
17. Host hardware receives the first seven bits of the next data byte into the receive shift register.
18. Repeat Steps 14 – 17 until all expected bytes have been received.
NACK
R/W Restart R/W (from Stop
ACK (from client) host )
SDA
1 1 1 1 0 A9 A8 0 A7 A6 A5 A4 A3 A2 A1 A0 1 1 1 1 0 A9 A8 1 D7 D6 D5 D4 D3 D2 D1 D0
MMA
Hardware sets MMA
on detection of Start
Hardware sets
NACKIF,
Hardware sets Software sets Start, CNTIF
MDR MDR, wait for Start clearing MDR
Datasheet
PIC18F26/46/56Q83
ACKSTAT
Client's ACK copied
to ACKSTAT
Received data
DS40002253C-page 733
transferred to
I2CxRXB, I2CxRXIF
RXBF is set
PIC18F26/46/56Q83
I2C - Inter-Integrated Circuit Module
Important: Client hardware has priority over host hardware in Multi-Host mode. Host mode
communication can only be initiated when SMA = 0.
Important: The I2C Specification does not require the SCL signal to have a 50% duty cycle. In other
words, one host’s clock signal may have a low time that is 60% of the SCL period and a high time that is
40% of the SCL period, while another host may be 50/50. This creates a timing difference between the two
clock signals, which may result in data loss.
Wait state
Host 1
SCL
Host 2
SCL
Actual bus
SCL
attempting to address the ‘losing’ host as a client. In this case, the host that lost arbitration must switch to its Client
mode and check to see if an address matches.
Filename: Bus Collision.vsdx
Title: Important: The I2C Specification states that a bus collision cannot occur during a Start condition. If a
Last Edit: 1/9/2019
First Used: collision occurs during a Start, BCLIF will be set during the addressing phase.
Notes:
Start Stop
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
R/W
ACK (from client)
SDA
1 1 1 Host 2 loses arbitration, hardware releases SDA
(Host 2 )
CNTIF;
RSTEN = 0, so
host issues
MMA Host 2 loses arbitration, hardware clears MMA Stop
Host 2 loses arbitration, hardware sets BCLIF (software must clear BCLIF to
BCLIF
resume communication)
PIC18F26/46/56Q83
Client's ACK copied
ACKSTAT to ACKSTAT
DS40002253C-page 737
37.5.1 I2CxCON0
Name: I2CxCON0
Offset: 0x0294
Bit 7 6 5 4 3 2 1 0
EN RSEN S CSTR MDR MODE[2:0]
Access R/W R/W R/W/HS/HC R/C/HS/HC R R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. SDA and SCL pins must be configured as open-drain I/Os and use either internal or external pull-up resistors.
2. SDA and SCL signals must configure both the input and output PPS registers for each signal.
3. CSTR can be set by multiple hardware sources; all sources must be addressed by user software before the
SCL line can be released.
4. SMA is set on the same SCL edge as CSTR for a matching received address.
5. In this mode, ADRIE needs to be set, allowing an interrupt to clear the BCLIF condition and the ACK of a
matching address.
6. In 10-bit Client mode (when ABD = 1), CSTR will be set when the high address has not been read from
I2CxRXB before the low address is shifted in.
37.5.2 I2CxCON1
Name: I2CxCON1
Offset: 0x0295
Bit 7 6 5 4 3 2 1 0
ACKCNT ACKDT ACKSTAT ACKT P RXO TXU CSD
Access R/W R/W R R R/S/HC R/W/HS R/W/HS R/W
Reset 0 0 0 0 0 0 0 0
Bit 2 – RXO Receive Overflow Status (used only when MODE = 0xx or MODE = 11x)(3)
Value Description
1 Set when SMA = 1 and a host receives data when RXBF = 1
0 No client receive Overflow condition
Bit 1 – TXU Transmit Underflow Status (used only when MODE = 0xx or MODE = 11x)(3)
Value Description
1 Set when SMA = 1 and a host transmits data when TXBE = 1
0 No client transmit Underflow condition
Bit 0 – CSD Clock Stretching Disable (used only when MODE = 0xx or MODE = 11x)
Value Description
1 When SMA = 1, the CSTR bit will not be set
0 Client clock stretching proceeds normally
Notes:
1. Software writes to ACKDT must be followed by a minimum SDA setup time before clearing CSTR.
2. A NACK may still be generated by hardware when bus errors are present as indicated by the I2CxSTAT1 or
I2CxERR registers.
3. This bit can only be set when CSD = 1.
4. If SCL is high (SCL = 1) when this bit is set, the current clock pulse will complete (SCL = 0) with the proper
SCL/SDA timing required for a valid Stop condition; any data in the transmit or receive shift registers will be
lost.
37.5.3 I2CxCON2
Name: I2CxCON2
Offset: 0x0296
Bit 7 6 5 4 3 2 1 0
ACNT GCEN FME ABD SDAHT[1:0] BFRET[1:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 6 – GCEN General Call Address Enable (used when MODE = 00x or MODE = 11x)
Value Description
1 General Call Address (0x00) causes an address match event
0 General Call Addressing is disabled
37.5.4 I2CxSTAT0
Name: I2CxSTAT0
Offset: 0x0298
Bit 7 6 5 4 3 2 1 0
BFRE SMA MMA R D
Access R R R R R
Reset 0 0 0 0 0
Bit 3 – D Data
Value Description
1 Indicates that the last byte received or transmitted was data
0 Indicates that the last byte received or transmitted was an address
Notes:
1. This bit holds the R/W bit information following the last received address match. Addresses transmitted by the
host do not affect the host’s R bit, and addresses appearing on the bus without a match do not affect the R bit.
2. I2CxCLK must have a valid clock source selected for this bit to function.
37.5.5 I2CxSTAT1
Name: I2CxSTAT1
Offset: 0x0299
Bit 7 6 5 4 3 2 1 0
TXWE TXBE RXRE CLRBF RXBF
Access R/W/HS R R/W/HS R/S R
Reset 0 1 0 0 0
Notes:
1. This bit, when set, will cause a NACK to be issued.
2. Used as a trigger source for DMA operations.
3. This bit is special function; it can only be set by user software and always reads ‘0’.
37.5.6 I2CxPIR
Name: I2CxPIR
Offset: 0x029A
Bit 7 6 5 4 3 2 1 0
CNTIF ACKTIF WRIF ADRIF PCIF RSCIF SCIF
Access R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS
Reset 0 0 0 0 0 0 0
Bit 6 – ACKTIF Acknowledge Status Time Interrupt Flag (used only when MODE = 0xx or MODE = 11x)(1,2)
Value Description
1 Acknowledge sequence detected, set on the 9th falling SCL edge for any byte when addressed as a
client
0 Acknowledge sequence not detected
Bit 4 – WRIF Data Write Interrupt Flag (used only when MODE = 0xx or MODE = 11x)(1)
Value Description
1 Data byte detected, set on the 8th falling SCL edge for a received data byte
0 Data byte not detected
Bit 3 – ADRIF Address Interrupt Flag (used only when MODE = 0xx or MODE = 11x)(1)
Value Description
1 Address detected, set on the 8th falling SCL edge for a matching received address byte
0 Address not detected
Notes:
1. Enabled interrupt flags are OR’ed to produce the PIRx[I2CxIF] bit.
2. ACKTIF is not set by a matching 10-bit high address byte with the R/W bit clear. It is only set after the
matching low address byte is shifted in.
37.5.7 I2CxPIE
Name: I2CxPIE
Offset: 0x029B
Bit 7 6 5 4 3 2 1 0
CNTIE ACKTIE WRIE ADRIE PCIE RSCIE SCIE
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
Notes:
1. Enabled interrupt flags are OR’ed to produce the PIRx[I2CxIF] bit.
2. When ACKTIE is set (ACKTIE = 1) and ACKTIF becomes set (ACKTIF = 1), if an ACK is generated, CSTR is
also set. If a NACK is generated, CSTR remains unchanged.
3. When WRIE is set (WRIE = 1) and WRIF becomes set (WRIF = 1), CSTR is also set.
4. When ADRIE is set (ADRIE = 1) and ADRIF becomes set (ADRIF = 1), CSTR is also set.
37.5.8 I2CxERR
Name: I2CxERR
Offset: 0x0297
Bit 7 6 5 4 3 2 1 0
BTOIF BCLIF NACKIF BTOIE BLCIE NACKIE
Access R/W/HS R/W/HS R/W/HS R/W R/W R/W
Reset 0 0 0 0 0 0
Notes:
1. Enabled error interrupt flags are OR’ed to produce the PIRx[I2CxEIF] bit.
2. User software must select the bus time-out source in the I2CxBTOC register.
3. NACKIF is also set when any of the TXWE, RXRE, TXU, or RXO bits are set.
4. NACKIF is not set for the NACK response to a nonmatching client address.
37.5.9 I2CxCLK
Name: I2CxCLK
Offset: 0x029E
Bit 7 6 5 4 3 2 1 0
CLK[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
CLK Selection
11000-11111 Reserved
10111 CLC8_out
10110 CLC7_out
10101 CLC6_out
10100 CLC5_out
10011 CLC4_out
10010 CLC3_out
10001 CLC2_out
10000 CLC1_out
01111 SMT1 overflow
01100-01110 Reserved
01011 TU16B_out
01010 TU16A_out
01001 TMR6 post scaled output
01000 TMR4 post scaled output
00111 TMR2 post scaled output
00110 TMR0 overflow
00101 EXTOSC
00100 Clock Reference output
00011 MFINTOSC (500 kHz)
00010 HFINTOSC
00001 FOSC
00000 FOSC/4
37.5.10 I2CxBAUD
Name: I2CxBAUD
Offset: 0x029D
Bit 7 6 5 4 3 2 1 0
BAUD[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Note: It is recommended to write this register only when the module is Idle (MMA = 0 or SMA = 0), or when the
module is clock stretching (CSTR = 1 or MDR = 1).
37.5.11 I2CxCNT
Name: I2CxCNT
Offset: 0x028C
Bit 15 14 13 12 11 10 9 8
CNT[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
CNT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. It is recommended to write this register only when the module is Idle (MMA = 0 or SMA = 0), or when the
module is clock stretching (CSTR = 1 or MDR = 1).
2. CNTIF is set on the 9th falling SCL edge when I2CxCNT = 0.
37.5.12 I2CxBTO
Name: I2CxBTO
Offset: 0x029C
Bit 7 6 5 4 3 2 1 0
TOREC TOBY32 TOTIME[5:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. It is recommended to write this register only when the module is Idle (MMA = 0 or SMA = 0), or when the
module is clock stretching (CSTR = 1 or MDR = 1).
2. When TOBY32 is set (TOBY32 = 1) and the LFINTOSC, MFINTOSC, or SOSC is selected as the BTO clock
source, the time-out time (TOTIME) will be approximately in milliseconds.
37.5.13 I2CxBTOC
Name: I2CxBTOC
Offset: 0x029F
Bit 7 6 5 4 3 2 1 0
BTOC[3:0]
Access R/W R/W R/W R/W
Reset 0 0 0 0
BTOC Selection
1111 - 1001 Reserved
1000 SOSC
0111 MFINTOSC (32 kHz)
0110 LFINTOSC
0101 TU16B_out
0100 TU16A_out
0011 TMR6_postscaled
0010 TMR4_postscaled
0001 TMR2_postscaled
0000 Reserved
37.5.14 [I2CxADB0]
Name: I2CxADB0
Offset: 0x028E
Bit 7 6 5 4 3 2 1 0
ADB[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Note:
1. This register is read-only except in Host 10-bit Address mode (MODE = 101).
37.5.15 I2CxADB1
Name: I2CxADB1
Offset: 0x028F
Bit 7 6 5 4 3 2 1 0
ADB[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Note:
1. This register is read-only in 7-bit Client Address modes (MODE = 0xx).
37.5.16 I2CxADR0
Name: I2CxADR0
Offset: 0x0290
Bit 7 6 5 4 3 2 1 0
ADR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
37.5.17 I2CxADR1
Name: I2CxADR1
Offset: 0x0291
Bit 7 6 5 4 3 2 1 0
ADR[6:0]
Access R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1
Note:
1. The ‘11110’ bit pattern used in the 10-bit address high byte is defined by the I2C Specification. It is up to the
user to define these bits. These bit values are compared to the received address by hardware to determine a
match. The bit pattern transmitted by the host must be the same as the client address’s bit pattern used for
comparison or a match will not occur.
37.5.18 I2CxADR2
Name: I2CxADR2
Offset: 0x0292
Bit 7 6 5 4 3 2 1 0
ADR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
37.5.19 I2CxADR3
Name: I2CxADR3
Offset: 0x0293
Bit 7 6 5 4 3 2 1 0
ADR[6:0]
Access R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1
Note:
1. The ‘11110’ bit pattern used in the 10-bit address high byte is defined by the I2C Specification. It is up to the
user to define these bits. These bit values are compared to the received address by hardware to determine a
match. The bit pattern transmitted by the host must be the same as the client address’s bit pattern used for
comparison or a match will not occur.
37.5.20 I2CxTXB
Name: I2CxTXB
Offset: 0x028B
Bit 7 6 5 4 3 2 1 0
TXB[7:0]
Access W W W W W W W W
Reset x x x x x x x x
Note: This register is write-only. Reading this register will return a value of 0x00.
37.5.21 I2CxRXB
Name: I2CxRXB
Offset: 0x028A
Bit 7 6 5 4 3 2 1 0
RXB[7:0]
Access R R R R R R R R
Reset x x x x x x x x
0x00
... Reserved
0x0289
0x028A I2C1RXB 7:0 RXB[7:0]
0x028B I2C1TXB 7:0 TXB[7:0]
7:0 CNT[7:0]
0x028C I2C1CNT
15:8 CNT[15:8]
0x028E I2C1ADB0 7:0 ADB[7:0]
0x028F I2C1ADB1 7:0 ADB[7:0]
0x0290 I2C1ADR0 7:0 ADR[7:0]
0x0291 I2C1ADR1 7:0 ADR[6:0]
0x0292 I2C1ADR2 7:0 ADR[7:0]
0x0293 I2C1ADR3 7:0 ADR[6:0]
0x0294 I2C1CON0 7:0 EN RSEN S CSTR MDR MODE[2:0]
0x0295 I2C1CON1 7:0 ACKCNT ACKDT ACKSTAT ACKT P RXO TXU CSD
0x0296 I2C1CON2 7:0 ACNT GCEN FME ABD SDAHT[1:0] BFRET[1:0]
0x0297 I2C1ERR 7:0 BTOIF BCLIF NACKIF BTOIE BLCIE NACKIE
0x0298 I2C1STAT0 7:0 BFRE SMA MMA R D
0x0299 I2C1STAT1 7:0 TXWE TXBE RXRE CLRBF RXBF
0x029A I2C1PIR 7:0 CNTIF ACKTIF WRIF ADRIF PCIF RSCIF SCIF
0x029B I2C1PIE 7:0 CNTIE ACKTIE WRIE ADRIE PCIE RSCIE SCIE
0x029C I2C1BTO 7:0 TOREC TOBY32 TOTIME[5:0]
0x029D I2C1BAUD 7:0 BAUD[7:0]
0x029E I2C1CLK 7:0 CLK[4:0]
0x029F I2C1BTOC 7:0 BTOC[3:0]
4. Each FIFO can be configured either as a transmit or receive FIFO. The FIFO control keeps track of the FIFO
head and tail and calculates the user address. In a TX FIFO, the user address points to the address in RAM
where the data for the next transmit message is stored. In an RX FIFO, the user address points to the address
in RAM where the data of the next receive message will be read. The user notifies the FIFO that a message is
written to or read from RAM by incrementing the head/tail of the FIFO.
5. The TXQ is a special transmit FIFO that transmits the messages, based on the ID of the messages stored in
the queue.
6. The TEF stores the message IDs of the transmitted messages.
7. A free-running Time Base Counter (TBC) is used to timestamp received messages. Messages in the TEF can
also be timestamped.
8. The CAN controller module generates interrupts when new messages are received or when messages are
transmitted successfully.
The CANRX input pin is selected with the CANRXPPS register. The CANTX output pin is selected with each pin’s
RxyPPS register.
Note: The CANRX pin defaults to pin RB3, but the CANTX has no default location and must be assigned to a pin
before CAN transmissions can occur.
In modes that enable the CANRX pin, the user must ensure that the appropriate TRIS bit for CANRX is set to
configure the pin as an input, and the associated ANSEL bit for that pin is cleared to enable the digital input buffer.
In addition, in modes that enable the CANTX pin, the appropriate TRIS bit for the associated pin must be cleared to
enable pin output.
CX TX TX Handler
Timestamping
TX Prioritization
Interrupt Control
CX RX RX Handler
Device RAM
The modes of operations can be grouped into four main groups: Configuration, Normal, Sleep and Debug (see Figure
38-2).
Loopback
Modes
Configuration
Mode
Sleep Mode
Clock Off
CxTX Recessive
Listen Only
Mode
RX Only
Normal TX Pin High
Mode TXREQ Ignored
RX and TX
c
SERRLOM = 1?
Protocol
Exception Event
No TX
Bus Off
Clear All TXREQx Restricted Operation
bits (Reset TX Mode
FIFOs/TXQ) RX
Debug Modes TX: Only ACK,
TXREQx Ignored
External/Internal
Loopback
Mode
Listen Only
Mode
Restricted
Operation
Mode
The CAN Protocol Module must be initialized before activation. This is only possible when the module is in
Configuration mode, OPMOD[2:0] = 100. The Configuration mode is requested by setting REQOP[2:0] = 100.
The CAN Protocol module will protect the user from accidentally violating the CAN protocol through programming
errors. The following registers and bit fields can only be programmed during Configuration mode:
• CxCON: WAKFIL, CLKSEL, PXEDIS, ISOCRECEN, TXQEN, STEF, SERRLOM, ESIGM, RTXAT
• CxNBTCFG, C1DBTCFG and C1TDC
• CxTXQCON: PLSIZE[2:0], FSIZE[4:0]
• CxFIFOCON: TXEN, RXTSEN, PLSIZE[2:0], FSIZE[4:0]
• CxTEFCON: TEFTSEN, FSIZE[4:0]
• CxFIFOBA
The CAN Protocol module is not allowed to enter Configuration mode during transmission or reception to prevent the
module from causing errors on the CAN bus. The following registers are Reset when exiting Configuration mode:
• CxTREC
• CxBDIAG0
• CxBDIAG1
In Configuration mode, FRESET is set in the CxFIFOCON, CxTXQCON, and CxTEFCON registers, and all FIFOs
and the TXQ are Reset.
38.3 Configuration
CAN bit times have four segments, as specified in ISO11898-1 (see Figure 38-3).
Synchronization Segment (SYNC) – Synchronizes the different nodes connected on the CAN bus. A bit edge is
expected to be within this segment. The Synchronization Segment is always one TQ.
Propagation Segment (PRSEG) – Compensates for the propagation delay on the bus. PRSEG has to be longer
than the maximum propagation delay.
Phase Segment 1 (PHSEG1) – Compensates for errors that may occur due to phase shifts in the edges. The time
segment may be automatically lengthened during resynchronization to compensate for the phase shift.
Phase Segment 2 (PHSEG2) – Compensates for errors that may occur due to phase shifts in the edges. The time
segment may be automatically shortened during resynchronization to compensate for the phase shift.
In the Bit Time registers, PRSEG and PHSEG1 are combined to create TSEG1. PHSEG2 is called TSEG2. Each
segment has multiple Time Quanta (TQ). The sample point lies between TSEG1 and TSEG2. Table 38-1 shows the
ranges for the bit time configuration parameters.
Figure 38-3. Partition of Bit Time
TBIT
SY
PRSEG PHSEG1 PHSEG2
NC
SY
TSEG1 TSEG2
NC
Sample Point
The total number of TQ in a bit time is programmable and can be calculated using Equation 38-3.
Equation 38-3. Number of NTQ in a NBT
NBT = NSYNC + NTSEG1 + NTSEG2
NTQ
Table 38-1. Nominal Bit Rate Configuration Ranges
38.3.3.3 Synchronization
To compensate for phase shifts between the oscillator frequencies of the nodes on the CAN bus, each CAN controller
must be able to synchronize to the relevant edge of the incoming signal. The CAN controller expects an edge in the
received signal to occur within the SYNC segment. Only recessive-to-dominant edges are used for synchronization.
There are two mechanisms used for synchronization:
• Hard Synchronization – Forces the edge that has occurred to lie within the SYNC segment. The bit time
counter is restarted with SYNC.
• Resynchronization – If the edge falls outside the SYNC segment, PHSEG1 or PHSEG2 will be adjusted.
For a more detailed description of the CAN synchronization, refer to ISO11898-1:2015.
...........continued
Parameter Constraint Value Unit Equations and
Comments
NSJW 1 to 128 NTQ; SJW 32 NTQ Maximizing NSJW
≤ min(NPHSEG1, lessens the
NPHSEG2) requirement for the
oscillator tolerance.
CxNBTCFG Value
BRP[7:0] 0
TSEG[7:0] 126
TSEG2[6:0] 31
SJW[6:0] 31
TEF
TXQ
FIFO 1
FIFO 3
All objects in one transmit FIFO use the same payload size (number of data bytes), which is determined by the
PLSIZE[2:0] bits (CxFIFOCONy[30:28]).
For example:
• If TEF is 4 messages deep (NElements (TEF) = 4) and TEFTSEN is clear, then the size of TEF = STEF = 4 x (0 +
8) = 32 bytes
• If NElements (TXQ) = 1, PayLoad (TXQ) = 12, then the size of TXQ = STXQ = 1 x (8 + 12) = 20 bytes
• If NElements (FIFO) = 3, PayLoad (FIFO) = 8, then the size of FIFO = SFIFO = 3 x (8 + 8) = 48 bytes
Therefore, SRAM = STEF + STXQ + SFIFO = 32 + 20 + 48 = 100 bytes.
DATA FRAME
ARBITRATION(12/32b)
CTRL(6b)
CRC(16b)
CRC
CAN BASE CRC(15b)
DEL
CRC
CAN EXT CRC(15b)
DEL
ERROR
ANYWHERE WITHIN DATA FRAME ERRFLAG(6b) ERRDEL(8b) IFS ( 3b) or OVL
OVERLOAD
EOF or ERRDEL or OVLDEL OVLFLAG(6b) OVLDEL(8b) IFS ( 3b) or OVL
time after appending a message. This ensures that all messages in the TXQ are transmitted, including the appended
messages.
In case RTXAT = 0, unlimited retransmission attempts will be used for all transmit FIFOs and the TXQ, and TXATx
will be ignored.
IDLE
Any TXREQ
Calculate
TX Priority
Result: Index
New TX Index or
Received a Message?
Safe Msg to TEF
ABORT ALL c
Clr All TXREQ
Set All TXABT
Re-Init TX
Attempts
Based on New
TX ABORT Index
Set
TXABT[Index] Abort: Set ABAT TX
Pending[Index]
Wait for Clr TXREQ[Index]
Suspend Time Set
TXATIF[Index]
STEF = 1?
c
Lost Arbitration
Set
TXLARB[Index]
are only saved if STEF (CxCON[19]) is set. The sequence number (SEQ) of the transmitted message is copied into
the TEF object. The payload data are not stored. Transmitted messages are timestamped if TEFTSEN is set.
Table 38-6 specifies the TEF object. The first two words of the TEF object are a copy of the transmit message object.
Optionally, the TEF object contains the timestamp when the message is transmitted.
SEQ[22:0]: Bits 22-0 of the sequence to keep track of transmitted messages in Transmit Event FIFO
TXMSGTS[31:0]: Transmit Message Timestamp bits
Note:
1. (TXMSGTS[31:0]) only exist in objects where TEFTSEN (CxTEFCON[5]) is set.
Yes and RTR Match Filter Object 0 Yes and Not RTR
Yes and RTR Match Filter Object 1 Yes and Not RTR
Yes and RTR Match Filter Object 12 Yes and Not RTR
Accept Message:
Set TXREQ[Index] Discard Message Receive Rest of Message
Store in FIFO [Index]
Done
Start Matching
No
Check IDE:
Yes No No Match
CxFLTOBJy.EXIDE == RXMAB.IDE?
Yes RXMAB.IDE == 0? No
Yes
CxFLTOBJy.EID == RXMAB.EID,
Don’t Care if CxMASKy.MEID[i] = 0 No No Match
Yes
Yes
Data Bytes:
No Match
CxCON.DNCNTx > 0 ?
Yes
Compare:
CxFLTOBJy.EID[0:N] == RXDB[17 : M] ?
Don’t Care if CxMASKy.MEID[i] = 0
Yes
Match
• Nonzero, the filtering will commence on as many data bits as specified in DNCNTx. A filter hit will require
matching of the SIDx bits and a match of n data bits with the filter’s EID[0:17] bits. Data Byte 0[7] is always
compared to EID[0], Data Byte 0[6] to EID[1], Data Byte 2[6] to EID[17].
• Greater than 18, indicating that the user-selected number of bits is greater than the total number of EIDx bits.
The filter comparison will terminate with the 18th bit of the data.
• Greater than 16, and the received message has DLC = 2, indicating a payload of two data bytes. The filter
comparison will terminate with the 16th bit of the data.
• Greater than 8, and the received message has DLC = 1, indicating a payload of one data byte. The filter
comparison will terminate with the 8th bit of the data.
• Greater than 0, and the received message has DLC = 0, indicating no data payload. The filter comparison will
terminate with the identifier.
Table 38-7. Data Byte Filter Configuration
DNCNT[4:0] Received Message Data Bits to be EIDx Bits Used for Acceptance
Compared Byte [bits] Filter
00000 No Comparison No Comparison
00001 Data Byte 0[7] EID[0]
00010 Data byte 0[7:6] EID[0:1]
00011 Data byte 0[7:5] EID[0:2]
00100 Data byte 0[7:4] EID[0:3]
00101 Data byte 0[7:3] EID[0:4]
00110 Data byte 0[7:2] EID[0:5]
00111 Data byte 0[7:1] EID[0:6]
01000 Data byte 0[7:0] EID[0:7]
01001 Data byte 0[7:0] and Data Byte 1[7] EID[0:8]
01010 Data byte 0[7:0] and Data Byte 1[7:6] EID[0:9]
01011 Data byte 0[7:0] and Data Byte 1[7:5] EID[0:10]
01100 Data byte 0[7:0] and Data Byte 1[7:4] EID[0:11]
01101 Data byte 0[7:0] and Data Byte 1[7:3] EID[0:12]
01110 Data byte 0[7:0] and Data Byte 1[7:2] EID[0:13]
01111 Data byte 0[7:0] and Data Byte 1[7:1] EID[0:14]
10000 Data byte 0[7:0] and Data Byte 1[7:0] EID[0:15]
10001 Byte 0[7:0] and Byte 1[7:0] and Byte EID[0:16]
2[7]
10010 to 11111 Byte 0[7:0] and Byte 1[7:0] and Byte EID[0:17]
2[7:6]
Figure 38-14 illustrates how the first 18 data bits of the received message data payload are compared with the
corresponding EIDx bits of the message acceptance filter (EID[17:0] bits in the C1FLTOBJxH/L registers). The IDE bit
of the received message must be ‘0’.
Accept/Reject Message
SID10 SID9 SID0 EID0 EID1 EID7 EID8 EID9 EID15 EID16 EID17
MESSAGE ACCEPTANCE
MESSAGE ACCEPTANCE FILTER EID[0:17]
FILTER SID[10:0]
Note: The DeviceNet filtering configuration shown for the EIDx bits is DNCNT[4:0] = 10010.
After the receive message object is read from RAM, the RX FIFO needs to be incremented by setting the UINC bit
(CxFIFOCONy[8]). This will make the CAN Protocol module increment to the tail of the FIFO and update CxFIFOUAy.
Now the application can read the next message from the RX FIFO.
Table 38-8. Receive Message Object
Idle
Transmit Error
Store Message to
Frame
Object
Set Error Flags
Set RXIF
Error
Receive Rest of
Receive Message
Arbitration and
CTRL Field
Filter Match?
Receive c
Data Bytes 0-3
Receive Rest of
Message
Before resetting an RX FIFO using FRESET, ensure that no enabled filter is pointing to the FIFO.
FIFO Objects in Payload per Timestamp Bytes in Bytes in FIFO Start Address
FIFO Object Object
TEF 12 N/A Yes 12 144 0x1400
TXQ 8 32 N/A 40 320 0x1490
FIFO 1 5 64 N/A 72 360 0x15D0
FIFO 2 16 64 Yes 76 1216 0x1738
FIFO 3 N/A - - - - 0x1BF8
CxFIFOSTA1: MO1
FIFOCI = 0
TFEIF = 1 MO2
TFHIF = 1
TFNIF = 1 MO3
CxFIFOCON1: MO4
TXREQ = 0
Figure 38-17 illustrates the status of FIFO 1 after the first message (MSG0) is loaded. MO0 now contains MSG0. The
user application sets the UINC bit (CxFIFOCON1[8]), which causes the FIFO head to advance. The user address
now points to MO1. TFEIF is cleared since the FIFO is no longer empty. The user application now sets TXREQ to
request the transmission of MSG0.
Figure 38-17. FIFO 1 - First Message Loaded
C1FIFOSTA1: MO1
FIFOCI = 0
TFEIF = 0 MO2
TFHIF = 1
TFNIF = 1 MO3
CxFIFOCON1: MO4
TXREQ = 1
Figure 38-18 illustrates the status of FIFO 1 after MSG0 is transmitted. The FIFO is empty again. TFEIF is set and
TXREQ is cleared. FIFOCIx bits now point to MO1 with user address 0x218.
Figure 38-18. FIFO 1 - First Message Transmitted
CxFIFOSTA1: MO1
FIFOCI = 1
TFEIF = 1 MO2
TFHIF = 1
TFNIF = 1 MO3
CxFIFOCON1: MO4
TXREQ = 0
Figure 38-19 illustrates the status of FIFO 1 after three more messages are loaded: MSG1-MSG3. The user address
now points to MO4. TFHIF is cleared because the FIFO is now less than half empty.
Figure 38-19. FIFO 1 - Three More Messages Loaded
CxFIFOSTA1: MO1/MSG1
FIFOCI = 1
TFEIF = 0 MO2/MSG2
TFHIF = 0
TFNIF = 1 MO3/MSG3
CxFIFOCON1: MO4
TXREQ = 0
Figure 38-20 illustrates the status of FIFO 1 after two more messages are loaded: MSG4 and MSG5. CxFIFOUA1
now points to MO1. All status flags are now cleared because the FIFO is full. The user address and the FIFO index
now point to MO1. The user application now sets TXREQ to request the transmission of MSG1-MSG5.
Figure 38-20. FIFO 1 - FIFO Fully Loaded
CxFIFOSTA1: MO1/MSG1
FIFOCI = 1
TFEIF = 0 MO2/MSG2
TFHIF = 0
TFNIF = 0 MO3/MSG3
CxFIFOCON1: MO4/MSG4
TXREQ = 1
Figure 38-21 illustrates the status of FIFO 1 after MSG1-MSG5 are transmitted. The FIFO is empty again. All status
flags are set and TXREQ is cleared. The user address and the FIFO index point to MO1 again.
CxFIFOSTA1: MO1
FIFOCI = 1
TFEIF = 1 MO2
TFHIF = 1
TFNIF = 1 MO3
CxFIFOCON1: MO4
TXREQ = 0
CxFIFOSTA2: MO1
FIFOCI = 0
RFFIF = 0 MO2
RFHIF = 0
RFNIF = 0
RXOVIF = 0
MO15
Figure 38-23 illustrates the status of FIFO 2 after the first message (MSG0) is received. MO0 now contains MSG0.
The FIFO index now points to MO1. RFNIF is set since the FIFO is not empty anymore.
Figure 38-23. FIFO 2 - First Message Received
CxFIFOSTA2: MO1
FIFOCI = 1
RFFIF = 0 MO2
RFHIF = 0
RFNIF = 1
RXOVIF = 0
MO15
Figure 38-24 illustrates the status of FIFO 2 after MSG0 is read. The user application reads the message from
RAM and sets the UINC bit (CxFIFOCON2[8]). The user address increments and points to MO1. The FIFO index is
unchanged. The FIFO is empty again. All flags are cleared.
CxFIFOSTA2: MO1
FIFOCI = 1
RFFIF = 0 MO2
RFHIF = 0
RFNIF = 0
RXOVIF = 0
MO15
Figure 38-25 illustrates the status of FIFO 2 after eight more messages are received: MSG1-MSG8. The user
address still points to MO1. RFNIF and RFHIF are set because the FIFO is now half full. The FIFO index points to
MO9.
Figure 38-25. FIFO 2 - Half Full
CxFIFOSTA2: MO1/MSG1
FIFOCI = 9
RFFIF = 0 MO2/MSG2
RFHIF = 1
RFNIF = 1
RXOVIF = 0
MO8/MSG8
MO9
MO10
MO15
Figure 38-26 illustrates the status of FIFO 2 after ten more messages are received: MSG5-MSG15. The user address
still points to MO1. The FIFO index points to MO0. RFNIF and RFHIF are set.
Figure 38-26. FIFO 2 - FIFO Almost Full
CxFIFOSTA2: MO1/MSG1
FIFOCI = 0
RFFIF = 0 MO2/MSG2
RFHIF = 1
RFNIF = 1
RXOVIF = 0
MO15/MSG15
Figure 38-27 illustrates the status of FIFO 2 after one more message is received: MSG16. All status flags are set
because the FIFO is full. The user address and the FIFO index point to MO1.
CxFIFOSTA2: MO1/MSG1
FIFOCI = 1
RFFIF = 1 MO2/MSG2
RFHIF = 1
RFNIF = 1
RXOVIF = 0
MO15/MSG15
Figure 38-28 illustrates the status of FIFO 2 after one more message is received. Since FIFO 2 is already full, an
overflow occurs. The message is discarded and RXOVIF is set. The user address and FIFO index has not changed.
Figure 38-28. FIFO 2 - FIFO Overflow
CxFIFOSTA2: MO1/MSG1
FIFOCI = 1
RFFIF = 1 MO2/MSG2
RFHIF = 1
RFNIF = 1
RXOVIF = 1
MO15/MSG15
Figure 38-29 illustrates the status of FIFO 2 after the application cleared RXOVIF and read two more messages.
RFFIF is clear because the FIFO is not full anymore. The user address points to MO3. The FIFO index has not
changed.
Figure 38-29. FIFO 2 - Two More Messages Read
CxFIFOSTA2: MO1
FIFOCI = 1
RFFIF = 0 MO2
RFHIF = 1
RFNIF = 1 MO3/MSG3
RXOVIF = 0
MO4/MSG4
MO15/MSG15
CxTXQSTA: MO1
TXQEIF = 1
TXQNIF = 1 MO2
CxTXQCON:
TXREQ = 0
MO7
Figure 38-31 illustrates the status of the TXQ after the first message (MSG0) is loaded. MO0 now contains MSG0.
The user application sets the UINC bit, which causes the FIFO head to advance. The user address now points to
MO1. TXQEIF is cleared, since the queue is not empty anymore. The user application now sets TXREQ to request
the transmission of MSG0.
Figure 38-31. TXQ - First Message Loaded
CxTXQSTA: MO1
TXQEIF = 0
TXQNIF = 1 MO2
CxTXQCON:
TXREQ = 1
MO7
Figure 38-32 illustrates the status of the TXQ after MSG0 is transmitted. The TXQ is empty again. TXQEIF is set and
TXREQ is cleared. The user address still points to MO1 because UINC is not set.
Figure 38-32. TXQ - First Message Transmitted
CxTXQSTA: MO1
TXQEIF = 1
TXQNIF = 1 MO2
CxTXQCON:
TXREQ = 0
MO7
Figure 38-33 illustrates the status of the TXQ after MSG1 is loaded and UINC is set. The user address now points to
the next free message object: MO0.
Figure 38-33. TXQ - Next Message Loaded
CxTXQSTA: MO1/MSG1
TXQEIF = 0
TXQNIF = 1 MO2
CxTXQCONL:
TXREQ = 0
MO7
Figure 38-34 illustrates the status of the TXQ after six more messages are loaded: MSG2-MSG7. The user address
now points to the last free message object: MO7.
CxTXQSTA: MO1/MSG1
TXQEIF = 0
TXQNIF = 1 MO2/MSG3
CxTXQCON: MO3/MSG4
TXREQ = 0
MO4/MSG5
MO5/MSG6
MO6/MSG7
MO7
Figure 38-35 illustrates the status of the TXQ after MSG8 is loaded and UINC is set. The TXQ is now full, all flags
are cleared. The user address now points to MO0. The user application now sets TXREQ. The messages will be
transmitted based on the priority of their IDs.
Figure 38-35. TXQ - Full
CxTXQSTA: MO1/MSG1
TXQEIF = 0
TXQNIF = 0 MO2/MSG3
CxTXQCON: MO3/MSG4
TXREQ = 1
MO4/MSG5
MO5/MSG6
MO6/MSG7
MO7/MSG8
CxTEFSTA: MO1
TEFFIF = 0
TEFHIF = 0 MO2
TEFNEIF = 0
TEFOVIF = 0
MO11
Figure 38-37 shows the status of the TEF after the first transmit message is stored. MO0 contains ID0, the ID of
MSG0. TEFNEIF is set since the TEF is not empty. The user address points to MO0.
Figure 38-37. TEF - First Transmit Message is Stored
CxTEFSTA: MO1
TEFFIF = 0
TEFHIF = 0 MO2
TEFNEIF = 1
TEFOVIF = 0
MO11
Figure 38-38 illustrates the status of the TEF after ID0 is read. The user application reads the ID from RAM and sets
the UINC bit (C1TEFCONL[8]). The user address increments and points to MO1. The TEF is empty again. All flags
are cleared.
Figure 38-38. TEF - First ID Read
CxTEFSTA: MO1
TEFFIF = 0
TEFHIF = 0 MO2
TEFNEIF = 0
TEFOVIF = 0
MO11
Figure 38-39 illustrates the status of the TEF after six more messages are transmitted: MSG1-MSG6. The user
address points to MO1. TEFNEIF and TEFHIF are set because the TEF is now half full.
Figure 38-39. TEF - Half Full
CxTEFSTA: MO1/ID1
TEFFIF = 0
TEFHIF = 1 MO2/ID2
TEFNEIF = 1
TEFOVIF = 0
MO6/ID6
MO7
MO8
MO11
Figure 38-40 illustrates the status of the TEF after five more messages are transmitted: MSG7-MSG11. The user
address still points to MO1. TEFNEIF and TEFHIF are set.
CxTEFSTA: MO1/ID1
TEFFIF = 0
TEFHIF = 1 MO2/ID2
TEFNEIF = 1
TEFOVIF = 0
MO11/ID11
Figure 38-41 illustrates the status of the TEF after one more message is transmitted: MSG12. All status flags are set
because the TEF is full. The user address points to MO1.
Figure 38-41. TEF - Full
CxTEFSTA: MO1/ID1
TEFFIF = 1
TEFHIF = 1 MO2/ID2
TEFNEIF = 1
TEFOVIF = 0
MO11/ID11
Figure 38-42 illustrates the status of the TEF after one more message is transmitted. Since the TEF is already full, an
overflow occurs. The ID is discarded and TEFOVIF is set. The user address remains unchanged.
Figure 38-42. TEF - Overflow
CxTEFSTA: MO1/ID1
TEFFIF = 1
TEFHIF = 1 MO2/ID2
TEFNEIF = 1
TEFOVIF = 1
MO11/ID11
Figure 38-43 illustrates the status of the TEF after the application cleared TEFOVIF and read one more message.
TEFFIF is clear because the TEF is not full anymore. The user address points to MO2.
Figure 38-43. TEF - One More ID Read
CxTEFSTA: MO1
TEFFIF = 0
TEFHIF = 1 MO2/ID2
TEFNEIF = 1
TEFOVIF = 0 MO3/ID3
MO11/ID11
38.10 Timestamping
The CAN Protocol module contains a Time Base Counter (TBC). The TBC is a 32-bit free-running counter that
increments on multiples of SYSCLK and rolls over to zero when:
• TBCPRE[9:0] bits (CxTSCON[9:0]) are used to configure the prescaler for the TBC.
• Setting TBCEN (CxTSCON[16]) enables the TBC.
• Clearing TBCEN disables, stops and resets the TBC.
• The TBC has to be disabled before writing to C1TBC by clearing TBCEN.
• TEFTSEN (CxTEFCON[5]) has to be set to timestamp messages in the TEF.
• RXTSEN (CxFIFOCONy[5]) has to be set to timestamp messages in the individual RX FIFO.
• The application can read C1TBC at any time. Similar to any multibyte counter, the application has to consider
that the counter increments and might roll over while reading different bytes of the counter.
All timestamps are 32 bits, allowing timestamps to be used for system time synchronization with high resolution.
A rollover of the TBC will generate an interrupt if TBCIE is set.
Messages can be timestamped either at the beginning of a frame or at the end, depending on the TSEOF bit
(C1TSCON[17]). Table 38-10 specifies the reference points when the timestamping occurs. At the reference point,
the value of the TBC (C1TBC) is captured and stored into the message object:
• Receive Message Object: The TBC value is stored in the RXMSGTSx bits (see Table 38-8).
• TEF Object: The TBC value is stored in the TXMSGTSx bits (see Table 38-6).
Table 38-10. Reference Point
38.11 Interrupts
Interrupts can be classified into multiple layers. Lower layer interrupts propagate to higher layers by multiplexing them
into single interrupts. Figure 38-44 illustrates the layers of interrupts.
• FIFO Individual Interrupts
• FIFO Combined Interrupts
• Main Interrupts
These interrupts are then funneled into three separate module interrupts:
• Receive Interrupt
• Transmit Interrupt
• Information Interrupt
All module interrupts are persistent, meaning the condition that caused the interrupt must be cleared within the
module for the interrupt request to be removed.
CxTXQCON, CxTXQSTA FIFO Individual FIFO Combined Main Interrupts Interrupt Pins
CxFIFOCONy, CxFIFOSTAy Interrupts Interrupts
RFFIE
RFFIF 3 FIFOS
CxINT.RXIE
RX Interrupt
3x CxINT.RXIF
RFHIE
3x CxRXIF<RFIF<3:1>>
RFHIF
RFNIE
RFNIF
1 TXQ
TXQEIE
TXQEIF
1x CxTXIF.TFIF<0>
TXQNIE
TXQNIF
TFEIE
TFEIF 3 FIFOS
CxINT.TXIE
TX Interrupt
4x CxINT.TXIF
TFHIE
3x CxTXIF<3:1>
TFHIF
TFNIE
TFNIF
CxINT.RXOVIE
3x CxINT.RXOVIF
RXOVIE 3 FIFOS
CxRXOVIF<3:1>
3x
RXOVIF
TXATIE 1 TXQ
CxTXATIF<0>
1x
TXATIF
CxINT.TXATIE
3x CxINT.TXATIF
TXATIE 3 FIFOS
CxTXATIF<3:1>
3x
TXATIF
CiTEFCONL
CiTEFSTA
TEFOVIE 1 FIFO
CxINT.TEFIE
TEFOVIF
CxINT.TEFIF
TEFFIE
TEFFIF CxINT.IVMIE Info Interrupt
OR
CxINT.IVMIF
TEFHIE
TEFHIF
CxINT.WAKIE
TEFNEIE CxINT.WAKIF
TEFNEIF
CxINT.CERRIE
CxINT.CERRIF
CxINT.MODIE
CxINT.MODIF
CxINT.TBCIE
CxINT.TBCIF
CxINT.SERRIE
CxINT.SERRIF
Both interrupts can be enabled individually. The interrupts cannot be cleared by the application; they will be cleared
when the condition of the FIFO terminates.
Both interrupt sources are OR’d together and reflected in the TFIF0 flag (CxTXIF[0]).
by reading one register, the application can check the status of all FIFOs for a particular interrupt (e.g., any RFIFx
pending).
The FIFO interrupts are enabled in CxFIFOCONy.
TXQ interrupts are enabled in CxTXQCON.
Clearing of the FIFO interrupts is explained in FIFO Individual Interrupts.
status has to wait until the beginning of the 7th bit of the EOF field, since the received frame is only valid at this point.
The complete message has to be saved and the FIFO has to be updated until the end of the arbitration field of the
next message.
In case of an RX MAB overflow, the new message that caused the overflow will be discarded. The module continues
to store the message that is completely received and filtered. Afterwards, the module will be able to receive new
messages on the bus. The application will be notified using the SERRIF bit.
The SERRIF bit (CxINT[12]) will be cleared by writing a zero to the bit. This will also clear the SERRIF condition from
the ICODEx bits.
Handling of TX MAB Underflow Errors
ISO11898-1:2015 requires MAC data consistency: a transmitted message must contain consistent data. If data errors
occur due to ECC errors, or TX MAB underflow, the transmission will not start. If the transmission is in progress, it will
stop and the module will transition to either Restricted Operation or Listen Only mode, which is selectable using the
SERRLOM bit (CxCON[18]).
The module handles these errors by stopping the transmission and transitioning to Restricted Operation or Listen
Only mode. The CxTX pin will be forced high. Additionally, all TXREQs will be ignored. The application will be notified
using SERRIF. The module will continue to receive messages.
Notes:
1. The flags will be cleared when the condition of the FIFO terminates, initiated by the UINC bit
(CxFIFOCONy[8]).
2. The flags need to be cleared in the preceding hierarchies.
Error
Active
Error
Bus Off
Passive
TEC > 255
The error-free message counter, together with the error counters and error flags, can be used to determine the quality
of the bus.
transmit FIFOs when entering the Bus Off state to ensure that the module does not try to retransmit indefinitely. The
application will be notified by CERRIF and has the option to queue new messages for transmission.
The module signals the exit from the Bus Off state with the CERRIF bit and by setting the TXBOERR bit
(CxBDIAG1[23]). Additionally, C1TREC will be Reset.
38.13.1 CxCON
Name: CxCON
Offset: 0x0100
Bit 31 30 29 28 27 26 25 24
TXBWS[3:0] ABAT REQOP[2:0]
Access R/W R/W R/W R/W S/HC R/W R/W R/W
Reset 0 0 0 0 0 1 0 0
Bit 23 22 21 20 19 18 17 16
OPMOD[2:0] TXQEN STEF SERRLOM RTXAT
Access R R R R/W R/W R/W R/W
Reset 1 0 0 1 1 0 0
Bit 15 14 13 12 11 10 9 8
ON SIDL BUSY WFT[1:0] WAKFIL
Access R/W R/W R R/W R/W R/W
Reset 0 0 0 1 1 1
Bit 7 6 5 4 3 2 1 0
CLKSEL DNCNT[4:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Value Description
011 Sets Listen Only mode
010 Sets Internal Loopback mode
001 Sets Disable mode
000 Unimplemented
Value Description
01 T01 Filter
00 T00 Filter
Bits 4:0 – DNCNT[4:0] DeviceNet™ Filter Bit Number (see 38.7.2.3. Filtering on Data Bytes and Table 38-7 for
more details
Value Description
11111-10 Invalid selection (compares up to 18 bits of data with EIDx)
011
10010 Compares up to Data Byte 2, bit 6 with EID17
10001 Compares up to Data byte 2, bit 7 with EID16
... ...
00010 Compares up to Data byte 0 bit 6 with EID1
00001 Compares up to Data byte 0 bit 7 with EID0
00000 Does not compare data bytes
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxCONT: Accesses the top byte CON[31:24]
– CxCONU: Accesses the upper byte CON[23:16]
– CxCONH: Accesses the high byte CON[15:8]
– CxCONL: Accesses the low byte CON[7:0]
2. These bits can only be modified in Configuration mode (OPMOD[2:0] = 100).
38.13.2 CxNBTCFG
Name: CxNBTCFG
Offset: 0x0104
Bit 31 30 29 28 27 26 25 24
BRP[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
TSEG1[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 1 1 1 1 1 0
Bit 15 14 13 12 11 10 9 8
TSEG2[6:0]
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 1 1 1 1
Bit 7 6 5 4 3 2 1 0
SJW[6:0]
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 1 1 1 1
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxNBTCFGT: Accesses the top byte NBTCFG[31:24]
– CxNBTCFGU: Accesses the upper byte NBTCFG[23:16]
– CxNBTCFGH: Accesses the high byte NBTCFG[15:8]
– CxNBTCFGL: Accesses the low byte NBTCFG[7:0]
2. This register can only be modified in Configuration mode (OPMOD[2:0] = 100).
38.13.3 CxTBC
Name: CxTBC
Offset: 0x0110
Bit 31 30 29 28 27 26 25 24
TBC[31:24]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
TBC[23:16]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
TBC[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
TBC[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxTBCT: Accesses the top byte TBC[31:24]
– CxTBCU: Accesses the upper byte TBC[23:16]
– CxTBCH: Accesses the high byte TBC[15:8]
– CxTBCL: Accesses the low byte TBC[7:0]
2. The Time Base Counter (TBC will be stopped and reset when TBCEN = 0 to save power).
3. The TBC prescaler count will be reset on any write to CxTBC (TBCPREx will be unaffected).
38.13.4 CxTSCON
Name: CxTSCON
Offset: 0x0114
Bit 31 30 29 28 27 26 25 24
Access
Reset
Bit 23 22 21 20 19 18 17 16
TSEOF TBCEN
Access R/W R/W
Reset 0 0
Bit 15 14 13 12 11 10 9 8
TBCPRE[9:8]
Access R/W R/W
Reset 0 0
Bit 7 6 5 4 3 2 1 0
TBCPRE[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Note:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxTSCONT: Accesses the top byte TSCON[31:24]
– CxTSCONU: Accesses the upper byte TSCON[23:16]
– CxTSCONH: Accesses the high byte TSCON[15:8]
– CxTSCONL: Accesses the low byte TSCON[7:0]
38.13.5 CxVEC
Name: CxVEC
Offset: 0x0118
Bit 31 30 29 28 27 26 25 24
RXCODE[6:0]
Access R R R R R R R
Reset 1 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
TXCODE[6:0]
Access R R R R R R R
Reset 1 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
FILHIT[4:0]
Access R R R R R
Reset 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
ICODE[6:0]
Access R R R R R R R
Reset 1 0 0 0 0 0 0
Value Description
01010 Filter 10
00001 Filter 1
00000 Filter 0
Note:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxVECT: Accesses the top byte VEC[31:24]
– CxVECU: Accesses the upper byte VEC[23:16]
– CxVECH: Accesses the high byte VEC[15:8]
– CxVECL: Accesses the low byte VEC[7:0]
38.13.6 CxINT
Name: CxINT
Offset: 0x011C
Bit 31 30 29 28 27 26 25 24
IVMIE WAKIE CERRIE SERRIE RXOVIE TXATIE
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
TEFIE MODIE TBCIE RXIE TXIE
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
IVMIF WAKIF CERRIF SERRIF RXOVIF TXATIF
Access HS/C HS/C HS/C HS/C R R
Reset 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
TEFIF MODIF TBCIF RXIF TXIF
Access R HS/C HS/C R R
Reset 0 0 0 0 0
Value Description
1 Transmit event FIFO interrupt occurred
0 No transmit event FIFO interrupt
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxINTT: Accesses the top byte INT[31:24]
– CxINTU: Accesses the upper byte INT[23:16]
– CxINTH: Accesses the high byte INT[15:8]
– CxINTL: Accesses the low byte INT[7:0]
2. Flag is set by hardware and cleared by application.
38.13.7 CxRXIF
Name: CxRXIF
Offset: 0x0120
Bit 31 30 29 28 27 26 25 24
Access
Reset
Bit 23 22 21 20 19 18 17 16
Access
Reset
Bit 15 14 13 12 11 10 9 8
Access
Reset
Bit 7 6 5 4 3 2 1 0
RFIF[2:0]
Access R R R
Reset 0 0 0
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxRXIFT: Accesses the top byte RXIF[31:24]
– CxRXIFU: Accesses the upper byte RXIF[23:16]
– CxRXIFH: Accesses the high byte RXIF[15:8]
– CxRXIFL: Accesses the low byte RXIF[7:0]
2. RFIFx is the ‘or’ of all enabled RX FIFO flags (individual flags need to be cleared in the FIFO register).
38.13.8 CxTXIF
Name: CxTXIF
Offset: 0x0124
Bit 31 30 29 28 27 26 25 24
Access
Reset
Bit 23 22 21 20 19 18 17 16
Access
Reset
Bit 15 14 13 12 11 10 9 8
Access
Reset
Bit 7 6 5 4 3 2 1 0
TFIF[3:0]
Access R R R R
Reset 0 0 0 0
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxTXIFT: Accesses the top byte TXIF[31:24]
– CxTXIFU: Accesses the upper byte TXIF[23:16]
– CxTXIFH: Accesses the high byte TXIF[15:8]
– CxTXIFL: Accesses the low byte TXIF[7:0]
2. TFIFx is the ‘or’ of all enabled TX FIFO flags (individual flags need to be cleared in the FIFO register).
38.13.9 CxRXOVIF
Name: CxRXOVIF
Offset: 0x0128
Bit 31 30 29 28 27 26 25 24
Access
Reset
Bit 23 22 21 20 19 18 17 16
Access
Reset
Bit 15 14 13 12 11 10 9 8
Access
Reset
Bit 7 6 5 4 3 2 1 0
RFOVIF[2:0]
Access R R R
Reset 0 0 0
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxRXOVIFT: Accesses the top byte RXOVIF[31:24]
– CxRXOVIFU: Accesses the upper byte RXOVIF[23:16]
– CxRXOVIFH: Accesses the high byte RXOVIF[15:8]
– CxRXOVIFL: Accesses the low byte RXOVIF[7:0]
2. RFOVIFx mirrors the overflow bit of its respective FIFO register, individual flags need to be cleared in said
FIFO register.
38.13.10 CxTXATIF
Name: CxTXATIF
Offset: 0x012C
Bit 31 30 29 28 27 26 25 24
Access
Reset
Bit 23 22 21 20 19 18 17 16
Access
Reset
Bit 15 14 13 12 11 10 9 8
Access
Reset
Bit 7 6 5 4 3 2 1 0
TFATIF[3:0]
Access R R R R
Reset 0 0 0 0
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxTXATIFT: Accesses the top byte TXATIF[31:24]
– CxTXATIFU: Accesses the upper byte TXATIF[23:16]
– CxTXATIFH: Accesses the high byte TXATIF[15:8]
– CxTXATIFL: Accesses the low byte TXATIF[7:0]
2. TFATIFx mirrors the transmit attempt interrupt bit of its respective FIFO register, individual flags need to be
cleared in said FIFO register.
38.13.11 CxTXREQ
Name: CxTXREQ
Offset: 0x0130
Bit 31 30 29 28 27 26 25 24
Access
Reset
Bit 23 22 21 20 19 18 17 16
Access
Reset
Bit 15 14 13 12 11 10 9 8
Access
Reset
Bit 7 6 5 4 3 2 1 0
TXREQ[3:0]
Access R/W R/W R/W R/W
Reset 0 0 0 0
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxTXREQT: Accesses the top byte TXREQ[31:24]
– CxTXREQU: Accesses the upper byte TXREQ[23:16]
– CxTXREQH: Accesses the high byte TXREQ[15:8]
– CxTXREQL: Accesses the low byte TXREQ[7:0]
2. These bits are only valid if the associated objects are configured as transmit objects (TXEN = 1). Otherwise,
setting them has no effect.
38.13.12 CxTREC
Name: CxTREC
Offset: 0x0134
Bit 31 30 29 28 27 26 25 24
Access
Reset
Bit 23 22 21 20 19 18 17 16
TXBO TXBP RXBP TXWARN RXWARN EWARN
Access R R R R R R
Reset 1 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
TERRCNT[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
RERRCNT[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Note:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxTRECT: Accesses the top byte TREC[31:24]
– CxTRECU: Accesses the upper byte TREC[23:16]
– CxTRECH: Accesses the high byte TREC[15:8]
– CxTRECL: Accesses the low byte TREC[7:0]
38.13.13 CxBDIAG0
Name: CxBDIAG0
Offset: 0x0138
Bit 31 30 29 28 27 26 25 24
Access
Reset
Bit 23 22 21 20 19 18 17 16
Access
Reset
Bit 15 14 13 12 11 10 9 8
NTERRCNT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
NRERRCNT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Note:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxBDIAG0T: Accesses the top byte BDIAG0[31:24]
– CxBDIAG0U: Accesses the upper byte BDIAG0[23:16]
– CxBDIAG0H: Accesses the high byte BDIAG0[15:8]
– CxBDIAG0L: Accesses the low byte BDIAG0[7:0]
38.13.14 CxBDIAG1
Name: CxBDIAG1
Offset: 0x013C
Bit 31 30 29 28 27 26 25 24
DLCMM
Access R/W
Reset 0
Bit 23 22 21 20 19 18 17 16
TXBOERR NCRCERR NSTUFERR NFORMERR NACKERR NBIT1ERR NBIT0ERR
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
EFMSGCNT[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
EFMSGCNT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 21 – NCRCERR Received Message with CRC Incorrect Checksum in Non-Data Segment
The CRC Checksum of a received message is considered incorrect if the CRC of the incoming message does not
match with the CRC calculated from the received data.
Bit 19 – NFORMERR Received Frame with a Fixed Format Error in Non-Data Segment
A fixed format error occurs when a part of the incoming frame with a fixed format has the wrong format
Note:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxBDIAG1T: Accesses the top byte BDIAG1[31:24]
– CxBDIAG1U: Accesses the upper byte BDIAG1[23:16]
– CxBDIAG1H: Accesses the high byte BDIAG1[15:8]
– CxBDIAG1L: Accesses the low byte BDIAG1[7:0]
38.13.15 CxTEFCON
Name: CxTEFCON
Offset: 0x0140
Bit 31 30 29 28 27 26 25 24
FSIZE[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
Access
Reset
Bit 15 14 13 12 11 10 9 8
FRESET UINC
Access S/HC S/HC
Reset 1 0
Bit 7 6 5 4 3 2 1 0
TEFTSEN TEFOVIE TEFFIE TEFHIE TEFNEIE
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
Value Description
1 Interrupt is enabled for FIFO full
0 Interrupt is disabled for FIFO full
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxTEFCONT: Accesses the top byte TEFCON[31:24]
– CxTEFCONU: Accesses the upper byte TEFCON[23:16]
– CxTEFCONH: Accesses the high byte TEFCON[15:8]
– CxTEFCONL: Accesses the low byte TEFCON[7:0]
2. These bits can only be modified in Configuration mode (OPMOD[2:0] = 100.
38.13.16 CxTEFSTA
Name: CxTEFSTA
Offset: 0x0144
Bit 31 30 29 28 27 26 25 24
Access
Reset
Bit 23 22 21 20 19 18 17 16
Access
Reset
Bit 15 14 13 12 11 10 9 8
Access
Reset
Bit 7 6 5 4 3 2 1 0
TEFOVIF TEFFIF TEFHIF TEFNEIF
Access HS/C R R R
Reset 0 0 0 0
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxTEFSTAT: Accesses the top byte TEFSTA[31:24]
– CxTEFSTAU: Accesses the upper byte TEFSTA[23:16]
– CxTEFSTAH: Accesses the high byte TEFSTA[15:8]
– CxTEFSTAL: Accesses the low byte TEFSTA[7:0]
2. These bits are read-only and reflect the status of the FIFO.
38.13.17 CxTEFUA
Name: CxTEFUA
Offset: 0x0148
Bit 31 30 29 28 27 26 25 24
TEFUA[31:24]
Access R R R R R R R R
Reset x x x x x x x x
Bit 23 22 21 20 19 18 17 16
TEFUA[23:16]
Access R R R R R R R R
Reset x x x x x x x x
Bit 15 14 13 12 11 10 9 8
TEFUA[15:8]
Access R R R R R R R R
Reset x x x x x x x x
Bit 7 6 5 4 3 2 1 0
TEFUA[7:0]
Access R R R R R R R R
Reset x x x x x x x x
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxTEFUAT: Accesses the top byte TEFUA[31:24]
– CxTEFUAU: Accesses the upper byte TEFUA[23:16]
– CxTEFUAH: Accesses the high byte TEFUA[15:8]
– CxTEFUAL: Accesses the low byte TEFUA[7:0]
2. This register is not ensured to read correctly in Configuration mode and may only be accessed when the
module is not in Configuration mode.
38.13.18 CxFIFOBA
Name: CxFIFOBA
Offset: 0x014C
Bit 31 30 29 28 27 26 25 24
FIFOBA[31:24]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
FIFOBA[23:16]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
FIFOBA[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
FIFOBA[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
38.13.19 CxTXQCON
Name: CxTXQCON
Offset: 0x0150
Bit 31 30 29 28 27 26 25 24
PLSIZE[2:0] FSIZE[4:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
TXAT[1:0] TXPRI[4:0]
Access R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
FRESET TXREQ UINC
Access S/HC R/W/HC S/HC
Reset 1 0 0
Bit 7 6 5 4 3 2 1 0
TXEN TXATIE TXQEIE TXQNIE
Access R R/W R/W R/W
Reset 1 0 0 0
Value Description
00000 Lowest message priority
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxTXQCONT: Accesses the top byte TXQCON[31:24]
– CxTXQCONU: Accesses the upper byte TXQCON[23:16]
– CxTXQCONH: Accesses the high byte TXQCON[15:8]
– CxTXQCONL: Accesses the low byte TXQCON[7:0]
2. These bits can only be modified in Configuration mode (OPMOD[2:0] = 100.
38.13.20 CxTXQSTA
Name: CxTXQSTA
Offset: 0x0154
Bit 31 30 29 28 27 26 25 24
Access
Reset
Bit 23 22 21 20 19 18 17 16
Access
Reset
Bit 15 14 13 12 11 10 9 8
TXQCI[4:0]
Access R R R R R
Reset 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
TXABT TXLARB TXERR TXATIF TXQEIF TXQNIF
Access R R R HS/C R R
Reset 0 0 0 0 1 1
Value Description
1 TXQ is not full
0 TXQ is full
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxTXQSTAT: Accesses the top byte TXQSTA[31:24]
– CxTXQSTAU: Accesses the upper byte TXQSTA[23:16]
– CxTXQSTAH: Accesses the high byte TXQSTA[15:8]
– CxTXQSTAL: Accesses the low byte TXQSTA[7:0]
2. The TXQCI[4:0] bits give a zero-indexed value to the message in the TXQ. IF the TXQ is four messages deep
(FSIZE = 3), TXQCIx will take on a value of 0 to 3, depending on the state of the TXQ.
3. These bits are updated when a message completes (or aborts) or when the TXQ is reset.
38.13.21 CxTXQUA
Name: CxTXQUA
Offset: 0x0158
Bit 31 30 29 28 27 26 25 24
TXQUA[31:24]
Access R R R R R R R R
Reset x x x x x x x x
Bit 23 22 21 20 19 18 17 16
TXQUA[23:16]
Access R R R R R R R R
Reset x x x x x x x x
Bit 15 14 13 12 11 10 9 8
TXQUA[15:8]
Access R R R R R R R R
Reset x x x x x x x x
Bit 7 6 5 4 3 2 1 0
TXQUA[7:0]
Access R R R R R R R R
Reset x x x x x x x x
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxTXQUAT: Accesses the top byte TXQUA[31:24]
– CxTXQUAU: Accesses the upper byte TXQUA[23:16]
– CxTXQUAH: Accesses the high byte TXQUA[15:8]
– CxTXQUAL: Accesses the low byte TXQUA[7:0]
2. This register is not ensured to read correctly in Configuration mode and may only be accessed when the
module is not in Configuration mode.
38.13.22 CxFIFOCONy
Name: CxFIFOCONy
Offset: 0x00
Bit 31 30 29 28 27 26 25 24
PLSIZE[2:0] FSIZE[4:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
TXAT[1:0] TXPRI[4:0]
Access R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
FRESET TXREQ UINC
Access S/HC R/W/HC S/HC
Reset 1 0 0
Bit 7 6 5 4 3 2 1 0
TXEN RTREN RXTSEN TXATIE RXOVIE TFERFFIE TFHRFHIE TFNRFNIE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Value Description
1 FIFO will be reset when bit is set, cleared by hardware whenever FIFO is reset, user needs to poll
whether this bit is clear before taking any action
0 No effect
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxFIFOCONyT: Accesses the top byte FIFOCONy[31:24]
– CxFIFOCONyU: Accesses the upper byte FIFOCONy[23:16]
– CxFIFOCONyH: Accesses the high byte FIFOCONy[15:8]
– CxFIFOCONyL: Accesses the low byte FIFOCONy[7:0]
2. [y] denotes FIFO number, from 1 to 3.
3. These bits can only be modified in Configuration mode (OPMOD[2:0] = 100).
38.13.23 CxFIFOSTAy
Name: CxFIFOSTAy
Offset: 0x00
Bit 31 30 29 28 27 26 25 24
Access
Reset
Bit 23 22 21 20 19 18 17 16
Access
Reset
Bit 15 14 13 12 11 10 9 8
FIFOCI[4:0]
Access [R [R [R [R [R
Reset 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
TXABT TXLARB TXERR TXATIF RXOVIF TFERFFIF TFHRFHIF TFNRFNIF
Access R R R HS/C HS/C R R R
Reset 0 0 0 0 0 0 0 0
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxFIFOSTAyT: Accesses the top byte FIFOSTAy[31:24]
– CxFIFOSTAyU: Accesses the upper byte FIFOSTAy[23:16]
– CxFIFOSTAyH: Accesses the high byte FIFOSTAy[15:8]
– CxFIFOSTAyL: Accesses the low byte FIFOSTAy[7:0]
2. [y] denotes FIFO number, from 1 to 3.
3. FIFOCI[4:0] gives a zero-indexed value to the message in the FIFO. If the FIFO is four message deep (FSIZE
= 3), FIFOCIx will take on a value of 0 to 3, depending on the state of the FIFO.
4. This bit is updated when a message completes (or aborts) or when the FIFO is reset.
5. This bit is reset on any read of this register or when the TXQ is reset.
38.13.24 CxFIFOUAy
Name: CxFIFOUAy
Offset: 0x00
Bit 31 30 29 28 27 26 25 24
FIFOUA[31:24]
Access R R R R R R R R
Reset x x x x x x x x
Bit 23 22 21 20 19 18 17 16
FIFOUA[23:16]
Access R R R R R R R R
Reset x x x x x x x x
Bit 15 14 13 12 11 10 9 8
FIFOUA[15:8]
Access R R R R R R R R
Reset x x x x x x x x
Bit 7 6 5 4 3 2 1 0
FIFOUA[7:0]
Access R R R R R R R R
Reset x x x x x x x x
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxFIFOCONyT: Accesses the top byte FIFOCONy[31:24]
– CxFIFOCONyU: Accesses the upper byte FIFOCONy[23:16]
– CxFIFOCONyH: Accesses the high byte FIFOCONy[15:8]
– CxFIFOCONyL: Accesses the low byte FIFOCONy[7:0]
2. [y] denotes FIFO number, from 1 to 3.
3. This register is not ensured to read correctly in Configuration mode and may only be accessed when the
module is not in Configuration mode.
38.13.25 CxFLTCON0
Name: CxFLTCON0
Offset: 0x0180
Bit 31 30 29 28 27 26 25 24
FLTEN3 F3BP[4:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
FLTEN2 F2BP[4:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
FLTEN1 F1BP[4:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
FLTEN0 F0BP[4:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Value Description
1 Filter is enabled
0 Filter is disabled
Note:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxFLTCON0T: Accesses the top byte FLTCON0[31:24]
– CxFLTCON0U: Accesses the upper byte FLTCON0[23:16]
– CxFLTCON0H: Accesses the high byte FLTCON0[15:8]
– CxFLTCON0L: Accesses the low byte FLTCON0[7:0]
38.13.26 CxFLTCON1
Name: CxFLTCON1
Offset: 0x0184
Bit 31 30 29 28 27 26 25 24
FLTEN7 F7BP[4:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
FLTEN6 F6BP[4:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
FLTEN5 F5BP[4:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
FLTEN4 F4BP[4:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Value Description
1 Filter is enabled
0 Filter is disabled
Note:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxFLTCON1T: Accesses the top byte FLTCON1[31:24]
– CxFLTCON1U: Accesses the upper byte FLTCON1[23:16]
– CxFLTCON1H: Accesses the high byte FLTCON1[15:8]
– CxFLTCON1L: Accesses the low byte FLTCON1[7:0]
38.13.27 CxFLTCON2
Name: CxFLTCON2
Offset: 0x0188
Bit 31 30 29 28 27 26 25 24
FLTEN11 F11BP[4:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
FLTEN10 F10BP[4:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
FLTEN9 F9BP[4:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
FLTEN8 F8BP[4:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Value Description
1 Filter is enabled
0 Filter is disabled
Note:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxFLTCON2T: Accesses the top byte FLTCON2[31:24]
– CxFLTCON2U: Accesses the upper byte FLTCON2[23:16]
– CxFLTCON2H: Accesses the high byte FLTCON2[15:8]
– CxFLTCON2L: Accesses the low byte FLTCON2[7:0]
38.13.28 CxFLTOBJy
Name: CxFLTOBJy
Offset: 0x00
Bit 31 30 29 28 27 26 25 24
EXIDE EID[17:13]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
EID[12:5]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
EID[4:0] SID[10:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
SID[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxFLTOBJyT: Accesses the top byte FLTOBJy[31:24]
– CxFLTOBJyU: Accesses the upper byte FLTOBJy[23:16]
– CxFLTOBJyH: Accesses the high byte FLTOBJy[15:8]
– CxFLTOBJyL: Accesses the low byte FLTOBJy[7:0]
2. [y] denotes Filter number, from 0 to 11.
38.13.29 CxMASKy
Name: CxMASKy
Offset: 0x00
Bit 31 30 29 28 27 26 25 24
MIDE MEID[17:13]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bit 23 22 21 20 19 18 17 16
MEID[12:5]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8
MEID[4:0] MSID[10:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
MSID[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– CxMASKyT: Accesses the top byte MASKy[31:24]
– CxMASKyU: Accesses the upper byte MASKy[23:16]
– CxMASKyH: Accesses the high byte MASKy[15:8]
– CxMASKyL: Accesses the low byte MASKy[7:0]
2. Each Mask is associated with a filter,[y] denotes Filter number, from 0 to 11.
0x00
... Reserved
0xFF
7:0 CLKSEL DNCNT[4:0]
15:8 ON SIDL BUSY WFT[1:0] WAKFIL
0x0100 C1CON
23:16 OPMOD[2:0] TXQEN STEF SERRLOM RTXAT
31:24 TXBWS[3:0] ABAT REQOP[2:0]
7:0 SJW[6:0]
15:8 TSEG2[6:0]
0x0104 C1NBTCFG
23:16 TSEG1[7:0]
31:24 BRP[7:0]
0x0108
... Reserved
0x010F
7:0 TBC[7:0]
15:8 TBC[15:8]
0x0110 C1TBC
23:16 TBC[23:16]
31:24 TBC[31:24]
7:0 TBCPRE[7:0]
15:8 TBCPRE[9:8]
0x0114 C1TSCON
23:16 TSEOF TBCEN
31:24
7:0 ICODE[6:0]
15:8 FILHIT[4:0]
0x0118 C1VEC
23:16 TXCODE[6:0]
31:24 RXCODE[6:0]
7:0 TEFIF MODIF TBCIF RXIF TXIF
15:8 IVMIF WAKIF CERRIF SERRIF RXOVIF TXATIF
0x011C C1INT
23:16 TEFIE MODIE TBCIE RXIE TXIE
31:24 IVMIE WAKIE CERRIE SERRIE RXOVIE TXATIE
7:0 RFIF[2:0]
15:8
0x0120 C1RXIF
23:16
31:24
7:0 TFIF[3:0]
15:8
0x0124 C1TXIF
23:16
31:24
7:0 RFOVIF[2:0]
15:8
0x0128 C1RXOVIF
23:16
31:24
7:0 TFATIF[3:0]
15:8
0x012C C1TXATIF
23:16
31:24
7:0 TXREQ[3:0]
15:8
0x0130 C1TXREQ
23:16
31:24
7:0 RERRCNT[7:0]
15:8 TERRCNT[7:0]
0x0134 C1TREC
23:16 TXBO TXBP RXBP TXWARN RXWARN EWARN
31:24
...........continued
7:0 NRERRCNT[7:0]
15:8 NTERRCNT[7:0]
0x0138 C1BDIAG0
23:16
31:24
7:0 EFMSGCNT[7:0]
15:8 EFMSGCNT[15:8]
0x013C C1BDIAG1
23:16 TXBOERR NCRCERR NSTUFERR NFORMERR NACKERR NBIT1ERR NBIT0ERR
31:24 DLCMM
7:0 TEFTSEN TEFOVIE TEFFIE TEFHIE TEFNEIE
15:8 FRESET UINC
0x0140 C1TEFCON
23:16
31:24 FSIZE[4:0]
7:0 TEFOVIF TEFFIF TEFHIF TEFNEIF
15:8
0x0144 C1TEFSTA
23:16
31:24
7:0 TEFUA[7:0]
15:8 TEFUA[15:8]
0x0148 C1TEFUA
23:16 TEFUA[23:16]
31:24 TEFUA[31:24]
7:0 FIFOBA[7:0]
15:8 FIFOBA[15:8]
0x014C C1FIFOBA
23:16 FIFOBA[23:16]
31:24 FIFOBA[31:24]
7:0 TXEN TXATIE TXQEIE TXQNIE
15:8 FRESET TXREQ UINC
0x0150 C1TXQCON
23:16 TXAT[1:0] TXPRI[4:0]
31:24 PLSIZE[2:0] FSIZE[4:0]
7:0 TXABT TXLARB TXERR TXATIF TXQEIF TXQNIF
15:8 TXQCI[4:0]
0x0154 C1TXQSTA
23:16
31:24
7:0 TXQUA[7:0]
15:8 TXQUA[15:8]
0x0158 C1TXQUA
23:16 TXQUA[23:16]
31:24 TXQUA[31:24]
7:0 TXEN RTREN RXTSEN TXATIE RXOVIE TFERFFIE TFHRFHIE TFNRFNIE
15:8 FRESET TXREQ UINC
0x015C C1FIFOCON1
23:16 TXAT[1:0] TXPRI[4:0]
31:24 PLSIZE[2:0] FSIZE[4:0]
7:0 TXABT TXLARB TXERR TXATIF RXOVIF TFERFFIF TFHRFHIF TFNRFNIF
15:8 FIFOCI[4:0]
0x0160 C1FIFOSTA1
23:16
31:24
7:0 FIFOUA[7:0]
15:8 FIFOUA[15:8]
0x0164 C1FIFOUA1
23:16 FIFOUA[23:16]
31:24 FIFOUA[31:24]
7:0 TXEN RTREN RXTSEN TXATIE RXOVIE TFERFFIE TFHRFHIE TFNRFNIE
15:8 FRESET TXREQ UINC
0x0168 C1FIFOCON2
23:16 TXAT[1:0] TXPRI[4:0]
31:24 PLSIZE[2:0] FSIZE[4:0]
7:0 TXABT TXLARB TXERR TXATIF RXOVIF TFERFFIF TFHRFHIF TFNRFNIF
15:8 FIFOCI[4:0]
0x016C C1FIFOSTA2
23:16
31:24
...........continued
7:0 FIFOUA[7:0]
15:8 FIFOUA[15:8]
0x0170 C1FIFOUA2
23:16 FIFOUA[23:16]
31:24 FIFOUA[31:24]
7:0 TXEN RTREN RXTSEN TXATIE RXOVIE TFERFFIE TFHRFHIE TFNRFNIE
15:8 FRESET TXREQ UINC
0x0174 C1FIFOCON3
23:16 TXAT[1:0] TXPRI[4:0]
31:24 PLSIZE[2:0] FSIZE[4:0]
7:0 TXABT TXLARB TXERR TXATIF RXOVIF TFERFFIF TFHRFHIF TFNRFNIF
15:8 FIFOCI[4:0]
0x0178 C1FIFOSTA3
23:16
31:24
7:0 FIFOUA[7:0]
15:8 FIFOUA[15:8]
0x017C C1FIFOUA3
23:16 FIFOUA[23:16]
31:24 FIFOUA[31:24]
7:0 FLTEN0 F0BP[4:0]
15:8 FLTEN1 F1BP[4:0]
0x0180 C1FLTCON0
23:16 FLTEN2 F2BP[4:0]
31:24 FLTEN3 F3BP[4:0]
7:0 FLTEN4 F4BP[4:0]
15:8 FLTEN5 F5BP[4:0]
0x0184 C1FLTCON1
23:16 FLTEN6 F6BP[4:0]
31:24 FLTEN7 F7BP[4:0]
7:0 FLTEN8 F8BP[4:0]
15:8 FLTEN9 F9BP[4:0]
0x0188 C1FLTCON2
23:16 FLTEN10 F10BP[4:0]
31:24 FLTEN11 F11BP[4:0]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x018C C1FLTOBJ0
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x0190 C1MASK0
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x0194 C1FLTOBJ1
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x0198 C1MASK1
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x019C C1FLTOBJ2
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01A0 C1MASK2
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01A4 C1FLTOBJ3
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
...........continued
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01A8 C1MASK3
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01AC C1FLTOBJ4
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01B0 C1MASK4
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01B4 C1FLTOBJ5
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01B8 C1MASK5
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01BC C1FLTOBJ6
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01C0 C1MASK6
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01C4 C1FLTOBJ7
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01C8 C1MASK7
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01CC C1FLTOBJ8
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01D0 C1MASK8
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01D4 C1FLTOBJ9
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01D8 C1MASK9
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01DC C1FLTOBJ10
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
...........continued
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01E0 C1MASK10
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01E4 C1FLTOBJ11
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01E8 C1MASK11
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
PIC18F-Based Application
JTAG
Controller
TDO
TDO
TMS
TMS
TCK
TCK
TDI
TDI
Standard
JTAG Connector
TDI
TDO
TCK
TMS
TRST (optional)
In PIC18-Q83 devices, hardware for the JTAG boundary scan is a Core Independent Peripheral (CIP) with additional
integrated logic in all I/O ports. A logical block diagram of the JTAG module is shown in Figure 39-2. It consists of the
following key elements:
• TAP Interface Pins (TDI, TMS, TCK and TDO)
• TAP Controller
• Instruction Shift Register and Instruction Register (IR)
• Data Registers
TDO Selector
Instruction Shift Register (MUX)
TDI
TDO
Device ID Registers
Data Selector
(MUX)
39.1.1 TAP
The Test Access Port (TAP) on the PIC18-Q83 is a general-purpose port that provides test access to many built-in
support functions and test logic defined in IEEE Standard 1149.1. The TAP is disabled by programming the JTAGEN
bit in CONFIG2 (the TAP, by default, is enabled in the bit’s unprogrammed state). While enabled, the designated I/O
pins become dedicated TAP pins. The PIC implements a 4-pin JTAG interface with these pins:
• TCK (Test Clock): Provides the clock for test logic.
• TMS (Test Mode Select): Input used by the TAP to control test operations.
• TDI (Test Data Input): Serial input for test instructions and data.
• TDO (Test Data Output): Serial output for test instructions and data.
To minimize I/O loss due to JTAG, the optional TAP Reset (TRST) input pin, specified in the standard, is not
implemented on PIC18-Q83 devices. For convenience, a “soft” TAP Reset has been included in the TAP controller,
using the TMS and TCK pins. To force a port Reset, apply a logic high to the TMS pin for at least five rising edges of
TCK. Note that device Resets (including POR) do not automatically result in a TAP Reset; this must be done by the
external JTAG controller using the soft TAP Reset.
Test-Logic
Reset
TMS = 0
Run-Test/Idle TMS = 1 Select-DR-Scan TMS = 1 Select-IR-Scan TMS = 1
TMS = 0 TMS = 0
TMS = 1 Capture-DR TMS = 1 Capture-IR
TMS = 0 TMS = 0 TMS = 0 TMS = 0
Shift-DR Shift-IR
TMS = 1 TMS = 1
Exit-1-DR Exit-1-IR
By manipulating the state of TMS and the clock pulses on TCK, the TAP controller can be moved through all of
the defined module states to capture, shift and update various instruction and/or data registers. Figure 39-3 shows
the state changes on TMS as the controller cycles through its state machine. Figure 39-4 shows the timing of TMS
and TCK while transitioning the controller through the appropriate module states for shifting in an instruction. In this
example, the sequence shown demonstrates how an instruction is read by the TAP controller. All TAP controller
states are entered on the rising edge of the TCK pin. In this example, the TAP controller starts in the Test-Logic Reset
state. Since the state of the TAP controller is dependent on the previous instruction, and therefore may be unknown,
it is good programming practice to begin in the Test-Logic Reset state.
TCK
TMS
Instruction Da ta (LSB)
TDI
Run_Test
Idle Sele ct_IR_Scan Shift_IR Update_IR
TAP
State
Sele ct_DR_Scan Capture_IR Exit_IR Run_Test
Idle
TDO
(1) (2) (3)
Note 1: TDO pin is always in a high-impedance state, until the first falling edge of TCK, in either the Shift_IR or Shift_DR
states.
2: TDO is no longer high-impedance; the initial state of the Instruction Register (IR) is shifted out on the falling edge of
TCK.
3: TDO returns to high-impedance again on the first falling edge of TCK in the Exit_IR state.
When TMS is asserted low on the next rising edge of TCK, the TAP controller will move into the Run-Test/Idle state.
On the next two rising edges of TCK, TMS is high; this moves the TAP controller to the Select-IR-Scan state.
On the next two rising edges of TCK, TMS is held low; this moves the TAP controller into the Shift-IR state. An
instruction is shifted into the Instruction Shift register via the TDI on the next four rising edges of TCK. After the TAP
controller enters this state, the TDO pin goes from a High-Impedance state to Active. The controller shifts out the
initial state of the Instruction Register (IR) on the TDO pin, on the falling edges of TCK, and continues to shift out the
contents of the Instruction Register while in the Shift-IR state. The TDO returns to the High-Impedance state on the
first falling edge of TCK upon exiting the Shift state.
On the next three rising edges of TCK, the TAP controller exits the Shift-IR state, updates the Instruction Register
and then moves back to the Run-Test/Idle state. Data, or another instruction, can now be shifted into the appropriate
Data or Instruction Register.
• Bypass register: A single-bit register which allows the boundary scan test data to pass through the selected
device to adjacent devices. The Bypass register is placed between the TDI and TDO pins when the BYPASS
instruction is active.
• Device ID Register: A 32-bit part identifier. It consists of an 11-bit manufacturer ID assigned by the IEEE (29h for
Microchip Technology), device part number and device revision identifier. When the IDCODE instruction is active,
the Device ID register is placed between the TDI and TDO pins. The device data ID is then shifted out onto the
TDO pin, on the next 32 falling edges of TCK, after the TAP controller is in the Shift-DR.
I C O I C O I C O
O I
C C
I O
O PIC18F I
C Internal C
I Logic O
O I
C C
I O
TAP Controller
Figure 39-6. Boundary Scan Cell and Its Relationship to the I/O Port
Input Buffer
Port Input
VDD
SEL
Rev. 10-000256B
2/5/2019
EN
OUT
- Trigger/
Interrupt HLVDIF
+ Generation
RDY INTH INTL
Bandgap
Reference
EN Volatge
Since the HLVD can be software enabled through the EN bit, setting and clearing the enable bit does not produce a
false HLVD event glitch. Each time the HLVD module is enabled, the RDY bit can be used to detect when the module
is stable and ready to use.
The INTH and INTL bits determine the overall operation of the module. When INTH is set, the module monitors for
rises in VDD above the trip point set by the bits. When INTL is set, the module monitors for drops in VDD below the trip
point set by the SEL bits. When both the INTH and INTL bits are set, any changes above or below the trip point set
by the SEL bits can be monitored.
The OUT bit can be read to determine if the voltage is greater than or less than the selected trip point.
40.1 Operation
When the HLVD module is enabled, a comparator uses an internally generated voltage reference as the set point.
The set point is compared with the trip point, where each node in the resistor divider represents a trip point voltage.
The “trip point” voltage is the voltage level at which the device detects a high or low-voltage event, depending on the
configuration of the module.
When the supply voltage is equal to the trip point, the voltage tapped off of the resistor array is equal to the internal
reference voltage generated by the voltage reference module. The comparator then generates an interrupt signal by
setting the HLVDIF bit.
The trip point voltage is software programmable using the SEL bits.
40.2 Setup
To set up the HLVD module:
1. Select the desired HLVD trip point by writing the value to the SEL bits.
2. Depending on the application to detect high-voltage peaks or low-voltage drops or both, set the INTH or INTL
bit appropriately.
3. Enable the HLVD module by setting the EN bit.
4. Clear the HLVD Interrupt Flag (HLVDIF), which may have been set from a previous interrupt.
5. If interrupts are desired, enable the HLVD interrupt by setting the HLVDIE and GIE bits.
An interrupt will not be generated until the RDY bit is set.
Important: Before changing any module settings (interrupts and tripping point), first disable the
module (EN = 0), make the changes and re-enable the module. This prevents the generation of
false HLVD events.
VDD
VHLVD
HLVDIF
EN
RDY TFVRST
CASE 2:
VDD
VHLVD
HLVDIF
EN
RDY TFVRST
CASE 1:
HLVDIF may not be Set
VHLVD
VDD
HLVDIF
EN
TIRVST
RDY
HLVDIF Cleared in Software
Band Gap Reference Voltage is Stable
CASE 2:
VHLVD
VDD
HLVDIF
EN
TIRVST
RDY
40.5 Applications
In many applications, it is desirable to detect a drop below, or rise above, a particular voltage threshold. For example,
the HLVD module can be periodically enabled to detect Universal Serial Bus (USB) attach or detach. This assumes
the device is powered by a lower voltage source than the USB when detached. An attach indicates a High-Voltage
Detect from, for example, 3.3V to 5V (the voltage on USB) and vice versa for a detach. This feature can save a
design a few extra components and an attach signal (input pin).
For general battery applications, the figure below shows a possible voltage curve. Over time, the device voltage
decreases. When the device voltage reaches voltage, VA, the HLVD logic generates an interrupt at time, TA. The
interrupt can cause the execution of an Interrupt Service Routine (ISR), which will allow the application to perform
“housekeeping tasks” and a controlled shutdown before the device voltage exits the valid operating range at TB. This
will give the application a time window, represented by the difference between TA and TB, to safely exit.
VA
VB
Voltage
TA TB
Time
40.9.1 HLVDCON0
Name: HLVDCON0
Offset: 0x04A
Bit 7 6 5 4 3 2 1 0
EN OUT RDY INTH INTL
Access R/W R R R/W R/W
Reset 0 x x 0 0
40.9.2 HLVDCON1
Name: HLVDCON1
Offset: 0x04B
Bit 7 6 5 4 3 2 1 0
SEL[3:0]
Access R/W R/W R/W R/W
Reset 0 0 0 0
0x00
... Reserved
0x49
0x4A HLVDCON0 7:0 EN OUT RDY INTH INTL
0x4B HLVDCON1 7:0 SEL[3:0]
ADFVR
1x To ADC module
2x as reference and
4x input channel
FVR Buffer 1
CDAFVR
To DAC and
1x
Comparator modules,
2x
4x To ADC module as
input channel only
FVR Buffer 2
EN +
_ RDY
Any peripheral
requiring Fixed
Reference
41.3.1 FVRCON
Name: FVRCON
Offset: 0x3D7
Important: This register is shared between the Fixed Voltage Reference (FVR) module and the
temperature indicator module.
Bit 7 6 5 4 3 2 1 0
EN RDY TSEN TSRNG CDAFVR[1:0] ADFVR[1:0]
Access R/W R R/W R/W R/W R/W R/W R/W
Reset 0 q 0 0 0 0 0 0
Notes:
1. This output goes to the DAC and comparator modules, and to the ADC module as an input channel only.
2. This output goes to the ADC module as a reference and an input channel.
3. Fixed Voltage Reference output cannot exceed VDD.
0x00
... Reserved
0x03D6
0x03D7 FVRCON 7:0 EN RDY TSEN TSRNG CDAFVR[1:0] ADFVR[1:0]
TSRNG VMEAS
Temperature Indicator
Module
To ADC
TSEN
GND
The output of the circuit is measured using the internal Analog-to-Digital Converter. A channel is reserved for the
temperature circuit output. Refer to the “ADCC - Analog-to-Digital Converter with Computation Module” chapter
for more details.
The ON/OFF bit for the module is located in the FVRCON register. The circuit is enabled by setting the TSEN bit.
When the module is disabled, the circuit draws no current. Refer to the “FVR - Fixed Reference Voltage” chapter
for more details.
Important: The standard parameters for the Temperature Sensor for both high range and low range are
stored in the DIA table. Refer to the DIA table in the “Memory Organization” chapter for more details.
Min. VDD, TSRNG = 1 (High Range) Min. VDD, TSRNG = 0 (Low Range)
≥ 2.5 ≥ 1.8
If the application requires more precise temperature measurement, additional calibrations steps will be necessary.
For these applications, two-point or three-point calibration is recommended. For additional information on two-
point calibration method, refer to the following Microchip application note, available at the corporate website
(www.microchip.com):
• AN2798, “Using the PIC16F/PIC18F Ground Referenced Temperature Indicator Module”
42.4.1 FVRCON
Name: FVRCON
Offset: 0x3D7
Important: This register is shared between the Fixed Voltage Reference (FVR) module and the
temperature indicator module.
Bit 7 6 5 4 3 2 1 0
EN RDY TSEN TSRNG CDAFVR[1:0] ADFVR[1:0]
Access R/W R R/W R/W R/W R/W R/W R/W
Reset 0 q 0 0 0 0 0 0
Notes:
1. This output goes to the DAC and comparator modules, and to the ADC module as an input channel only.
2. This output goes to the ADC module as a reference and an input channel.
3. Fixed Voltage Reference output cannot exceed VDD.
0x00
... Reserved
0x03D6
0x03D7 FVRCON 7:0 EN RDY TSEN TSRNG CDAFVR[1:0] ADFVR[1:0]
PREF
FVR_buffer1 11 Positive
Reference
10 Select
VREF+ pin
Reserved 01
00
VDD
NREF
VREF - pin
1 Negative
Reference
0 Select
VSS CS
AN0
ANa VREF- VREF+
External
FOSC/n Fosc
.
Channel FOS C
ANz ADC Divider
Inputs ADC_clk
sampled Clock
VSS input Select
ADCRC
Temp Indicator
Internal DAC1_output
Channel ADC CLOCK SOURCE
FVR_buffer1
Inputs
FVR_buffer2 ADC
Sample Circuit
PCH
set bit ADIF
ADRESH ADRESL
Trigger Select
ACT
ON
. . .
VSS
Trigger Sources
AUTO CONVERSION
TRIGGER
Important: Analog voltages on any pin that is defined as a digital input may cause the input buffer to
conduct excess current.
Important: To reduce the chance of measurement error, it is recommended to discharge the Sample-
and-Hold capacitor when switching between ADC channels by starting a conversion on a channel
connected to VSS and terminating the conversion after the acquisition time has elapsed. If the ADC does
not have a dedicated VSS input channel, the VSS selection through the DAC output channel can be used. If
the DAC is in use, a free input channel can be connected to VSS, and can be used in place of the DAC.
Important: When CS = 0, the clock can be divided using the ADCLK register to meet the ADC clock
period requirements.
The time to complete one bit conversion is defined as the TAD. Refer to Figure 43-2 for the complete timing details of
the ADC conversion.
For correct conversion, the appropriate TAD specification must be met. Refer to the ADC Timing Specifications table
in the “Electrical Specifications” chapter of the device data sheet for more details. The table below gives examples
of appropriate ADC clock selections.
Table 43-1. ADC Clock Period (TAD) Vs. Device Operating Frequencies(1,3)
ADC Clock ADC Clock Period (TAD) for Different Device Frequency (FOSC)
ADCLK
Source 64 MHz 32 MHz 20 MHz 16 MHz 8 MHz 4 MHz 1 MHz
FOSC/2 ‘b000000 31.25 ns(2) 62.5 ns(2) 100 ns(2) 125 ns(2) 250 ns(2) 500 ns 2.0 μs
FOSC/4 ‘b000001 62.5 ns(2) 125 ns(2) 200 ns(2) 250 ns(2) 500 ns 1.0 μs 4.0 μs
FOSC/6 ‘b000010 93.75 ns(2) 187.5 ns(2) 300 ns(2) 375 ns(2) 750 ns 1.5 μs 6.0 μs
FOSC/8 ‘b000011 125 ns(2) 250 ns(2) 400 ns(2) 500 ns 1.0 μs 2.0 μs 8.0 μs
... ... ... ... ... ... ... ... ...
FOSC/16 ‘b000111 250 ns(2) 500 ns 800 ns 1.0 μs 2.0 μs 4.0 μs 16.0 μs(2)
... ... ... ... ... ... ... ... ...
FOSC/32 ‘b001111 500 ns 1.0 μs 1.6 μs 2.0 μs 4.0 μs 8.0 μs 32.0 μs(2)
... ... ... ... ... ... ... ... ...
FOSC/64 ‘b0111111 1.0 μs 2.0 μs 3.2 μs 4.0 μs 8.0 μs 16.0 μs(2) 64.0 μs(2)
... ... ... ... ... ... ... ... ...
FOSC/128 ‘b111111 2.0 μs 4.0 μs 6.4 μs 8.0 μs 16.0 μs(2) 32.0 μs(2) 128.0 μs(2)
ADCRC CS = 1 1.0-6.0 μs 1.0-6.0 μs 1.0-6.0 μs 1.0-6.0 μs 1.0-6.0 μs 1.0-6.0 μs 1.0-6.0 μs
Notes:
1. Refer to the "Electrical Specifications" chapter of the device data sheet to see the TAD parameter for the ADCRC source
typical TAD value.
2. These values violate the required TAD time.
3. The ADC clock period (TAD) and total ADC conversion time can be minimized when the ADC clock is derived from the system
clock FOSC. However, the ADCRC oscillator source must be used when conversions are to be performed with the device in
Sleep mode.
Important:
• Except for the ADCRC clock source, any changes in the system clock frequency will change the ADC
clock frequency, which may adversely affect the ADC result.
• The internal control logic of the ADC runs off of the clock selected by the CS bit. When the CS bit is
set to ‘1’ (ADC runs on ADCRC), there may be unexpected delays in operation when setting the ADC
control bits.
43.1.5 Interrupts
The ADC module allows for the ability to generate an interrupt upon completion of an Analog-to-Digital Conversion.
The ADC interrupt flag is the ADIF bit in the PIRx register. The ADC interrupt enable is the ADIE bit in the PIEx
register. The ADIF bit must be cleared by software.
Important:
1. The ADIF bit is set at the completion of every conversion, regardless of whether or not the ADC
interrupt is enabled.
2. The ADC operates during Sleep only when the ADCRC oscillator is selected.
This interrupt will be generated while the device is operating and while in Sleep. If the device is in Sleep, the interrupt
will wake up the device. Upon waking from Sleep, the next instruction following the SLEEP instruction is always
executed. If the user is attempting to wake up from Sleep and resume in-line code execution, the ADIE bit and the
GIEL bit must both be set and the GIE bit must be cleared. When all three of these bits are set, the execution will
switch to the Interrupt Service Routine.
ADRESH ADRESL
Important: Writes to the ADRES register pair are always right justified, regardless of the selected format
mode. Therefore, a data read after writing to ADRES when FM = 0 will be shifted left four places.
Important: The GO bit needs to not be set in the same instruction that turns on the ADC. Refer to the
ADC Conversion Procedure (Basic Mode) section for more details.
conversion. This allows the SLEEP instruction to be executed, which can reduce system noise during the conversion.
If the ADC interrupt is enabled, the device will wake up from Sleep when the conversion completes. If the ADC
interrupt is disabled, the device remains in Sleep and the ADC module is turned off after the conversion completes,
although the ON bit remains set.
; This code block configures the ADC for polling, Vdd and Vss references,
; ADCRC oscillator, and AN0 input.
; Conversion start & polling for completion are included.
BANKSEL ADCON1 ;
clrf ADCON1 ;
//Setup ADC
ADCON0bits.FM = 1; //right justify
ADCON0bits.CS = 1; //ADCRC Clock
ADPCH = 0x00; //RA0 is Analog channel
TRISAbits.TRISA0 = 1; //Set RA0 to input
ANSELAbits.ANSELA0 = 1; //Set RA0 to analog
ADCON0bits.ON = 1; //Turn ADC On
while (1) {
ADCON0bits.GO = 1; //Start conversion
while (ADCON0bits.GO); //Wait for conversion done
resultHigh = ADRESH; //Read result
resultLow = ADRESL; //Read result
}
}
TACQ = Amplifier Settling Time + Hold Capacitor Charging Time + Temperature Coefficient
TACQ = TAMP + TC + TCOFF
1
VAPPLIED 1 − = VCHOLD ; [1] VCHOLD charged to within ½ lsb
2n + 1 − 1
−TC
VAPPLIED 1 − e RC = VCHOLD ; [2] VCHOLD charge response to VAPPLIED
−TC
1
VAPPLIED 1 − e RC = VAPPLIED 1 − ; Combining [1] and [2]
2n + 1 − 1
TC = − 28 pF 1 kΩ + 7 kΩ + 10 kΩ ln 0.0001221
TC = 4.54 μs
Therefore:
TACQ = 7.79 μs
Important:
• The reference voltage (VREF) has no effect on the equation, since it cancels itself out.
• The charge holding capacitor (CHOLD) is not discharged after each conversion.
• The maximum recommended impedance for analog sources is 10 kΩ. This is required to meet the pin
leakage specification.
Sampling
VDD
Switch
Analog
VT 0.6V SS
RS Input pin RIC 1K RSS
VSS Ref-
Rev. 30-000115B
6/27/2017
Full-Scale Range
FFFh
FFEh
FFDh
FFCh
ADC Output Code
FFBh
03h
02h
01h
00h
Analog Input Voltage
0.5 LSB 1.5 LSB
REF- Zero-Scale
Transition Full-Scale
Transition REF+
The charge pump can be enabled by setting the CPON bit. Once enabled, the pump will undergo a start-up time to
stabilize the charge pump output. Once the output stabilizes and is ready for use, the CPRDY bit will be set.
CALC
TMD
ADRES
CRS
ADFLTR
Set
Error Threshold
ADERR Interrupt
Average/ Calculation Logic
1 Flag
Filter ADPREV
0
ADSTPT
ADUTH ADLTH
PSIS
Register Clear
Value after Cycle(1) Completion Threshold Operations Value at ADCHmIF Interrupt
Mode MD Event
and its subsidiaries
© 2020-2022 Microchip Technology Inc.
rotatethispage90
ADACC and CNT ADACC ADCNT Retrigger Threshold Test Interrupt AOV ADFLTR ADCNT
Basic 0 ACLR = 1 Unchanged Unchanged No Every Sample If threshold=true N/A N/A count
S1 + ADACC or If (ADCNT=0xFF):
ADACC ADACC/
Accumulate 1 ACLR = 1 (S2-S1)(2) + ADCNT, otherwise: No Every Sample If threshold=true count
Overflow 2CRS
ADACC ADCNT+1
ACLR = 1 or S1 + ADACC or If (ADCNT=0xFF):
ADACC ADACC/
Average 2 ADCNT≥ADRPT at (S2-S1) + ADCNT, otherwise: No If ADCNT≥ADRPT If threshold=true count
Overflow 2CRS
GO set or retrigger ADACC ADCNT+1
Each repetition:
Each repetition:
same as
Burst ACLR = 1 or at GO same as Average Repeat while ADACC ADACC/
3 Average End If ADCNT≥ADRPT If threshold=true ADRPT
Average set or retrigger End with ADCNT<ADRPT Overflow 2CRS
with sum of all
ADCNT=ADRPT
samples
S1+ADACC-
ADACC/
ADACC/ If (ADCNT=0xFF):
Low-pass ADACC 2CRS
4 ACLR = 1 2CRS or (S2- ADCNT, otherwise: No If ADCNT≥ADRPT If threshold=true count
Filter Overflow (Filtered
S1)+ADACC- ADCNT+1
Value)
ADACC/2CRS
1. When DSEN = 0 then Cycle means one conversion. When DSEN = 1 then Cycle means two conversions.
2. S1 and S2 are abbreviations for Sample 1 and Sample 2, respectively. When DSEN = 0, S1 = ADRES; When DSEN = 1, S1 = ADPREV and S2 = ADRES.
PIC18F26/46/56Q83
DS40002253C-page 894
PIC18F26/46/56Q83
ADC - Analog-to-Digital Converter with Com...
Important: When ADC is operating from ADCRC, up to five ADCRC clock cycles are required to execute
the ADACC clearing operation.
The CRS bits control the data shift on the accumulator result, which effectively divides the value in the accumulator
registers. For the Accumulate mode of the digital filter, the shift provides a simple scaling operation. For the Average/
Burst Average mode, the calculated average is only accurate when the number of samples agrees with the number of
bits shifted. For the Low-Pass Filter mode, the shift is an integral part of the filter, and determines the cutoff frequency
of the filter. Table 43-3 shows the -3 dB cutoff frequency in ωT (radians) and the highest signal attenuation obtained
by this filter at Nyquist frequency (ωT = π).
Table 43-3. Low-Pass Filter -3 dB Cutoff Frequency
ADRPT value. In this mode, when ADRPT = 2CRS, the final accumulated value will be divided by the number of
samples, allowing for a threshold comparison operation on the average of all gathered samples.
Important:
• The threshold tests are signed operations.
• If the AOV bit is set, a threshold interrupt is signaled. It is good practice for threshold interrupt
handlers to verify the validity of the threshold by checking the AOV bit.
VDD VDD
ADCAP
Additional
Sample
Capacitors
VDD
Note 1 Note 1
Voltage
VSS
Note 1: External Capacitive Sensor voltage during the conversion phase m ay vary as per the configuration of the
corresponding pin.
Important: The external charging overrides the TRIS/LAT/Guard outputs setting of the respective I/O pin.
If there is a device attached to this pin, precharge must not be used.
channel is connected to CHOLD. This allows charge averaging to proceed between the precharged channel and the
CHOLD capacitor.
Important: When ADPRE > 0, setting ADACQ to ‘0’ will set a maximum acquisition time. When
precharge is disabled, setting ADACQ to ‘0’ will disable hardware acquisition time control.
ADGRDA
RA
RB CGUARD
ADGRDB
VSS
ADGRDA
ADGRDB
Note 1: External Capacitive Sensor voltage during the conversion phase m ay vary as per the configuration of the corresponding pin.
Context information is stored in duplicated registers located in device memory and can only be accessed through the
A/D Context Selection (ADCTX) Register or via Direct Memory Access (DMA).
Important: The ADCLK and ADACT registers are not included as part of a channel context.
The conversion clock rate selected by ADCLK and the auto-conversion trigger source selected by ADACT are used
for all contexts. For example, if Context 1 enables the Timer1 overflow as the auto-conversion trigger source, the
Timer1 overflow trigger will be used for all other contexts as well. If user software configures the auto-conversion
trigger to use the Timer0 overflow as the trigger source for Context 2, Context 1 will be reconfigured in hardware to
also use the Timer0 overflow as the trigger source.
The table below highlights the registers that are part of a context.
Table 43-4. ADC Context Registers
Register Bit Pos. Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
ADCON0(1) 7:0 ON CONT CSEN CS FM GO
ADCON1 7:0 PPOL IPEN GPOL DSEN
ADCON2 7:0 PSIS CRS[2:0] ACLR MD[2:0]
ADCON3 7:0 CALC[2:0] SOI TMD[2:0]
ADSTAT 7:0 AOV UTHR LTHR MATH STAT[2:0]
ADREF 7:0 NREF PREF[1:0]
ADPCH 7:0 PCH[5:0]
7:0 PRE[7:0]
ADPRE
15:8 PRE[12:8]
7:0 ADACQ[7:0]
ADACQ
15:8 ADACQ[12:8]
ADCAP 7:0 CAP[4:0]
ADRPT 7:0 RPT[7:0]
ADCNT 7:0 CNT[7:0]
7:0 FLTR[7:0]
ADFLTR
15:8 FLTR[15:8]
7:0 RES[7:0]
ADRES
15:8 RES[15:8]
7:0 PREV[7:0]
ADPREV
15:8 PREV[15:8]
7:0 ACC[7:0]
ADACC 15:8 ACC[15:8]
23:16 ACC[17:16]
7:0 STPT[7:0]
ADSTPT
15:8 STPT[15:8]
...........continued
Register Bit Pos. Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
7:0 ERR[7:0]
ADERR
15:8 ERR[15:8]
7:0 LTH[7:0]
ADLTH
15:8 LTH[15:8]
7:0 UTH[7:0]
ADUTH
15:8 UTH[15:8]
Note:
1. The ADCON0 register is not included as part of a channel context with the exception of bit 6 (CONT).
The A/D Context Selection (ADCTX) register selects the context number that will be given read/write access. The A/D
Context Display Select (CTXSW) bit is used to determine the read/write status of the A/D Channel Context Selection
(CTX) bits, which are used to determine the channel context number.
When CTXSW is set (CTXSW = 1), the CTX bits display the context number the sequencer is currently scanning, or
the context number that was active when the sequencer stopped scanning due to a context threshold interrupt.
Important: When CTXSW is set, the CTX bits are read-only and may only be read while context
sequencing is enabled (CSEN = 1).
When CTXSW is clear (CTXSW = 0), the CTX bits display the context number as selected by user software. Any
context can be selected by writing the CTX bits with the desired context number.
Remember: The context number is always one number greater than the value written into the CTX bits.
For example, when the CTX bits are written with zero (CTX = 0), Context 1 is in view.
Once the context number has been written into the CTX bits, the selected channel context is available for software
access. After each ADC register is configured, the register value is copied into the associated context register.
Data can also be read from the ADC’s data registers (ADFLTR, ADRES, etc.) using the same steps above. Rather
than configuring the desired ADC registers in step 2, user software can instead read data from the desired data
registers.
It is highly recommended to verify that the STAT bits of the ADSTAT register are clear (STAT = 0) before
WARNING
changing any context registers. Modifying context registers during an active conversion may lead to data
corruption.
void configADCContext(void)
{
ADCTX = 0x00; // Select Context 1
// Configure ADC registers for Context 1
ADLTHL = 0x10; // Lower threshold = 1000
ADLTHH = 0x27;
ADUTHL = 0xE8; // Upper threshold = 10,000
ADUTHH = 0x03;
ADSTPTL = 0x00; // Setpoint = 0
ADSTPTH = 0x00;
ADACCU = 0x00;
ADRPT = 0x10; // Accumulate 16 samples
ADPCH = 0x00; // PCH ANA0;
ADCON1 = 0x00;
ADCON2 = 0x01; // Accumulate_mode
ADCON3 = 0x04;
ADSTAT = 0x00;
ADREF = 0x00; // ADNREF VSS; ADPREF VDD;
ADCON0 = 0x04; // CONT = 0
Important: If a context’s CONT bit is set and both the SOI and SSI bits are clear, the scanner will
repeatedly scan that context indefinitely without scanning any further channels.
If Context 1’s CONT bit is clear (CONT = 0), the sequencer will scan Context 1, and when the conversion completes,
the channel threshold test is performed. If ADCH1IF is set, the sequencer checks Context 1’s SSI bit to determine
whether to proceed to the next channel context. If SSI is set, the sequencer clears GO and the scanner stops. If the
SSI bit is clear, the sequencer will proceed to the next channel that has the CHEN bit set.
Important: When the CONT bit is clear, the SOI bit is ignored.
The scan sequence ends when any context’s channel threshold interrupt occurs and that context’s SSI bit is set.
If the sequencer has scanned all enabled channels and no interrupt occurs, or no context’s SSI bit is set, the
sequencer will return to Context 1 (or the first enabled channel context) and repeat the scanning process until
software clears the GO bit.
Important: The final channel in a sequence need to set the Threshold Interrupt Mode Select (TMD) bits
to “Interrupt regardless of the threshold test results” (TMD = 111) and set the SSI bit. These settings allow
the scanner to stop after the scan sequence has completed.
PIC18F26/46/56Q83
Title:
Last Edit: 7/18/2019
First Used:
Notes: ADC - Analog-to-Digital Converter with Com...
GO = 1
NO NO
NO NO
YES
Contextm NO ADCON0. NO GO = 0
CONT = 1? CSEN = 1? (Scan ends)
YES
Notes:
Note 1: If all channels are disabled (ADCSEL[1..4].CHEN = 0), the scanner stops, but the GO bit remains set. No interrupts will
1. If all and
occur, if software
channels arerelies on a hardware
disabled clear of GO to continue
(ADCSEL[1..4].CHEN code
= 0), the execution,
scanner the but
stops, program will stall
the GO indefinitely.
bit remains set. No
2: ADC computation modes (Average, Burst-Average, etc.) are included in the Perform ADC Operation block.
interrupts will occur. If software relies on a hardware clear of GO to continue code execution, the program will
stall indefinitely.
2. ADC computation modes (Average, Burst Average, etc.) are included in the ‘Perform ADC Operation’ block.
void scanOnce(void)
{
configScan124(); // Configure sequencer
ADCON0bits.ON = 1; // Enable the ADC
void configScan124(void)
{
configADCContext(); // Configure channel contexts
ADCSEL1.CHEN = 1; // Enable Context 1
ADCSEL1.SSI = 0; // Don't stop on interrupt
ADCSEL2.CHEN = 1; // Enable Context 2
ADCSEL2.SSI = 0; // Don't stop on interrupt
ADCSEL3.CHEN = 0; // Context 3 not included in scan
ADCSEL3.SSI = 0; // Don't stop on interrupt
ADCSEL4.CHEN = 0; // Enable Context 4
ADCSEL4.SSI = 1; // Stop scan on last context
void main(void)
{
TMR1_Initialize(); // Configure TMR1
configScan124(); // Configure sequencer
ADACT = TMR1_overflow; // TMR1 is Auto-Conversion trigger
ADCON0bits.ON = 1; // Enable the ADC
T1CONbits.ON = 1; // Start TMR1
while(1)
{
// wait for ADCH4IF = 1 and service ISR
}
}
43.7.1 ADCON0
Name: ADCON0
Offset: 0x3F3
Bit 7 6 5 4 3 2 1 0
ON CONT CSEN CS FM GO
Access R/W R/W R/W R/W R/W R/W/HC/HS
Reset 0 0 0 0 0 0
Notes:
1. This bit requires ON bit to be set.
2. If cleared by software while a conversion is in progress, the results of the conversion up to this point will be
transferred to ADRES and the state machine will be reset, but the ADIF interrupt flag bit will not be set; filter
and threshold operations will not be performed.
43.7.2 ADCON1
Name: ADCON1
Offset: 0x3F4
Bit 7 6 5 4 3 2 1 0
PPOL IPEN GPOL DSEN
Access R/W R/W R/W R/W
Reset 0 0 0 0
43.7.3 ADCON2
Name: ADCON2
Offset: 0x3F5
Bit 7 6 5 4 3 2 1 0
PSIS CRS[2:0] ACLR MD[2:0]
Access R/W R/W R/W R/W R/W/HC R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. To correctly calculate an average, the number of samples (set in ADRPT) must be 2CRS.
2. CRS = ‘b111 and ‘b000 are reserved.
3. This bit is cleared by hardware when the accumulator operation is complete; depending on oscillator
selections, the delay may be many instructions.
4. See the section for full mode descriptions.
43.7.4 ADCON3
Name: ADCON3
Offset: 0x3F6
Bit 7 6 5 4 3 2 1 0
CALC[2:0] SOI TMD[2:0]
Access R/W R/W R/W R/W/HC R/W R/W R/W
Reset 0 0 0 0 0 0 0
ADERR
CALC DSEN = 0 Single-Sample DSEN = 1 CVD Double- Application
Mode Sample Mode(1)
111 Reserved Reserved Reserved
110 Reserved Reserved Reserved
101 ADFLTR-ADSTPT ADFLTR-ADSTPT Average/filtered value vs. setpoint
First derivative of filtered value(3)
100 ADPREV-ADFLTR ADPREV-ADFLTR
(negative)
011 Reserved Reserved Reserved
010 ADRES-ADFLTR (ADRES-ADPREV)-ADFLTR Actual result vs. averaged/filtered value
001 ADRES-ADSTPT (ADRES-ADPREV)-ADSTPT Actual result vs. setpoint
First derivative of single measurement(2)
000 ADRES-ADPREV ADRES-ADPREV
Actual CVD result(2)
Notes:
1. When DSEN = 1 and PSIS = 0, ADERR is computed only after every second sample.
2. When PSIS = 0.
3. When PSIS = 1.
43.7.5 ADSTAT
Name: ADSTAT
Offset: 0x3F7
Bit 7 6 5 4 3 2 1 0
AOV UTHR LTHR MATH STAT[2:0]
Access R/C/HS/HC R R R/W/HS R R R
Reset 0 0 0 0 0 0 0
Notes:
1. The MATH bit cannot be cleared by software while STAT = ‘b100.
2. If ADC clock source is ADCRC, and FOSC < ADCRC, the indicated status may not be valid.
3. STAT = ‘b100 appears between the two triggers when DSEN = 1 and CONT = 0.
43.7.6 ADCLK
Name: ADCLK
Offset: 0x3FA
Bit 7 6 5 4 3 2 1 0
CS[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Note: ADC Clock divider is only available if FOSC is selected as the ADC clock source (CS = 0).
43.7.7 ADREF
Name: ADREF
Offset: 0x3F8
Bit 7 6 5 4 3 2 1 0
NREF PREF[1:0]
Access R/W R/W R/W
Reset 0 0 0
43.7.8 ADPCH
Name: ADPCH
Offset: 0x3EC
Bit 7 6 5 4 3 2 1 0
PCH[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
...........continued
PCH ADC Positive Channel Input
001111 RB7/ANB7
001110 RB6/ANB6
001101 RB5/ANB5
001100 RB4/ANB4
001011 RB3/ANB3
001010 RB2/ANB2
001001 RB1/ANB1
001000 RB0/ANB0
000111 RA7/ANA7
000110 RA6/ANA6
000101 RA5/ANA5
000100 RA4/ANA4
000011 RA3/ANA3
000010 RA2/ANA2
000001 RA1/ANA1
000000 RA0/ANA0
Notes:
1. Refer to the “Fixed Voltage Reference Module” chapter for more details.
2. Refer to the “Digital-to-Analog Converter Module” chapter for more details.
3. Refer to the “Temperature Indicator Module” chapter for more details.
4. 40/44/48-pin devices only.
5. 48-pin devices only.
43.7.9 ADPRE
Name: ADPRE
Offset: 0x3F1
Bit 15 14 13 12 11 10 9 8
PRE[12:8]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
PRE[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• ADPREH: Accesses the high byte ADPRE[12:8]
• ADPREL: Accesses the low byte ADPRE[7:0]
43.7.10 ADACQ
Name: ADACQ
Offset: 0x3EE
Bit 15 14 13 12 11 10 9 8
ACQ[12:8]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
ACQ[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• ADACQH: Accesses the high byte ADACQ[12:8]
• ADACQL: Accesses the low byte ADACQ[7:0]
43.7.11 ADCAP
Name: ADCAP
Offset: 0x3F0
Bit 7 6 5 4 3 2 1 0
CAP[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
43.7.12 ADRPT
Name: ADRPT
Offset: 0x3E7
Bit 7 6 5 4 3 2 1 0
RPT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
43.7.13 ADCNT
Name: ADCNT
Offset: 0x3E6
Bit 7 6 5 4 3 2 1 0
CNT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
43.7.14 ADFLTR
Name: ADFLTR
Offset: 0x3E1
Bit 15 14 13 12 11 10 9 8
FLTR[15:8]
Access R R R R R R R R
Reset x x x x x x x x
Bit 7 6 5 4 3 2 1 0
FLTR[7:0]
Access R R R R R R R R
Reset x x x x x x x x
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• ADFLTRH: Accesses the high byte ADFLTR[15:8]
• ADFLTRL: Accesses the low byte ADFLTR[7:0]
43.7.15 ADRES
Name: ADRES
Offset: 0x3EA
Bit 15 14 13 12 11 10 9 8
RES[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
RES[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• ADRESH: Accesses the high byte ADRES[15:18]
• ADRESL: Accesses the low byte ADRES[7:0]
43.7.16 ADPREV
Name: ADPREV
Offset: 0x3E8
Bit 15 14 13 12 11 10 9 8
PREV[15:8]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
PREV[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
Notes:
1. If PSIS = 0, ADPREV is formatted the same way as ADRES is, depending on the FM bit.
2. The individual bytes in this multibyte register can be accessed with the following register names:
– ADPREVH: Accesses ADPREV[15:8]
– ADPREVL: Accesses ADPREV[7:0]
43.7.17 ADACC
Name: ADACC
Offset: 0x3E3
Important: This register contains signed two’s complement accumulator value and the upper unused bits
contain copies of the sign bit.
Bit 23 22 21 20 19 18 17 16
ACC[17:16]
Access R/W R/W
Reset x x
Bit 15 14 13 12 11 10 9 8
ACC[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
Bit 7 6 5 4 3 2 1 0
ACC[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
Notes:
1. This register can only be written when GO = 0.
2. The individual bytes in this multibyte register can be accessed with the following register names:
– ADACCU: Accesses the upper byte ADACC[17:16]
– ADACCH: Accesses the high byte ADACC[15:8]
– ADACCL: Accesses the low byte ADACC[7:0]
43.7.18 ADSTPT
Name: ADSTPT
Offset: 0x3DF
Bit 15 14 13 12 11 10 9 8
STPT[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
STPT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• ADSTPTH: Accesses the high byte ADSTPT[15:8]
• ADSTPTH: Accesses the low byte ADSTPT[7:0]
43.7.19 ADERR
Name: ADERR
Offset: 0x3DD
Bit 15 14 13 12 11 10 9 8
ERR[15:8]
Access R R R R R R R R
Reset x x x x x x x x
Bit 7 6 5 4 3 2 1 0
ERR[7:0]
Access R R R R R R R R
Reset x x x x x x x x
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• ADERRH: Accesses the high byte ADERR[15:8]
• ADERRL: Accesses the low byte ADERR[7:0]
43.7.20 ADLTH
Name: ADLTH
Offset: 0x3D9
Bit 15 14 13 12 11 10 9 8
LTH[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
LTH[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• ADLTHH: Accesses the high byte ADLTH[15:8]
• ADLTHL: Accesses the low byte ADLTH[7:0]
43.7.21 ADUTH
Name: ADUTH
Offset: 0x3DB
Bit 15 14 13 12 11 10 9 8
UTH[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
UTH[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• ADUTHH: Accesses the high byte ADUTH[15:8]
• ADUTHL: Accesses the low byte ADUTH[7:0]
43.7.22 ADACT
Name: ADACT
Offset: 0x3F9
Bit 7 6 5 4 3 2 1 0
ACT[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
...........continued
ACT Auto-Conversion Trigger Source
000111 TMR5_overflow
000110 TMR4_postscaled
000101 TMR3_overflow
000100 TMR2_postscaled
000011 TMR1_overflow
000010 TMR0_overflow
000001 Pin selected by ADACTPPS
000000 External Trigger Disabled
43.7.23 ADCP
Name: ADCP
Offset: 0x3D8
Bit 7 6 5 4 3 2 1 0
CPON CPRDY
Access R/W R
Reset 0 0
43.7.24 ADCTX
Name: ADCTX
Offset: 0x3FB
Bit 7 6 5 4 3 2 1 0
CTXSW CTX[1:0]
Access R/W R/W R/W
Reset 0 0 0
Notes:
1. The context number is always one number greater than the value written into the CTX bits. For example, when
the CTX bits are written with zero (CTX = 0), Context 1 is in view.
2. When CTXSW is set, the CTX bits are read-only and may only be read while context sequencing is enabled
(CSEN = 1).
43.7.25 ADCSELx
Name: ADCSELx
Offset: 0x3FC,0x3FD,0x3FE,0x3FF
Bit 7 6 5 4 3 2 1 0
CHEN SSI
Access R/W R/W
Reset 0 0
0x00
... Reserved
0x03D7
0x03D8 ADCP 7:0 CPON CPRDY
7:0 LTH[7:0]
0x03D9 ADLTH
15:8 LTH[15:8]
7:0 UTH[7:0]
0x03DB ADUTH
15:8 UTH[15:8]
7:0 ERR[7:0]
0x03DD ADERR
15:8 ERR[15:8]
7:0 STPT[7:0]
0x03DF ADSTPT
15:8 STPT[15:8]
7:0 FLTR[7:0]
0x03E1 ADFLTR
15:8 FLTR[15:8]
7:0 ACC[7:0]
0x03E3 ADACC 15:8 ACC[15:8]
23:16 ACC[17:16]
0x03E6 ADCNT 7:0 CNT[7:0]
0x03E7 ADRPT 7:0 RPT[7:0]
7:0 PREV[7:0]
0x03E8 ADPREV
15:8 PREV[15:8]
7:0 RES[7:0]
0x03EA ADRES
15:8 RES[15:8]
0x03EC ADPCH 7:0 PCH[5:0]
0x03ED Reserved
7:0 ACQ[7:0]
0x03EE ADACQ
15:8 ACQ[12:8]
0x03F0 ADCAP 7:0 CAP[4:0]
7:0 PRE[7:0]
0x03F1 ADPRE
15:8 PRE[12:8]
0x03F3 ADCON0 7:0 ON CONT CSEN CS FM GO
0x03F4 ADCON1 7:0 PPOL IPEN GPOL DSEN
0x03F5 ADCON2 7:0 PSIS CRS[2:0] ACLR MD[2:0]
0x03F6 ADCON3 7:0 CALC[2:0] SOI TMD[2:0]
0x03F7 ADSTAT 7:0 AOV UTHR LTHR MATH STAT[2:0]
0x03F8 ADREF 7:0 NREF PREF[1:0]
0x03F9 ADACT 7:0 ACT[5:0]
0x03FA ADCLK 7:0 CS[5:0]
0x03FB ADCTX 7:0 CTXSW CTX[1:0]
0x03FC ADCSEL1 7:0 CHEN SSI
0x03FD ADCSEL2 7:0 CHEN SSI
0x03FE ADCSEL3 7:0 CHEN SSI
0x03FF ADCSEL4 7:0 CHEN SSI
R
PSS
2n 2n to 1 DACx_output
To Peripherals
Steps MUX
EN
R
R DACxOUTn
OEn(1)
R
NSS
Note: 1. The output enable bits are configured so that they act as a one-hot system, meaning only one DAC output
can be enabled at a time.
44.5.1 DACxCON
Name: DACxCON
Offset: 0x7F
Bit 7 6 5 4 3 2 1 0
EN OE[1:0] PSS[1:0] NSS
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
OE DAC Outputs
11 DACxOUT is disabled
10 DACxOUT is enabled on pin RA2 only
01 DACxOUT is enabled on pin RB7 only
00 DACxOUT is disabled
44.5.2 DACxDATL
Name: DACxDATL
Offset: 0x7D
Bit 7 6 5 4 3 2 1 0
DACxR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
0x00
... Reserved
0x7C
0x7D DAC1DATL 7:0 DAC1R[7:0]
0x7E Reserved
0x7F DAC1CON 7:0 EN OE[1:0] PSS[1:0] NSS
VIN+ +
Output
VIN- –
VIN-
VIN+
Output
Note:
1. The black areas of the output of the comparator represent the uncertainty due to input offsets and response
time.
Interrupt INTP
Rising
Edge set bit
NCH EN(1)
CxIF
Interrupt INTN
Falling
EN(1) Edge
CxVN +
HYS POL
CxOUT_sync To Other
See CMxPCH Peripherals
Register SYNC
TRIS bit
0
PPS CxOUT
(1)
D Q 1
PCH EN
Note 1: When EN = 0, all multiplexer inputs are disconnected and the Comparator will produce a ‘0’ at the output.
The comparator output can also be routed to an external pin through the RxyPPS register. Refer to the “PPS -
Peripheral Pin Select Module” chapter for more details. The corresponding TRIS bit must be clear to enable the pin
as an output.
Important: The internal output of the comparator is latched with each instruction cycle. Unless otherwise
specified, external outputs are not latched.
The associated interrupt flag bit, CxIF bit of the respective PIR register, must be cleared in software to successfully
detect another edge.
Important: Although a comparator is disabled, an interrupt will be generated by changing the output
polarity with the POL bit.
Important: To use CxINy+ and CxINy- pins as analog input, the appropriate bits must be set in the
ANSEL register and the corresponding TRIS bits must also be set to disable the output drivers.
Analog
VT 0.6V
RS Input pin RIC
To Comparator
VSS
Note:
1. See the "Electrical Specifications" chapter.
45.12.1 CMxCON0
Name: CMxCON0
Offset: 0x070,0x074
Bit 7 6 5 4 3 2 1 0
EN OUT POL HYS SYNC
Access R/W R R/W R/W R/W
Reset 0 0 0 0 0
45.12.2 CMxCON1
Name: CMxCON1
Offset: 0x071,0x075
Bit 7 6 5 4 3 2 1 0
INTP INTN
Access R/W R/W
Reset 0 0
45.12.3 CMxNCH
Name: CMxNCH
Offset: 0x072,0x076
Bit 7 6 5 4 3 2 1 0
NCH[2:0]
Access R/W R/W R/W
Reset 0 0 0
45.12.4 CMxPCH
Name: CMxPCH
Offset: 0x073,0x077
Bit 7 6 5 4 3 2 1 0
PCH[2:0]
Access R/W R/W R/W
Reset 0 0 0
45.12.5 CMOUT
Name: CMOUT
Offset: 0x06F
Bit 7 6 5 4 3 2 1 0
C2OUT C1OUT
Access R R
Reset 0 0
0x00
... Reserved
0x6E
0x6F CMOUT 7:0 C2OUT C1OUT
0x70 CM1CON0 7:0 EN OUT POL HYS SYNC
0x71 CM1CON1 7:0 INTP INTN
0x72 CM1NCH 7:0 NCH[2:0]
0x73 CM1PCH 7:0 PCH[2:0]
0x74 CM2CON0 7:0 EN OUT POL HYS SYNC
0x75 CM2CON1 7:0 INTP INTN
0x76 CM2NCH 7:0 NCH[2:0]
0x77 CM2PCH 7:0 PCH[2:0]
VPULLUP
RPULLUP
(optional)
VDD
- ZCDxIN RSERIES
External
Zcpinv + voltage
source
RPULLDOWN
(optional)
POL
OUT pin
Interrupt
det
INTP Set
ZCDxIF
INTN flag
Interrupt
det
The ZCD module is useful when monitoring an A/C waveform for, but not limited to, the following purposes:
• A/C period measurement
• Accurate long term time measurement
VMAXPEAK
VPEAK VMINPEAK
Z CPINV
Note: In this example, the impedance value is calculated for a peak current of 300 μA.
Equation 46-2. R-C Equations
VPEAK = external voltage source peak voltage
f = external voltage source frequency
C = series capacitor
R = series resistor
VC = peak capacitor voltage
Φ = capacitor induced zero-crossing phase advance in radians
TΦ = time ZC event occurs before actual zero-crossing
VPEAK
Z=
3 × 10−4
1
XC =
2πfC
R= Z2 − XC2
VC = XC 3 × 10−4
XC
Φ = tan −1
R
TΦ = Φ
2πf
f = 60 Hz
C = 0.1 μF
VPEAK 169.7 = 565.7 kΩ
Z= =
3 × 10−4 3 × 10−4
1 = 1
XC = = 26.53 kΩ
2πfC 2π × 60 × 10−7
Ra = 560 kΩ used
VPEAK
IPEAK = = 302.7 × 10−6A
ZR
VC = XC × IPEAK = 8.0 V
XC
Φ = tan −1 = 0.047 radians
R
TΦ = Φ = 125.6 μs
2πf
This offset time can be compensated for by adding a pull-up or pull-down biasing resistor to the ZCD pin. A pull-up
resistor is used when the external voltage source is varying relative to VSS. A pull-down resistor is used when
the voltage is varying relative to VDD. The resistor adds a bias to the ZCD pin so that the target external voltage
source must go to zero to pull the pin voltage to the ZCPINV switching voltage. The pull-up or pull-down value can be
determined with the equations shown below.
RSERIES ZCPINV
Rpulldown =
VDD − ZCPINV
Tip: It is recommended that the maximum peak voltage be no more than six times the minimum peak
voltage.
46.10.1 ZCDCON
Name: ZCDCON
Offset: 0x04C
Bit 7 6 5 4 3 2 1 0
SEN OUT POL INTP INTN
Access R/W R R/W R/W R/W
Reset 0 x 0 0 0
0x00
... Reserved
0x4B
0x4C ZCDCON 7:0 SEN OUT POL INTP INTN
The two-word instructions execute in two instruction cycles and three-word instructions execute in three instruction
cycles.
One instruction cycle consists of four oscillator periods. Thus, for an oscillator frequency of 4 MHz, the normal
instruction execution time is 1 μs. If a conditional test is true, or the Program Counter is changed as a result of an
instruction, the instruction execution time is 2 μs. Two-word branch instructions (if true) take 3 μs.
Figure 47-1, Figure 47-2 and Figure 47-3 show the general formats that the instructions can have. All examples use
the convention ‘nnh’ to represent a hexadecimal number.
The Instruction Set Summary, shown in Table 47-2, lists the standard instructions recognized by the Microchip
MPASMTM Assembler.
Standard Instruction Set provides a description of each instruction.
Table 47-1. Opcode Field Descriptions
Field Description
RAM access bit
a a = 0: RAM location in Access RAM (BSR register is ignored)
a = 1: RAM bank is specified by BSR register (default)
ACCESS ACCESS = 0: RAM access bit symbol
BANKED BANKED = 1: RAM access bit symbol
bbb Bit address within an 8-bit file register (0 to 7)
BSR Bank Select Register (BSR). Used to select the current RAM bank.
Destination select bit
d d = 0: store result in WREG
d = 1: store result in file register f (default)
dest Destination: either the WREG register or the specified register file location
f 8-bit register file address (00h to FFh)
fn FSR Number (0 to 2)
12-bit register file address (000h to FFFh) or 14-bit register file address (0000h to 3FFFh).
fs
This is the source address.
12-bit register file address (000h to FFFh) or 14-bit register file address (0000h to 3FFFh).
fd
This is the destination address.
7-bit literal offset for FSR2 to used as register file address (000h to FFFh). This is the source
zs
address.
7-bit literal offset for FSR2 to used as register file address (000h to FFFh). This is the
zd
destination address.
k Literal field, constant data or label (may be either a 6-bit, 8-bit, 12-bit or a 20-bit value)
label Label name
mm The mode of the TBLPTR register for the table read and table write instructions.
Only used with table read and table write instructions:
...........continued
Field Description
The relative address (two’s complement number) for relative branch instructions, or the direct
n
address for call/branch and return instructions.
PRODH Product of multiply high byte
PRODL Product of multiply low byte
Fast Call/Return mode select bit
s s = 0: do not update into/from shadow registers (default)
s = 1: certain registers loaded into/from shadow registers (Fast mode)
u Unused or unchanged
W W = 0: Destination select bit symbol
WREG Working register (accumulator)
Don’t care (‘0’ or ‘1’). The assembler will generate code with x = 0. It is the recommended
x
form of use for compatibility with all Microchip software tools.
TBLPTR 21-bit Table Pointer (points to a program memory location)
TABLAT 8-bit table latch
TOS Top-of-stack (TOS)
PC Program Counter
PCL Program Counter low byte
PCH Program Counter high byte
PCLATH Program Counter high byte latch
PCLATU Program Counter upper byte Latch
GIE Global Interrupt Enable bit
WDT Watchdog Timer
TO Time-Out bit
PD Power-Down bit
C, DC, Z, OV, N ALU Status bits: Carry, Digit Carry, Zero, Overflow, Negative
{ } Optional argument
[ ] Indexed address
( ) Contents
< > Register bit field
[expr]<n> Specifies bit n of the register indicated by pointer expr
→ Assigned to
∈ In the set of
italics User defined term (font is Courier)
15 10 9 8 7 0
15 12 11 0
15 12 11 0
15 4 3 0
15 12 11 0
1111 FILE #
15 12 11 0
1111 FILE #
15 12 11 9 8 7 0
15 8 7 0
15 8 7 0
15 12 11 0
15 9 8 7 0
15 12 11 0
15 11 10 0
15 8 7 0
PIC18F26/46/56Q83
MOVWF f, a Move WREG to f 1 0110 111a ffff ffff None
...........continued
Mnemonic, 16-Bit Instruction Word
Operands Status
Description Cycles Affected Notes
MSb LSb
rotatethispage90
PIC18F26/46/56Q83
INFSNZ f, d, a Increment f, Skip if Not 0 1–4 0100 10da ffff ffff None 1, 2
...........continued
Mnemonic, 16-Bit Instruction Word
Operands Status
Description Cycles Affected Notes
MSb LSb
rotatethispage90
BTFSS f, b, a Bit Test f, Skip if Set 1–4 1010 bbba ffff ffff None 1, 2
CONTROL INSTRUCTIONS
BNC n Branch if Not Carry 1–2 1110 0011 nnnn nnnn None 2
BNN n Branch if Not Negative 1–2 1110 0111 nnnn nnnn None 2
BNOV n Branch if Not Overflow 1–2 1110 0101 nnnn nnnn None 2
BNZ n Branch if Not Zero 1–2 1110 0001 nnnn nnnn None 2
CALLW — Call subroutine using WREG 2 0000 0000 0001 0100 None 2
PIC18F26/46/56Q83
1110 1111 kkkk kkkk
RETLW k Return with literal in WREG 2 0000 1100 kkkk kkkk None 2
RETURN s Return from Subroutine 2 0000 0000 0001 001s None 2
INHERENT INSTRUCTIONS
CLRWDT — Clear Watchdog Timer 1 0000 0000 0000 0100 TO, PD
and its subsidiaries
© 2020-2022 Microchip Technology Inc.
...........continued
Mnemonic, 16-Bit Instruction Word
Operands Status
Description Cycles Affected Notes
MSb LSb
rotatethispage90
ADDLW k Add literal and WREG 1 0000 1111 kkkk kkkk C, DC, Z, OV, N
ANDLW k AND literal with WREG 1 0000 1011 kkkk kkkk Z, N
Inclusive OR literal with
IORLW k 1 0000 1001 kkkk kkkk Z, N
WREG
PIC18F26/46/56Q83
1111 00kk kkkk kkkk
RETLW k Return with literal in WREG 2 0000 1100 kkkk kkkk None
Subtract literal (k) from FSR
SUBFSR fn, k 1 1110 1001 fnfnkk kkkk None
(fn)
SUBLW k Subtract WREG from literal 1 0000 1000 kkkk kkkk C, DC, Z, OV, N
and its subsidiaries
© 2020-2022 Microchip Technology Inc.
...........continued
Mnemonic, 16-Bit Instruction Word
Operands Status
Description Cycles Affected Notes
MSb LSb
rotatethispage90
PIC18F26/46/56Q83
1. When a PORT register is modified as a function of itself (e.g., MOVF PORTB, 1, 0), the value used will be that value present on the pins themselves. For
4. fs and fd do not cover the full memory range. 2 MSbs of bank selection are forced to 0b00 to limit the range of these instructions to the lower 4k
addressing space.
PIC18F26/46/56Q83
Instruction Set Summary
Important: All PIC18 instructions may take an optional label argument preceding the instruction
mnemonic for use in symbolic addressing. If a label is used, the instruction format then becomes:
{label} instruction argument(s).
Operands 0 ≤ k ≤ 63
fn ∈ [0, 1, 2]
Operation (FSRfn) + k → FSRfn
Status Affected None
Encoding 1110 1000 fnfnkk kkkk
Description The 6-bit literal ‘k’ is added to the contents of the FSR specified by ‘fn’.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to FSR
Before Instruction
FSR2 = 03FFh
After Instruction
FSR2 = 0422h
Operands 0 ≤ k ≤ 255
Operation (W) + k → W
Status Affected N, OV, C, DC, Z
Encoding 0000 1111 kkkk kkkk
Description The contents of W are added to the 8-bit literal ‘k’ and the result is placed in W.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Before Instruction
W = 10h
After Instruction
W = 25h
ADDWF Add W to f
Syntax ADDWF f {,d {,a}}
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (W) + (f) → dest
Status Affected N, OV, C, DC, Z
Encoding 0010 01da ffff ffff
Description Add W to register ‘f’. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is ‘1’, the result is stored back
in register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
W = 17h
REG = 0C2h
After Instruction
W = 0D9h
REG = 0C2h
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
...........continued
ADDWFC Add W and Carry Bit to f
Syntax ADDWFC f {,d {,a}}
Description Add W, the Carry flag and data memory location ‘f’. If ‘d’ is ‘0’, the result is stored in W. If ‘d’
is ‘1’, the result is placed in data memory location ‘f’.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
Carry bit = 1
REG = 02h
W = 4Dh
After Instruction
Carry bit = 0
REG = 02h
W = 50h
Operands 0 ≤ k ≤ 255
Operation (W) .AND. k → W
Status Affected N, Z
Encoding 0000 1011 kkkk kkkk
Description The contents of W are AND’ed with the 8-bit literal ‘k’. The result is placed in W.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Before Instruction
W = A3h
After Instruction
W = 03h
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (W) .AND. (f) → dest
Status Affected N, Z
Encoding 0001 01da ffff ffff
Description The contents of W are AND’ed with register ‘f’. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is
‘1’, the result is stored back in register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
W = 17h
REG = C2h
After Instruction
W = 02h
REG = C2h
BC Branch if Carry
Syntax BC n
...........continued
BC Branch if Carry
Syntax BC n
Description If the Carry bit is ‘1’, then the program will branch. The two’s complement number ‘2n’ is
added to the PC. Since the PC will have incremented to fetch the next instruction, the new
address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.
Words 1
Cycles 1 (2)
Q Cycle Activity:
If Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation
If No Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data No operation
Example: HERE BC 5
Before Instruction
PC = address (HERE)
After Instruction
If Carry = 1; PC = address (HERE + 12)
If Carry = 0; PC = address (HERE + 2)
Operands 0 ≤ f ≤ 255
0≤b≤7
a ∈ [0, 1]
Operation 0 → f<b>
Status Affected None
Encoding 1001 bbba ffff ffff
...........continued
BCF Bit Clear f
Syntax BCF f, b {,a}
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write register ‘f’
Before Instruction
FLAG_REG = C7h
After Instruction
FLAG_REG = 47h
BN Branch if Negative
Syntax BN n
Description If the NEGATIVE bit is ‘1’, then the program will branch. The two’s complement number ‘2n’
is added to the PC. Since the PC will have incremented to fetch the next instruction, the new
address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.
Words 1
Cycles 1 (2)
Q Cycle Activity:
If Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation
If No Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data No operation
Before Instruction
PC = address (HERE)
After Instruction
If NEGATIVE = 1; PC = address (Jump)
If NEGATIVE = 0; PC = address (HERE + 2)
Description If the Carry bit is ‘0’, then the program will branch. The two’s complement number ‘2n’ is
added to the PC. Since the PC will have incremented to fetch the next instruction, the new
address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.
Words 1
Cycles 1 (2)
Q Cycle Activity:
If Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation
If No Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data No operation
Before Instruction
PC = address (HERE)
After Instruction
If Carry = 0; PC = address (Jump)
If Carry = 1; PC = address (HERE + 2)
Description If the NEGATIVE bit is ‘0’, then the program will branch. The two’s complement number ‘2n’
is added to the PC. Since the PC will have incremented to fetch the next instruction, the new
address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.
Words 1
Cycles 1 (2)
Q Cycle Activity:
If Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation
If No Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data No operation
Before Instruction
PC = address (HERE)
After Instruction
If NEGATIVE = 0; PC = address (Jump)
If NEGATIVE = 1; PC = address (HERE + 2)
Description If the OVERFLOW bit is ‘0’, then the program will branch. The two’s complement number
‘2n’ is added to the PC. Since the PC will have incremented to fetch the next instruction, the
new address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.
...........continued
BNOV Branch if Not Overflow
Syntax BNOV n
Words 1
Cycles 1 (2)
Q Cycle Activity:
If Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation
If No Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data No operation
Before Instruction
PC = address (HERE)
After Instruction
If OVERFLOW = 0; PC = address (Jump)
If OVERFLOW = 1; PC = address (HERE + 2)
Description If the ZERO bit is ‘0’, then the program will branch. The two’s complement number ‘2n’ is
added to the PC. Since the PC will have incremented to fetch the next instruction, the new
address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.
Words 1
Cycles 1 (2)
Q Cycle Activity:
If Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
If No Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data No operation
Before Instruction
PC = address (HERE)
After Instruction
If ZERO = 0; PC = address (Jump)
If ZERO = 1; PC = address (HERE + 2)
Description If the OVERFLOW bit is ‘1’, then the program will branch. The two’s complement number
‘2n’ is added to the PC. Since the PC will have incremented to fetch the next instruction, the
new address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.
Words 1
Cycles 1 (2)
Q Cycle Activity:
If Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation
If No Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data No operation
Before Instruction
PC = address (HERE)
After Instruction
If OVERFLOW = 1; PC = address (Jump)
If OVERFLOW = 0; PC = address (HERE + 2)
Description The two’s complement number ‘2n’ is added to the PC. Since the PC will have incremented
to fetch the next instruction, the new address will be PC + 2 + 2n. This instruction is a
two-cycle instruction.
Words 1
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation
Before Instruction
PC = address (HERE)
After Instruction
PC = address (Jump)
Operands 0 ≤ f ≤ 255
0≤b≤7
a ∈ [0, 1]
Operation 1 → f<b>
Status Affected None
Encoding 1000 bbba ffff ffff
Words 1
...........continued
BSF Bit Set f
Syntax BSF f, b {,a}
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write register ‘f’
Before Instruction
FLAG_REG = 0Ah
After Instruction
FLAG_REG = 8Ah
Operands 0 ≤ f ≤ 255
0≤b≤7
a ∈ [0, 1]
Operation Skip if (f<b>) = 0
Description If bit ‘b’ in register ‘f’ is ‘0’, then the next instruction is skipped. If bit ‘b’ is ‘0’, then the
next instruction fetched during the current instruction execution is discarded and a NOP is
executed instead, making this a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1 (2)
Note: Three cycles if skip and followed by a two-word instruction. Four cycles if skip and
followed by a three-word instruction.
Q Cycle Activity:
If no skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
If skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Example:
HERE BTFSC FLAG, 1, 0
FALSE:
TRUE:
Before Instruction
PC = address (HERE)
After Instruction
If FLAG<1> = 0; PC = address (TRUE)
If FLAG<1> = 1; PC = address (FALSE)
Operands 0 ≤ f ≤ 255
0≤b≤7
a ∈ [0, 1]
Operation Skip if (f<b>) = 1
Description If bit ‘b’ in register ‘f’ is ‘1’, then the next instruction is skipped. If bit ‘b’ is ‘1’, then the
next instruction fetched during the current instruction execution is discarded and a NOP is
executed instead, making this a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
...........continued
BTFSS Bit Test File, Skip if Set
Syntax BTFSS f, b {,a}
Words 1
Cycles 1 (2)
Note: Three cycles if skip and followed by a two-word instruction. Four cycles if skip and
followed by a three-word instruction.
Q Cycle Activity:
If no skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
If skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Example:
HERE BTFSS FLAG, 1, 0
FALSE:
TRUE:
Before Instruction
PC = address (HERE)
After Instruction
If FLAG<1> = 0; PC = address (FALSE)
If FLAG<1> = 1; PC = address (TRUE)
Operands 0 ≤ f ≤ 255
0≤b≤7
a ∈ [0, 1]
Operation (f<b>) → f<b>
Status Affected None
Encoding 0111 bbba ffff ffff
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write register ‘f’
Before Instruction
PORTC = 0111 0101 [75h]
After Instruction
PORTC = 0110 0101 [65h]
BZ Branch if Zero
Syntax BZ n
Description If the ZERO bit is ‘1’, then the program will branch. The two’s complement number ‘2n’ is
added to the PC. Since the PC will have incremented to fetch the next instruction, the new
address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.
Words 1
Cycles 1 (2)
Q Cycle Activity:
If Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation
If No Jump:
Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data No operation
Before Instruction
PC = address (HERE)
After Instruction
If ZERO = 1; PC = address (Jump)
If ZERO = 0; PC = address (HERE + 2)
Operands 0 ≤ k ≤ 1048575
s ∈ [0, 1]
Operation (PC) + 4 → TOS
k → PC<20:1>
If s = 1
(W) → WREG_CSHAD
(STATUS) → STATUS_CSHAD
(BSR) → BSR_CSHAD
Q Cycle Activity:
Q1 Q2 Q3 Q4
Read literal ‘k’<19:8>
Decode Read literal ‘k’<7:0> PUSH PC to stack Write to PC
PC = address (HERE)
After Instruction
PC = address (THERE)
TOS = address (HERE + 4)
WREG_CSHAD = (WREG)
BSR_CSHAD = (BSR)
STATUS_CSHAD = (STATUS)
Operands None
Operation (PC) + 2 → TOS
(W) → PCL
(PCLATH) → PCH
(PCLATU) → PCU
Status Affected None
Encoding 0000 0000 0001 0100
Description First, the return address (PC + 2) is pushed onto the return stack. Next, the contents of
W are written to PCL; the existing value is discarded. Then, the contents of PCLATH and
PCLATU are latched onto PCH and PCU respectively. The second cycle is executed as a
NOP instruction while the new next instruction is fetched. Unlike CALL, there is no option to
update W, STATUS or BSR.
Words 1
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read WREG PUSH PC to stack No operation
No operation No operation No operation No operation
PC = address (HERE)
PCLATH = 10h
PCLATU = 00h
W = 06h
After Instruction
PC = address 001006h
TOS = address (HERE + 2)
PCLATH = 10h
PCLATU = 00h
W = 06h
CLRF Clear f
Syntax CLRF f {,a}
Operands 0 ≤ f ≤ 255
a ∈ [0, 1]
Operation 000h → f
1→Z
Status Affected Z
Encoding 0110 101a ffff ffff
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write register ‘f’
Before Instruction
FLAG_REG = 5Ah
After Instruction
FLAG_REG = 00h
Operands None
Operation 000h → WDT
1 → TO
1 → PD
Description CLRWDT instruction resets the Watchdog Timer. It also resets the STATUS bits, and TO and
PD are set.
Words 1
...........continued
CLRWDT Clear Watchdog Timer
Syntax CLRWDT
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No operation Process Data No operation
Example: CLRWDT
Before Instruction
WDT Counter = ?
After Instruction
WDT Counter = 00h
TO = 1
PD = 1
COMF Complement f
Syntax COMF f {,d {,a}}
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f) → dest
Status Affected N, Z
Encoding 0001 11da ffff ffff
Description The contents of register ‘f’ are complemented. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is ‘1’,
the result is stored back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
REG = 13h
After Instruction
REG = 13h
W = ECh
Operands 0 ≤ f ≤ 255
a ∈ [0, 1]
Operation (f) – (W), skip if (f) = (W)
(unsigned comparison)
Status Affected None
Encoding 0110 001a ffff ffff
Description Compares the contents of data memory location ‘f’ to the contents of W by performing an
unsigned subtraction. If the contents of ‘f’ are equal to the contents of WREG, then the
fetched instruction is discarded and a NOP is executed instead, making this a two-cycle
instruction.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1 (2)
Note: Three cycles if skip and followed by a two-word instruction. Four cycles if skip and
followed by a three-word instruction.
Q Cycle Activity:
If no skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
If skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Example:
HERE CPFSEQ REG, 0
NEQUAL:
EQUAL:
Before Instruction
PC = address (HERE)
W=?
REG = ?
After Instruction
If REG = W; PC = address (EQUAL)
If REG ≠ W; PC = address (NEQUAL)
Operands 0 ≤ f ≤ 255
a ∈ [0, 1]
Operation (f) – (W), skip if (f) > (W)
(unsigned comparison)
Status Affected None
Encoding 0110 010a ffff ffff
Description Compares the contents of data memory location ‘f’ to the contents of W by performing an
unsigned subtraction. If the contents of ‘f’ are greater than the contents of WREG, then
the fetched instruction is discarded and a NOP is executed instead, making this a two-cycle
instruction.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1 (2)
Note: Three cycles if skip and followed by a two-word instruction. Four cycles if skip and
followed by a three-word instruction.
Q Cycle Activity:
If no skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
If skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Example:
HERE CPFSGT REG, 0
NGREATER:
GREATER:
Before Instruction
PC = address (HERE)
W=?
REG = ?
After Instruction
If REG > W; PC = address (GREATER)
If REG ≤ W; PC = address (NGREATER)
Operands 0 ≤ f ≤ 255
a ∈ [0, 1]
Operation (f) – (W), skip if (f) < (W)
(unsigned comparison)
Status Affected None
Encoding 0110 000a ffff ffff
...........continued
CPFSLT Compare f with W, Skip if f < W
Syntax CPFSLT f {,a}
Description Compares the contents of data memory location ‘f’ to the contents of W by performing an
unsigned subtraction. If the contents of ‘f’ are less than the contents of WREG, then the
fetched instruction is discarded and a NOP is executed instead, making this a two-cycle
instruction.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1 (2)
Note: Three cycles if skip and followed by a two-word instruction. Four cycles if skip and
followed by a three-word instruction.
Q Cycle Activity:
If no skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
If skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Example:
HERE CPFSLT REG, 1
NLESS:
LESS:
Before Instruction
PC = address (HERE)
W=?
REG = ?
After Instruction
If REG < W; PC = address (LESS)
If REG ≥ W; PC = address (NLESS)
Operands None
Operation If [(W<3:0>) > 9] or [DC = 1] then
(W<3:0>) + 6 → W<3:0>;
else
(W<3:0>) → W<3:0>;
Status Affected C
Encoding 0000 0000 0000 0111
Description DAW adjusts the 8-bit value in W, resulting from the earlier addition of two variables (each in
packed BCD format) and produces a correct packed BCD result.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register W Process Data Write register W
Example 1: DAW
Before Instruction
W = A5h
C=0
DC = 0
After Instruction
W = 05h
C=1
DC = 0
Example 2: DAW
Before Instruction
W = CEh
C=0
DC = 0
After Instruction
W = 34h
C=1
DC = 0
DECF Decrement f
Syntax DECF f {,d {,a}}
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f) – 1 → dest
Status Affected C, DC, N, OV, Z
Encoding 0000 01da ffff ffff
Description Decrement register ‘f’. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is ‘1’, the result is stored
back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
CNT = 01h
Z=0
After Instruction
CNT = 00h
Z=1
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
...........continued
DECFSZ Decrement f, Skip if 0
Syntax DECFSZ f {,d {,a}}
Description The contents of register ‘f’ are decremented. If ‘d’ is ‘0’, the result is placed in W. If ‘d’ is ‘1’,
the result is placed back in register ‘f’ (default).
If the result is ‘0’, the next instruction, which is already fetched, is discarded and a NOP is
executed instead, making it a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1 (2)
Note: Three cycles if skip and followed by a two-word instruction. Four cycles if skip and
followed by a three-word instruction.
Q Cycle Activity:
If no skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
If skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
No operation No operation No operation No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
No operation No operation No operation No operation
No operation No operation No operation No operation
Example:
HERE DECFSZ CNT, 1, 1
GOTO LOOP
CONTINUE
Before Instruction
CNT = ?
PC = address (HERE)
After Instruction
CNT = CNT – 1
If CNT = 0; PC = address (CONTINUE)
If CNT ≠ 0; PC = address (HERE + 2)
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f) – 1 → dest, skip if result ≠ 0
Description The contents of register ‘f’ are decremented. If ‘d’ is ‘0’, the result is placed in W. If ‘d’ is ‘1’,
the result is placed back in register ‘f’ (default).
If the result is not ‘0’, the next instruction, which is already fetched, is discarded and a NOP
is executed instead, making it a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1 (2)
Note: Three cycles if skip and followed by a two-word instruction. Four cycles if skip and
followed by a three-word instruction.
Q Cycle Activity:
If no skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
If skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
No operation No operation No operation No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
No operation No operation No operation No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Example:
HERE DCFSNZ TEMP, 1, 0
ZERO:
NZERO:
Before Instruction
TEMP = ?
PC = address (HERE)
After Instruction
TEMP = TEMP – 1
If TEMP = 0; PC = address (ZER0)
If TEMP ≠ 0; PC = address (NZERO)
Operands 0 ≤ k ≤ 1048575
Operation k → PC<20:1>
Status Affected None
Encoding 1110 1111 k7kkk kkkk0
1st word (k<7:0>)
1111 k19kkk kkkk kkkk8
2nd word (k<19:8>)
Description GOTO allows an unconditional branch anywhere within entire 2-Mbyte memory range. The
20-bit value ‘k’ is loaded into PC<20:1>. GOTO is always a two-cycle instruction.
Words 2
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Read literal ‘k’<19:8>
Decode Read literal ‘k’<7:0> No operation Write to PC
PC = address (HERE)
After Instruction
PC = address (THERE)
INCF Increment f
Syntax INCF f {,d {,a}}
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f) + 1 → dest
Status Affected C, DC, N, OV, Z
Encoding 0010 10da ffff ffff
Description The contents of register ‘f’ are incremented. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is ‘1’,
the result is stored back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
CNT = FFh
Z=0
C=?
DC = ?
After Instruction
CNT = 00h
Z=1
C=1
DC = 1
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f) + 1 → dest, skip if result = 0
Description The contents of register ‘f’ are incremented. If ‘d’ is ‘0’, the result is placed in W. If ‘d’ is ‘1’,
the result is placed back in register ‘f’ (default).
If the result is ‘0’, the next instruction, which is already fetched, is discarded and a NOP is
executed instead, making it a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1 (2)
Note: Three cycles if skip and followed by a two-word instruction. Four cycles if skip and
followed by a three-word instruction.
Q Cycle Activity:
If no skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
If skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
No operation No operation No operation No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
No operation No operation No operation No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Example:
HERE INCFSZ CNT, 1, 0
NZERO:
ZERO:
Before Instruction
CNT = ?
PC = address (HERE)
After Instruction
CNT = CNT + 1
If CNT = 0; PC = address (ZERO)
If CNT ≠ 0; PC = address (NZERO)
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f) + 1 → dest, skip if result ≠ 0
Description The contents of register ‘f’ are incremented. If ‘d’ is ‘0’, the result is placed in W. If ‘d’ is ‘1’,
the result is placed back in register ‘f’ (default).
If the result is not ‘0’, the next instruction, which is already fetched, is discarded and a NOP
is executed instead, making it a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1 (2)
Note: Three cycles if skip and followed by a two-word instruction. Four cycles if skip and
followed by a three-word instruction.
Q Cycle Activity:
If no skip:
Q1 Q2 Q3 Q4
If skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
No operation No operation No operation No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
No operation No operation No operation No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Example:
HERE INFSNZ REG, 1, 0
ZERO:
NZERO:
Before Instruction
REG = ?
PC = address (HERE)
After Instruction
REG = REG + 1
If REG = 0; PC = address (ZER0)
If REG ≠ 0; PC = address (NZERO)
Operands 0 ≤ k ≤ 255
Operation (W) .OR. k → W
Status Affected N, Z
Encoding 0000 1001 kkkk kkkk
Description The contents of W are ORed with the 8-bit literal ‘k’. The result is placed in W.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to W
Before Instruction
W = 9Ah
After Instruction
W = B5h
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (W) .OR. (f) → dest
Status Affected N, Z
Encoding 0001 00da ffff ffff
Description Inclusive OR W with register ‘f’. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is ‘1’, the result is
stored back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
RESULT = 13h
W = 91h
After Instruction
RESULT = 13h
W = 93h
Operands 0 ≤ fn ≤ 2
0 ≤ k ≤ 16383
Operation k → FSRfn
Status Affected None
Encoding 1110 1110 00fnfn k13kkk10
1111 00k9k kkkk kkkk0
Description The 14-bit literal ‘k’ is loaded into the File Select Register ‘fn’.
Words 2
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Write literal ‘k’<13:10> to
Decode Read literal ‘k’<13:10> Process Data
FSRfn<13:10>
Write literal ‘k’<9:0> to
No operation Read literal ‘k’<9:0> No operation
FSRfn<9:0>
Before Instruction
FSR2H = ?
FSR2L = ?
After Instruction
FSR2H = 03h
FSR2L = ABh
MOVF Move f
Syntax MOVF f {,d {,a}}
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f) → dest
Status Affected N, Z
Encoding 0101 00da ffff ffff
Description The contents of register ‘f’ are moved to a destination. If ‘d’ is ‘0’, the result is stored in W. If
‘d’ is ‘1’, the result is stored back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
...........continued
MOVF Move f
Syntax MOVF f {,d {,a}}
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
REG = 22h
W = FFh
After Instruction
REG = 22h
W = 22h
MOVFF Move f to f
Syntax MOVFF fs, fd
Operands 0 ≤ fs ≤ 4095
0 ≤ fd ≤ 4095
Operation (fs) → fd
Status Affected None
Encoding 1100 fsfsfsfs fsfsfsfs fsfsfsfs
1111 fdfdfdfd fdfdfdfd fdfdfdfd
Description The contents of source register ‘fs’ are moved to destination register ‘fd’. Location of source
‘fs’ can be anywhere in the 4096-byte data space (000h to FFFh) and location of destination
‘fd’ can also be anywhere from 000h to FFFh.
MOVFF is particularly useful for transferring a data memory location to a peripheral register
(such as the transmit buffer or an I/O port).
The MOVFF instruction cannot use the PCL, TOSU, TOSH or TOSL as the destination
register.
Note:
MOVFF has curtailed the source and destination range to the lower 4 Kbyte space of
memory (Banks 1 through 15). For everything else, use MOVFFL.
Words 2
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Before Instruction
Address of REG1 = 100h
Address of REG2 = 200h
REG1 = 33h
REG2 = 11h
After Instruction
Address of REG1 = 100h
Address of REG2 = 200h
REG1 = 33h
REG2 = 33h
Operands 0 ≤ fs ≤ 16383
0 ≤ fd ≤ 16383
Operation (fs) → fd
Status Affected None
Encoding 0000 0000 0110 fsfsfsfs
1111 fsfsfsfs fsfsfsfs fsfsfdfd
1111 fdfdfdfd fdfdfdfd fdfdfdfd
Description The contents of source register ‘fs’ are moved to destination register ‘fd’. Location of
source ‘fs’ can be anywhere in the 16 Kbyte data space (0000h to 3FFFh) and location
of destination ‘fd’ can also be anywhere from 0000h to 3FFFh. Either source or destination
can be W (a useful special situation).
MOVFFL is particularly useful for transferring a data memory location to a peripheral register
(such as the transmit buffer or an I/O port).
The MOVFFL instruction cannot use the PCL, TOSU, TOSH or TOSL as the destination
register.
Words 3
Cycles 3
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No operation No operation No operation
Decode Read register ‘fs’ Process Data No operation
No operation
Decode No operation Write register ‘fd’
No dummy read
Before Instruction
Contents of 2000h = 33h
Contents of 200Ah = 11h
After Instruction
Contents of 2000h = 33h
Contents of 200Ah = 33h
Operands 0 ≤ k ≤ 63
Operation k → BSR
Status Affected None
Encoding 0000 0001 00kk kkkk
Description The 6-bit literal ‘k’ is loaded into the Bank Select Register (BSR<5:0>). The value of
BSR<7:6> always remains ‘0’.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to BSR
Example: MOVLB 5
Before Instruction
BSR = 02h
After Instruction
BSR = 05h
Operands 0 ≤ k ≤ 255
Operation k→W
Status Affected None
Encoding 0000 1110 kkkk kkkk
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to W
Before Instruction
W=?
After Instruction
W = 5Ah
MOVWF Move W to f
Syntax MOVWF f {,a}
Operands 0 ≤ f ≤ 255
a ∈ [0, 1]
Operation (W) → f
Status Affected None
Encoding 0110 111a ffff ffff
Description Move data from W to register ‘f’. Location ‘f’ can be anywhere in the 256-byte bank.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read W Process Data Write register ‘f’
Before Instruction
W = 4Fh
REG = FFh
After Instruction
W = 4Fh
REG = 4Fh
Operands 0 ≤ k ≤ 255
Operation (W) x k → PRODH:PRODL
...........continued
MULLW Multiply literal with W
Syntax MULLW k
Description An unsigned multiplication is carried out between the contents of W and the 8-bit literal ‘k’.
The 16-bit result is placed in the PRODH:PRODL register pair. PRODH contains the high
byte. W is unchanged.
None of the Status flags are affected. Note that neither overflow nor carry is possible in this
operation. A zero result is possible but not detected.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Write registers
Decode Read literal ‘k’ Process Data
PRODH:PRODL
Before Instruction
W = E2h
PRODH = ?
PRODL = ?
After Instruction
W = E2h
PRODH = ADh
PRODL = 08h
Operands 0 ≤ f ≤ 255
a ∈ [0, 1]
Operation (W) x (f) → PRODH:PRODL
Status Affected None
Encoding 0000 001a ffff ffff
...........continued
MULWF Multiply W with f
Syntax MULWF f {,a}
Description An unsigned multiplication is carried out between the contents of W and the register file
location ‘f’. The 16-bit result is placed in the PRODH:PRODL register pair. PRODH contains
the high byte. Both W and ‘f’ are unchanged.
None of the Status flags are affected. Note that neither overflow nor carry is possible in this
operation. A zero result is possible but not detected.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Write registers
Decode Read register ‘f’ Process Data
PRODH:PRODL
Before Instruction
W = C4h
REG = B5h
PRODH = ?
PRODL = ?
After Instruction
W = C4h
REG = B5h
PRODH = 8Ah
PRODL = 94h
NEGF Negate f
Syntax NEGF f {,a}
Operands 0 ≤ f ≤ 255
a ∈ [0, 1]
Operation (f) + 1 → f
Status Affected N, OV, C, DC, Z
Encoding 0110 110a ffff ffff
...........continued
NEGF Negate f
Syntax NEGF f {,a}
Description Location ‘f’ is negated using two’s complement. The result is placed in the data memory
location ‘f’.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write register ‘f’
Before Instruction
REG = 0011 1010 [3Ah]
After Instruction
REG = 1100 0110 [C6h]
NOP No Operation
Syntax NOP
Operands None
Operation No operation
Status Affected None
Encoding 0000 0000 0000 0000
1111 xxxx xxxx xxxx
Description No operation.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No operation No operation No operation
Example: None.
Operands None
Operation (TOS) → bit bucket
Status Affected None
Encoding 0000 0000 0000 0110
Description The TOS value is pulled off the return stack and is discarded. The TOS value then becomes
the previous value that was pushed onto the return stack. This instruction is provided to
enable the user to properly manage the return stack to incorporate a software stack. (See
the PUSH instruction description).
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No operation POP TOS value No operation
Example:
POP
GOTO NEW
Before Instruction
TOS = 0031A2h
Stack (1 level down) = 014332h
After Instruction
TOS = 014332h
PC = address (NEW)
Operands None
Operation (PC) + 2 → TOS
Status Affected None
Encoding 0000 0000 0000 0101
Description The PC + 2 is pushed onto the top of the return stack. The previous TOS value is pushed
down on the stack. This instruction allows implementing a software stack by modifying TOS
and then pushing it onto the return stack. (See the POP instruction description).
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Example: PUSH
Before Instruction
TOS = 00345Ah
PC = 000124h
After Instruction
TOS = 000126h
PC = 000126h
Stack (1 level down) = 00345Ah
Description Subroutine call with a jump up to 1K from the current location. First, return address (PC + 2)
is pushed onto the stack. Then, add the two’s complement number ‘2n’ to the PC. Since the
PC will have incremented to fetch the next instruction, the new address will be PC + 2 + 2n.
This instruction is a two-cycle instruction.
Words 1
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Read literal ‘n’
Decode Process Data Write to PC
PUSH PC to stack
No operation No operation No operation No operation
Before Instruction
PC = address (HERE)
After Instruction
PC = address (Jump)
TOS = address (HERE + 2)
RESET Reset
Syntax RESET
Operands None
...........continued
RESET Reset
Syntax RESET
Operation Reset all registers and flags that are affected by a MCLR Reset.
Status Affected All
Encoding 0000 0000 1111 1111
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Start Reset No operation No operation
Example: RESET
Before Instruction
All Registers = ?
All Flags = ?
After Instruction
All Registers = Reset Value
All Flags = Reset Value
Operands s ∈ [0, 1]
Operation (TOS) → PC
If s = 1, context is restored into WREG, STATUS, BSR, FSR0H, FSR0L, FSR1H, FSR1L,
FSR2H, FSR2L, PRODH, PRODL, PCLATH and PCLATU registers from the corresponding
shadow registers.
If s = 0, there is no change in status of any register.
PCLATU, PCLATH are unchanged.
...........continued
RETFIE Return from Interrupt
Syntax RETFIE {s}
Description Return from interrupt. Stack is popped and Top-of-Stack (TOS) is loaded into the PC.
Interrupts are enabled by setting either the high- or low-priority Global Interrupt Enable bit.
If ‘s’ = 1, the contents of the shadow registers WREG_SHAD, STATUS_SHAD, BSR_SHAD,
FSR0H_SHAD, FSR0L_SHAD, FSR1H_SHAD, FSR1L_SHAD, FSR2H_SHAD,
FSR2L_SHAD, PRODH_SHAD, PRODL_SHAD, PCLATH_SHAD and PCLATU_SHAD are
loaded into corresponding registers. There are two sets of shadow registers, main context
and low context. The set retrieved on RETFIE instruction execution depends on what the
state of operation of the CPU was when RETFIE was executed.
If ‘s’ = 0, no update of these registers occurs (default).
The upper and high address latches (PCLATU/H) remain unchanged.
Words 1
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No operation Process Data POP PC from stack
No operation No operation No operation No operation
Example: RETFIE 1
After Instruction
PC = (TOS)
WREG = (WREG_SHAD)
BSR = (BSR_SHAD)
STATUS = (STATUS_SHAD)
FSR0H/L = (FSR0H/L_SHAD)
FSR1H/L = (FSR1H/L_SHAD)
FSR2H/L = (FSR2H/L_SHAD)
PRODH/L = (PRODH/L_SHAD)
PCLATH/U = (PCLATH/U_SHAD)
Operands 0 ≤ k ≤ 255
Operation k→W
(TOS) → PC
PCLATU, PCLATH are unchanged
Status Affected None
Encoding 0000 1100 kkkk kkkk
Description W is loaded with the 8-bit literal ‘k’. The Program Counter is loaded from the top of the stack
(the return address). The upper and high address latches (PCLATU/H) remain unchanged.
Words 1
...........continued
RETLW Return Literal to W
Syntax RETLW k
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
POP PC from stack
Decode Read literal ‘k’ Process Data
Write to W
No operation No operation No operation No operation
Example:
CALL TABLE ; W contains table offset value
BACK ; W now has table value (after RETLW)
:
:
TABLE
ADDWF PCL ; W = offset
RETLW k0 ; Begin table
RETLW k1 ;
:
:
RETLW kn ; End of table
Before Instruction
W = 07h
After Instruction
W = value of kn
Operands s ∈ [0, 1]
Operation (TOS) → PC
If s = 1
(WREG_CSHAD) → WREG
(STATUS_CSHAD) → STATUS
(BSR_CSHAD) → BSR
PCLATU, PCLATH are unchanged
Description Return from subroutine. The stack is popped and the top of the stack (TOS) is loaded
into the Program Counter. If ‘s’ = 1, the contents of the shadow registers WREG_CSHAD,
STATUS_CSHAD and BSR_CSHAD, are loaded into their corresponding registers. If ‘s’
= 0, no update of these registers occurs (default). The upper and high address latches
(PCLATU/H) remain unchanged.
Words 1
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No operation Process Data POP PC from stack
No operation No operation No operation No operation
Example: RETURN 1
After Instruction
PC = (TOS)
WREG = (WREG_CSHAD)
BSR = (BSR_CSHAD)
STATUS = (STATUS_CSHAD)
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f<n>) → dest<n+1>
(f<7>) → C
(C) → dest<0>
Status Affected C, N, Z
Encoding 0011 01da ffff ffff
Description The contents of register ‘f’ are rotated one bit to the left through the Carry flag. If ‘d’ is ‘0’,
the result is stored in W. If ‘d’ is ‘1’, the result is stored back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
C register f
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
REG = 1110 0110 [E6h]
W=?
C=0
After Instruction
REG = 1110 0110 [E6h]
W = 1100 1100 [CCh]
C=1
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f<n>) → dest<n+1>
(f<7>) → dest<0>
Status Affected N, Z
Encoding 0100 01da ffff ffff
Description The contents of register ‘f’ are rotated one bit to the left. If ‘d’ is ‘0’, the result is stored in W.
If ‘d’ is ‘1’, the result is stored back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
register f
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
REG = 1010 1011 [ABh]
After Instruction
REG = 0101 0111 [57h]
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f<n>) → dest<n-1>
(f<0>) → C
(C) → dest<7>
...........continued
RRCF Rotate Right f through Carry
Syntax RRCF f {,d {,a}}
Status Affected C, N, Z
Encoding 0011 00da ffff ffff
Description The contents of register ‘f’ are rotated one bit to the right through the Carry flag. If ‘d’ is ‘0’,
the result is stored in W. If ‘d’ is ‘1’, the result is stored back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
C register f
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
REG = 1110 0110 [E6h]
W=?
C=0
After Instruction
REG = 1110 0110 [E6h]
W = 0111 0011 [73h]
C=0
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f<n>) → dest<n-1>
(f<0>) → dest<7>
Status Affected N, Z
Encoding 0100 00da ffff ffff
...........continued
RRNCF Rotate Right f (No Carry)
Syntax RRNCF f {,d {,a}}
Description The contents of register ‘f’ are rotated one bit to the right. If ‘d’ is ‘0’, the result is stored in
W. If ‘d’ is ‘1’, the result is stored back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
register f
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
REG = 1101 0111 [D7h]
After Instruction
REG = 1110 1011 [EBh]
Before Instruction
REG = 1101 0111 [D7h]
W=?
After Instruction
REG = 1101 0111 [D7h]
W = 1110 1011 [EBh]
SETF Set f
Syntax SETF f {,a}
Operands 0 ≤ f ≤ 255
a ∈ [0, 1]
Operation FFh → f
...........continued
SETF Set f
Syntax SETF f {,a}
Description The contents of the specified register ‘f’ are set to FFh.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write register ‘f’
Before Instruction
REG = 5Ah
After Instruction
REG = FFh
Operands None
Operation 00h → WDT
1 → TO
0 → PD
Status Affected TO, PD
Encoding 0000 0000 0000 0011
Description The Power-down Status (PD) bit is cleared. The Time-Out Status TO) bit is set. Watchdog
Timer is cleared. The processor is put into Sleep mode with the oscillator stopped.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No operation Process Data Go to Sleep
Example: SLEEP
Before Instruction
TO = ?
PD = ?
After Instruction
TO = 1 †
PD = 0
Operands 0 ≤ k ≤ 63
fn ∈ [0, 1, 2]
Operation (FSRfn) – k → FSRfn
Status Affected None
Encoding 1110 1001 fnfnkk kkkk
Description The 6-bit literal ‘k’ is subtracted from the contents of the FSR specified by ‘fn’.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to FSR
Before Instruction
FSR2 = 03FFh
After Instruction
FSR2 = 03DCh
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (W) – (f) – (C) → dest
Status Affected N, OV, C, DC, Z
Encoding 0101 01da ffff ffff
...........continued
SUBFWB Subtract f from W with Borrow
Syntax SUBFWB f {,d {,a}}
Description Subtract register ‘f’ and Carry flag (Borrow) from W (two’s complement method). If ‘d’ is ‘0’,
the result is stored in W. If ‘d’ is ‘1’, the result is stored back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
REG = 03h
W = 02h
C=1
After Instruction
REG = FFh (two’s complement)
W = 02h
C=0
Z=0
N = 1 (result is negative)
Before Instruction
REG = 02h
W = 05h
C=1
After Instruction
REG = 02h
W = 03h
C=1
Z=0
N = 0 (result is positive)
Before Instruction
REG = 01h
W = 02h
C=0
After Instruction
REG = 00h
W = 02h
C=1
Z = 1 (result is zero)
N=0
Operands 0 ≤ k ≤ 255
Operation k – (W) → W
Status Affected N, OV, C, DC, Z
Encoding 0000 1000 kkkk kkkk
Description W is subtracted from the 8-bit literal ‘k’. The result is placed in W.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to W
Before Instruction
W = 01h
C=?
After Instruction
W = 01h
C = 1 (result is positive)
Z=0
N=0
Before Instruction
W = 02h
C=?
After Instruction
W = 00h
C=1
Z = 1 (result is zero)
N=0
Before Instruction
W = 03h
C=?
After Instruction
W = FFh (two’s complement)
C=0
Z=0
N = 1 (result is negative)
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f) – (W) → dest
Status Affected N, OV, C, DC, Z
Encoding 0101 11da ffff ffff
Description Subtract W from register ‘f’ (two’s complement method). If ‘d’ is ‘0’, the result is stored in W.
If ‘d’ is ‘1’, the result is stored back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
REG = 03h
W = 02h
C=?
After Instruction
REG = 01h (two’s complement)
W = 02h
C = 1 (result is positive)
Z=0
N=0
Before Instruction
REG = 02h
W = 02h
C=?
After Instruction
REG = 02h
W = 00h
C=1
Z = 1 (result is zero)
N=0
Before Instruction
REG = 01h
W = 02h
C=?
After Instruction
REG = FFh (two’s complement)
W = 02h
C=0
Z=0
N = 1 (result is negative)
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f) – (W) – (C) → dest
Status Affected N, OV, C, DC, Z
Encoding 0101 10da ffff ffff
Description Subtract W and the Carry flag (Borrow) from register ‘f’ (two’s complement method). If ‘d’ is
‘0’, the result is stored in W. If ‘d’ is ‘1’, the result is stored back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
REG = 19h (0001 1001)
W = 0Dh (0000 1101)
C=1
After Instruction
REG = 0Ch (0000 1100)
W = 0Dh (0000 1101)
C = 1 (result is positive)
Z=0
N=0
Before Instruction
REG = 1Bh (0001 1011)
W = 1Ah (0001 1010)
C=0
After Instruction
REG = 1Bh (0001 1011)
W = 00h
C=1
Z = 1 (result is zero)
N=0
Before Instruction
REG = 03h (0000 0011)
W = 0Eh (0000 1110)
C=1
After Instruction
REG = F5h (1111 0101) (two’s complement)
W = 0Eh (0000 1110)
C=0
Z=0
N = 1 (result is negative)
SWAPF Swap f
Syntax SWAPF f {,d {,a}}
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (f<3:0>) → dest<7:4>
(f<7:4>) → dest<3:0>
Status Affected None
Encoding 0011 10da ffff ffff
Description The upper and lower nibbles of register ‘f’ are exchanged. If ‘d’ is ‘0’, the result is stored in
W. If ‘d’ is ‘1’, the result is stored back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
...........continued
SWAPF Swap f
Syntax SWAPF f {,d {,a}}
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
REG = 53h
After Instruction
REG = 35h
Operands None
Operation If TBLRD *
(Prog Mem (TBLPTR)) → TABLAT
TBLPTR – No Change
If TBLRD *+
(Prog Mem (TBLPTR)) → TABLAT
(TBLPTR) + 1 → TBLPTR
If TBLRD *-
(Prog Mem (TBLPTR)) → TABLAT
(TBLPTR) – 1 → TBLPTR
If TBLRD +*
(TBLPTR) + 1 → TBLPTR
(Prog Mem (TBLPTR)) → TABLAT
mm=0 *
mm=1 *+
mm=2 *-
mm=3 +*
...........continued
TBLRD Table Read
Syntax TBLRD *
TBLRD *+
TBLRD *-
TBLRD +*
Description This instruction is used to read the contents of Program Memory. To address the program
memory, a pointer called Table Pointer (TBLPTR) is used.
The TBLPTR (a 21-bit pointer) points to each byte in the program memory. TBLPTR has a
2-Mbyte address range.
TBLPTR[0] = 0: Least Significant Byte of Program Memory Word
TBLPTR[0] = 1: Most Significant Byte of Program Memory Word
The TBLRD instruction can modify the value of TBLPTR as follows:
• no change (TBLRD *)
• post-increment (TBLRD *+)
• post-decrement (TBLRD *-)
• pre-increment (TBLRD +*)
Words 1
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No operation No operation No operation
No operation No operation
No operation No operation
(Read Program Memory) (Write TABLAT)
Example 1: TBLRD *+
Before Instruction
TABLAT = 55h
TBLPTR = 00A356h
MEMORY (00A356h) = 34h
After Instruction
TABLAT = 34h
TBLPTR = 00A357h
Example 2: TBLRD +*
Before Instruction
TABLAT = AAh
TBLPTR = 01A357h
MEMORY (01A357h) = 12h
MEMORY (01A358h) = 34h
After Instruction
TABLAT = 34h
TBLPTR = 01A358h
Operands None
Operation If TBLWT *
(TABLAT) → Holding Register
TBLPTR – No Change
If TBLWT *+
(TABLAT) → Holding Register
(TBLPTR) + 1 → TBLPTR
If TBLWT *-
(TABLAT) → Holding Register
(TBLPTR) – 1 → TBLPTR
If TBLWT +*
(TBLPTR) + 1 → TBLPTR
(TABLAT) → Holding Register
mm=0 *
mm=1 *+
mm=2 *-
mm=3 +*
Description This instruction uses the three LSBs of TBLPTR to determine which of the eight holding
registers the TABLAT is written to. The holding registers are used to program the contents
of Program Memory. (Refer to the “Program Flash Memory” section for additional details on
programming Flash memory.)
The TBLPTR (a 21-bit pointer) points to each byte in the program memory. TBLPTR has a
2-Mbyte address range. The LSb of the TBLPTR selects which byte of the program memory
location to access.
TBLPTR[0] = 0: Least Significant Byte of Program Memory Word
TBLPTR[0] = 1: Most Significant Byte of Program Memory Word
The TBLWT instruction can modify the value of TBLPTR as follows:
• no change (TBLWT *)
• post-increment (TBLWT *+)
• post-decrement (TBLWT *-)
• pre-increment (TBLWT +*)
Words 1
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No operation No operation No operation
No operation No operation
No operation No operation
(Read TABLAT) (Write to Holding Register)
Example 1: TBLWT *+
Before Instruction
TABLAT = 55h
TBLPTR = 00A356h
HOLDING REGISTER (00A356h) = FFh
Example 2: TBLWT +*
Before Instruction
TABLAT = 34h
TBLPTR = 01389Ah
HOLDING REGISTER (01389Ah) = FFh
HOLDING REGISTER (01389Bh) = FFh
Operands 0 ≤ f ≤ 255
a ∈ [0, 1]
Operation Skip if f = 0
Description If ‘f’ = 0, the next instruction fetched during the current instruction execution is discarded
and a NOP is executed, making this a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1 (2)
Note: Three cycles if skip and followed by a two-word instruction. Four cycles if skip and
followed by a three-word instruction.
Q Cycle Activity:
If no skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
If skip:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
No operation No operation No operation No operation
Example:
HERE TSTFSZ CNT, 1
NZERO:
ZERO:
Before Instruction
PC = address (HERE)
After Instruction
If CNT = 0; PC = address (ZERO)
If CNT ≠ 0; PC = address (NZERO)
Operands 0 ≤ k ≤ 255
Operation (W) .XOR. k → W
Status Affected N, Z
Encoding 0000 1010 kkkk kkkk
Description The contents of W are XORed with the 8-bit literal ‘k’. The result is placed in W.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to W
Before Instruction
W = B5h
After Instruction
W = 1Ah
Operands 0 ≤ f ≤ 255
d ∈ [0, 1]
a ∈ [0, 1]
Operation (W) .XOR. (f) → dest
Status Affected N, Z
Encoding 0001 10da ffff ffff
Description Exclusive OR the contents of W with register ‘f’. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is
‘1’, the result is stored back in the register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed
Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Byte-Oriented and Bit-Oriented
Instructions in Indexed Literal Offset Mode for details.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination
Before Instruction
REG = AFh
W = B5h
After Instruction
REG = 1Ah
W = B5h
Important: The instruction set extension and the Indexed Literal Offset Addressing mode were designed
for optimizing applications written in C; the user may likely never use these instructions directly in
assembler. The syntax for these commands is provided as a reference for users who may be reviewing
code that has been generated by a compiler.
Important: Enabling the PIC18 instruction set extension may cause legacy applications to behave
erratically or fail entirely. Refer to 47.2.3. Byte-Oriented and Bit-Oriented Instructions in Indexed Literal
Offset Mode for details.
PIC18F26/46/56Q83
3. Only available when extended instruction set is enabled.
Important: All PIC18 instructions may take an optional label argument preceding the instruction
mnemonic for use in symbolic addressing. If a label is used, the instruction format then becomes:
{label} instruction argument(s)
Operands 0 ≤ k ≤ 63
Operation (FSR2) + k → FSR2
(TOS) → PC
Status Affected None
Encoding 1110 1000 11kk kkkk
Description The 6-bit literal ‘k’ is added to the contents of FSR2. A RETURN is then executed by loading
the PC with the TOS. The instruction takes two cycles to execute; a NOP is performed during
the second cycle. This may be thought of as a special case of the ADDFSR instruction,
where fn = 3 (binary ‘11’); it operates only on FSR2.
Words 1
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to destination
No operation No operation No operation No operation
Before Instruction
FSR2 = 03FFh
PC = 0100h
After Instruction
FSR2 = 0422h
PC = (TOS)
Operands 0 ≤ zs ≤ 127
0 ≤ fd ≤ 4095
Operation ((FSR2) + zs) → fd
Status Affected None
Encoding 1110 1011 0zszszs zszszszs
1111 fdfdfdfd fdfdfdfd fdfdfdfd
...........continued
MOVSF Move Indexed to f
Syntax MOVSF [zs], fd
Description The contents of the source register are moved to destination register ‘fd’. The actual address
of the source register is determined by adding the 7-bit literal offset ‘zs’ in the first word to
the value of FSR2. The address of the destination register is specified by the 12-bit literal ‘fd’
in the second word. Both addresses can be anywhere in the 4096-byte data space (000h to
FFFh).
Note:
MOVSF has curtailed the destination range to the lower 4 Kbyte space in memory (Banks 1
through 15). For everything else, use MOVSFL.
Words 2
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Determine source address Determine source address Read source register
No operation
Decode No operation Write register ‘fd’
No dummy read
Before Instruction
FSR2 = 80h
Contents of 85h = 33h
REG2 = 11h
Address of REG2 = 100h
After Instruction
FSR2 = 80h
Contents of 85h = 33h
REG2 = 33h
Address of REG2 = 100h
Operands 0 ≤ zs ≤ 127
0 ≤ fd ≤ 16383
Operation ((FSR2) + zs) → fd
Status Affected None
Encoding 0000 0000 0110 0010
1111 xxxzs zszszszs zszsfdfd
1111 fdfdfdfd fdfdfdfd fdfdfdfd
...........continued
MOVSFL Move Indexed to f (Long Range)
Syntax MOVSFL [zs], fd
Description The contents of the source register are moved to destination register ‘fd’. The actual address
of the source register is determined by adding the 7-bit literal offset ‘zs’ in the first word to
the value of FSR2 (14 bits). The address of the destination register is specified by the 14-bit
literal ‘fd’ in the second word. Both addresses can be anywhere in the 16 Kbyte data space
(0000h to 3FFFh). The MOVSFL instruction cannot use the PCL, TOSU, TOSH or TOSL
as the destination register. If the resultant source address points to an indirect addressing
register, the value returned will be 00h.
Words 3
Cycles 3
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No operation No operation No operation
Decode Read source register Process Data No operation
No operation
Decode No operation Write register ‘fd’
No dummy read
Before Instruction
FSR2 = 2080h
Contents of 2085h = 33h
REG2 = 11h
Address of REG2 = 2000h
After Instruction
FSR2 = 2080h
Contents of 2085h = 33h
REG2 = 33h
Address of REG2 = 2000h
Operands 0 ≤ zs ≤ 127
0 ≤ zd ≤ 127
Operation ((FSR2) + zs) → ((FSR2) + zd)
Status Affected None
Encoding 1110 1011 1zszszs zszszszs
1111 xxxx xzdzdzd zdzdzdzd
...........continued
MOVSS Move Indexed to Indexed
Syntax MOVSS [zs], [zd]
Description The contents of the source register are moved to the destination register. The addresses
of the source and destination registers are determined by adding the 7-bit literal offsets ‘zs’
or ‘zd’ respectively to the value of FSR2. Both registers can be located anywhere in the 16
Kbyte data memory space (0000h to 3FFFh).
The MOVSS instruction cannot use the PCL, TOSU, TOSH or TOSL as the destination
register.
If the resultant source address points to an indirect addressing register, the value returned
will be 00h. If the resultant destination address points to an indirect addressing register, the
instruction will execute as a NOP.
Words 2
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Determine source address Determine source address Read source register
Determine destination Determine destination
Decode Write to destination register
address address
Before Instruction
FSR2 = 80h
Contents of 85h = 33h
Contents of 86h = 11h
After Instruction
FSR2 = 80h
Contents of 85h = 33h
Contents of 86h = 33h
Operands 0 ≤ k ≤ 255
Operation k → FSR2
(FSR2) – 1 → FSR2
Status Affected None
Encoding 1111 1010 kkkk kkkk
Description The 8-bit literal ‘k’ is written to the data memory address specified by FSR2. FSR2 is
decremented by 1 after the operation. This instruction allows users to push values onto a
software stack.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to destination
Before Instruction
FSR2 = 01ECh
Contents of 01ECh = 00h
After Instruction
FSR2 = 01EBh
Contents of 01ECh = 08h
Operands 0 ≤ k ≤ 63
Operation (FSR2) – k → FSR2
(TOS) → PC
Status Affected None
Encoding 1110 1001 11kk kkkk
Description The 6-bit literal ‘k’ is subtracted from the contents of FSR2. A RETURN is then executed
by loading the PC with the TOS. The instruction takes two cycles to execute; a NOP is
performed during the second cycle. This may be thought of as a special case of the SUBFSR
instruction, where fn = 3 (binary ‘11’); it operates only on FSR2.
Words 1
Cycles 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to destination
No operation No operation No operation No operation
Before Instruction
FSR2 = 03FFh
PC = 0100h
After Instruction
FSR2 = 03DCh
PC = (TOS)
Important: Enabling the PIC18 instruction set extension may cause legacy applications to behave
erratically or fail entirely.
In addition to the new commands in the extended set, enabling the extended instruction set also enables
Indexed Literal Offset Addressing mode (the “Indexed Addressing with Literal Offset” section in the “Memory
Organization” chapter). This has a significant impact on the way many commands of the standard PIC18 instruction
set are interpreted.
When the extended set is disabled, addresses embedded in opcodes are treated as literal memory locations: Either
as a location in the Access Bank (‘a’ = 0), or in a GPR bank designated by the BSR (‘a’ = 1). When the extended
instruction set is enabled and ‘a’ = 0, however, a file register argument of 5Fh or less is interpreted as an offset from
the pointer value in FSR2 and not as a literal address. For practical purposes, this means that all instructions using
the Access RAM bit as an argument – that is, all byte-oriented and bit-oriented instructions, or almost half of the core
PIC18 instructions – may behave differently when the extended instruction set is enabled.
When the content of FSR2 is 00h, the boundaries of the Access RAM are essentially remapped to their original
values. This may be useful in creating backward compatible code. If this technique is used, it may be necessary to
save the value of FSR2 and restore it when moving back and forth between C and assembly routines to preserve
the Stack Pointer. Users must also keep in mind the syntax requirements of the extended instruction set (see
47.2.3.1. Extended Instruction Syntax with Standard PIC18 Commands).
Although the Indexed Literal Offset Addressing mode can be very useful for dynamic stack and pointer manipulation,
it can also be very annoying if a simple arithmetic operation is carried out on the wrong register. Users who are
accustomed to the PIC18 programming must keep in mind that, when the extended instruction set is enabled, register
addresses of 5Fh or less are used for Indexed Literal Offset Addressing.
Representative examples of typical byte-oriented and bit-oriented instructions in the Indexed Literal Offset
Addressing mode are provided in 47.2.4. Considerations when Enabling the Extended Instruction Set to show how
execution is affected. The operand conditions shown in the examples are applicable to all instructions of these types.
Related Links
9.6. Data Memory and the Extended Instruction Set
Additionally, the Indexed Literal Offset Addressing mode may create issues with legacy applications written to the
PIC18 assembler. This is because instructions in the legacy code may attempt to address registers in the Access
Bank below 5Fh. Since these addresses are interpreted as literal offsets to FSR2 when the instruction set extension
is enabled, the application may read or write to the wrong data addresses.
When porting an application to a PIC18 device supporting extensions to the instruction set, it is very important to
consider the type of code. A large, re-entrant application that is written in ‘C’ and benefits from efficient compilation
will do well when using the instruction set extensions. Legacy applications that heavily use the Access Bank will most
likely not benefit from using the extended instruction set.
Operands 0 ≤ k ≤ 95
d ∈ [0, 1]
Operation (W) + ((FSR2) + k) → dest
Status Affected N, OV, C, DC, Z
Encoding 0010 01d0 kkkk kkkk
Description The contents of W are added to the contents of the register indicated by FSR2, offset by
the value ‘k’. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is ‘1’, the result is stored back in the
register ‘f’ (default).
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to destination
Before Instruction
W = 17h
OFST = 2Ch
FSR2 = 0A00h
Contents of 0A2Ch = 20h
After Instruction
W = 37h
Contents of 0A2Ch = 20h
Operands 0 ≤ k ≤ 95
0≤b≤7
Operation 1 → ((FSR2) + k)<b>
Description Bit ‘b’ of the register indicated by FSR2, offset by the value ‘k’, is set.
...........continued
BSF Bit Set Indexed (Indexed Literal Offset Mode)
Syntax BSF [k], b
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to destination
Before Instruction
FLAG_OFST = 0Ah
FSR2 = 0A00h
Contents of 0A0Ah = 55h
After Instruction
Contents of 0A0Ah = D5h
Operands 0 ≤ k ≤ 95
Operation FFh → ((FSR2) + k)
Description The contents of the register indicated by FSR2, offset by the value ‘k’, are set to FFh.
Words 1
Cycles 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to destination
Before Instruction
OFST = 2Ch
FSR2 = 0A00h
Contents of 0A2Ch = 00h
After Instruction
Contents of 0A2Ch = FFh
ICSPDAT
VDD 2 4 6 NC
ICSPCLK
1 3 5 Target
VPP/MCLR VSS PC Board
Bottom Side
Pin Description
1 = VPP/MCLR
2 = VDD Target
3 = VSS (ground)
4 = ICSPDAT
5 = ICSPCLK
6 = No Connect
Another connector often found in use with the PICkit™ programmers is a standard 6-pin header with 0.1 inch spacing.
Refer to Figure 48-2.
For additional interface recommendations, refer to the specific device programmer manual prior to PCB design.
It is recommended that isolation devices be used to separate the programming pins from other circuitry. The type of
isolation is highly dependent on the specific application and may include devices such as resistors, diodes, or even
jumpers. See Figure 48-3 for more information.
Figure 48-2. PICkit™ Programmer Style Connector Interface
Pin 1 Indicator
1
2
3
4
5
6
Pin Description(1):
1 = VPP/MCLR
2 = VDD Target
3 = VSS (ground)
4 = ICSPDAT
5 = ICSPCLK
6 = No Connect
Note:
1. The 6-pin header (0.100" spacing) accepts 0.025" square pins.
Figure 48-3. Typical Connection for ICSP™ Programming
External
Programming VDD Device to be
Signals Programmed
VDD VDD
VPP MCLR/VPP
VSS VSS
Data ICSPDAT
Clock ICSPCLK
* * *
To Normal Connections
00 U2ERRIE 7:0 TXMTIE PERIE ABDOVE CERIE FERIE RXBKIE RXFOIE TXCIE
0x01
... Reserved
0x37
0x38 BOOTREG 7:0 BPOUT BOOTDONE B1 B0
0x39 CLKRCON 7:0 EN DC[1:0] DIV[2:0]
0x3A CLKRCLK 7:0 CLK[4:0]
0x3B
... Reserved
0x3F
0x40 NVMCON0 7:0 GO
0x41 NVMCON1 7:0 WRERR NVMCMD[2:0]
0x42 NVMLOCK 7:0 NVMLOCK[7:0]
7:0 NVMADR[7:0]
0x43 NVMADR 15:8 NVMADR[15:8]
23:16 NVMADR[21:16]
7:0 NVMDAT[7:0]
0x46 NVMDAT
15:8 NVMDAT[15:8]
0x48 VREGCON 7:0 PMSYS[1:0] VREGPM[1:0]
0x49 BORCON 7:0 SBOREN BORRDY
0x4A HLVDCON0 7:0 EN OUT RDY INTH INTL
0x4B HLVDCON1 7:0 SEL[3:0]
0x4C ZCDCON 7:0 SEN OUT POL INTP INTN
0x4D
... Reserved
0x5F
0x60 PMD0 7:0 SYSCMD FVRMD HLVDMD CRCMD SCANMD CLKRMD IOCMD
0x61 PMD1 7:0 SMT1MD TMR6MD TMR5MD TMR4MD TMR3MD TMR2MD TMR1MD TMR0MD
0x62 PMD2 7:0 CANMD TU16BMD TU16AMD
0x63 PMD3 7:0 ACTMD DAC1MD ADCMD C2MD C1MD ZCDMD
0x64 PMD4 7:0 CWG3MD CWG2MD CWG1MD DSM1MD NCO3MD NCO2MD NCO1MD
0x65 PMD5 7:0 PWM4MD PWM3MD PWM2MD PWM1MD CCP3MD CCP2MD CCP1MD
0x66 PMD6 7:0 U5MD U4MD U3MD U2MD U1MD SPI2MD SPI1MD I2C1MD
0x67 PMD7 7:0 CLC8MD CLC7MD CLC6MD CLC5MD CLC4MD CLC3MD CLC2MD CLC1MD
0x68 PMD8 7:0 DMA8MD DMA7MD DMA6MD DMA5MD DMA4MD DMA3MD DMA2MD DMA1MD
0x69 Reserved
0x6A MD1CON0 7:0 EN OUT OPOL BIT
0x6B MD1CON1 7:0 CHPOL CHSYNC CLPOL CLSYNC
0x6C MD1SRC 7:0 MS[5:0]
0x6D MD1CARL 7:0 CL[4:0]
0x6E MD1CARH 7:0 CH[4:0]
0x6F CMOUT 7:0 C2OUT C1OUT
0x70 CM1CON0 7:0 EN OUT POL HYS SYNC
0x71 CM1CON1 7:0 INTP INTN
0x72 CM1NCH 7:0 NCH[2:0]
0x73 CM1PCH 7:0 PCH[2:0]
0x74 CM2CON0 7:0 EN OUT POL HYS SYNC
0x75 CM2CON1 7:0 INTP INTN
0x76 CM2NCH 7:0 NCH[2:0]
0x77 CM2PCH 7:0 PCH[2:0]
0x78 WDTCON0 7:0 PS[4:0] SEN
0x79 WDTCON1 7:0 CS[2:0] WINDOW[2:0]
0x7A WDTPSL 7:0 PSCNTL[7:0]
0x7B WDTPSH 7:0 PSCNTH[7:0]
0x7C WDTTMR 7:0 TMR[4:0] STATE PSCNT[17:16]
0x7D DAC1DATL 7:0 DAC1R[7:0]
...........continued
0x7E Reserved
0x7F DAC1CON 7:0 EN OE[1:0] PSS[1:0] NSS
0x80 SPI1RXB 7:0 RXB[7:0]
0x81 SPI1TXB 7:0 TXB[7:0]
7:0 TCNTL[7:0]
0x82 SPI1TCNT
15:8 TCNTH[2:0]
0x84 SPI1CON0 7:0 EN LSBF MST BMODE
0x85 SPI1CON1 7:0 SMP CKE CKP FST SSP SDIP SDOP
0x86 SPI1CON2 7:0 BUSY SSFLT SSET TXR RXR
0x87 SPI1STATUS 7:0 TXWE TXBE RXRE CLB RXBF
0x88 SPI1TWIDTH 7:0 TWIDTH[2:0]
0x89 SPI1BAUD 7:0 BAUD[7:0]
0x8A SPI1INTF 7:0 SRMTIF TCZIF SOSIF EOSIF RXOIF TXUIF
0x8B SPI1INTE 7:0 SRMTIE TCZIE SOSIE EOSIE RXOIE TXUIE
0x8C SPI1CLK 7:0 CLKSEL[4:0]
0x8D SPI2RXB 7:0 RXB[7:0]
0x8E SPI2TXB 7:0 TXB[7:0]
7:0 TCNTL[7:0]
0x8F SPI2TCNT
15:8 TCNTH[2:0]
0x91 SPI2CON0 7:0 EN LSBF MST BMODE
0x92 SPI2CON1 7:0 SMP CKE CKP FST SSP SDIP SDOP
0x93 SPI2CON2 7:0 BUSY SSFLT SSET TXR RXR
0x94 SPI2STATUS 7:0 TXWE TXBE RXRE CLB RXBF
0x95 SPI2TWIDTH 7:0 TWIDTH[2:0]
0x96 SPI2BAUD 7:0 BAUD[7:0]
0x97 SPI2INTF 7:0 SRMTIF TCZIF SOSIF EOSIF RXOIF TXUIF
0x98 SPI2INTE 7:0 SRMTIE TCZIE SOSIE EOSIE RXOIE TXUIE
0x99 SPI2CLK 7:0 CLKSEL[4:0]
0x9A
... Reserved
0xAB
0xAC ACTCON 7:0 ACTEN ACTUD ACTLOCK ACTORS
0xAD OSCCON1 7:0 NOSC[2:0] NDIV[3:0]
0xAE OSCCON2 7:0 COSC[2:0] CDIV[3:0]
0xAF OSCCON3 7:0 CSWHOLD SOSCPWR ORDY NOSCR
0xB0 OSCTUNE 7:0 TUN[5:0]
0xB1 OSCFRQ 7:0 FRQ[3:0]
0xB2 OSCSTAT 7:0 EXTOR HFOR MFOR LFOR SOR ADOR PLLR
0xB3 OSCEN 7:0 EXTOEN HFOEN MFOEN LFOEN SOSCEN ADOEN PLLEN
0xB4 PRLOCK 7:0 PRLOCKED
0xB5 SCANPR 7:0 PR[2:0]
0xB6 DMA1PR 7:0 PR[2:0]
0xB7 DMA2PR 7:0 PR[2:0]
0xB8 DMA3PR 7:0 PR[2:0]
0xB9 DMA4PR 7:0 PR[2:0]
0xBA DMA5PR 7:0 PR[2:0]
0xBB DMA6PR 7:0 PR[2:0]
0xBC DMA7PR 7:0 PR[2:0]
0xBD DMA8PR 7:0 PR[2:0]
0xBE MAINPR 7:0 PR[2:0]
0xBF ISRPR 7:0 PR[2:0]
0xC0
... Reserved
0xD3
0xD4 CLCDATA 7:0 CLC8OUT CLC7OUT CLC6OUT CLC5OUT CLC4OUT CLC3OUT CLC2OUT CLC1OUT
0xD5 CLCSELECT 7:0 SLCT[2:0]
0xD6 CLCnCON 7:0 EN OUT INTP INTN MODE[2:0]
0xD7 CLCnPOL 7:0 POL G4POL G3POL G2POL G1POL
0xD8 CLCnSEL0 7:0 D1S[7:0]
...........continued
...........continued
...........continued
...........continued
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x018C C1FLTOBJ0
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x0190 C1MASK0
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x0194 C1FLTOBJ1
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x0198 C1MASK1
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x019C C1FLTOBJ2
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01A0 C1MASK2
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01A4 C1FLTOBJ3
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01A8 C1MASK3
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01AC C1FLTOBJ4
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01B0 C1MASK4
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01B4 C1FLTOBJ5
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01B8 C1MASK5
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01BC C1FLTOBJ6
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01C0 C1MASK6
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
...........continued
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01C4 C1FLTOBJ7
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01C8 C1MASK7
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01CC C1FLTOBJ8
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01D0 C1MASK8
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01D4 C1FLTOBJ9
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01D8 C1MASK9
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01DC C1FLTOBJ10
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01E0 C1MASK10
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
7:0 SID[7:0]
15:8 EID[4:0] SID[10:8]
0x01E4 C1FLTOBJ11
23:16 EID[12:5]
31:24 EXIDE EID[17:13]
7:0 MSID[7:0]
15:8 MEID[4:0] MSID[10:8]
0x01E8 C1MASK11
23:16 MEID[12:5]
31:24 MIDE MEID[17:13]
0x01EC
... Reserved
0x01FF
0x0200 PPSLOCK 7:0 PPSLOCKED
0x0201 RA0PPS 7:0 RA0PPS[6:0]
0x0202 RA1PPS 7:0 RA1PPS[6:0]
0x0203 RA2PPS 7:0 RA2PPS[6:0]
0x0204 RA3PPS 7:0 RA3PPS[6:0]
0x0205 RA4PPS 7:0 RA4PPS[6:0]
0x0206 RA5PPS 7:0 RA5PPS[6:0]
0x0207 RA6PPS 7:0 RA6PPS[6:0]
0x0208 RA7PPS 7:0 RA7PPS[6:0]
0x0209 RB0PPS 7:0 RB0PPS[6:0]
0x020A RB1PPS 7:0 RB1PPS[6:0]
0x020B RB2PPS 7:0 RB2PPS[6:0]
0x020C RB3PPS 7:0 RB3PPS[6:0]
0x020D RB4PPS 7:0 RB4PPS[6:0]
0x020E RB5PPS 7:0 RB5PPS[6:0]
0x020F RB6PPS 7:0 RB6PPS[6:0]
...........continued
...........continued
...........continued
...........continued
...........continued
...........continued
...........continued
7:0 FSRL[7:0]
0x037D FSR0_SHAD
15:8 FSRH[5:0]
7:0 FSRL[7:0]
0x037F FSR1_SHAD
15:8 FSRH[5:0]
7:0 FSRL[7:0]
0x0381 FSR2_SHAD
15:8 FSRH[5:0]
7:0 PROD[7:0]
0x0383 PROD_SHAD
15:8 PROD[15:8]
0x0385
... Reserved
0x0386
0x0387 TU16ACON0 7:0 ON CPOL OM OPOL RDSEL PRIE ZIE CIE
0x0388 TU16ACON1 7:0 RUN OSEN CLR LIMIT CAPT PRIF ZIF CIF
0x0389 TU16AHLT 7:0 EPOL CSYNC START[1:0] RESET[1:0] STOP[1:0]
0x038A TU16APS 7:0 PS[7:0]
7:0 TMR[7:0]
0x038B TU16ATMR
15:8 TMR[15:8]
7:0 CR[7:0]
0x038B TU16ACR
15:8 CR[15:8]
7:0 PR[7:0]
0x038D TU16APR
15:8 PR[15:8]
0x038F TU16ACLK 7:0 CLK[4:0]
0x0390 TU16AERS 7:0 ERS[5:0]
0x0391
... Reserved
0x0392
0x0393 TU16BCON0 7:0 ON CPOL OM OPOL RDSEL PRIE ZIE CIE
0x0394 TU16BCON1 7:0 RUN OSEN CLR LIMIT CAPT PRIF ZIF CIF
0x0395 TU16BHLT 7:0 EPOL CSYNC START[1:0] RESET[1:0] STOP[1:0]
0x0396 TU16BPS 7:0 PS[7:0]
7:0 TMR[7:0]
0x0397 TU16BTMR
15:8 TMR[15:8]
7:0 CR[7:0]
0x0397 TU16BCR
15:8 CR[15:8]
7:0 PR[7:0]
0x0399 TU16BPR
15:8 PR[15:8]
0x039B TU16BCLK 7:0 CLK[4:0]
0x039C TU16BERS 7:0 ERS[5:0]
0x039D
... Reserved
0x03BA
0x03BB TUCHAIN 7:0 CH16AB
0x03BC CWG1CLK 7:0 CS
0x03BD CWG1ISM 7:0 ISM[4:0]
0x03BE CWG1DBR 7:0 DBR[5:0]
0x03BF CWG1DBF 7:0 DBF[5:0]
0x03C0 CWG1CON0 7:0 EN LD MODE[2:0]
0x03C1 CWG1CON1 7:0 IN POLD POLC POLB POLA
0x03C2 CWG1AS0 7:0 SHUTDOWN REN LSBD[1:0] LSAC[1:0]
0x03C3 CWG1AS1 7:0 AS7E AS6E AS5E AS4E AS3E AS2E AS1E AS0E
0x03C4 CWG1STR 7:0 OVRD OVRC OVRB OVRA STRD STRC STRB STRA
0x03C5 CWG2CLK 7:0 CS
0x03C6 CWG2ISM 7:0 ISM[4:0]
0x03C7 CWG2DBR 7:0 DBR[5:0]
0x03C8 CWG2DBF 7:0 DBF[5:0]
0x03C9 CWG2CON0 7:0 EN LD MODE[2:0]
0x03CA CWG2CON1 7:0 IN POLD POLC POLB POLA
0x03CB CWG2AS0 7:0 SHUTDOWN REN LSBD[1:0] LSAC[1:0]
0x03CC CWG2AS1 7:0 AS7E AS6E AS5E AS4E AS3E AS2E AS1E AS0E
...........continued
0x03CD CWG2STR 7:0 OVRD OVRC OVRB OVRA STRD STRC STRB STRA
0x03CE CWG3CLK 7:0 CS
0x03CF CWG3ISM 7:0 ISM[4:0]
0x03D0 CWG3DBR 7:0 DBR[5:0]
0x03D1 CWG3DBF 7:0 DBF[5:0]
0x03D2 CWG3CON0 7:0 EN LD MODE[2:0]
0x03D3 CWG3CON1 7:0 IN POLD POLC POLB POLA
0x03D4 CWG3AS0 7:0 SHUTDOWN REN LSBD[1:0] LSAC[1:0]
0x03D5 CWG3AS1 7:0 AS7E AS6E AS5E AS4E AS3E AS2E AS1E AS0E
0x03D6 CWG3STR 7:0 OVRD OVRC OVRB OVRA STRD STRC STRB STRA
0x03D7 FVRCON 7:0 EN RDY TSEN TSRNG CDAFVR[1:0] ADFVR[1:0]
0x03D8 ADCP 7:0 CPON CPRDY
7:0 LTH[7:0]
0x03D9 ADLTH
15:8 LTH[15:8]
7:0 UTH[7:0]
0x03DB ADUTH
15:8 UTH[15:8]
7:0 ERR[7:0]
0x03DD ADERR
15:8 ERR[15:8]
7:0 STPT[7:0]
0x03DF ADSTPT
15:8 STPT[15:8]
7:0 FLTR[7:0]
0x03E1 ADFLTR
15:8 FLTR[15:8]
7:0 ACC[7:0]
0x03E3 ADACC 15:8 ACC[15:8]
23:16 ACC[17:16]
0x03E6 ADCNT 7:0 CNT[7:0]
0x03E7 ADRPT 7:0 RPT[7:0]
7:0 PREV[7:0]
0x03E8 ADPREV
15:8 PREV[15:8]
7:0 RES[7:0]
0x03EA ADRES
15:8 RES[15:8]
0x03EC ADPCH 7:0 PCH[5:0]
0x03ED Reserved
7:0 ACQ[7:0]
0x03EE ADACQ
15:8 ACQ[12:8]
0x03F0 ADCAP 7:0 CAP[4:0]
7:0 PRE[7:0]
0x03F1 ADPRE
15:8 PRE[12:8]
0x03F3 ADCON0 7:0 ON CONT CSEN CS FM GO
0x03F4 ADCON1 7:0 PPOL IPEN GPOL DSEN
0x03F5 ADCON2 7:0 PSIS CRS[2:0] ACLR MD[2:0]
0x03F6 ADCON3 7:0 CALC[2:0] SOI TMD[2:0]
0x03F7 ADSTAT 7:0 AOV UTHR LTHR MATH STAT[2:0]
0x03F8 ADREF 7:0 NREF PREF[1:0]
0x03F9 ADACT 7:0 ACT[5:0]
0x03FA ADCLK 7:0 CS[5:0]
0x03FB ADCTX 7:0 CTXSW CTX[1:0]
0x03FC ADCSEL1 7:0 CHEN SSI
0x03FD ADCSEL2 7:0 CHEN SSI
0x03FE ADCSEL3 7:0 CHEN SSI
0x03FF ADCSEL4 7:0 CHEN SSI
0x0400 ANSELA 7:0 ANSELA7 ANSELA6 ANSELA5 ANSELA4 ANSELA3 ANSELA2 ANSELA1 ANSELA0
0x0401 WPUA 7:0 WPUA7 WPUA6 WPUA5 WPUA4 WPUA3 WPUA2 WPUA1 WPUA0
0x0402 ODCONA 7:0 ODCA7 ODCA6 ODCA5 ODCA4 ODCA3 ODCA2 ODCA1 ODCA0
0x0403 SLRCONA 7:0 SLRA7 SLRA6 SLRA5 SLRA4 SLRA3 SLRA2 SLRA1 SLRA0
0x0404 INLVLA 7:0 INLVLA7 INLVLA6 INLVLA5 INLVLA4 INLVLA3 INLVLA2 INLVLA1 INLVLA0
0x0405 IOCAP 7:0 IOCAP7 IOCAP6 IOCAP5 IOCAP4 IOCAP3 IOCAP2 IOCAP1 IOCAP0
0x0406 IOCAN 7:0 IOCAN7 IOCAN6 IOCAN5 IOCAN4 IOCAN3 IOCAN2 IOCAN1 IOCAN0
0x0407 IOCAF 7:0 IOCAF7 IOCAF6 IOCAF5 IOCAF4 IOCAF3 IOCAF2 IOCAF1 IOCAF0
...........continued
0x0408 ANSELB 7:0 ANSELB7 ANSELB6 ANSELB5 ANSELB4 ANSELB3 ANSELB2 ANSELB1 ANSELB0
0x0409 WPUB 7:0 WPUB7 WPUB6 WPUB5 WPUB4 WPUB3 WPUB2 WPUB1 WPUB0
0x040A ODCONB 7:0 ODCB7 ODCB6 ODCB5 ODCB4 ODCB3 ODCB2 ODCB1 ODCB0
0x040B SLRCONB 7:0 SLRB7 SLRB6 SLRB5 SLRB4 SLRB3 SLRB2 SLRB1 SLRB0
0x040C INLVLB 7:0 INLVLB7 INLVLB6 INLVLB5 INLVLB4 INLVLB3 INLVLB2 INLVLB1 INLVLB0
0x040D IOCBP 7:0 IOCBP7 IOCBP6 IOCBP5 IOCBP4 IOCBP3 IOCBP2 IOCBP1 IOCBP0
0x040E IOCBN 7:0 IOCBN7 IOCBN6 IOCBN5 IOCBN4 IOCBN3 IOCBN2 IOCBN1 IOCBN0
0x040F IOCBF 7:0 IOCBF7 IOCBF6 IOCBF5 IOCBF4 IOCBF3 IOCBF2 IOCBF1 IOCBF0
0x0410 ANSELC 7:0 ANSELC7 ANSELC6 ANSELC5 ANSELC4 ANSELC3 ANSELC2 ANSELC1 ANSELC0
0x0411 WPUC 7:0 WPUC7 WPUC6 WPUC5 WPUC4 WPUC3 WPUC2 WPUC1 WPUC0
0x0412 ODCONC 7:0 ODCC7 ODCC6 ODCC5 ODCC4 ODCC3 ODCC2 ODCC1 ODCC0
0x0413 SLRCONC 7:0 SLRC7 SLRC6 SLRC5 SLRC4 SLRC3 SLRC2 SLRC1 SLRC0
0x0414 INLVLC 7:0 INLVLC7 INLVLC6 INLVLC5 INLVLC4 INLVLC3 INLVLC2 INLVLC1 INLVLC0
0x0415 IOCCP 7:0 IOCCP7 IOCCP6 IOCCP5 IOCCP4 IOCCP3 IOCCP2 IOCCP1 IOCCP0
0x0416 IOCCN 7:0 IOCCN7 IOCCN6 IOCCN5 IOCCN4 IOCCN3 IOCCN2 IOCCN1 IOCCN0
0x0417 IOCCF 7:0 IOCCF7 IOCCF6 IOCCF5 IOCCF4 IOCCF3 IOCCF2 IOCCF1 IOCCF0
0x0418 ANSELD 7:0 ANSELD7 ANSELD6 ANSELD5 ANSELD4 ANSELD3 ANSELD2 ANSELD1 ANSELD0
0x0419 WPUD 7:0 WPUD7 WPUD6 WPUD5 WPUD4 WPUD3 WPUD2 WPUD1 WPUD0
0x041A ODCOND 7:0 ODCD7 ODCD6 ODCD5 ODCD4 ODCD3 ODCD2 ODCD1 ODCD0
0x041B SLRCOND 7:0 SLRD7 SLRD6 SLRD5 SLRD4 SLRD3 SLRD2 SLRD1 SLRD0
0x041C INLVLD 7:0 INLVLD7 INLVLD6 INLVLD5 INLVLD4 INLVLD3 INLVLD2 INLVLD1 INLVLD0
0x041D
... Reserved
0x041F
0x0420 ANSELE 7:0 ANSELE2 ANSELE1 ANSELE0
0x0421 WPUE 7:0 WPUE3 WPUE2 WPUE1 WPUE0
0x0422 ODCONE 7:0 ODCE2 ODCE1 ODCE0
0x0423 SLRCONE 7:0 SLRE2 SLRE1 SLRE0
0x0424 INLVLE 7:0 INLVLE3 INLVLE2 INLVLE1 INLVLE0
0x0425 IOCEP 7:0 IOCEP3
0x0426 IOCEN 7:0 IOCEN3
0x0427 IOCEF 7:0 IOCEF3
0x0428 ANSELF 7:0 ANSELF7 ANSELF6 ANSELF5 ANSELF4 ANSELF3 ANSELF2 ANSELF1 ANSELF0
0x0429 WPUF 7:0 WPUF7 WPUF6 WPUF5 WPUF4 WPUF3 WPUF2 WPUF1 WPUF0
0x042A ODCONF 7:0 ODCF7 ODCF6 ODCF5 ODCF4 ODCF3 ODCF2 ODCF1 ODCF0
0x042B SLRCONF 7:0 SLRF7 SLRF6 SLRF5 SLRF4 SLRF3 SLRF2 SLRF1 SLRF0
0x042C INLVLF 7:0 INLVLF7 INLVLF6 INLVLF5 INLVLF4 INLVLF3 INLVLF2 INLVLF1 INLVLF0
0x042D
... Reserved
0x043F
7:0 ACC[7:0]
0x0440 NCO1ACC 15:8 ACC[15:8]
23:16 ACC[19:16]
7:0 INC[7:0]
0x0443 NCO1INC 15:8 INC[15:8]
23:16 INC[19:16]
0x0446 NCO1CON 7:0 EN OUT POL PFM
0x0447 NCO1CLK 7:0 PWS[2:0] CKS[4:0]
7:0 ACC[7:0]
0x0448 NCO2ACC 15:8 ACC[15:8]
23:16 ACC[19:16]
7:0 INC[7:0]
0x044B NCO2INC 15:8 INC[15:8]
23:16 INC[19:16]
0x044E NCO2CON 7:0 EN OUT POL PFM
0x044F NCO2CLK 7:0 PWS[2:0] CKS[4:0]
7:0 ACC[7:0]
0x0450 NCO3ACC 15:8 ACC[15:8]
23:16 ACC[19:16]
...........continued
7:0 INC[7:0]
0x0453 NCO3INC 15:8 INC[15:8]
23:16 INC[19:16]
0x0456 NCO3CON 7:0 EN OUT POL PFM
0x0457 NCO3CLK 7:0 PWS[2:0] CKS[4:0]
0x0458 FSCMCON 7:0 FSCMSFI FSCMSEV FSCMPFI FSCMPEV FSCMFFI FSCMFEV
0x0459 IVTLOCK 7:0 IVTLOCKED
7:0 IVTADL[7:0]
0x045A IVTAD 15:8 IVTADH[7:0]
23:16 IVTADU[4:0]
7:0 IVTBASEL[7:0]
0x045D IVTBASE 15:8 IVTBASEH[7:0]
23:16 IVTBASEU[4:0]
0x0460 PWM1ERS 7:0 ERS[4:0]
0x0461 PWM1CLK 7:0 CLK[4:0]
0x0462 PWM1LDS 7:0 LDS[4:0]
7:0 PR[7:0]
0x0463 PWM1PR
15:8 PR[15:8]
0x0465 PWM1CPRE 7:0 CPRE[7:0]
0x0466 PWM1PIPOS 7:0 PIPOS[7:0]
0x0467 PWM1GIR 7:0 S1P2 S1P1
0x0468 PWM1GIE 7:0 S1P2 S1P1
0x0469 PWM1CON 7:0 EN LD ERSPOL ERSNOW
0x046A PWM1S1CFG 7:0 POL2 POL1 PPEN MODE[2:0]
7:0 P1[7:0]
0x046B PWM1S1P1
15:8 P1[15:8]
7:0 P2[7:0]
0x046D PWM1S1P2
15:8 P2[15:8]
0x046F PWM2ERS 7:0 ERS[4:0]
0x0470 PWM2CLK 7:0 CLK[4:0]
0x0471 PWM2LDS 7:0 LDS[4:0]
7:0 PR[7:0]
0x0472 PWM2PR
15:8 PR[15:8]
0x0474 PWM2CPRE 7:0 CPRE[7:0]
0x0475 PWM2PIPOS 7:0 PIPOS[7:0]
0x0476 PWM2GIR 7:0 S1P2 S1P1
0x0477 PWM2GIE 7:0 S1P2 S1P1
0x0478 PWM2CON 7:0 EN LD ERSPOL ERSNOW
0x0479 PWM2S1CFG 7:0 POL2 POL1 PPEN MODE[2:0]
7:0 P1[7:0]
0x047A PWM2S1P1
15:8 P1[15:8]
7:0 P2[7:0]
0x047C PWM2S1P2
15:8 P2[15:8]
0x047E PWM3ERS 7:0 ERS[4:0]
0x047F PWM3CLK 7:0 CLK[4:0]
0x0480 PWM3LDS 7:0 LDS[4:0]
7:0 PR[7:0]
0x0481 PWM3PR
15:8 PR[15:8]
0x0483 PWM3CPRE 7:0 CPRE[7:0]
0x0484 PWM3PIPOS 7:0 PIPOS[7:0]
0x0485 PWM3GIR 7:0 S1P2 S1P1
0x0486 PWM3GIE 7:0 S1P2 S1P1
0x0487 PWM3CON 7:0 EN LD ERSPOL ERSNOW
0x0488 PWM3S1CFG 7:0 POL2 POL1 PPEN MODE[2:0]
7:0 P1[7:0]
0x0489 PWM3S1P1
15:8 P1[15:8]
7:0 P2[7:0]
0x048B PWM3S1P2
15:8 P2[15:8]
0x048D PWM4ERS 7:0 ERS[4:0]
...........continued
...........continued
0x04C8 TRISC 7:0 TRISC7 TRISC6 TRISC5 TRISC4 TRISC3 TRISC2 TRISC1 TRISC0
0x04C9 TRISD 7:0 TRISD7 TRISD6 TRISD5 TRISD4 TRISD3 TRISD2 TRISD1 TRISD0
0x04CA TRISE 7:0 Reserved TRISE2 TRISE1 TRISE0
0x04CB TRISF 7:0 TRISF7 TRISF6 TRISF5 TRISF4 TRISF3 TRISF2 TRISF1 TRISF0
0x04CC
... Reserved
0x04CD
0x04CE PORTA 7:0 RA7 RA6 RA5 RA4 RA3 RA2 RA1 RA0
0x04CF PORTB 7:0 RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0
0x04D0 PORTC 7:0 RC7 RC6 RC5 RC4 RC3 RC2 RC1 RC0
0x04D1 PORTD 7:0 RD7 RD6 RD5 RD4 RD3 RD2 RD1 RD0
0x04D2 PORTE 7:0 RE3 RE2 RE1 RE0
0x04D3 PORTF 7:0 RF7 RF6 RF5 RF4 RF3 RF2 RF1 RF0
0x04D4
... Reserved
0x04D5
0x04D6 INTCON0 7:0 GIE/GIEH GIEL IPEN INT2EDG INT1EDG INT0EDG
0x04D7 INTCON1 7:0 STAT[1:0]
0x04D8 STATUS 7:0 TO PD N OV Z DC C
7:0 FSRL[7:0]
0x04D9 FSR2
15:8 FSRH[5:0]
0x04DB PLUSW2 7:0 PLUSW[7:0]
0x04DC PREINC2 7:0 PREINC[7:0]
0x04DD POSTDEC2 7:0 POSTDEC[7:0]
0x04DE POSTINC2 7:0 POSTINC[7:0]
0x04DF INDF2 7:0 INDF[7:0]
0x04E0 BSR 7:0 BSR[5:0]
7:0 FSRL[7:0]
0x04E1 FSR1
15:8 FSRH[5:0]
0x04E3 PLUSW1 7:0 PLUSW[7:0]
0x04E4 PREINC1 7:0 PREINC[7:0]
0x04E5 POSTDEC1 7:0 POSTDEC[7:0]
0x04E6 POSTINC1 7:0 POSTINC[7:0]
0x04E7 INDF1 7:0 INDF[7:0]
0x04E8 WREG 7:0 WREG[7:0]
7:0 FSRL[7:0]
0x04E9 FSR0
15:8 FSRH[5:0]
0x04EB PLUSW0 7:0 PLUSW[7:0]
0x04EC PREINC0 7:0 PREINC[7:0]
0x04ED POSTDEC0 7:0 POSTDEC[7:0]
0x04EE POSTINC0 7:0 POSTINC[7:0]
0x04EF INDF0 7:0 INDF[7:0]
0x04F0 PCON0 7:0 STKOVF STKUNF WDTWV RWDT RMCLR RI POR BOR
0x04F1 PCON1 7:0 PORVDDIO3 PORVDDIO2 RVREG MEMV RCM
0x04F2 CPUDOZE 7:0 IDLEN DOZEN ROI DOE DOZE[2:0]
7:0 PROD[7:0]
0x04F3 PROD
15:8 PROD[15:8]
0x04F5 TABLAT 7:0 TABLAT[7:0]
7:0 TBLPTR[7:0]
0x04F6 TBLPTR 15:8 TBLPTR[15:8]
23:16 TBLPTR21 TBLPTR[20:16]
0x04F9 PCL 7:0 PCL[7:0]
7:0 PCLATH[7:0]
0x04FA PCLAT
15:8 PCLATU[4:0]
0x04FC STKPTR 7:0 STKPTR[6:0]
7:0 TOS[7:0]
0x04FD TOS 15:8 TOS[15:8]
23:16 TOS[20:16]
...........continued
0x0500
... Reserved
0x2FFFFF
300000 CONFIG1 7:0 RSTOSC[2:0] FEXTOSC[2:0]
300001 CONFIG2 7:0 FCMENS FCMENP FCMEN JTAGEN CSWEN PR1WAY CLKOUTEN
300002 CONFIG3 7:0 BOREN[1:0] LPBOREN IVT1WAY MVECEN PWRTS[1:0] MCLRE
300003 CONFIG4 7:0 XINST LVP STVREN PPS1WAY ZCD BORV[1:0]
300004 CONFIG5 7:0 WDTE[1:0] WDTCPS[4:0]
300005 CONFIG6 7:0 WDTCCS[2:0] WDTCWS[2:0]
300006 CONFIG7 7:0 DEBUG SAFEN BBEN BBSIZE[2:0]
300007 CONFIG8 7:0 WRTAPP WRTSAF WRTD WRTC WRTB
300008 CONFIG9 7:0 ODCON BPEN BOOTPINSEL[1:0]
300009 CONFIG10 7:0 CP
30000A30
CONFIG11 7:0 BOOTPOR COE CFGSCEN DATSCEN SAFSCEN APPSCEN BOOTCOE BOOTSCEN
000A
7:0 BCRCPOL[7:0]
30000B30 CRC Boot 15:8 BCRCPOL[15:8]
000B Polynomial 23:16 BCRCPOL[23:16]
31:24 BCRCPOL[31:24]
7:0 BCRCSEED[7:0]
30000F30 15:8 BCRCSEED[15:8]
CRC Boot Seed
000F 23:16 BCRCSEED[23:16]
31:24 BCRCSEED[31:24]
7:0 BCRCERES[7:0]
30001330 CRC Boot Expected 15:8 BCRCERES[15:8]
0013 Value 23:16 BCRCERES[23:16]
31:24 BCRCERES[31:24]
7:0 CRCPOL[7:0]
30001730 15:8 CRCPOL[15:8]
CRC Polynomial
0017 23:16 CRCPOL[23:16]
31:24 CRCPOL[31:24]
7:0 CRCSEED[7:0]
30001B30 15:8 CRCSEED[15:8]
CRC Seed
001B 23:16 CRCSEED[23:16]
31:24 CRCSEED[31:24]
7:0 CRCERES[7:0]
30001F30 CRC Expected 15:8 CRCERES[15:8]
001F Value 23:16 CRCERES[23:16]
31:24 CRCERES[31:24]
0x300023
... Reserved
0x3FFFFB
7:0 MJRREV[1:0] MNRREV[5:0]
0x3FFFFC REVISIONID
15:8 1010[3:0] MJRREV[5:2]
7:0 DEV[7:0]
0x3FFFFE DEVICEID
15:8 DEV[15:8]
Maximum current(1)
• on VSS pin -40°C ≤ TA ≤ +85°C 350 mA
85°C < TA ≤ +125°C 120 mA
• on VDD pin (28-pin devices) -40°C ≤ TA ≤ +85°C 250 mA
85°C < TA ≤ +125°C 85 mA
• on VDD pin (40-pin devices) -40°C ≤ TA ≤ +85°C 350 mA
85°C < TA ≤ +125°C 120 mA
• on any standard I/O pin ±50 mA
Notes:
1. Maximum current rating requires even load distribution across I/O pins. Maximum current rating may be
limited by the device package power dissipation characterizations, see the Thermal Characteristics section to
calculate device specifications.
2. Power dissipation is calculated as follows:
PDIS = VDD x {IDD - Σ IOH} + Σ {(VDD - VOH) x IOH} + Σ (VOI x IOL).
† NOTICE: Stresses above those listed under “Absolute Maximum Ratings” may cause permanent damage to the
device. This is a stress rating only and functional operation of the device at those or any other conditions above those
indicated in the operation listings of this specification is not implied. Exposure above maximum rating conditions for
extended periods may affect device reliability.
Parameter Ratings
VDD — Operating Supply Voltage(1) VDDMIN +1.8V
VDDMAX +5.5V
TA — Operating Ambient Temperature Range
Industrial Temperature TA_MIN -40°C
TA_MAX +85°C
Extended Temperature TA_MIN -40°C
TA_MAX +125°C
Note:
1. See the Parameter Supply Voltage in the “DC Characteristics” chapter for more details.
Figure 50-1. Voltage Frequency Graph, -40°C ≤ TA ≤ +125°C
Notes:
• The shaded region indicates the permissible combinations of voltage and frequency.
• Refer to the “External Clock/Oscillator Timing Requirements” table in the “AC Characteristics” chapter for
each Oscillator mode’s supported frequencies.
50.3 DC Characteristics
Figure 50-2. POR and POR Rearm with Slow Rising VDD
VDD
VPOR
VPORR
SVDD
VSS
NPOR(1)
POR REARM
VSS
TVLOW(3) TPOR(2)
Notes:
1. When NPOR is low, the device is held in Reset.
2. TPOR 1 μs typical.
3. TVLOW 2.7 μs typical.
...........continued
Standard Operating Conditions (unless otherwise stated)
Param. Sym. Device Min. Typ.† Max. Units Conditions
No. Characteristics
VDD Note
† Data in “Typ.” column is at 3.0V, 25°C unless otherwise stated. These parameters are for design guidance only
and are not tested.
Notes:
1. The test conditions for all IDD measurements in Active Operation mode are: OSC1 = external square wave,
from rail-to-rail; all I/O pins are outputs driven low; MCLR = VDD; WDT disabled.
2. The supply current is mainly a function of the operating voltage and frequency. Other factors, such as I/O
pin loading and switching rate, oscillator type, internal code execution pattern and temperature, also have an
impact on the current consumption.
3. IDDDOZE = [IDDIDLE*(N-1)/N] + IDDHFO16/N where N = Doze Ratio (see the CPUDOZE register).
4. PMD bits are all in the Default state, no modules are disabled.
...........continued
Standard Operating Conditions (unless otherwise stated)
Param. Sym. Device Min. Typ.† Max. Max. Units Conditions
No. Characteristics +85°C +125°C
VDD VREGPM Note
D208 IPD_CMP Comparator — 62 84.2 120 μA 3.0V ‘b11
...........continued
Standard Operating Conditions (unless otherwise stated)
Param. No. Sym. Device Min. Typ.† Max. Units Conditions
Characteristics
Input Leakage Current(1)
D340 IIL I/O PORTS — ±5 ±125 nA VSS ≤ VPIN ≤ VDD,
Pin at high-
impedance, 85°C
D341 — ±5 ±1000 nA VSS ≤ VPIN ≤ VDD,
Pin at high-
impedance, 125°C
D342 MCLR(2) — ±50 ±200 nA VSS ≤ VPIN ≤ VDD,
Pin at high-
impedance, 85°C
Weak Pull-up Current
D350 IPUR 80 140 200 μA VDD = 3.0V,
VPIN = VSS
Output Low Voltage
D360 VOL I/O PORTS — — 0.6 V IOL = 10.0 mA,
VPIN = 3.0V
Output High Voltage
D370 VOH I/O PORTS VDD - 0.7 — — V IOH = 6.0 mA,
VPIN = 3.0V
All I/O Pins
D380 CIO — 5 50 pF
† Data in “Typ” column is at 3.0V, 25°C unless otherwise stated. These parameters are for design guidance only and
are not tested.
Notes:
1. Negative current is defined as current sourced by the pin.
2. The leakage current on the MCLR pin is strongly dependent on the applied voltage level. The specified levels
represent normal operating conditions. Higher leakage current may be measured at different input voltages.
...........continued
Standard Operating Conditions (unless otherwise stated)
Param Sym. Device Characteristics Min. Typ† Max. Units Conditions
No.
MEM30 EP Flash Memory Cell Endurance -40°C ≤ TA ≤ +85°C
10k — — E/W (Note 1)
50.4 AC Characteristics
Figure 50-3. Load Conditions
Load Condition
Pin
CL
VSS
CLKIN
CLKOUT
(CLKOUT Mode)
...........continued
Standard Operating Conditions (unless otherwise stated)
Param No. Sym. Characteristic Min. Typ. † Max. Units Conditions
Secondary Oscillator
OS10 FSEC Clock Frequency 32.4 32.768 33.1 kHz (Note 4)
System Oscillator
OS20 FOSC System Clock — — 64 MHz (Note 2, Note 3)
Frequency
OS21 FCY Instruction — FOSC/4 — MHz
Frequency
OS22 TCY Instruction Period 62.5 1/FCY — ns
Notes:
1. Instruction cycle period (TCY) equals four times the input oscillator time base period. All specified values are
based on characterization data for that particular oscillator type under standard operating conditions with the
device executing code. Exceeding these specified limits may result in an unstable oscillator operation and/or
higher than expected current consumption. All devices are tested to operate at “min” values with an external
clock applied to OSC1 pin. When an external clock input is used, the “max” cycle time limit is “DC” (no clock)
for all devices.
2. The system clock frequency (FOSC) is selected by the “main clock switch controls” as described in the
“Power Saving Operation Modes” section.
3. The system clock frequency (FOSC) must meet the voltage requirements defined in the “Standard Operating
Conditions” section.
4. LP, XT and HS oscillator modes require an appropriate crystal or resonator to be connected to the device.
For clocking the device with the external square wave, one of the EC mode selections must be used.
...........continued
Standard Operating Conditions (unless otherwise stated)
Param No. Sym. Characteristic Min. Typ. † Max. Units Conditions
OS53* FLFOSC Internal LFINTOSC — 31 — kHz
Frequency
OS54* THFOSCST HFINTOSC Wake- — 30 40 μs VREGPM = 0x
up from Sleep Start-
— 100 — μs VREGPM = 1x
up Time
System Clock at 4
MHz
Figure 50-5. Precision Calibrated HFINTOSC Frequency Accuracy Over Device VDD and Temperature
125
± 5%
85
± 3%
Temperature (°C)
60
± 2%
0
± 5%
-40
1.8 2.0 2.3 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
...........continued
Standard Operating Conditions (unless otherwise stated)
Param No. Sym. Characteristic Min. Typ. † Max. Units Conditions
PLL02 FPLLOUT PLL Output 16 — 64 MHz (Note 1)
Frequency Range
PLL03* FPLLST PLL Lock Time — 200 — μs
PLL04* FPLLJIT PLL Output -0.25 — 0.25 %
Frequency Stability
* These parameters are characterized but not tested.
† Data in “Typ” column is at 3.0V, 25°C unless otherwise stated. These parameters are for design guidance only
and are not tested.
Note:
1. The output frequency of the PLL must meet the FOSC requirements listed in Parameter D002.
...........continued
Standard Operating Conditions (unless otherwise stated)
Param No. Sym. Characteristic Min. Typ. † Max. Units Conditions
IO7* TIOR_SLRDIS Port I/O rise time, slew rate disabled — 5 — ns VDD = 3.0V
IO8* TIOF_SLREN Port I/O fall time, slew rate enabled — 25 — ns VDD = 3.0V
IO9* TIOF_SLRDIS Port I/O fall time, slew rate disabled — 5 — ns VDD = 3.0V
IO10* TINT INT pin high or low time to trigger an interrupt 25 — — ns
IO11* TIOC Interrupt-on-Change minimum high or low time 25 — — ns
to trigger interrupt
* These parameters are characterized but not tested.
50.4.5 Reset, WDT, Oscillator Start-Up Timer, Power-Up Timer, Brown-Out Reset and Low-Power Brown-
Out Reset Specifications
Figure 50-7. Reset, Watchdog Timer, Oscillator Start-Up Timer and Power-Up Timer Timing
VDD
MCLR
RST01
Internal
POR
RST04
PWRT
Time-out RST05
OSC
Start-up Time
Internal Reset(1)
Watchdog Timer
Reset(1)
RST03
RST02
RST02
I/O pins
Note:
1. Asserted low.
RST08
Reset
RST04(1)
(due to BOR)
Note:
1. Only if the PWRTE Configuration bit is programmed to ‘1’; 2 ms delay if PWRTE = 0.
Table 50-11.
Standard Operating Conditions (unless otherwise stated)
Param No. Sym. Characteristic Min. Typ. † Max. Units Conditions
RST01* TMCLR MCLR Pulse Width — — — μs
Low to ensure Reset
RST02* TIOZ I/O high-impedance — — 2 μs
from Reset detection
RST03 TWDT Watchdog Timer Time- — 16 — ms WDTCPS =
out Period 00100
RST04* TPWRT Power-up Timer — 65 — ms
Period
RST05 TOST Oscillator Start-up — 1024 — TOSC
Timer Period(1,2)
RST06 VBOR Brown-out Reset 2.7 2.85 3.0 V BORV = 00
Voltage
2.55 2.7 2.85 V BORV = 01
2.3 2.45 2.6 V BORV = 10
1.8 1.9 2.1 V BORV = 11
AD03 EDL Differential Nonlinearity Error — ±0.1 ±1.0 LSb ADCREF+ = 3.0V,
ADCREF- = 0V
...........continued
Standard Operating Conditions (unless otherwise stated)
VDD = 3.0V, TA = 25°C, TAD = 500ns
AD21 TCNV Conversion Time — 14 TAD+2TCY — — Using FOSC as the ADC clock
source CS = 0
BSF ADCON0, GO
1 TCY
AD22
AD24 1 TCY
1 TCY AD20
ADC_clk
ADIF
GO DONE
BSF ADCON0, GO
1 TCY
AD22
AD24
2 TCY(1) AD21
ADC_clk
ADIF
GO DONE
Note 1: If the ADC clock source is selected as ADCRC, a time of 1 TCY is added before the ADC clock starts. This allows
the SLEEP instruction to be executed, if any.
...........continued
Standard Operating Conditions (unless otherwise stated)
VDD = 3.0V, TA = 25°C
...........continued
Standard Operating Conditions (unless otherwise stated)
Operating Temperature: -40°C≤TA≤+125°C
T0CKI
40 41
42
T1CKI
45 46
47 49
TMR0 or
TMR1
CC01 CC02
CC03
Note: Refer to the Load Conditions figure for more details.
SP71* TSCH SCK output high time 0.5 TSCK — 0.5 TSCK ns
- 12 + 12
SP72* TSCL SCK output low time 0.5 TSCK — 0.5 TSCK ns
- 12 + 12
SP73* TDIV2SCH, Setup time of SDI data 85 — — ns
input to SCK edge
TDIV2SCL
...........continued
Standard Operating Conditions (unless otherwise stated)
Param Sym. Characteristic Min. Typ. † Max. Units Conditions
No.
SP83* TSCH2SSH, SS ↑ after last SCK TSCK - 10 — — ns
edge
TSCL2SSH
...........continued
Standard Operating Conditions (unless otherwise stated)
Param No. Sym. Characteristic Min. Typ. † Max. Units Conditions
SP83* TSCH2SSH, SS ↑ after SCK edge 20 — — ns
TSCL2SSH
SCK
(CKP = 1)
SP79 SP78
SP80
SP75, SP76
SP74
SP73
Note: Refer to the Load Conditions figure for more details.
SP81
SCK
(CKP = 0)
SP71 SP72
SP79
SP73
SCK
(CKP = 1)
SP80
SP78
SP75, SP76
SP74
Note: Refer to the Load Conditions figure for more details.
Figure 50-15. SPI Client Mode Timing (CKE = 0)
SS
SP70
SCK SP83
(CKP = 0)
SP71 SP72
SP78 SP79
SCK
(CKP = 1)
SP79 SP78
SP80
SP74
SP73
Note: Refer to the Load Conditions figure for more details.
SP70
SCK SP83
(CKP = 0)
SP71 SP72
SCK
(CKP = 1)
SP80
SP77
SP75, SP76
SDI
MSb In bit 6 - - - -1 LSb In
SP74
SCL
SP91 SP93
SP90 SP92
SDA
Start Stop
Condition Condition
Note: Refer to the Load Conditions figure for more details.
...........continued
Standard Operating Conditions (unless otherwise stated)
Param. No. Sym. Characteristic Min. Max. Units Conditions
SP103* TF SDA and SCL 100 kHz — 250 ns
fall time mode
400 kHz 20 × 250 ns CB is specified to
mode (VDD/ be from 10-400 pF
5.5V)
1 MHz 20 × 120 ns
mode (VDD/
5.5V)
SP106* THD:DAT Data input hold 100 kHz 0 — ns
time mode
400 kHz 0 — ns
mode
1 MHz 0 — ns
mode
SP107* TSU:DAT Data input setup 100 kHz 250 — ns (Note 2)
time mode
400 kHz 100 — ns
mode
1 MHz 50 — ns
mode
SP109* TAA Output valid 100 kHz — 3450 ns (Note 1)
from clock mode
400 kHz — 900 ns
mode
1 MHz 450 ns
mode
SP110* TBUF Bus free time 100 kHz 4700 — ns Time the bus must
mode be free before a
new transmission
400 kHz 1300 — ns can start
mode
1 MHz 500 — ns
mode
SP111 CB Bus capacitive 100 kHz — 400 pF
loading mode
400 kHz — 400 pF
mode
1 MHz — 26 pF (Note 3)
mode
...........continued
Standard Operating Conditions (unless otherwise stated)
Param. No. Sym. Characteristic Min. Max. Units Conditions
* These parameters are characterized but not tested.
Notes:
1. As a transmitter, the device must provide this internal minimum delay time to bridge the undefined region
(min. 300 ns) of the falling edge of SCL to avoid unintended generation of Start or Stop conditions.
2. A Fast mode (400 kHz) I2C bus device can be used in a Standard mode (100 kHz) I2C bus system, but the
requirement TSU:DAT ≥ 250 ns must then be met. This will automatically be the case if the device does not
stretch the low period of the SCL signal. If such a device does stretch the low period of the SCL signal, it
must output the next data bit to the SDA line TR max. + TSU:DAT = 1000 + 250 = 1250 ns (according to the
Standard mode I2C bus specification), before the SCL line is released.
3. Using internal I2C pull-ups. For greater bus capacitance use external pull-ups.
SCL
SP90
SP106
SP107
SP91 SP92
SDA
In
SP110
SP109
SP109
SDA
Out
Note: In the event the full Microchip part number cannot be marked on one line, it will
be carried over to the next line, thus limiting the number of available
characters for customer-specific information.
PIC18F26Q83
SP e3
1926017
XXXXXXXXXXXXXXXXXXXX PIC18F26Q83
XXXXXXXXXXXXXXXXXXXX SO e3
XXXXXXXXXXXXXXXXXXXX
YYWWNNN 1926017
XXXXXXXXXXXX PIC18F26Q83
XXXXXXXXXXXX SS e3
YYWWNNN 1926017
926017
XXXXXXXXXXXXXXXXXX PIC18F46Q83
XXXXXXXXXXXXXXXXXX P e3
XXXXXXXXXXXXXXXXXX
YYWWNNN 1926017
XXXXXXXXXX 18F46Q83
XXXXXXXXXX PT e3
XXXXXXXXXX
YYWWNNN 1926017
PIN 1 PIN 1
XXXXXXXX 18F56Q83
XXXXXXXX 6LX e3
YYWWNNN 1926017
18F56Q83
/PT
1526017
28-Lead Skinny Plastic Dual In-Line (SP) – 300 mil Body [SPDIP]
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
NOTE 1
E1
1 2 3
A A2
L c
A1 b1
b e eB
Units INCHES
Dimension Limits MIN NOM MAX
Number of Pins N 28
Pitch e .100 BSC
Top to Seating Plane A – – .200
Molded Package Thickness A2 .120 .135 .150
Base to Seating Plane A1 .015 – –
Shoulder to Shoulder Width E .290 .310 .335
Molded Package Width E1 .240 .285 .295
Overall Length D 1.345 1.365 1.400
Tip to Seating Plane L .110 .130 .150
Lead Thickness c .008 .010 .015
Upper Lead Width b1 .040 .050 .070
Lower Lead Width b .014 .018 .022
Overall Row Spacing § eB – – .430
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. § Significant Characteristic.
3. Dimensions D and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed .010" per side.
4. Dimensioning and tolerancing per ASME Y14.5M.
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
D A B
N
(DATUM A)
(DATUM B)
E1 E
1 2
28X b
e 0.15 C A B
TOP VIEW
A
A1
C A A2
SEATING
PLANE 28X
0.10 C A
SIDE VIEW
c
L
(L1)
VIEW A-A
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Number of Pins N 28
Pitch e 0.65 BSC
Overall Height A - - 2.00
Molded Package Thickness A2 1.65 1.75 1.85
Standoff A1 0.05 - -
Overall Width E 7.40 7.80 8.20
Molded Package Width E1 5.00 5.30 5.60
Overall Length D 9.90 10.20 10.50
Foot Length L 0.55 0.75 0.95
Footprint L1 1.25 REF
Lead Thickness c 0.09 - 0.25
Foot Angle 0° 4° 8°
Lead Width b 0.22 - 0.38
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Dimensions D and E1 do not include mold flash or protrusions. Mold flash or
protrusions shall not exceed 0.20mm per side.
3. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
G1
28
SILK SCREEN
C
Y1
1 2
X1
E
Notes:
1. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
2. For best soldering results, thermal vias, if used, should be filled or tented to avoid solder loss during
reflow process
28-Lead Very Thin Plastic Quad Flat, No Lead Package (5N) - 6x6x1.0 mm Body [VQFN]
4.10x4.10 mm Exposed Pad, Wettable Flanks (Stepped)
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
D A B
NOTE 1 N
1
2
E
(DATUM B)
(DATUM A)
2X
0.10 C
2X
0.10 C
TOP VIEW
SEE DETAIL A
C
SEATING
PLANE
SIDE VIEW
0.10 C A B
D2
0.10 C A B
E2
2 (K)
1
NOTE 1
N
L 28X b
e 0.10 C A B
0.05 C
BOTTOM VIEW
Microchip Technology Drawing C04-401C Sheet 1 of 2
28-Lead Very Thin Plastic Quad Flat, No Lead Package (5N) - 6x6x1.0 mm Body [VQFN]
4.10x4.10 mm Exposed Pad, Wettable Flanks (Stepped)
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
0.10 C
A A4
C
SEATING
PLANE
(A3)
L1 28X
A1
0.08 C
DETAIL A
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Number of Terminals N 28
Pitch e 0.65 BSC
Overall Height A 0.80 0.90 1.00
Standoff A1 0.00 0.02 0.05
Terminal Thickness A3 0.20 REF
Step Height A4 0.05 0.12 0.19
Overall Width E 6.00 BSC
Exposed Pad Width E2 4.00 4.10 4.20
Overall Length D 6.00 BSC
Exposed Pad Length D2 4.00 4.10 4.20
Terminal Width b 0.25 0.30 0.35
Terminal Length L 0.50 0.60 0.70
Step Length L1 0.035 0.060 0.085
Terminal-to-Exposed Pad K 0.35 REF
Notes :
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Package is saw singulated
3. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
28-Lead Very Thin Plastic Quad Flat, No Lead Package (5N) - 6x6x1.0 mm Body [VQFN]
4.10x4.10 mm Exposed Pad, Wettable Flanks (Stepped)
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
C1
X2
EV
28
2 ØV
C2 Y2
EV G1
Y1
X1
E SILK SCREEN
Notes:
1. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
2. For best soldering results, thermal vias, if used, should be filled or tented to avoid solder loss during
reflow process
NOTE 1
E1
1 2 3
A A2
L c
b1
A1
b e eB
Units INCHES
Dimension Limits MIN NOM MAX
Number of Pins N 40
Pitch e .100 BSC
Top to Seating Plane A – – .250
Molded Package Thickness A2 .125 – .195
Base to Seating Plane A1 .015 – –
Shoulder to Shoulder Width E .590 – .625
Molded Package Width E1 .485 – .580
Overall Length D 1.980 – 2.095
Tip to Seating Plane L .115 – .200
Lead Thickness c .008 – .015
Upper Lead Width b1 .030 – .070
Lower Lead Width b .014 – .023
Overall Row Spacing § eB – – .700
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. § Significant Characteristic.
3. Dimensions D and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed .010" per side.
4. Dimensioning and tolerancing per ASME Y14.5M.
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
40-Lead Very Thin Plastic Quad Flat, No Lead Package (NHX) - 5x5 mm Body [VQFN]
With 3.7x3.7 mm Exposed Pad and Wettable Flanks
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
A1 40X
0.08 C
D A
0.10 C
N
B
NOTE 1
1
2
E
(DATUM B)
(DATUM A)
2X
0.10 C
2X
0.10 C
TOP VIEW (A3)
A
C SEATING
L
0.10 C A B PLANE
D2 SIDE VIEW
0.10 C A B
A A
0.10
E2
NOTE 1
0.05
2
1
SECTION A-A
ROTATED 180°
(K)
N
e 40X b
e
2 0.07 C A B
BOTTOM VIEW 0.04 C
40-Lead Very Thin Plastic Quad Flat, No Lead Package (NHX) - 5x5 mm Body [VQFN]
With 3.7x3.7 mm Exposed Pad and Wettable Flanks
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Number of Terminals N 40
Pitch e 0.40 BSC
Overall Height A 0.80 0.85 0.90
Standoff A1 0.00 0.02 0.05
Terminal Thickness A3 0.203 REF
Overall Length D 5.00 BSC
Exposed Pad Length D2 3.60 3.70 3.80
Overall Width E 5.00 BSC
Exposed Pad Width E2 3.60 3.70 3.80
Terminal Width b 0.15 0.20 0.25
Terminal Length L 0.30 0.40 0.50
Terminal-to-Exposed-Pad K 0.25 REF
Notes :
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Package is saw singulated
3. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
40-Lead Very Thin Plastic Quad Flat, No Lead Package (NHX) - 5x5 mm Body [VQFN]
With 3.7x3.7 mm Exposed Pad and Wettable Flanks
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
C1
X2
EV
G2
ØV
CH
C2 Y2 G1
EV
Y1
X1
SILK SCREEN E
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
D A
D1 B
NOTE 2
(DATUM A)
(DATUM B)
E1 E
NOTE 1 A A
2X
N
0.20 H A B
2X 1 2 3
0.20 H A B 4X 11 TIPS
TOP VIEW
0.20 C A B
A A2
C
SEATING PLANE
0.10 C A1
SIDE VIEW
1 2 3
NOTE 1
44 X b
e 0.20 C A B
BOTTOM VIEW
Microchip Technology Drawing C04-076C Sheet 1 of 2
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
L θ
(L1)
SECTION A-A
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Number of Leads N 44
Lead Pitch e 0.80 BSC
Overall Height A - - 1.20
Standoff A1 0.05 - 0.15
Molded Package Thickness A2 0.95 1.00 1.05
Overall Width E 12.00 BSC
Molded Package Width E1 10.00 BSC
Overall Length D 12.00 BSC
Molded Package Length D1 10.00 BSC
Lead Width b 0.30 0.37 0.45
Lead Thickness c 0.09 - 0.20
Lead Length L 0.45 0.60 0.75
Footprint L1 1.00 REF
Foot Angle θ 0° 3.5° 7°
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Exact shape of each corner is optional.
3. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
44-Lead Plastic Thin Quad Flatpack (PT) - 10X10X1 mm Body, 2.00 mm Footprint [TQFP]
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
C1
44
1
2
G
C2
Y1
X1 E
SILK SCREEN
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Contact Pitch E 0.80 BSC
Contact Pad Spacing C1 11.40
Contact Pad Spacing C2 11.40
Contact Pad Width (X44) X1 0.55
Contact Pad Length (X44) Y1 1.50
Distance Between Pads G 0.25
Notes:
1. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
Microchip Technology Drawing No. C04-2076B
48-Lead Very Thin Plastic Quad Flat, No Lead Package (6MX) - 6x6 mm Body [VQFN]
With 4.1x4.1 mm Exposed Pad and Stepped Wettable Flanks
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
48X
0.08 C
0.10 C
D A B
NOTE 1
N
1
2
E
(DATUM B)
(DATUM A)
2X
0.05 C
2X
0.05 C
TOP VIEW A1
(A3)
0.10 C A B A
D2 SEATING
C
PLANE
SIDE VIEW
0.10 C A B
E2
A4
e
2
A A (K)
2
1
D3
2X CH
N SECTION A–A
L 48X b
e 0.10 C A B
0.05 C
BOTTOM VIEW
Microchip Technology Drawing C04-504 Rev A Sheet 1 of 2
48-Lead Very Thin Plastic Quad Flat, No Lead Package (6MX) - 6x6 mm Body [VQFN]
With 4.1x4.1 mm Exposed Pad and Stepped Wettable Flanks
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Number of Terminals N 48
Pitch e 0.40 BSC
Overall Height A 0.80 0.85 0.90
Standoff A1 0.00 0.02 0.05
Terminal Thickness A3 0.20 REF
Overall Length D 6.00 BSC
Exposed Pad Length D2 4.00 4.10 4.20
Overall Width E 6.00 BSC
Exposed Pad Width E2 4.00 4.10 4.20
Exposed Pad Corner Chamfer CH 0.35 REF
Terminal Width b 0.15 0.20 0.25
Terminal Length L 0.30 0.40 0.50
Terminal-to-Exposed-Pad K 0.55 REF
Wettable Flank Step Length D3 - - 0.085
Wettable Flank Step Height A4 0.10 - 0.19
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Package is saw singulated
3. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
48-Lead Very Thin Plastic Quad Flat, No Lead Package (6MX) - 6x6 mm Body [VQFN]
With 4.1x4.1 mm Exposed Pad and Stepped Wettable Flanks
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
C1
X2
EV
48
1
ØV
2
G2
C2 Y2
EV
G1
Y1
X1
SILK SCREEN E
48-Lead Thin Quad Flatpack (PT) - 7x7x1.0 mm Body [TQFP] With Exposed Pad
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
D
D1
D1/2
D
A B
NOTE 1
E1 E
A A
E1/2
E1/4 N
48X TIPS
12
0.20 C A-B D 4X
D1/4 0.20 H A-B D
A
TOP VIEW
0.10 C H
C
SEATING
PLANE 0.08 C
A1 SIDE VIEW
A2
D2 4X
12 0.20 H A-B D
4X
N
0.20
E2
e 48x b
e/2 0.08 C A-B D
TOP VIEW
48-Lead Thin Quad Flatpack (PT) - 7x7x1.0 mm Body [TQFP] With Exposed Pad
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
L
(L1)
SECTION A-A
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Number of Leads N 48
Lead Pitch e 0.50 BSC
Overall Height A - - 1.20
Standoff A1 0.05 - 0.15
Molded Package Thickness A2 0.95 1.00 1.05
Foot Length L 0.45 0.60 0.75
Footprint L1 1.00 REF
Foot Angle 0° 3.5° 7°
Overall Width E 9.00 BSC
Overall Length D 9.00 BSC
Molded Package Width E1 7.00 BSC
Molded Package Length D1 7.00 BSC
Exposed Pad Width E2 3.50 BSC
Exposed Pad Length D2 3.50 BSC
Lead Thickness c 0.09 - 0.16
Lead Width b 0.17 0.22 0.27
Mold Draft Angle Top 11° 12° 13°
Mold Draft Angle Bottom 11° 12° 13°
Notes :
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Chamfers at corners are optional; size may vary.
3. Dimensions D1 and E1 do not include mold flash or protrusions. Mold flash or
protrusions shall not exceed 0.25mm per side.
4. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
48-Lead Thin Quad Flatpack (PT) - 7x7x1.0 mm Body [TQFP] With Thermal Tab
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
C1
X2
C2 Y2
Y1
X1
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Contact Pitch E 0.50 BSC
Optional Center Tab Width X2 3.50
Optional Center Tab Length Y2 3.50
Contact Pad Spacing C1 8.40
Contact Pad Spacing C2 8.40
Contact Pad Width (X48) X1 0.30
Contact Pad Length (X48) Y1 1.50
Notes:
1. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
Microchip Technology Drawing No. C04-2183A
Customer Support
Users of Microchip products can receive assistance through several channels:
• Distributor or Representative
• Local Sales Office
• Embedded Solutions Engineer (ESE)
• Technical Support
Customers should contact their distributor, representative or ESE for support. Local sales offices are also available to
help customers. A listing of sales offices and locations is included in this document.
Technical support is available through the website at: www.microchip.com/support
Examples:
• PIC18F26Q83 T-E/SP: Tape and Reel, Extended temperature, 28-lead SPDIP
• PIC18F46Q83 T-I/PT: Tape and Reel, Industrial temperature, 44-lead TQFP
• PIC18F56Q83 T-I/VSX: Tape and Reel, Industrial temperature, 48-lead VQFN
Notes:
1. Tape and Reel identifier only appears in the catalog part number description. This identifier is used for ordering
purposes and is not printed on the device package. Check with your Microchip Sales Office for package
availability with the Tape and Reel option.
2. Small form-factor packaging options may be available. Please check www.microchip.com/packaging for small-
form factor package availability, or contact your local Sales Office.
Legal Notice
This publication and the information herein may be used only with Microchip products, including to design, test,
and integrate Microchip products with your application. Use of this information in any other manner violates these
terms. Information regarding device applications 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. Contact your
local Microchip sales office for additional support or, obtain additional support at www.microchip.com/en-us/support/
design-help/client-support-services.
THIS INFORMATION IS PROVIDED BY MICROCHIP "AS IS". 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 ANY IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE,
OR WARRANTIES RELATED TO ITS CONDITION, QUALITY, OR PERFORMANCE.
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL, OR
CONSEQUENTIAL LOSS, DAMAGE, COST, OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
INFORMATION OR ITS USE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW,
MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THE INFORMATION OR ITS USE
WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR
THE INFORMATION.
Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees
to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting
from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights
unless otherwise stated.
Trademarks
The Microchip name and logo, the Microchip logo, Adaptec, AnyRate, AVR, AVR logo, AVR Freaks, BesTime,
BitCloud, CryptoMemory, CryptoRF, dsPIC, flexPWR, HELDO, IGLOO, JukeBlox, KeeLoq, Kleer, LANCheck,
LinkMD, maXStylus, maXTouch, MediaLB, megaAVR, Microsemi, Microsemi logo, MOST, MOST logo, MPLAB,
OptoLyzer, PIC, picoPower, PICSTART, PIC32 logo, PolarFire, Prochip Designer, QTouch, SAM-BA, SenGenuity,
SpyNIC, SST, SST Logo, SuperFlash, Symmetricom, SyncServer, Tachyon, TimeSource, tinyAVR, UNI/O, Vectron,
and XMEGA are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.
AgileSwitch, APT, ClockWorks, The Embedded Control Solutions Company, EtherSynch, Flashtec, Hyper Speed
Control, HyperLight Load, IntelliMOS, Libero, motorBench, mTouch, Powermite 3, Precision Edge, ProASIC, ProASIC
Plus, ProASIC Plus logo, Quiet- Wire, SmartFusion, SyncWorld, Temux, TimeCesium, TimeHub, TimePictra,
TimeProvider, TrueTime, WinPath, and ZL are registered trademarks of Microchip Technology Incorporated in the
U.S.A.
Adjacent Key Suppression, AKS, Analog-for-the-Digital Age, Any Capacitor, AnyIn, AnyOut, Augmented Switching,
BlueSky, BodyCom, CodeGuard, CryptoAuthentication, CryptoAutomotive, CryptoCompanion, CryptoController,
dsPICDEM, dsPICDEM.net, Dynamic Average Matching, DAM, ECAN, Espresso T1S, EtherGREEN, GridTime,
IdealBridge, In-Circuit Serial Programming, ICSP, INICnet, Intelligent Paralleling, Inter-Chip Connectivity,
JitterBlocker, Knob-on-Display, maxCrypto, maxView, memBrain, Mindi, MiWi, MPASM, MPF, MPLAB Certified
logo, MPLIB, MPLINK, MultiTRAK, NetDetach, NVM Express, NVMe, Omniscient Code Generation, PICDEM,
PICDEM.net, PICkit, PICtail, PowerSmart, PureSilicon, QMatrix, REAL ICE, Ripple Blocker, RTAX, RTG4, SAM-
ICE, Serial Quad I/O, simpleMAP, SimpliPHY, SmartBuffer, SmartHLS, SMART-I.S., storClad, SQI, SuperSwitcher,
SuperSwitcher II, Switchtec, SynchroPHY, Total Endurance, TSHARC, USBCheck, VariSense, VectorBlox, VeriPHY,
ViewSpan, WiperLock, XpressConnect, and ZENA are trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.
The Adaptec logo, Frequency on Demand, Silicon Storage Technology, Symmcom, and Trusted Time are registered
trademarks of Microchip Technology Inc. in other countries.
GestIC is a registered trademark of Microchip Technology Germany II GmbH & Co. KG, a subsidiary of Microchip
Technology Inc., in other countries.
All other trademarks mentioned herein are property of their respective companies.
© 2020-2022, Microchip Technology Incorporated and its subsidiaries. All Rights Reserved.
ISBN: 978-1-5224-9441-6
Authorized Distributor
Microchip:
PIC18F26Q83T-I/5N PIC18F56Q83T-I/PT PIC18F26Q83T-I/SO PIC18F26Q83T-I/SS PIC18F46Q83T-I/PT
PIC18F56Q83T-I/6MX