2.0 Guidelines for Getting Started with 16-Bit Microcontrollers........................................................................................................ 29
3.0 CPU ........................................................................................................................................................................................... 35
5.0 Direct Memory Access Controller (DMA) ................................................................................................................................... 63
6.0 Flash Program Memory.............................................................................................................................................................. 71
20.0 Enhanced Parallel Master Port (EPMP) ................................................................................................................................... 237
21.0 Real-Time Clock and Calendar (RTCC) with Timestamp......................................................................................................... 249
26.0 Comparator Voltage Reference................................................................................................................................................ 313
27.0 Charge Time Measurement Unit (CTMU) ................................................................................................................................ 315
29.0 Special Features ...................................................................................................................................................................... 327
30.0 Development Support............................................................................................................................................................... 343
31.0 Instruction Set Summary.......................................................................................................................................................... 345
Index ................................................................................................................................................................................................. 413
The Microchip Website ...................................................................................................................................................................... 419
Customer Change Notification Service .............................................................................................................................................. 419
Customer Support .............................................................................................................................................................................. 419
Product Identification System ............................................................................................................................................................ 421
2
C) ..................................................................................................................................................... 219
It is our intention to provide our valued customers with the best documentation possible to ensure successful use of your Microchip
products. To this end, we will continue to improve our publications to better suit your needs. Our publications will be refined and
enhanced as new volumes and updates are introduced.
If you have any questions or comments regarding this publication, please contact the Marketing Communications Department via
E-mail at docerrors@microchip.com. We welcome your feedback.
Most Current Data Sheet
To obtain the most up-to-date version of this data sheet, please register at our Worldwide Website at:
http://www.microchip.com
You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page.
The last character of the literature number is the version number, (e.g., DS30000000A is version A of document DS30000000).
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current
devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision
of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Your local Microchip sales office (see last page)
When contacting a sales office, please specify which device, revision of silicon and data sheet (include literature number) you are
using.
Customer Notification System
Register on our website at www.microchip.com to receive the most current information on all of our products.
DS30010118E-page 12 2016-2020 Microchip Technology Inc.
Page 13
PIC24FJ256GA705 FAMILY
Referenced Sources
This device data sheet is based on the following
individual chapters of the “dsPIC33/PIC24 FamilyReference Manual”. These documents should be
considered as the general reference for the operation
of a particular module or device feature.
Note 1: To access the documents listed below,
browse to the documentation section of the
PIC24FJ256GA705 product page of the
Microchip website (www.microchip.com) or
select a family reference manual section
from the following list.
In addition to parameters, features and
other documentation, the resulting page
provides links to the related family
reference manual sections.
DS30010118E-page 14 2016-2020 Microchip Technology Inc.
Page 15
PIC24FJ256GA705 FAMILY
1.0DEVICE OVERVIEW
This document contains device-specific information for
the following devices:
• PIC24FJ64GA705• PIC24FJ256GA704
• PIC24FJ128GA705• PIC24FJ64GA702
• PIC24FJ256GA705• PIC24FJ128GA702
• PIC24FJ64GA704• PIC24FJ256GA702
• PIC24FJ128GA704
The PIC24FJ256GA705 family introduces large Flash
and SRAM memory in smaller package sizes. This is a
16-bit microcontroller family with a broad peripheral
feature set and enhanced computational performance.
This family also offers a new migration option for those
high-performance applications which may be outgrowing their 8-bit platforms, but do not require the numerical
processing power of a Digital Signal Processor (DSP).
Table 1-3 lists the functions of the various pins shown
in the pinout diagrams.
1.1Core Features
1.1.116-BIT ARCHITECTURE
Central to all PIC24F devices is the 16-bit modified
Harvard architecture, first introduced with Microchip’s
dsPIC® Digital Signal Controllers (DSCs). The PIC24F
CPU core offers a wide range of enhancements,
such as:
• 16-bit data and 24-bit address paths with the
ability to move information between data and
memory spaces
• Linear addressing of up to 12 Mbytes (program
space) and 32 Kbytes (data)
• A 16-element Working register array with built-in
software stack support
• A 17 x 17 hardware multiplier with support for
integer math
• Hardware support for 32 by 16-bit division
• An instruction set that supports multiple
addressing modes and is optimized for high-level
languages, such as ‘C’
• Operational performance up to 16 MIPS
1.1.2POWER-SAVING TECHNOLOGY
The PIC24FJ256GA705 family of devices includes
Retention Sleep, a low-power mode with essential
circuits being powered from a separate low-voltage
regulator.
This new low-power mode also supports the continuous
operation of the low-power, on-chip Real-Time Clock/
Calendar (RTCC), making it possible for an application
to keep time while the device is otherwise asleep.
Aside from this new feature, PIC24FJ256GA705 family
devices also include all of the legacy power-saving
features of previous PIC24F microcontrollers, such as:
• On-the-Fly Clock Switching, allowing the selection
of a lower power clock during run time
• Doze Mode Operation, for maintaining peripheral
clock speed while slowing the CPU clock
• Instruction-Based Power-Saving Modes, for quick
invocation of the Idle and Sleep modes
1.1.3OSCILLATOR OPTIONS AND
FEATURES
All of the devices in the PIC24FJ256GA705 family offer
six different oscillator options, allowing users a range of
choices in developing application hardware. These
include:
• Two Crystal modes
• External Clock (EC) mode
• A Phase-Locked Loop (PLL) frequency multiplier,
which allows processor speeds up to 32 MHz
• An internal Fast RC Oscillator (FRC), a nominal
8 MHz output with multiple frequency divider
options
• A separate internal Low-Power RC Oscillator
(LPRC), 31 kHz nominal for low-power,
timing-insensitive applications.
The internal oscillator block also provides a stable
reference source for the Fail-Safe Clock Monitor
(FSCM). This option constantly monitors the main clock
source against a reference signal provided by the internal oscillator and enables the controller to switch to the
internal oscillator, allowing for continued low-speed
operation or a safe application shutdown.
1.1.4EASY MIGRATION
Regardless of the memory size, all devices share the
same rich set of peripherals, allowing for a smooth
migration path as applications grow and evolve. The
consistent pinout scheme used throughout the entire
family also aids in migrating from one device to the next
larger device.
The PIC24F family is pin-compatible with devices in the
dsPIC33 family, and shares some compatibility with the
pinout schema for PIC18 and dsPIC30. This extends
the ability of applications to grow from the relatively
simple, to the powerful and complex, yet still selecting
a Microchip device.
PIC24FJ256GA705 family devices have a Direct Memory
Access (DMA) Controller. This module acts in concert
with the CPU, allowing data to move between data
memory and peripherals without the intervention of the
CPU, increasing data throughput and decreasing execution time overhead. Six independently programmable
channels make it possible to service multiple peripherals
at virtually the same time, with each channel peripheral
performing a different operation. Many types of data
transfer operations are supported.
1.3Other Special Features
• Peripheral Pin Select: The Peripheral Pin Select
(PPS) feature allows most digital peripherals to be
mapped over a fixed set of digital I/O pins. Users
may independently map the input and/or output of
any one of the many digital peripherals to any one
of the I/O pins.
• Configurable Logic Cell: The Configurable
Logic Cell (CLC) module allows the user to
specify combinations of signals as inputs to a
logic function and to use the logic output to control
other peripherals or I/O pins.
• Timing Modules: The PIC24FJ256GA705 family
provides three independent, general purpose,
16-bit timers (two of which can be combined
into a 32-bit timer). The devices also include
four multiple output advanced
Capture/Compare/PWM/Timer peripherals, and
three independent legacy Input Capture and
three independent legacy Output Compare modules.
• Communications: The PIC24FJ256GA705 family
incorporates a range of serial
communication peripherals to handle a range of
application requirements. There are two indepen-
2
C modules that support both Master and
dent I
Slave modes of operation. Devices also have,
through the PPS feature, two independent UARTs
with built-in IrDA
three SPI modules.
• Analog Features: All members of the
PIC24FJ256GA705 family include a 12-bit A/D
Converter (A/D) module and a triple comparator
module. The A/D module incorporates a range of
new features that allow the converter to assess
and make decisions on incoming data, reducing
CPU overhead for routine A/D conversions. The
comparator module includes three analog
comparators that are configurable for a wide
range of operations.
• CTMU Interface: In addition to their other analog
features, members of the PIC24FJ256GA705
family include the CTMU interface module. This
provides a convenient method for precision time
measurement and pulse generation, and can serve
as an interface for capacitive sensors.
®
encoders/decoders and
• Enhanced Parallel Master/Parallel Slave Port:
This module allows rapid and transparent access to
the microcontroller data bus, and enables the CPU
to directly address external data memory. The
parallel port can function in Master or Slave mode,
accommodating data widths of four or eight bits and
address widths of up to ten bits in Master modes.
• Real-Time Clock and Calendar (RTCC): This
module implements a full-featured clock and
calendar with alarm functions in hardware, freeing
up timer resources and program memory space
for use of the core application.
1.4Details on Individual Family
Members
Devices in the PIC24FJ256GA705 family are available
in 28-pin, 44-pin and 48-pin packages. The general
block diagram for all devices is shown in Figure 1-1.
The devices are differentiated from each other in
five ways:
1. Flash program memory (64 Kbytes for
PIC24FJ64GA70X devices, 128 Kbytes for
PIC24FJ128GA70X devices, 256 Kbytes for
PIC24FJ256GA70X devices).
2. Available I/O pins and ports (22 pins on two
ports for 28-pin devices, and 36 and 40 pins on
three ports for 44-pin/48-pin devices).
3.Enhanced Parallel Master Port (EPMP) is only
available on 44-pin/48-pin devices.
4.Analog input channels (10 channels for 28-pin
devices and 14 channels for 44-pin/48-pin
devices).
5.CTMU input channels (12 channels for 28-pin
devices and 13 channels for 44-pin/48-pin
devices)
All other features for devices in this family are identical.
These are summarized in Ta bl e 1 - 1 and Ta bl e 1- 2.
A list of the pin features available on the
PIC24FJ256GA705 family devices, sorted by function, is shown in Tab le 1 -3 . Note that this table shows
the pin location of individual peripheral features and not
how they are multiplexed on the same pin. This
information is provided in the pinout diagrams in the
beginning of this data sheet. Multiplexed features are
sorted by the priority given to a feature, with the highest
priority peripheral being listed first.
DS30010118E-page 16 2016-2020 Microchip Technology Inc.
Page 17
PIC24FJ256GA705 FAMILY
TABLE 1-1:DEVICE FEATURES FOR THE PIC24FJXXXGA702: 28-PIN DEVICES
Features PIC24FJ64GA702PIC24FJ128GA702PIC24FJ256GA702
DS30010118E-page 28 2016-2020 Microchip Technology Inc.
Page 29
PIC24FJ256GA705 FAMILY
PIC24FJXXX
VDD
VSS
VDD
VSS
VSS
VDD
AVDD
AVSS
VDD
VSS
C1
R1
VDD
MCLR
VCAP
R2
C7
C2
(2)
C3
(2)
C4
(2)
C5
(2)
C6
(2)
Key (all values are recommendations):
C1 through C6: 0.1 µF, 50V ceramic
C7: 10 µF, 16V or greater, ceramic
R1: 10 kΩ
R2: 100Ω to 470Ω
Note 1:See Section 2.4 “Voltage Regulator Pin
(V
CAP)” for an explanation of voltage
regulator pin connections.
2:The example shown is for a PIC24F device
with five V
DD/VSS and AVDD/AVSS pairs.
Other devices may have more or less pairs;
adjust the number of decoupling capacitors
appropriately.
(1)
2.0GUIDELINES FOR GETTING
STARTED WITH 16-BIT
MICROCONTROLLERS
2.1Basic Connection Requirements
Getting started with the PIC24FJ256GA705 family of
16-bit microcontrollers requires attention to a minimal
set of device pin connections before proceeding with
development.
The following pins must always be connected:
DD and VSS pins
•All V
(see Section 2.2 “Power Supply Pins”)
•All AV
•MCLR
•V
These pins must also be connected if they are being
used in the end application:
• PGCx/PGDx pins used for In-Circuit Serial
• OSCI and OSCO pins when an external oscillator
Additionally, the following pins may be required:
•V
The minimum mandatory connections are shown in
Figure 2-1.
DD and AVSS pins, regardless of whether or
not the analog device features are used
(see Section 2.2 “Power Supply Pins”)
pin
(see Section 2.3 “Master Clear (MCLR) Pin”)
CAP pin
(see Section 2.4 “Voltage Regulator Pin (V
Programming™ (ICSP™) and debugging purposes
(see Section 2.5 “ICSP Pins”)
source is used
(see Section 2.6 “External Oscillator Pins”)
REF+/VREF- pins used when external voltage
reference for analog modules is implemented
Note:The AVDD and AVSS pins must always be
connected, regardless of whether any of
the analog modules are being used.
starting value is 10 k. Ensure that the MCLR
pin VIH and VIL specifications are met.
2: R2 470 will limit any current flowing into
MCLR
from the external capacitor, C, in the
event of a MCLR
pin breakdown, due to
Electrostatic Discharge (ESD) or Electrical
Overstress (EOS). Ensure that the MCLR
pin
V
IH and VIL specifications are met.
C1
R2
R1
V
DD
MCLR
PIC24FXXX
JP
2.2Power Supply Pins
2.2.1DECOUPLING CAPACITORS
The use of decoupling capacitors on every pair of
power supply pins, such as V
SS, is required.
AV
Consider the following criteria when using decoupling
capacitors:
• Value and type of capacitor: A 0.1 µF (100 nF),
25V-50V capacitor is recommended. The
capacitor should be a low-ESR device with a
self-resonance frequency in the range of 200 MHz
and higher. Ceramic capacitors are
recommended.
• Placement on the printed circuit board: The
decoupling capacitors should be placed as close
to the pins as possible. It is recommended to
place the capacitors on the same side of the
board as the device. If space is constricted, the
capacitor can be placed on another layer on the
PCB using a via; however, ensure that the trace
length from the pin to the capacitor is no greater
than 0.25 inch (6 mm).
• Handling high-frequency noise: If the board is
experiencing high-frequency noise (upward of
tens of MHz), add a second ceramic-type
capacitor in parallel to the above described
decoupling capacitor. The value of the second
capacitor can be in the range of 0.01 µF to
0.001 µF. Place this second capacitor next to
each primary decoupling capacitor. In high-speed
circuit designs, consider implementing a decade
pair of capacitances as close to the power and
ground pins as possible (e.g., 0.1 µF in parallel
with 0.001 µF).
• Maximizing performance: On the board layout
from the power supply circuit, run the power and
return traces to the decoupling capacitors first,
and then to the device pins. This ensures that the
decoupling capacitors are first in the power chain.
Equally important is to keep the trace length
between the capacitor and the power pins to a
minimum, thereby reducing PCB trace
inductance.
DD, VSS, AVDD and
2.3Master Clear (MCLR) Pin
The MCLR pin provides two specific device functions:
device Reset, and device programming and debugging. If programming and debugging are not required
in the end application, a direct connection to V
may be all that is required. The addition of other
components, to help increase the application’s
resistance to spurious Resets from voltage sags, may
be beneficial. A typical configuration is shown in
Figure 2-1. Other circuit designs may be implemented
depending on the application’s requirements.
During programming and debugging, the resistance
and capacitance that can be added to the pin must
be considered. Device programmers and debuggers
drive the MCLR
levels (V
IH and VIL) and fast signal transitions must
pin. Consequently, specific voltage
not be adversely affected. Therefore, specific values
of R1 and C1 will need to be adjusted based on the
application and PCB requirements. For example, it is
recommended that the capacitor, C1, be isolated
from the MCLR
pin during programming and debugging operations by using a jumper (Figure 2-2). The
jumper is replaced for normal run-time operations.
Any components associated with the MCLR
should be placed within 0.25 inch (6 mm) of the pin.
FIGURE 2-2:EXAMPLE OF MCLR PIN
CONNECTIONS
DD
pin
2.2.2BULK CAPACITORS
On boards with power traces running longer than six
inches in length, it is suggested to use a bulk
capacitance of 10 µF or greater located near the MCU.
The value of the capacitor should be determined based
on the trace resistance that connects the power supply
source to the device, and the maximum current drawn
by the device in the application. Typical values range
from 10 µF to 47 µF. The capacitor should be ceramic
and have a voltage rating of 25V or more to reduce DC
bias effects (see Section 2.4.1 “Considerations for
Ceramic Capacitors”).
DS30010118E-page 30 2016-2020 Microchip Technology Inc.
Page 31
PIC24FJ256GA705 FAMILY
10
1
0.1
0.01
0.001
0.010.11101001000 10,000
Frequency (MHz)
ESR ()
Note: Typical data measurement at +25°C, 0V DC bias.
2.4Voltage Regulator Pin (VCAP)
FIGURE 2-3:FREQUENCY vs. ESR
Note:This section applies only to PIC24FJ
devices with an on-chip voltage regulator.
Refer to Section 29.3 “On-Chip Voltage Regulator”
for details on connecting and using the on-chip
regulator.
A low-ESR (< 5Ω) capacitor is required on the V
CAP pin
to stabilize the voltage regulator output voltage. The
CAP pin must not be connected to VDD and must use a
V
capacitor of 10 µF connected to ground. The type can be
ceramic or tantalum. Suitable examples of capacitors
are shown in Table 2-1. Capacitors with equivalent
specifications can be used.
Designers may use Figure 2-3 to evaluate the ESR
equivalence of candidate devices.
The placement of this capacitor should be close to V
CAP.
It is recommended that the trace length not exceed
0.25 inch (6 mm). Refer to Section 32.0 “Electrical
Characteristics” for additional information.
.
TABLE 2-1:SUITABLE CAPACITOR EQUIVALENTS (0805 CASE SIZE)
In recent years, large value, low-voltage, surface-mount
ceramic capacitors have become very cost effective in
sizes up to a few tens of microfarad. The low-ESR, small
physical size and other properties make ceramic
capacitors very attractive in many types of applications.
Ceramic capacitors are suitable for use with the internal voltage regulator of this microcontroller. However,
some care is needed in selecting the capacitor to
ensure that it maintains sufficient capacitance over the
intended operating range of the application.
Typical low-cost, 10 µF ceramic capacitors are available
in X5R, X7R and Y5V dielectric ratings (other types are
also available, but are less common). The initial tolerance
specifications for these types of capacitors are often
specified as ±10% to ±20% (X5R and X7R) or -20%/
+80% (Y5V). However, the effective capacitance that
these capacitors provide in an application circuit will
also vary based on additional factors, such as the
applied DC bias voltage and the temperature. The total
in-circuit tolerance is, therefore, much wider than the
initial tolerance specification.
The X5R and X7R capacitors typically exhibit satisfactory temperature stability (ex: ±15% over a wide
temperature range, but consult the manufacturer’s data
sheets for exact specifications). However, Y5V capacitors typically have extreme temperature tolerance
specifications of +22%/-82%. Due to the extreme
temperature tolerance, a 10 µF nominal rated Y5V type
capacitor may not deliver enough total capacitance to
meet minimum internal voltage regulator stability and
transient response requirements. Therefore, Y5V
capacitors are not recommended for use with the
internal regulator if the application must operate over a
wide temperature range.
In addition to temperature tolerance, the effective
capacitance of large value ceramic capacitors can vary
substantially, based on the amount of DC voltage
applied to the capacitor. This effect can be very significant, but is often overlooked or is not always
documented.
A typical DC bias voltage vs. capacitance graph for
X7R type capacitors is shown in Figure 2-4.
FIGURE 2-4:DC BIAS VOLTAGE vs.
CAPACITANCE
CHARACTERISTICS
When selecting a ceramic capacitor to be used with the
internal voltage regulator, it is suggested to select a
high-voltage rating so that the operating voltage is a
small percentage of the maximum rated capacitor voltage. For example, choose a ceramic capacitor rated at
a minimum of 16V for the 1.8V core voltage. Suggested
capacitors are shown in Table 2-1.
2.5ICSP Pins
The PGCx and PGDx pins are used for In-Circuit Serial
Programming (ICSP) and debugging purposes. It is
recommended to keep the trace length between the
ICSP connector and the ICSP pins on the device as
short as possible. If the ICSP connector is expected to
experience an ESD event, a series resistor is recommended, with the value in the range of a few tens of
ohms, not to exceed 100Ω.
Pull-up resistors, series diodes and capacitors on the
PGCx and PGDx pins are not recommended as they
will interfere with the programmer/debugger communications to the device. If such discrete components are
an application requirement, they should be removed
from the circuit during programming and debugging.
Alternatively, refer to the AC/DC characteristics and
timing requirements information in the respective
device Flash programming specification for information
on capacitive loading limits, and pin Voltage Input High
IH) and Voltage Input Low (VIL) requirements.
(V
For device emulation, ensure that the “Communication
Channel Select” pins (i.e., PGCx/PGDx) programmed
into the device match the physical connections for the
ICSP to the Microchip debugger/emulator tool.
For more information on available Microchip
development tools connection requirements, refer to
Section 30.0 “Development Support”.
DS30010118E-page 32 2016-2020 Microchip Technology Inc.
Page 33
PIC24FJ256GA705 FAMILY
GND
`
`
`
OSCI
OSCO
SOSCO
SOSC I
Copper Pour
Primary Oscillator
Crystal
Secondary
Crystal
DEVICE PINS
Primary
Oscillator
C1
C2
Sec Oscillator: C1
Sec Oscillator: C2
(tied to ground)
GND
OSCO
OSCI
Bottom Layer
Copper Pour
Oscillator
Crystal
Top Layer Copper Pour
C2
C1
DEVICE PINS
(tied to ground)
(tied to ground)
Single-Sided and In-Line Layouts:
Fine-Pitch (Dual Sided) Layouts:
Oscillator
2.6External Oscillator Pins
Many microcontrollers have options for at least two
oscillators: a high-frequency Primary Oscillator and
a low-frequency Secondary Oscillator (refer to
Section 9.0 “Oscillator Configuration” for details).
The oscillator circuit should be placed on the same
side of the board as the device. Place the oscillator
circuit close to the respective oscillator pins with no
more than 0.5 inch (12 mm) between the circuit
components and the pins. The load capacitors should
be placed next to the oscillator itself, on the same side
of the board.
Use a grounded copper pour around the oscillator
circuit to isolate it from surrounding circuits. The
grounded copper pour should be routed directly to the
MCU ground. Do not run any signal traces or power
traces inside the ground pour. Also, if using a two-sided
board, avoid any traces on the other side of the board
where the crystal is placed.
Layout suggestions are shown in Figure 2-5. In-line
packages may be handled with a single-sided layout
that completely encompasses the oscillator pins. With
fine-pitch packages, it is not always possible to completely surround the pins and components. A suitable
solution is to tie the broken guard sections to a mirrored
ground layer. In all cases, the guard trace(s) must be
returned to ground.
In planning the application’s routing and I/O assignments, ensure that adjacent port pins, and other
signals in close proximity to the oscillator, are benign
(i.e., free of high frequencies, short rise and fall times,
and other similar noise).
For additional information and design guidance on
oscillator circuits, please refer to these Microchip
Application Notes, available at the corporate website
(www.microchip.com):
2.7Configuration of Analog and
Digital Pins During ICSP
Operations
If an ICSP compliant emulator is selected as a debugger,
it automatically initializes all of the A/D input pins (ANx)
as “digital” pins. This is done by clearing all bits in the
ANSx registers. Refer to Section 11.2 “Configuring
Analog Port Pins (ANSx)” for more specific information.
The bits in these registers that correspond to the A/D
pins that initialized the emulator must not be changed
by the user application firmware; otherwise,
communication errors will result between the debugger
and the device.
If your application needs to use certain A/D pins as
analog input pins during the debug session, the user
application must modify the appropriate bits during
initialization of the A/D module, as follows:
• Set the bits corresponding to the pin(s) to be
configured as analog. Do not change any other
bits, particularly those corresponding to the
PGCx/PGDx pair, at any time.
When a Microchip debugger/emulator is used as a
programmer, the user application firmware must
correctly configure the ANSx registers. Automatic
initialization of these registers is only done during
debugger operation. Failure to correctly configure the
register(s) will result in all A/D pins being recognized as
analog input pins, resulting in the port value being read
as a logic ‘0’, which may affect user application
functionality.
2.8Unused I/Os
Unused I/O pins should be configured as outputs and
driven to a Logic Low state. Alternatively, connect a
1kΩ to 10 kΩ resistor to V
the output to logic low.
SS on unused pins and drive
DS30010118E-page 34 2016-2020 Microchip Technology Inc.
Page 35
PIC24FJ256GA705 FAMILY
3.0CPU
Note:This data sheet summarizes the features of
this group of PIC24F devices. It is not
intended to be a comprehensive
reference source. For more information on
the CPU, refer to “CPU with Extended Data Space (EDS)”
(www.microchip.com/DS39732) in the
“dsPIC33/PIC24 Family Reference
Manual”. The information in this data sheet
supersedes the information in the FRM.
The PIC24F CPU has a 16-bit (data) modified Harvard
architecture with an enhanced instruction set and a
24-bit instruction word with a variable length opcode
field. The Program Counter (PC) is 23 bits wide and
addresses up to 4M instructions of user program
memory space. A single-cycle instruction prefetch
mechanism is used to help maintain throughput and
provides predictable execution. All instructions execute
in a single cycle, with the exception of instructions that
change the program flow, the double-word move
(MOV.D) instruction and the table instructions.
Overhead-free program loop constructs are supported
using the REPEAT instructions, which are interruptible
at any point.
PIC24F devices have sixteen, 16-bit Working registers
in the programmer’s model. Each of the Working
registers can act as a Data, Address or Address Offset
register. The 16
a Software Stack Pointer (SSP) for interrupts and calls.
The lower 32 Kbytes of the Data Space (DS) can be
accessed linearly. The upper 32 Kbytes of the Data
Space are referred to as Extended Data Space (EDS),
to which the extended data RAM, EPMP memory
space or program memory can be mapped.
The Instruction Set Architecture (ISA) has been
significantly enhanced beyond that of the PIC18, but
maintains an acceptable level of backward compatibility. All PIC18 instructions and addressing modes are
supported, either directly, or through simple macros.
Many of the ISA enhancements have been driven by
compiler efficiency needs.
th
Working register (W15) operates as
The core supports Inherent (no operand), Relative,
Literal, Memory Direct Addressing modes along with
three groups of addressing modes. All modes support
Register Direct and various Register Indirect modes.
Each group offers up to seven addressing modes.
Instructions are associated with predefined addressing
modes depending upon their functional requirements.
For most instructions, the core is capable of executing
a data (or program data) memory read, a Working register (data) read, a data memory write and a program
(instruction) memory read per instruction cycle. As a
result, three parameter instructions can be supported,
allowing trinary operations (for example, A + B = C) to
be executed in a single cycle.
A high-speed, 17-bit x 17-bit multiplier has been included
to significantly enhance the core arithmetic capability and
throughput. The multiplier supports Signed, Unsigned
and Mixed mode, 16-bit x 16-bit or 8-bit x 8-bit, integer
multiplication. All multiply instructions execute in a single
cycle.
The 16-bit ALU has been enhanced with integer divide
assist hardware that supports an iterative non-restoring
divide algorithm. It operates in conjunction with the
REPEAT instruction looping mechanism and a selection
of iterative divide instructions to support 32-bit (or 16-bit),
divided by 16-bit, integer signed and unsigned division.
All divide operations require 19 cycles to complete but
are interruptible at any cycle boundary.
The PIC24F has a vectored exception scheme with up
to eight sources of non-maskable traps and up to
118 interrupt sources. Each interrupt source can be
assigned to one of seven priority levels.
A block diagram of the CPU is shown in Figure 3-1.
3.1Programmer’s Model
The programmer’s model for the PIC24F is shown in
Figure 3-2. All registers in the programmer’s model are
memory-mapped and can be manipulated directly by
instructions.
A description of each register is provided in Tab le 3 -1 .
All registers associated with the programmer’s model
are memory-mapped.
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
bit 15-9Unimplemented: Read as ‘0’
bit 8DC: ALU Half Carry/Borrow bit
th
1 = A carry out from the 4
low-order bit (for byte-sized data) or 8th low-order bit (for word-sized data)
of the result occurred
0 = No carry out from the 4th or 8th low-order bit of the result has occurred
bit 7-5IPL[2:0]: CPU Interrupt Priority Level Status bits
(1,2)
111 = CPU Interrupt Priority Level is 7 (15); user interrupts are disabled
110 = CPU Interrupt Priority Level is 6 (14)
101 = CPU Interrupt Priority Level is 5 (13)
100 = CPU Interrupt Priority Level is 4 (12)
011 = CPU Interrupt Priority Level is 3 (11)
010 = CPU Interrupt Priority Level is 2 (10)
001 = CPU Interrupt Priority Level is 1 (9)
000 = CPU Interrupt Priority Level is 0 (8)
bit 4RA: REPEAT Loop Active bit
1 = REPEAT loop is in progress
0 = REPEAT loop is not in progress
bit 3N: ALU Negative bit
1 = Result was negative
0 = Result was not negative (zero or positive)
bit 2OV: ALU Overflow bit
1 = Overflow occurred for signed (two’s complement) arithmetic in this arithmetic operation
0 = No overflow has occurred
bit 1Z: ALU Zero bit
1 = An operation, which affects the Z bit, has set it at some time in the past
0 = The most recent operation, which affects the Z bit, has cleared it (i.e., a non-zero result)
bit 0
C: ALU Carry/Borrow
bit
1 = A carry out from the Most Significant bit (MSb) of the result occurred
0 = No carry out from the Most Significant bit of the result occurred
Note 1: The IPLx Status bits are read-only when NSTDIS (INTCON1[15]) = 1.
2: The IPLx Status bits are concatenated with the IPL3 Status bit (CORCON[3]) to form the CPU Interrupt
Priority Level (IPL). The value in parentheses indicates the IPL when IPL3 = 1.
DS30010118E-page 38 2016-2020 Microchip Technology Inc.
Page 39
PIC24FJ256GA705 FAMILY
REGISTER 3-2:CORCON: CPU CORE CONTROL REGISTER
U-0U-0U-0U-0U-0U-0U-0U-0
————————
bit 15bit 8
U-0U-0U-0U-0R/C-0R/W-1U-0U-0
————IPL3
bit 7bit 0
Legend:C = Clearable bit
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
bit 15-4Unimplemented: Read as ‘0’
bit 3IPL3: CPU Interrupt Priority Level Status bit
1 = CPU Interrupt Priority Level is greater than 7
0 = CPU Interrupt Priority Level is 7 or less
bit 2PSV: Program Space Visibility (PSV) in Data Space Enable
1 = Program space is visible in Data Space
0 = Program space is not visible in Data Space
bit 1-0Unimplemented: Read as ‘0’
(1)
(1)
(2)
PSV
(2)
——
Note 1: The IPL3 bit is concatenated with the IPL[2:0] bits (SR[7:5]) to form the CPU Interrupt Priority Level; see
Register 3-1 for bit description.
2: If PSV = 0, any reads from data memory at 0x8000 and above will cause an address trap error instead of
reading from the PSV section of program memory. This bit is not individually addressable.
The PIC24F ALU is 16 bits wide and is capable of addition, subtraction, bit shifts and logic operations. Unless
otherwise mentioned, arithmetic operations are two’s
complement in nature. Depending on the operation, the
ALU may affect the values of the Carry (C), Zero (Z),
Negative (N), Overflow (OV) and Digit Carry (DC)
Status bits in the SR register. The C and DC Status bits
operate as Borrow
for subtraction operations.
The ALU can perform 8-bit or 16-bit operations,
depending on the mode of the instruction that is used.
Data for the ALU operation can come from the W
register array, or data memory, depending on the
addressing mode of the instruction. Likewise, output
data from the ALU can be written to the W register array
or a data memory location.
The PIC24F CPU incorporates hardware support for
both multiplication and division. This includes a
dedicated hardware multiplier and support hardware
for 16-bit divisor division.
3.3.1MULTIPLIER
The ALU contains a high-speed, 17-bit x 17-bit
multiplier. It supports unsigned, signed or mixed sign
operation in several multiplication modes:
• 16-bit x 16-bit signed
• 16-bit x 16-bit unsigned
• 16-bit signed x 5-bit (literal) unsigned
• 16-bit unsigned x 16-bit unsigned
• 16-bit unsigned x 5-bit (literal) unsigned
• 16-bit unsigned x 16-bit signed
• 8-bit unsigned x 8-bit unsigned
and Digit Borrow bits, respectively,
3.3.2DIVIDER
The divide block supports 32-bit/16-bit and 16-bit/16-bit
signed and unsigned integer divide operations with the
following data sizes:
1. 32-bit signed/16-bit signed divide
2. 32-bit unsigned/16-bit unsigned divide
3. 16-bit signed/16-bit signed divide
4. 16-bit unsigned/16-bit unsigned divide
The quotient for all divide instructions ends up in W0
and the remainder in W1. The 16-bit signed and
unsigned DIV instructions can specify any W register
for both the 16-bit divisor (Wn), and any W register
(aligned) pair (W(m + 1):Wm) for the 32-bit dividend.
The divide algorithm takes one cycle per bit of divisor,
so both 32-bit/16-bit and 16-bit/16-bit instructions take
the same number of cycles to execute.
3.3.3MULTIBIT SHIFT SUPPORT
The PIC24F ALU supports both single bit and singlecycle, multibit arithmetic and logic shifts. Multibit shifts
are implemented using a shifter block, capable of
performing up to a 15-bit arithmetic right shift, or up to
a 15-bit left shift, in a single cycle. All multibit shift
instructions only support Register Direct Addressing for
both the operand source and result destination.
A full summary of instructions that use the shift
operation is provided in Table 3-2.
TABLE 3-2:INSTRUCTIONS THAT USE THE SINGLE BIT AND MULTIBIT SHIFT OPERATION
InstructionDescription
ASRArithmetic Shift Right Source register by one or more bits.
SLShift Left Source register by one or more bits.
LSRLogical Shift Right Source register by one or more bits.
DS30010118E-page 40 2016-2020 Microchip Technology Inc.
Page 41
PIC24FJ256GA705 FAMILY
4.0MEMORY ORGANIZATION
Note:This data sheet summarizes the features
of this group of PIC24F devices. It is not
intended to be a comprehensive reference source. For more information, refer
to “PIC24F Flash Program Memory”
(www.microchip.com/DS30009715) in
the “dsPIC33/PIC24 Family Reference Manual”. The information in this data sheet
supersedes the information in the FRM.
As Harvard architecture devices, PIC24F microcontrollers feature separate program and data memory
spaces and buses. This architecture also allows direct
access of program memory from the Data Space during
code execution.
4.1Program Memory Space
The program address memory space of the
PIC24FJ256GA705 family devices is 4M instructions.
The space is addressable by a 24-bit value derived
from either the 23-bit Program Counter (PC) during program execution, or from table operation or Data Space
remapping, as described in Section 4.3 “Interfacing
Program and Data Memory Spaces”.
User access to the program memory space is restricted
to the lower half of the address range (000000h to
7FFFFFh). The exception is the use of TBLRD/TBLWT
operations, which use TBLPAG[7] to permit access to
the Configuration bits and customer OTP sections of
the configuration memory space.
The memory map for the PIC24FJ256GA705 family of
devices is shown in Figure 4-1.
Note 1: Exact boundary addresses are determined by the size of the implemented program memory (Table 4-1).
FIGURE 4-1:PROGRAM SPACE MEMORY MAP FOR PIC24FJ256GA705 DEVICES
TABLE 4-1:PROGRAM MEMORY SIZES AND BOUNDARIES
Program Memory
Device
Upper Boundary
Write Blocks
(2)
(1)
Erase Blocks
(Instruction Words)
PIC24FJ256GA70X02AFFEh (88,064 x 24)68886
PIC24FJ128GA70X015FFEh (45,056 x 24)35244
PIC24FJ64GA70X00AFFEh (22,528 x 24)17622
Note 1: One Write Block = 128 Instruction Words; One Erase Block (Page) = 1024 Instruction Words.
2: To maintain integer page sizes, the memory sizes are not exactly half of each other.
(1)
DS30010118E-page 42 2016-2020 Microchip Technology Inc.
Page 43
PIC24FJ256GA705 FAMILY
4.1.1PROGRAM MEMORY
ORGANIZATION
The program memory space is organized in wordaddressable blocks. Although it is treated as 24 bits
wide, it is more appropriate to think of each address of
the program memory as a lower and upper word, with
the upper byte of the upper word being unimplemented.
The lower word always has an even address, while the
upper word has an odd address (Figure 4-2).
Program memory addresses are always word-aligned
on the lower word and addresses are incremented or
decremented by two during code execution. This
arrangement also provides compatibility with data
memory space addressing and makes it possible to
access data in the program memory space.
4.1.2HARD MEMORY VECTORS
All PIC24F devices reserve the addresses between
000000h and 000200h for hard-coded program execution vectors. A hardware Reset vector is provided to
redirect code execution from the default value of the PC
on a device Reset to the actual start of code. A GOTO
instruction is programmed by the user at 000000h, with
the actual address for the start of code at 000002h.
The PIC24FJ256GA705 family devices can have up to
two Interrupt Vector Tables (IVTs). The first is located
from addresses, 000004h to 0000FFh. The Alternate
Interrupt Vector Table (AIVT) can be enabled by the
AIVTDIS Configuration bit if the Boot Segment (BS) is
present and at least two pages in size. If the user has
configured a Boot Segment, the AIVT will be located at
the address, (BSLIM[12:0]
tables allow each of the many device interrupt sources
to be handled by separate Interrupt Service Routines
(ISRs).
A more detailed discussion of the Interrupt Vector
Tables is provided in Section 8.1 “Interrupt Vector
Tabl e”.
– 1) x 0x800. These vector
4.1.3CONFIGURATION BITS OVERVIEW
The Configuration bits are stored in the last page location of implemented program memory. These bits can be
set or cleared to select various device configurations.
There are two types of Configuration bits: system operation bits and code-protect bits. The system operation
bits determine the power-on settings for system-level
components, such as the oscillator and the Watchdog
Timer. The code-protect bits prevent program memory
from being read and written.
Table 4-2 lists all of the Configuration registers as well
as their Configuration register locations. Refer to
Section 29.0 “Special Features” for the full
Configuration register description for each specific
device.
The device implements intermediate security features
defined by the FSEC register. The Boot Segment (BS)
is the higher privileged segment and the General Segment (GS) is the lower privileged segment. The total
user code memory can be split into BS or GS. The size
of the segments is determined by the BSLIM[12:0] bits.
The relative location of the segments within user space
does not change, such that BS (if present) occupies the
memory area just after the Interrupt Vector Table (IVT)
and the GS occupies the space just after the BS (or if
the Alternate IVT is enabled, just after it).
The Configuration Segment (CS) is a small segment
(less than a page, typically just one row) within user
Flash address space. It contains all user configuration
data that are loaded by the NVM Controller during the
Reset sequence.
4.1.5CUSTOMER OTP MEMORY
PIC24FJ256GA705 family devices provide 256 bytes of
One-Time-Programmable (OTP) memory, located at
addresses, 801700h through 8017FEh. This memory
can be used for persistent storage of application-specific
information that will not be erased by reprogramming the
device. This includes many types of information, such as
(but not limited to):
• Application Checksums
• Code Revision Information
• Product Information
• Serial Numbers
• System Manufacturing Dates
• Manufacturing Lot Numbers
Customer OTP memory may be programmed in any
mode, including user RTSP mode, but it cannot be
erased. Data are not cleared by a chip erase.
Note:Do not write the OTP memory more than
one time. Writing to the OTP memory
more than once may result in a permanent
ECC Double-Bit Error (ECCDBE) trap.
DS30010118E-page 44 2016-2020 Microchip Technology Inc.
Page 45
PIC24FJ256GA705 FAMILY
Note: Memory areas are not shown to scale.
0000h
07FEh
FFFEh
LSB
Address
LSBMSB
MSB
Address
0001h
07FFh
1FFFh
FFFFh
8001h
8000h
7FFFh
0801h
0800h
2001h
Near
1FFEh
SFR
2000h
7FFEh
EDS Window
Space
Data Space
Upper 32 Kbytes
Data Space
Lower 32 Kbytes
Data Space
16 Kbytes Data RAM
SFR Space
47FFh
4801h
47FEh
4800h
Unimplemented
4.2Data Memory Space
The 16-bit wide data addresses in the data memory
space point to bytes within the Data Space (DS). This
Note:This data sheet summarizes the features of
this group of PIC24F devices. It is not
intended to be a comprehensive
reference source. For more information,
refer to “Data Memory with Extended Data Space (EDS)”
(www.microchip.com/DS39733) in the
“dsPIC33/PIC24 Family Reference
Manual”. The information in this data sheet
supersedes the information in the FRM.
The PIC24F core has a 16-bit wide data memory space,
addressable as a single linear range. The Data Space is
accessed using two Address Generation Units (AGUs),
one each for read and write operations. The Data Space
memory map is shown in Figure 4-2.
gives a DS address range of 16 Kbytes or 8K words.
The lower half (0000h to 7FFFh) is used for
implemented (on-chip) memory addresses.
The upper half of data memory address space (8000h to
FFFFh) is used as a window into the Extended Data
Space (EDS). This allows the microcontroller to directly
access a greater range of data beyond the standard
16-bit address range. EDS is discussed in detail in
Section 4.2.5 “Extended Data Space (EDS)”.
4.2.1DATA SPACE WIDTH
The data memory space is organized in byteaddressable, 16-bit wide blocks. Data are aligned in
data memory and registers as 16-bit words, but all Data
Space EAs resolve to bytes. The Least Significant
Bytes (LSBs) of each word have even addresses, while
the Most Significant Bytes (MSBs) have odd
addresses.
FIGURE 4-2:DATA SPACE MEMORY MAP FOR PIC24FJ256GA705 DEVICES
To maintain backward compatibility with PIC
improve Data Space memory usage efficiency, the
PIC24F instruction set supports both word and byte
operations. As a consequence of byte accessibility, all
EA calculations are internally scaled to step through
word-aligned memory. For example, the core recognizes
that Post-Modified Register Indirect Addressing mode,
[Ws++], will result in a value of Ws + 1 for byte
operations and Ws + 2 for word operations.
Data byte reads will read the complete word, which
contains the byte, using the LSB of any EA to determine which byte to select. The selected byte is placed
onto the LSB of the data path. That is, data memory
and registers are organized as two parallel, byte-wide
entities with shared (word) address decode, but
separate write lines. Data byte writes only write to the
corresponding side of the array or register which
matches the byte address.
All word accesses must be aligned to an even address.
Misaligned word data fetches are not supported, so
care must be taken when mixing byte and word
operations or translating from 8-bit MCU code. If a
misaligned read or write is attempted, an address error
trap will be generated. If the error occurred on a read,
the instruction underway is completed; if it occurred on
a write, the instruction will be executed but the write will
not occur. In either case, a trap is then executed, allowing the system and/or user to examine the machine
state prior to execution of the address Fault.
All byte loads into any W register are loaded into the
LSB. The Most Significant Byte (MSB) is not modified.
®
MCUs and
A Sign-Extend (SE) instruction is provided to allow users
to translate 8-bit signed data to 16-bit signed values.
Alternatively, for 16-bit unsigned data, users can clear
the MSB of any W register by executing a Zero-Extend
(ZE) instruction on the appropriate address.
Although most instructions are capable of operating on
word or byte data sizes, it should be noted that some
instructions operate only on words.
4.2.3NEAR DATA SPACE
The 8-Kbyte area between 0000h and 1FFFh is
referred to as the Near Data Space. Locations in this
space are directly addressable via a 13-bit absolute
address field within all memory direct instructions. The
remainder of the Data Space is addressable indirectly.
Additionally, the whole Data Space is addressable
using MOV instructions, which support Memory Direct
Addressing with a 16-bit address field.
4.2.4SPECIAL FUNCTION REGISTER
(SFR) SPACE
The first 2 Kbytes of the Near Data Space, from 0000h
to 07FFh, are primarily occupied with Special Function
Registers (SFRs). These are used by the PIC24F core
and peripheral modules for controlling the operation of
the device.
SFRs are distributed among the modules that they control and are generally grouped together by module.
Much of the SFR space contains unused addresses;
these are read as ‘0’. A diagram of the SFR space,
showing where the SFRs are actually implemented, is
shown in Tab le 4 -3 . Each implemented area indicates
a 32-byte region where at least one address is
implemented as an SFR. A complete list of implemented SFRs, including their addresses, is shown in
Note 1: The range of addressable memory available is dependent on the device pin count and EPMP implementation.
External
Memory
Access
Using
EPMP
(1)
Internal
Data
Memory
Space
(Lower
Word)
(Lower
Word)
(Upper
Word)
(Upper
Word)
Window
DSxPAG
= 001h
008000h
008800h
External
Memory
Access
Using
EPMP
(1)
047FEh
04800h
Unimplemented
4.2.5EXTENDED DATA SPACE (EDS)
The Extended Data Space (EDS) allows PIC24F
devices to address a much larger range of data than
would otherwise be possible with a 16-bit address
range. EDS includes any additional internal data
memory not directly accessible by the lower 32-Kbyte
data address space and any external memory through
EPMP.
In addition, EDS also allows read access to the
program memory space. This feature is called Program
Space Visibility (PSV) and is discussed in detail in
Section 4.3.3 “Reading Data from Program Memory
Using EDS”.
Figure 4-3 displays the entire EDS space. The EDS is
organized as pages, called EDS pages, with one page
equal to the size of the EDS window (32 Kbytes). A particular EDS page is selected through the Data Space
Read Page register (DSRPAG) or the Data Space Write
Page register (DSWPAG). For PSV, only the DSRPAG
register is used. The combination of the DSRPAG
register value and the 16-bit wide data address forms a
24-bit Effective Address (EA).
FIGURE 4-3:EXTENDED DATA SPACE
The data addressing range of the PIC24FJ256GA705
family devices depends on the version of the Enhanced
Parallel Master Port implemented on a particular device;
this is, in turn, a function of device pin count. Table 4-12
lists the total memory accessible by each of the devices
in this family. For more details on accessing external
memory using EPMP, refer to “Enhanced ParallelMaster Port (EPMP)” (www.microchip.com/DS39730)
in the“dsPIC33/PIC24 Family Reference Manual”.
.
TABLE 4-12:TOTAL ACCESSIBLE DATA
MEMORY
Family
Internal
RAM
PIC24FJXXXGA70X16K1K
Note:Accessing Page 0 in the EDS window will
generate an address error trap as Page 0
is the base data memory (data locations,
0800h to 7FFFh, in the lower Data Space).
External RAM
Access Using
EPMP
DS30010118E-page 54 2016-2020 Microchip Technology Inc.
Page 55
PIC24FJ256GA705 FAMILY
DSRPAG Reg
Select
Wn
98
15 Bits9 Bits
24-Bit EA
Wn[0] is Byte Select
0 = Extended SRAM and EPMP
1
0
; Set the EDS page from where the data to be read
mov#0x0002, w0
movw0, DSRPAG ;page 2 is selected for read
mov#0x0800, w1 ;select the location (0x800) to be read
bsetw1, #15;set the MSB of the base address, enable EDS mode
;Read a byte from the selected location
mov.b [w1++], w2;read Low byte
mov.b [w1++], w3;read High byte
;Read a word from the selected location
mov [w1], w2;
;Read Double - word from the selected location
mov.d [w1], w2;two word read, stored in w2 and w3
4.2.5.1Data Read from EDS
In order to read the data from the EDS space, first, an
Address Pointer is set up by loading the required EDS
page number into the DSRPAG register and assigning
the offset address to one of the W registers. Once the
above assignment is done, the EDS window is enabled
by setting bit 15 of the Working register which is
assigned with the offset address; then, the contents of
the pointed EDS location can be read.
Figure 4-4 illustrates how the EDS space address is
Example 4-1 shows how to read a byte, word and
double word from EDS.
Note:All read operations from EDS space have
an overhead of one instruction cycle.
Therefore, a minimum of two instruction
cycles are required to complete an EDS
read. EDS reads under the REPEAT
instruction; the first two accesses take
three cycles and the subsequent
accesses take one cycle.
generated for read operations.
When the Most Significant bit (MSb) of EA is ‘1’ and
DSRPAG[9] = 0, the lower nine bits of DSRPAG are
concatenated to the lower 15 bits of EA to form a 24-bit
EDS space address for read operations.
FIGURE 4-4:EDS ADDRESS GENERATION FOR READ OPERATIONS
mov#0x0002, w0
movw0, DSWPAG ;page 2 is selected for write
mov#0x0800, w1;select the location (0x800) to be written
bsetw1, #15 ;set the MSB of the base address, enable EDS mode
In order to write data to EDS, such as in EDS reads, an
Address Pointer is set up by loading the required EDS
page number into the DSWPAG register, and assigning
the offset address to one of the W registers. Once the
above assignment is done, then the EDS window is
enabled by setting bit 15 of the Working register,
assigned with the offset address, and the accessed
location can be written.
Figure 4-5 illustrates how the EDS address is generated
for write operations.
When the MSbs of EA are ‘1’, the lower nine bits of
DSWPAG are concatenated to the lower 15 bits of EA
to form a 24-bit EDS address for write operations.
Example 4-2 shows how to write a byte, word and
double word to EDS.
0x8000. While developing code in assembly, care must
be taken to update the Data Space Page registers when
an Address Pointer crosses the page boundary. The ‘C’
compiler keeps track of the addressing, and increments
or decrements the Page registers accordingly, while
accessing contiguous data memory locations.
Note 1: All write operations to EDS are executed
in a single cycle.
2: Use of Read-Modify-Write operation on
any EDS location under a REPEAT
instruction is not supported. For example:
BCLR, BSW, BTG, RLC f, RLNC f, RRC f,
RRNC f, ADD f, SUB f, SUBR f, AND f,
IOR f, XOR f, ASR f, ASL f.
3: Use the DSRPAG register while
performing Read-Modify-Write operations.
The Data Space Page registers (DSRPAG/DSWPAG)
do not update automatically while crossing a page
boundary, when the rollover happens, from 0xFFFF to
FIGURE 4-5:EDS ADDRESS GENERATION FOR WRITE OPERATIONS
EXAMPLE 4-2:EDS WRITE CODE IN ASSEMBLY
DS30010118E-page 56 2016-2020 Microchip Technology Inc.
Page 57
PIC24FJ256GA705 FAMILY
[Free Word]
PC[15:0]
000000000
015
W15 (
beforeCALL)
W15 (afterCALL)
Stack Grows Towards
Higher Address
0000h
PC[22:16]
POP : [--W15]
PUSH : [W15++]
TABLE 4-13:EDS MEMORY ADDRESS WITH DIFFERENT PAGES AND ADDRESSES
DSRPAG
(Data Space Read
Register)
(1)
x
001h001h
002h002h010000h to
003h
•
•
•
•
•
1FFh
000h000hInvalid AddressAddress Error Trap
Note 1: If the source/destination address is below 8000h, the DSRPAG and DSWPAG registers are not considered.
2: This Data Space can also be accessed by Direct Addressing.
3: When the source/destination address is above 8000h and DSRPAG/DSWPAG are ‘0’, an address error
trap will occur.
DSWPAG
(Data Space Write
Register)
(1)
x
003h
•
•
•
•
•
1FFh
Source/Destination
Address while
Indirect Addressing
24-Bit EA
Pointing to EDS
0000h to 1FFFh000000h to
001FFFh
2000h to 7FFFh002000h to
007FFFh
008000h to
00FFFEh
017FFEh
018000h to
0187FEh
8000h to FFFFh
FF8000h to
FFFFFEh
Comment
Near Data Space
(2)
EPMP Memory Space
•
•
•
•
(3)
4.2.6SOFTWARE STACK
Apart from its use as a Working register, the W15
register in PIC24F devices is also used as a Software
Stack Pointer (SSP). The pointer always points to the
first available free word and grows from lower to higher
addresses. It pre-decrements for stack pops and post-
Similarly, a Stack Pointer underflow (stack error) trap is
generated when the Stack Pointer address is found to
be less than 0800h. This prevents the stack from
interfering with the SFR space.
A write to the SPLIM register should not be immediately
followed by an indirect read operation using W15.
increments for stack pushes, as shown in Figure 4-6.
Note that for a PC push during any CALL instruction,
FIGURE 4-6:CALL STACK FRAME
the MSB of the PC is zero-extended before the push,
ensuring that the MSB is always clear.
Note:A PC push during exception processing
will concatenate the SRL register to the
MSB of the PC prior to the push.
The Stack Pointer Limit Value register (SPLIM), associated with the Stack Pointer, sets an upper address
boundary for the stack. SPLIM is uninitialized at Reset.
As is the case for the Stack Pointer, SPLIM[0] is forced
to ‘0’ as all stack operations must be word-aligned.
Whenever an EA is generated using W15 as a source
or destination pointer, the resulting address is compared with the value in SPLIM. If the contents of the
Stack Pointer (W15) and the SPLIM register are equal,
and a push operation is performed, a stack error trap
will not occur. The stack error trap will occur on a
subsequent push operation. Thus, for example, if it is
desirable to cause a stack error trap when the stack
grows beyond address 2000h in RAM, initialize the
SPLIM with the value, 1FFEh.
The PIC24F architecture uses a 24-bit wide program
space and 16-bit wide Data Space. The architecture is
also a modified Harvard scheme, meaning that data
can also be present in the program space. To use these
data successfully, they must be accessed in a way that
preserves the alignment of information in both spaces.
Aside from normal execution, the PIC24F architecture
provides two methods by which program space can be
accessed during operation:
• Using table instructions to access individual bytes
or words anywhere in the program space
• Remapping a portion of the program space into
the Data Space (Program Space Visibility)
Table instructions allow an application to read or write
to small areas of the program memory. This makes the
method ideal for accessing data tables that need to be
updated from time to time. It also allows access to all
bytes of the program word. The remapping method
allows an application to access a large block of data on
a read-only basis, which is ideal for look-ups from a
large table of static data. It can only access the least
significant word of the program word.
4.3.1ADDRESSING PROGRAM SPACE
Since the address ranges for the data and program
spaces are 16 and 24 bits, respectively, a method is
needed to create a 23-bit or 24-bit program address
from 16-bit data registers. The solution depends on the
interface method to be used.
For table operations, the 8-bit Table Memory Page
Address register (TBLPAG) is used to define a 32K word
region within the program space. This is concatenated
with a 16-bit EA to arrive at a full 24-bit program space
address. In this format, the MSBs of TBLPAG are
used to determine if the operation occurs in the user
memory (TBLPAG[7] = 0) or the configuration memory
(TBLPAG[7] = 1).
For remapping operations, the 10-bit Extended Data
Space Read register (DSRPAG) is used to define a
16K word page in the program space. When the Most
Significant bit (MSb) of the EA is ‘1’, and the MSb (bit 9)
of DSRPAG is ‘1’, the lower eight bits of DSRPAG are
concatenated with the lower 15 bits of the EA to form a
23-bit program space address. The DSRPAG[8] bit
decides whether the lower word (when the bit is ‘0’) or
the higher word (when the bit is ‘1’) of program memory
is mapped. Unlike table operations, this strictly limits
remapping operations to the user memory area.
Table 4-14 and Figure 4-7 show how the program EA is
created for table operations and remapping accesses
from the data EA. Here, P[23:0] refers to a program
space word, whereas D[15:0] refers to a Data Space
word.
TABLE 4-14:PROGRAM SPACE ADDRESS CONSTRUCTION
Access Type
Instruction Access
(Code Execution)
TBLRD/TBLWT
(Byte/Word Read/Write)
Program Space Visibility
(Block Remap/Read)
Note 1: Data EA[15] is always ‘1’ in this case, but is not used in calculating the program space address. Bit 15 of
the address is DSRPAG[0].
2: DSRPAG[9] is always ‘1’ in this case. DSRPAG[8] decides whether the lower word or higher word of
program memory is read. When DSRPAG[8] is ‘0’, the lower word is read, and when it is ‘1’, the higher
word is read.
Access
Space
User0PC[22:1]0
UserTBLPAG[7:0]Data EA[15:0]
Configuration TBLPAG[7:0]Data EA[15:0]
User0DSRPAG[7:0]
[23][22:16][15][14:1][0]
0xxx xxxxxxxx xxxx xxxx xxxx
1xxx xxxxxxxx xxxx xxxx xxxx
0xxxx xxxxxxx xxxx xxxx xxxx
Program Space Address
0xx xxxx xxxx xxxx xxxx xxx0
(2)
Data EA[14:0]
(1)
DS30010118E-page 58 2016-2020 Microchip Technology Inc.
Page 59
PIC24FJ256GA705 FAMILY
0Program Counter
23 Bits
1
DSRPAG[7:0]
8 Bits
EA
15 Bits
Program Counter
Select
TBLPAG
8 Bits
EA
16 Bits
Byte Select
0
0
1/0
User/Configuration
Table Operations
(2)
Program Space Visibility
(1)
Space Select
24 Bits
23 Bits
(Remapping)
1/0
1/0
Note 1: DSRPAG[8] acts as word select. DSRPAG[9] should always be ‘1’ to map program memory to data memory.
2: The instructions, TBLRDH/TBLWTH/TBLRDL/TBLWTL, decide if the higher or lower word of program memory is
accessed. TBLRDH/TBLWTH instructions access the higher word and TBLRDL/TBLWTL instructions access the
lower word. Table Read operations are permitted in the configuration memory space.
1-Bit
FIGURE 4-7:DATA ACCESS FROM PROGRAM SPACE ADDRESS GENERATION
The address for the table operation is determined by the data EA
within the page defined by the TBLPAG register.
Only read operations are shown; write operations are also valid in
the user memory area.
4.3.2DATA ACCESS FROM PROGRAM
MEMORY USING TABLE
INSTRUCTIONS
The TBLRDL and TBLWTL instructions offer a direct
method of reading or writing the lower word of any
address within the program space without going through
Data Space. The TBLRDH and TBLWTH instructions are
the only method to read or write the upper eight bits of a
program space word as data.
The PC is incremented by two for each successive
24-bit program word. This allows program memory
addresses to directly map to Data Space addresses.
Program memory can thus be regarded as two, 16-bit
word-wide address spaces, residing side by side, each
with the same address range. TBLRDL and TBLWTL
access the space which contains the least significant
data word, and TBLRDH and TBLWTH access the space
which contains the upper data byte.
Two table instructions are provided to move byte or
word-sized (16-bit) data to and from program space.
Both function as either byte or word operations.
1.TBLRDL (Table Read Low): In Word mode, it
maps the lower word of the program space
location (P[15:0]) to a data address (D[15:0]).
In Byte mode, either the upper or lower byte of
the lower program word is mapped to the lower
byte of a data address. The upper byte is
selected when byte select is ‘1’; the lower byte
is selected when it is ‘0’.
2. TBLRDH (Table Read High): In Word mode, it
maps the entire upper word of a program address
(P[23:16]) to a data address. Note that D[15:8],
the ‘phantom’ byte, will always be ‘0’.
In Byte mode, it maps the upper or lower byte of
the program word to D[7:0] of the data address,
as above. Note that the data will always be ‘0’
when the upper ‘phantom’ byte is selected (byte
select = 1).
In a similar fashion, two table instructions, TBLWTH
and TBLWTL, are used to write individual bytes or
words to a program space address. The details of
their operation are described in Section 6.0 “Flash
Program Memory”.
For all table operations, the area of program memory
space to be accessed is determined by the Table
Memory Page Address register (TBLPAG). TBLPAG
covers the entire program memory space of the
device, including user and configuration spaces. When
TBLPAG[7] = 0, the table page is located in the user
memory space. When TBLPAG[7] = 1, the page is
located in configuration space.
Note:Only Table Read operations will execute
in the configuration memory space where
Device IDs are located. Table Write
operations are not allowed.
FIGURE 4-8:ACCESS PROGRAM MEMORY WITH TABLE INSTRUCTIONS
DS30010118E-page 60 2016-2020 Microchip Technology Inc.
Page 61
PIC24FJ256GA705 FAMILY
; Set the EDS page from where the data to be read
mov#0x0202, w0
movw0, DSRPAG ;page 0x202, consisting lower words, is selected for read
mov#0x000A, w1 ;select the location (0x0A) to be read
bsetw1, #15;set the MSB of the base address, enable EDS mode
;Read a byte from the selected location
mov.b [w1++], w2;read Low byte
mov.b [w1++], w3;read High byte
;Read a word from the selected location
mov [w1], w2;
;Read Double - word from the selected location
mov.d [w1], w2;two word read, stored in w2 and w3
4.3.3READING DATA FROM PROGRAM
MEMORY USING EDS
The upper 32 Kbytes of Data Space may optionally be
mapped into any 16K word page of the program space.
This provides transparent access of stored constant
data from the Data Space without the need to use
special instructions (i.e., TBLRDL/H).
Program space access through the Data Space occurs
when the MSb of EA is ‘1’ and the DSRPAG[9] bit is
also ‘1’. The lower eight bits of DSRPAG are concatenated to the Wn[14:0] bits to form a 23-bit EA to access
program memory. The DSRPAG[8] decides which word
should be addressed; when the bit is ‘0’, the lower
word, and when ‘1’, the upper word of the program
memory is accessed.
The entire program memory is divided into 512 EDS
pages, from 200h to 3FFh, each consisting of 16K words
of data. Pages, 200h to 2FFh, correspond to the lower
words of the program memory, while 300h to 3FFh
correspond to the upper words of the program memory.
Using this EDS technique, the entire program memory
can be accessed. Previously, the access to the upper
Table 4-15 provides the corresponding 23-bit EDS
address for program memory with EDS page and
source addresses.
For operations that use PSV and are executed outside a
REPEAT loop, the MOV and MOV.D instructions will require
one instruction cycle in addition to the specified execution
time. All other instructions will require two instruction
cycles in addition to the specified execution time.
For operations that use PSV, which are executed inside
a REPEAT loop, there will be some instances that
require two instruction cycles in addition to the
specified execution time of the instruction:
• Execution in the first iteration
• Execution in the last iteration
• Execution prior to exiting the loop due to an
interrupt
• Execution upon re-entering the loop after an
interrupt is serviced
Any other iteration of the REPEAT loop will allow the
instruction accessing data, using PSV, to execute in a
single cycle.
word of the program memory was not supported.
TABLE 4-15:EDS PROGRAM ADDRESS WITH DIFFERENT PAGES AND ADDRESSES
DSRPAG
(Data Space Read Register)
Source Address while
Indirect Addressing
23-Bit EA Pointing
to EDS
Comment
200h
•
•
•
2FFh
300h
•
•
•
3FFh
8000h to FFFFh
000000h to 007FFEh
•
•
•
7F8000h to 7FFFFEh
000001h to 007FFFh
•
•
•
7F8001h to 7FFFFFh
000hInvalid AddressAddress error trap.
Note 1: When the source/destination address is above 8000h and DSRPAG/DSWPAG is ‘0’, an address error trap
will occur.
EXAMPLE 4-3:EDS READ CODE FROM PROGRAM MEMORY IN ASSEMBLY
Lower words of 4M program
instructions (8 Mbytes) for
read operations only.
Upper words of 4M program
instructions (4 Mbytes remaining;
4 Mbytes are phantom bytes) for
read operations only.
(1)
Page 62
PIC24FJ256GA705 FAMILY
23150
DSRPAG
Data SpaceProgram Space
0000h
8000h
FFFFh
202h
000000h
7FFFFEh
010000h
017FFEh
When DSRPAG[9:8] = 10 and EA[15] = 1:
EDS Window
The data in the page
designated by DSRPAG
are mapped into the
upper half of the data
memory space....
Data EA[14:0]
...while the lower
15 bits of the EA
specify an exact
address within the
EDS area. This corresponds exactly to the
same lower 15 bits of
the actual program
space address.
23150DSRPAG
Data SpaceProgram Space
0000h
8000h
FFFFh
302h
000000h
7FFFFEh
010001h
017FFFh
When DSRPAG[9:8] = 11 and EA[15] = 1:
The data in the page
designated by DSRPAG
are mapped into the
upper half of the data
memory space....
Data EA[14:0]
...while the lower
15 bits of the EA
specify an exact
address within the
EDS area. This corresponds exactly to the
same lower 15 bits of
the actual program
space address.
EDS Window
FIGURE 4-9:PROGRAM SPACE VISIBILITY OPERATION TO ACCESS LOWER WORD
FIGURE 4-10:PROGRAM SPACE VISIBILITY OPERATION TO ACCESS UPPER WORD
DS30010118E-page 62 2016-2020 Microchip Technology Inc.
Page 63
PIC24FJ256GA705 FAMILY
To I/O Ports
To DMA-Enabled
Peripherals
and Peripherals
DMACH0
DMAINT0
DMASRC0
DMADST0
DMACNT0
DMACH1
DMAINT1
DMASRC1
DMADST1
DMACNT1
DMACH4
DMAINT4
DMASRC4
DMADST4
DMACNT4
DMACH5
DMAINT5
DMASRC5
DMADST5
DMACNT5
DMACON
DMAH
DMAL
DMABUF
Channel 0Channel 1Channel 4Channel 5
Data RAM
Address Generation
Data RAM
Control
Logic
Data
Bus
CPU Execution Monitoring
5.0DIRECT MEMORY ACCESS
CONTROLLER (DMA)
Note:This data sheet summarizes the features
of the PIC24FJ256GA705 family of
devices. It is not intended to be a
comprehensive reference source. To
complement the information in this
data sheet, refer to “Direct Memory Access Controller (DMA)”
(www.microchip.com/DS30009742) in the
“dsPIC33/PIC24 Family Reference
Manual”. The information in this data sheet
supersedes the information in the FRM.
The Direct Memory Access (DMA) Controller is designed
to service high throughput data peripherals operating on
the SFR bus, allowing them to access data memory
directly and alleviating the need for CPU-intensive management. By allowing these data-intensive peripherals to
share their own data path, the main data bus is also
deloaded, resulting in additional power savings.
The DMA Controller functions both as a peripheral and a
direct extension of the CPU. It is located on the microcontroller data bus between the CPU and DMA-enabled
peripherals, with direct access to SRAM. This partitions
the SFR bus into two buses, allowing the DMA Controller
access to the DMA-capable peripherals located on the
new DMA SFR bus. The controller serves as a Master
device on the DMA SFR bus, controlling data flow from
DMA-capable peripherals.
The controller also monitors CPU instruction processing directly, allowing it to be aware of when the CPU
requires access to peripherals on the DMA bus and
automatically relinquishing control to the CPU as
needed. This increases the effective bandwidth for
handling data without DMA operations causing a
processor Stall. This makes the controller essentially
transparent to the user.
The DMA Controller has these features:
• Six Independent and Independently
Programmable Channels
• Concurrent Operation with the CPU (no DMA
caused Wait states)
• DMA Bus Arbitration
• Five Programmable Address modes
• Four Programmable Transfer modes
• Four Flexible Internal Data Transfer modes
• Byte or Word Support for Data Transfer
• 16-Bit Source and Destination Address Register
for Each Channel, Dynamically Updated and
Reloadable
• 16-Bit Transaction Count Register, Dynamically
Updated and Reloadable
• Upper and Lower Address Limit Registers
• Counter Half-Full Level Interrupt
• Software-Triggered Transfer
• Null Write mode for Symmetric Buffer Operations
A simplified block diagram of the DMA Controller is
shown in Figure 5-1.
The DMA Controller is capable of moving data between
addresses according to a number of different parameters.
Each of these parameters can be independently
configured for any transaction; in addition, any or all of
the DMA channels can independently perform a different transaction at the same time. Transactions are
classified by these parameters:
• Source and destination (SFRs and data RAM)
• Data size (byte or word)
• Trigger source
• Transfer mode (One-Shot, Repeated or
Continuous)
• Addressing modes (Fixed Address or Address
Blocks, with or without Address Increment/
Decrement)
In addition, the DMA Controller provides channel priority
arbitration for all channels.
5.1.1SOURCE AND DESTINATION
Using the DMA Controller, data may be moved between
any two addresses in the Data Space. The SFR space
(0000h to 07FFh), or the data RAM space (0800h to
FFFFh), can serve as either the source or the destination. Data can be moved between these areas in either
direction or between addresses in either area. The four
different combinations are shown in Figure 5-2.
If it is necessary to protect areas of data RAM, the DMA
Controller allows the user to set upper and lower address
boundaries for operations in the Data Space above the
SFR space. The boundaries are set by the DMAH and
DMAL Limit registers. If a DMA channel attempts an
operation outside of the address boundaries, the
transaction is terminated and an interrupt is generated.
5.1.2DATA SIZE
The DMA Controller can handle both 8-bit and 16-bit
transactions. Size is user-selectable using the SIZE bit
(DMACHn[1]). By default, each channel is configured
for word-sized transactions. When byte-sized transactions are chosen, the LSb of the source and/or
destination address determines if the data represent
the upper or lower byte of the data RAM location.
5.1.3TRIGGER SOURCE
The DMA Controller can use any one of the device’s
interrupt sources to initiate a transaction. The DMA
Trigger sources are listed in reverse order of their
natural interrupt priority and are shown in Table 5-1.
Since the source and destination addresses for any
transaction can be programmed independently of the
trigger source, the DMA Controller can use any trigger
to perform an operation on any peripheral. This also
allows DMA channels to be cascaded to perform more
complex transfer operations.
5.1.4TRANSFER MODE
The DMA Controller supports four types of data
transfers, based on the volume of data to be moved for
each trigger.
• One-Shot: A single transaction occurs for each
trigger.
• Continuous: A series of back-to-back transactions
occur for each trigger; the number of transactions
is determined by the DMACNTn transaction
counter.
• Repeated One-Shot: A single transaction is
performed repeatedly, once per trigger, until the
DMA channel is disabled.
• Repeated Continuous: A series of transactions
are performed repeatedly, one cycle per trigger,
until the DMA channel is disabled.
All transfer modes allow the option to have the source
and destination addresses, and counter value automatically reloaded after the completion of a transaction.
Repeated mode transfers do this automatically.
5.1.5ADDRESSING MODES
The DMA Controller also supports transfers between
single addresses or address ranges. The four basic
options are:
• Fixed-to-Fixed: Between two constant addresses
• Fixed-to-Block: From a constant source address
to a range of destination addresses
• Block-to-Fixed: From a range of source addresses
to a single, constant destination address
• Block-to-Block: From a range to source
addresses to a range of destination addresses
The option to select auto-increment or auto-decrement
of source and/or destination addresses is available for
Block Addressing modes.
In addition to the four basic modes, the DMA Controller
also supports Peripheral Indirect Addressing (PIA)
mode, where the source or destination address is generated jointly by the DMA Controller and a PIA-capable
peripheral. When enabled, the DMA channel provides
a base source and/or destination address, while the
peripheral provides a fixed range offset address.
For PIC24FJ256GA705 family devices, the 12-bit A/D
Converter module is the only PIA-capable peripheral.
Details for its use in PIA mode are provided in
Section 24.0 “12-Bit A/D Converter with Threshold
Detect”.
DS30010118E-page 64 2016-2020 Microchip Technology Inc.
Page 65
PIC24FJ256GA705 FAMILY
SFR Area
Data RAM
DMA RAM Area
SFR Area
Data RAM
DMA RAM Area
SFR Area
Data RAM
SFR Area
Data RAM
07FFh
0800h
DMASRCn
DMADSTn
DMA RAM Area
DMAL
DMAH
07FFh
0800h
DMASRCn
DMADSTn
DMAL
DMAH
07FFh
0800h
DMASRCn
DMADSTn
DMAL
DMAH
07FFh
0800h
DMASRCn
DMADSTn
DMAL
DMAH
DMA RAM Area
Peripheral to MemoryMemory to Peripheral
Peripheral to PeripheralMemory to Memory
Note: Relative sizes of memory areas are not shown to scale.
Each DMA channel functions independently of the
others, but also competes with the others for access to
the data and DMA buses. When access collisions
occur, the DMA Controller arbitrates between the
channels using a user-selectable priority scheme. Two
schemes are available:
• Round-Robin: When two or more channels
collide, the lower numbered channel receives
priority on the first collision. On subsequent collisions, the higher numbered channels each
receive priority based on their channel number.
• Fixed: When two or more channels collide, the
lowest numbered channel always receives
priority, regardless of past history; however, any
channel being actively processed is not available
for an immediate retrigger. If a higher priority
channel is continually requesting service, it will be
scheduled for service after the next lower priority
channel with a pending request.
5.2Typical Setup
To set up a DMA channel for a basic data transfer:
1.Enable the DMA Controller (DMAEN = 1) and
select an appropriate channel priority scheme
by setting or clearing PRSSEL.
2.Program DMAH and DMAL with the appropriate
upper and lower address boundaries for data
RAM operations.
3.Select the DMA channel to be used and disable
its operation (CHEN = 0).
4.Program the appropriate source and destination
addresses for the transaction into the channel’s
DMASRCn and DMADSTn registers. For PIA
mode addressing, use the base address value.
5.Program the DMACNTn register for the number
of triggers per transfer (One-Shot or Continuous
modes) or the number of words (bytes) to be
transferred (Repeated modes).
6.Set or clear the SIZE bit to select the data size.
7.Program the TRMODE[1:0] bits to select the
Data Transfer mode.
8.Program the SAMODE[1:0] and DAMODE[1:0]
bits to select the addressing mode.
9.Enable the DMA channel by setting CHEN.
10. Enable the trigger source interrupt.
5.3Peripheral Module Disable
Unlike other peripheral modules, the channels of the
DMA Controller cannot be individually powered down
using the Peripheral Module Disable (PMD) registers.
Instead, the channels are controlled as two groups. The
DMA0MD bit (PMD7[4]) selectively controls DMACH0
through DMACH3. The DMA1MD bit (PMD7[5]) controls
DMACH4 and DMACH5. Setting both bits effectively
disables the DMA Controller.
5.4DMA Registers
The DMA Controller uses a number of registers to control its operation. The number of registers depends on
the number of channels implemented for a particular
device.
There are always four module-level registers (one
control and three buffer/address):
• DMACON: DMA Engine Control Register
(Register 5-1)
• DMAH and DMAL: DMA High and Low Address
Limit Registers
• DMABUF: DMA Data Buffer
Each of the DMA channels implements five registers
(two control and three buffer/address):
• DMACHn: DMA Channel n Control Register
(Register 5-2)
• DMAINTn: DMA Channel n Interrupt Register
(Register 5-3)
• DMASRCn: DMA Data Source Address Pointer
for Channel n
• DMADSTn: DMA Data Destination
for Channel n
• DMACNTn: DMA Transaction Counter for
Channel n
For PIC24FJ256GA705 family devices, there are a
total of 34 registers.
Address Pointer
DS30010118E-page 66 2016-2020 Microchip Technology Inc.
Page 67
PIC24FJ256GA705 FAMILY
REGISTER 5-1:DMACON: DMA ENGINE CONTROL REGISTER
R/W-0U-0U-0U-0U-0U-0U-0U-0
DMAEN
bit 15bit 8
U-0U-0U-0U-0U-0U-0U-0R/W-0
———————PRSSEL
bit 7bit 0
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
bit 15DMAEN: DMA Module Enable bit
bit 14-1Unimplemented: Read as ‘0’
bit 0PRSSEL: Channel Priority Scheme Selection bit
———————
1 = Enables module
0 = Disables module and terminates all active DMA operation(s)
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
bit 15-13Unimplemented: Read as ‘0’
bit 12Reserved: Maintain as ‘0’
bit 11Unimplemented: Read as ‘0’
bit 10NULLW: Null Write Mode bit
1 = A dummy write is initiated to DMASRCn for every write to DMADSTn
0 = No dummy write is initiated
bit 9RELOAD: Address and Count Reload bit
(1)
1 = DMASRCn, DMADSTn and DMACNTn registers are reloaded to their previous values upon the
start of the next operation
0 = DMASRCn, DMADSTn and DMACNTn are not reloaded on the start of the next operation
bit 8CHREQ: DMA Channel Software Request bit
(3)
(2)
1 = A DMA request is initiated by software; automatically cleared upon completion of a DMA transfer
0 = No DMA request is pending
bit 7-6SAMODE[1:0]: Source Address Mode Selection bits
11 = DMASRCn is used in Peripheral Indirect Addressing and remains unchanged
10 = DMASRCn is decremented based on the SIZE bit after a transfer completion
01 = DMASRCn is incremented based on the SIZE bit after a transfer completion
00 = DMASRCn remains unchanged after a transfer completion
bit 5-4DAMODE[1:0]: Destination Address Mode Selection bits
11 = DMADSTn is used in Peripheral Indirect Addressing and remains unchanged
10 = DMADSTn is decremented based on the SIZE bit after a transfer completion
01 = DMADSTn is incremented based on the SIZE bit after a transfer completion
00 = DMADSTn remains unchanged after a transfer completion
1 = The corresponding channel is enabled
0 = The corresponding channel is disabled
Note 1: Only the original DMACNTn is required to be stored to recover the original DMASRCn and DMADSTn.
2: DMASRCn, DMADSTn and DMACNTn are always reloaded in Repeated mode transfers
(DMACHn[2] = 1), regardless of the state of the RELOAD bit.
3: The number of transfers executed while CHREQ is set depends on the configuration of TRMODE[1:0].
DS30010118E-page 68 2016-2020 Microchip Technology Inc.
Page 69
PIC24FJ256GA705 FAMILY
REGISTER 5-3:DMAINTn: DMA CHANNEL n INTERRUPT REGISTER
R-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
(1)
DBUFWF
bit 15bit 8
R/W-0R/W-0R/W-0R/W-0R/W-0U-0U-0R/W-0
HIGHIF
(1,2)
bit 7bit 0
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
CHSEL6CHSEL5CHSEL4CHSEL3CHSEL2CHSEL1CHSEL0
LOWIF
(1,2)
DONEIF
(1)
HALFIF
(1)
OVRUNIF
(1)
——HALFEN
bit 15DBUFWF: DMA Buffered Data Write Flag bit
(1)
1 = The content of the DMA buffer has not been written to the location specified in DMADSTn or
DMASRCn in Null Write mode
0 = The content of the DMA buffer has been written to the location specified in DMADSTn or DMASRCn
in Null Write mode
bit 14-8CHSEL[6:0]: DMA Channel Trigger Selection bits
See Table 5 -1 for a complete list.
bit 7HIGHIF: DMA High Address Limit Interrupt Flag bit
(1,2)
1 = The DMA channel has attempted to access an address higher than DMAH or the upper limit of the
data RAM space
0 = The DMA channel has not invoked the high address limit interrupt
bit 6LOWIF: DMA Low Address Limit Interrupt Flag bit
(1,2)
1 = The DMA channel has attempted to access the DMA SFR address lower than DMAL, but above
the SFR range (07FFh)
0 = The DMA channel has not invoked the low address limit interrupt
bit 5DONEIF: DMA Complete Operation Interrupt Flag bit
If CHEN = 1:
1 = The previous DMA session has ended with completion
0 = The current DMA session has not yet completed
If CHEN =
0:
1 = The previous DMA session has ended with completion
0 = The previous DMA session has ended without completion
bit 4HALFIF: DMA 50% Watermark Level Interrupt Flag bit
1 = DMACNTn has reached the halfway point to 0000h
0 = DMACNTn has not reached the halfway point
bit 3OVRUNIF: DMA Channel Overrun Flag bit
(1)
1 = The DMA channel is triggered while it is still completing the operation based on the previous trigger
0 = The overrun condition has not occurred
bit 2-1Unimplemented: Read as ‘0’
bit 0HALFEN: Halfway Completion Watermark bit
1 = Interrupts are invoked when DMACNTn has reached its halfway point and at completion
0 = An interrupt is invoked only at the completion of the transfer
(1)
(1)
Note 1: Setting these flags in software does not generate an interrupt.
2: Testing for address limit violations (DMASRCn or DMADSTn is either greater than DMAH or less than
0101000SPI1 General Interrupt1100111Comparator Interrupt
0101111I2C2 Slave Interrupt1101000INT4 Interrupt
0110000I2C2 Master Interrupt1101001INT3 Interrupt
0110001I2C2 Bus Collision Interrupt1101010INT2 Interrupt
0110010I2C1 Slave Interrupt1101011INT1 Interrupt
0110011I2C1 Master Interrupt1101100INT0 Interrupt
0110100I2C1 Bus Collision Interrupt1101101Interrupt-on-Change (IOC) Interrupt
DS30010118E-page 70 2016-2020 Microchip Technology Inc.
Page 71
PIC24FJ256GA705 FAMILY
0
Program Counter
24 Bits
Program
TBLPAG Reg
8 Bits
Working Reg EA
16 Bits
Using
Byte
24-Bit EA
0
1/0
Select
Table
Instruction
Counter
Using
User/Configuration
Space Select
6.0FLASH PROGRAM MEMORY
Note:This data sheet summarizes the features of
this group of PIC24F devices. It is not
intended to be a comprehensive reference
source. For more information, refer to
“PIC24F Flash Program Memory”
(www.microchip.com/DS30009715) in
the “dsPIC33/PIC24 Family Reference Manual”. The information in this data sheet
supersedes the information in the FRM.
The PIC24FJ256GA705 family of devices contains
internal Flash program memory for storing and executing application code. The program memory is readable,
writable and erasable. The Flash memory can be
programmed in four ways:
• In-Circuit Serial Programming™ (ICSP™)
• Run-Time Self-Programming (RTSP)
•JTAG
• Enhanced In-Circuit Serial Programming
(Enhanced ICSP)
ICSP allows a PIC24FJ256GA705 family device to be
serially programmed while in the end application circuit.
This is simply done with two lines for the programming
clock and programming data (named PGCx and PGDx,
respectively), and three other lines for power (V
ground (V
SS) and Master Clear (MCLR). This allows
customers to manufacture boards with unprogrammed
devices and then program the microcontroller just
before shipping the product. This also allows the most
recent firmware or a custom firmware to be
programmed.
DD),
RTSP is accomplished using TBLRD (Table Read) and
TBLWT (Table Write) instructions. With RTSP, the user
may write program memory data in blocks of
128 instructions (384 bytes) at a time and erase
program memory in blocks of 1024 instructions
(3072 bytes) at a time.
The device implements a 7-bit Error Correcting Code
(ECC). The NVM block contains a logic to write and
read ECC bits to and from the Flash memory. The
Flash is programmed at the same time as the
corresponding ECC parity bits. The ECC provides
improved resistance to Flash errors. ECC single bit
errors can be transparently corrected; ECC double-bit
errors result in a trap.
6.1Table Instructions and Flash
Programming
Regardless of the method used, all programming of
Flash memory is done with the Table Read and Table
Write instructions. These allow direct read and write
access to the program memory space from the data
memory while the device is in normal operating mode.
The 24-bit target address in the program memory is
formed using the TBLPAG[7:0] bits and the Effective
Address (EA) from a W register, specified in the table
instruction, as shown in Figure 6-1.
The TBLRDL and the TBLWTL instructions are used to
read or write to bits[15:0] of program memory. TBLRDL
and TBLWTL can access program memory in both
Word and Byte modes.
The TBLRDH and TBLWTH instructions are used to read
or write to bits[23:16] of program memory. TBLRDH and
TBLWTH can also access program memory in Word or
Byte mode.
The PIC24F Flash program memory array is organized
into rows of 128 instructions or 384 bytes. RTSP allows
the user to erase blocks of eight rows (1024 instructions) at a time and to program one row at a time. It is
also possible to program two instruction word blocks.
The 8-row erase blocks and single row write blocks are
edge-aligned, from the beginning of program memory, on
boundaries of 3072 bytes and 384 bytes, respectively.
When data are written to program memory using
TBLWT instructions, the data are not written directly to
memory. Instead, data written using Table Writes are
stored in holding latches until the programming
sequence is executed.
Any number of TBLWT instructions can be executed
and a write will be successfully performed. However,
128 TBLWT instructions are required to write the full row
of memory.
To ensure that no data are corrupted during a write, any
unused address should be programmed with
FFFFFFh. This is because the holding latches reset to
an unknown state, so if the addresses are left in the
Reset state, they may overwrite the locations on rows
which were not rewritten.
The basic sequence for RTSP programming is to set
the Table Pointer to point to the programming latches,
do a series of TBLWT instructions to load the buffers
and set the NVMADRU/NVMADR registers to point to
the destination. Programming is performed by setting
the control bits in the NVMCON register.
Data can be loaded in any order and the holding registers can be written to multiple times before performing
a write operation. Subsequent writes, however, will
wipe out any previous writes.
Note:Writing to a location multiple times without
erasing is not recommended.
6.3JTAG Operation
The PIC24F family supports JTAG boundary scan.
Boundary scan can improve the manufacturing
process by verifying pin to PCB connectivity.
6.4Enhanced In-Circuit Serial
Programming
Enhanced In-Circuit Serial Programming uses an onboard bootloader, known as the Program Executive
(PE), to manage the programming process. Using an
SPI data frame format, the Program Executive can
erase, program and verify program memory. For more
information on Enhanced ICSP, see the device
programming specification.
Note:The PGD2/PGC2 port on 28-pin packages
supports ICSP™ only, so Enhanced ICSP
programming does not work.
6.5Control Registers
There are four SFRs used to read and write the
program Flash memory: NVMCON, NVMADRU,
NVMADR and NVMKEY.
The NVMCON register (Register 6-1) controls which
blocks are to be erased, which memory type is to be
programmed and when the programming cycle starts.
NVMKEY is a write-only register that is used for write
protection. To start a programming or erase sequence,
the user must consecutively write 55h and AAh to the
NVMKEY register. Refer to Section 6.6 “Programming
Operations” for further details.
The NVMADRU/NVMADR registers contain the upper
byte and lower word of the destination of the NVM write
or erase operation. Some operations (chip erase)
operate on fixed locations and do not require an address
value.
All of the Table Write operations are single-word writes
(two instruction cycles), because only the buffers
are written. A programming cycle is required for
programming each row.
DS30010118E-page 72 2016-2020 Microchip Technology Inc.
6.6Programming Operations
A complete programming sequence is necessary for
programming or erasing the internal Flash in RTSP
mode. During a programming or erase operation, the
processor stalls (waits) until the operation is finished.
Setting the WR bit (NVMCON[15]) starts the operation
and the WR bit is automatically cleared when the
operation is finished.
Page 73
PIC24FJ256GA705 FAMILY
REGISTER 6-1:NVMCON: FLASH MEMORY CONTROL REGISTER
6.6.1PROGRAMMING ALGORITHM FOR
FLASH PROGRAM MEMORY
The user can program one row of Flash program memory
at a time. To do this, it is necessary to erase the 8-row
erase block containing the desired row. The general
process is:
1. Read eight rows of program memory
(1024 instructions) and store in data RAM.
2.Update the program data in RAM with the
desired new data.
3.Erase the block (see Example 6-1):
a) Set the NVMOP[3:0] bits (NVMCON[3:0]) to
‘0011’ to configure for block erase. Set the
WREN (NVMCON[14]) bit.
b) Write the starting address of the block to
be erased into the NVMADRU/NVMADR
registers.
c)Write 55h to NVMKEY.
d) Write AAh to NVMKEY.
e) Set the WR bit (NVMCON[15]). The erase
cycle begins and the CPU stalls for the dura-
tion of the erase cycle. When the erase is
done, the WR bit is cleared automatically.
4. Update the TBLPAG register to point to the programming latches on the device. Update the
NVMADRU/NVMADR registers to point to the
destination in the program memory.
5.Write the first 128 instructions from data RAM into
the program memory buffers (see Table 6-1).
6. Write the program block to Flash memory:
a) Set the NVMOPx bits to ‘0010’ to configure
for row programming. Set the WREN bit.
b) Write 55h to NVMKEY.
c)Write AAh to NVMKEY.
d) Set the WR bit. The programming cycle
begins and the CPU stalls for the duration
of the write cycle. When the write to Flash
memory is done, the WR bit is cleared
automatically.
7.Repeat Steps 4 through 6, using the next
available 128 instructions from the block in data
RAM, by incrementing the value in NVMADRU/
NVMADR until all 1024 instructions are written
back to Flash memory.
For protection against accidental operations, the write
initiate sequence for NVMKEY must be used to allow
any erase or program operation to proceed. After the
programming command has been executed, the user
must wait for the programming time until programming
is complete. The two instructions following the start of
the programming sequence should be NOPs, as shown
in Example 6-2.
TABLE 6-1:EXAMPLE PAGE ERASE
Step 1: Set the NVMCON register to erase a page.
MOV #0x4003, W0
MOV W0, NVMCON
Step 2: Load the address of the page to be erased into the NVMADR register pair.
; for next 5 instructions
MOV.B#0x55, W0
MOVW0, NVMKEY ; Write the 0x55 key
MOV.B#0xAA, W1 ;
MOVW1, NVMKEY ; Write the 0xAA key
BSETNVMCON, #WR; Start the programming sequence
NOP ; Required delays
NOP
BTSC NVMCON, #15 ; and wait for it to be
BRA $-2; completed
EXAMPLE 6-2:INITIATING A PROGRAMMING SEQUENCE
DS30010118E-page 76 2016-2020 Microchip Technology Inc.
Page 77
PIC24FJ256GA705 FAMILY
6.6.2PROGRAMMING A DOUBLE WORD
OF FLASH PROGRAM MEMORY
If a Flash location has been erased, it can be
programmed using Table Write instructions to write two
instruction words (2 x 24-bit) into the write latch. The
TBLPAG register is loaded with the address of the write
latches and the NVMADRU/NVMADR registers are
loaded with the address of the first of the two instruction
words to be programmed. The TBLWTL and TBLWTH
instructions write the desired data into the write latches.
To configure the NVMCON register for a two-word write,
set the NVMOPx bits (NVMCON[3:0]) to ‘0001’. The
write is performed by executing the unlock sequence
and setting the WR bit. An equivalent procedure in ‘C’,
using the MPLAB
functions, is shown in Example 6-3.
®
XC16 compiler and built-in hardware
TABLE 6-3:PROGRAMMING A DOUBLE WORD OF FLASH PROGRAM MEMORY
Step 1: Initialize the TBLPAG register for writing to the latches.
MOV#0xFA, W12
MOVW12, TBLPAG
Step 2: Load W0:W2 with the next two packed instruction words to program.
MOV#<LSW0>, W0
MOV#<MSB1:MSB0>, W1
MOV#<LSW1>, W2
Step 3: Set the Read Pointer (W6) and Write Pointer (W7), and load the (next set of) write latches.
// C example using MPLAB XC16
unsignedlong progAddr = 0xXXXXXX;// Address of word to program
unsignedint progData1L = 0xXXXX;// Data to program lower word of word 1
unsignedchar progData1H = 0xXX;// Data to program upper byte of word 1
unsignedint progData2L = 0xXXXX;// Data to program lower word of word 2
unsignedchar progData2H = 0xXX;// Data to program upper byte of word 2
//Set up NVMCON for word programming
NVMCON = 0x4001;// Initialize NVMCON
TBLPAG = 0xFA; // Point TBLPAG to the write latches
//Set up pointer to the first memory location to be written
NVMADRU = progAddr>>16;// Initialize PM Page Boundary SFR
NVMADR = progAddr & 0xFFFF;// Initialize lower word of address
//Perform TBLWT instructions to write latches
__builtin_tblwtl(0, progData1L); // Write word 1 to address low word
__builtin_tblwth(0, progData1H); // Write word 1 to upper byte
__builtin_tblwtl(1, progData2L); // Write word 2 to address low word
__builtin_tblwth(1, progData2H); // Write word 2 to upper byte
asm(“DISI #5”); // Block interrupts with priority <7 for next 5
// instructions
__builtin_write_NVM(); //
XC16 function to perform unlock sequence and set WR
EXAMPLE 6-3:PROGRAMMING A DOUBLE WORD OF FLASH PROGRAM MEMORY
(‘C’ LANGUAGE CODE)
DS30010118E-page 78 2016-2020 Microchip Technology Inc.
Page 79
PIC24FJ256GA705 FAMILY
MCLR
VDD
VDD Rise
Detect
POR
Sleep or Idle
Brown-out
Reset
Enable Voltage Regulator
RESET
Instruction
WDT
Module
Glitch Filter
BOR
Trap Conflict
Illegal Opcode
Uninitialized W Register
SYSRST
Configuration Mismatch
7.0RESETS
Note:This data sheet summarizes the features
of this group of PIC24F devices. It is not
intended to be a comprehensive
reference source. For more
information, refer to “Reset”
(www.microchip.com/DS39712) in the
“dsPIC33/PIC24 Family Reference
Manual”. The information in this data sheet
supersedes the information in the FRM.
The Reset module combines all Reset sources and
controls the device Master Reset Signal, SYSRST
following is a list of device Reset sources:
• POR: Power-on Reset
•MCLR
: Master Clear Pin Reset
•SWR: RESET Instruction
• WDT: Watchdog Timer Reset
• BOR: Brown-out Reset
• CM: Configuration Mismatch Reset
• TRAPR: Trap Conflict Reset
• IOPUWR: Illegal Opcode Reset
• UWR: Uninitialized W Register Reset
A simplified block diagram of the Reset module is
shown in Figure 7-1.
. The
Any active source of Reset will make the SYSRST
signal active. Many registers associated with the CPU
and peripherals are forced to a known Reset state.
Most registers are unaffected by a Reset; their status is
unknown on POR and unchanged by all other Resets.
Note:Refer to the specific peripheral or CPU
section of this manual for register Reset
states.
All types of device Reset will set a corresponding status
bit in the RCON register to indicate the type of Reset
(see Register 7-1). A POR will clear all bits, except for
the BOR and POR (RCON[1:0]) bits, which are set. The
user may set or clear any bit at any time during code
execution. The RCON bits only serve as status bits.
Setting a particular Reset status bit in software will not
cause a device Reset to occur.
The RCON register also has other bits associated with
the Watchdog Timer and device power-saving states.
The function of these bits is discussed in other sections
of this data sheet.
Note:The status bits in the RCON register
should be cleared after they are read so
that the next RCON register values after a
device Reset will be meaningful.
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
SWR
(1)
(1)
SBOREN
SWDTEN
(5)
(4)
RETEN
WDTO
(1)
(2)
BOR
(1)
(1)
——CM
SLEEP
(1)
IDLE
(1)
VREGS
POR
(3)
(1)
bit 15TRAPR: Trap Reset Flag bit
(1)
1 = A Trap Conflict Reset has occurred
0 = A Trap Conflict Reset has not occurred
bit 14IOPUWR: Illegal Opcode or Uninitialized W Register Access Reset Flag bit
1 = An illegal opcode detection, an illegal address mode or Uninitialized W register is used as an
Address Pointer and caused a Reset
0 = An illegal opcode or Uninitialized W register Reset has not occurred
bit 13SBOREN: Software Control Over the BOR Function bit
(5)
1 = BOR is enabled
0 = BOR is disabled
bit 12RETEN: Retention Mode Enable bit
(2)
1 = Retention mode is enabled while device is in Sleep mode (1.2V regulator supplies to the core)
0 = Retention mode is disabled; normal voltage levels are present
bit 11-10Unimplemented: Read as ‘0’
bit 9CM: Configuration Word Mismatch Reset Flag bit
(1)
1 = A Configuration Word Mismatch Reset has occurred
0 = A Configuration Word Mismatch Reset has not occurred
bit 8VREGS: Fast Wake-up from Sleep bit
(3)
1 = Fast wake-up is enabled (uses more power)
0 = Fast wake-up is disabled (uses less power)
bit 7EXTR: External Reset (MCLR
) Pin bit
(1)
1 = A Master Clear (pin) Reset has occurred
0 = A Master Clear (pin) Reset has not occurred
bit 6SWR: Software RESET (Instruction) Flag bit
(1)
1 = A RESET instruction has been executed
0 = A RESET instruction has not been executed
(1)
Note 1: All of the Reset status bits may be set or cleared in software. Setting one of these bits in software does not
cause a device Reset.
2: If the LPCFG Configuration bit is ‘1’ (unprogrammed), the retention regulator is disabled and the RETEN
bit has no effect. Retention mode preserves the SRAM contents during Sleep.
3: Re-enabling the regulator after it enters Standby mode will add a delay, T
VREG, when waking up from Sleep.
Applications that do not use the voltage regulator should set this bit to prevent this delay from occurring.
4: If the FWDTEN[1:0] Configuration bits are ‘11’ (unprogrammed), the WDT is always enabled, regardless of
the SWDTEN bit setting.
5: The BOREN[1:0] (FPOR[1:0]) Configuration bits must be set to ‘01’ in order for SBOREN to have an effect.
DS30010118E-page 80 2016-2020 Microchip Technology Inc.
Page 81
PIC24FJ256GA705 FAMILY
REGISTER 7-1:RCON: RESET CONTROL REGISTER (CONTINUED)
bit 5SWDTEN: Software Enable/Disable of WDT bit
1 = WDT is enabled
0 = WDT is disabled
bit 4WDTO: Watchdog Timer Time-out Flag bit
1 = WDT time-out has occurred
0 = WDT time-out has not occurred
bit 3SLEEP: Wake from Sleep Flag bit
(1)
1 = Device has been in Sleep mode
0 = Device has not been in Sleep mode
bit 2IDLE: Wake-up from Idle Flag bit
(1)
1 = Device has been in Idle mode
0 = Device has not been in Idle mode
bit 1BOR: Brown-out Reset Flag bit
(1)
1 = A Brown-out Reset has occurred (also set after a Power-on Reset)
0 = A Brown-out Reset has not occurred
bit 0POR: Power-on Reset Flag bit
(1)
1 = A Power-on Reset has occurred
0 = A Power-on Reset has not occurred
(4)
(1)
Note 1: All of the Reset status bits may be set or cleared in software. Setting one of these bits in software does not
cause a device Reset.
2: If the LPCFG
Configuration bit is ‘1’ (unprogrammed), the retention regulator is disabled and the RETEN
bit has no effect. Retention mode preserves the SRAM contents during Sleep.
3: Re-enabling the regulator after it enters Standby mode will add a delay, T
VREG, when waking up from Sleep.
Applications that do not use the voltage regulator should set this bit to prevent this delay from occurring.
4: If the FWDTEN[1:0] Configuration bits are ‘11’ (unprogrammed), the WDT is always enabled, regardless of
the SWDTEN bit setting.
5: The BOREN[1:0] (FPOR[1:0]) Configuration bits must be set to ‘01’ in order for SBOREN to have an effect.
TABLE 7-1:RESET FLAG BIT OPERATION
Flag BitSetting EventClearing Event
TRAPR (RCON[15])Trap Conflict EventPOR
IOPUWR (RCON[14])Illegal Opcode or Uninitialized W Register AccessPOR
CM (RCON[9])Configuration Mismatch ResetPOR
EXTR (RCON[7])MCLR ResetPOR
SWR (RCON[6])RESET InstructionPOR
WDTO (RCON[4])WDT Time-outCLRWDT, PWRSAV Instruction, POR
SLEEP (RCON[3])PWRSAV #0 InstructionPOR
IDLE (RCON[2])PWRSAV #1 InstructionPOR
BOR (RCON[1])POR, BOR—
POR (RCON[0])POR—
Note:All Reset flag bits may be set or cleared by the user software.
Most of the Special Function Registers (SFRs) associated with the PIC24F CPU and peripherals are reset to a
particular value at a device Reset. The SFRs are
grouped by their peripheral or CPU function and their
Reset values are specified in each section of this manual.
The Reset value for each SFR does not depend on the
type of Reset, with the exception of four registers. The
Reset value for the Reset Control register, RCON, will
depend on the type of device Reset. The Reset value
for the Oscillator Control register, OSCCON, will
depend on the type of Reset and the programmed
values of the FNOSC[2:0] bits in the FOSCSEL Flash
Configuration Word (see Table 7-2). The RCFGCAL
and NVMCON registers are only affected by a POR.
7.2Device Reset Times
The Reset times for various types of device Reset are
summarized in Tab le 7 -3 . Note that the Master Reset
Signal, SYSRST, is released after the POR delay time
expires.
The time at which the device actually begins to execute
code will also depend on the system oscillator delays,
which include the Oscillator Start-up Timer (OST) and
the PLL lock time. The OST and PLL lock times occur
in parallel with the applicable SYSRST
The Fail-Safe Clock Monitor (FSCM) delay determines
the time at which the FSCM begins to monitor the system
clock source after the SYSRST
signal is released.
delay times.
7.3Brown-out Reset (BOR)
PIC24FJ256GA705 family devices implement a BOR
circuit that provides the user with several configuration
and power-saving options. The BOR is controlled by the
BOREN[1:0] (FPOR[1:0]) Configuration bits.
When BOR is enabled, any drop of V
threshold results in a device BOR. Threshold levels are
described in Section 32.1 “DC Characteristics”.
DD below the BOR
7.4Clock Source Selection at Reset
If clock switching is enabled, the system clock source
at device Reset is chosen, as shown in Tab le 7 -2 . If
clock switching is disabled, the system clock source is
always selected according to the Oscillator Configuration bits. For more information, refer to “Oscillator”
(www.microchip.com/DS39700) in the “dsPIC33/PIC24Family Reference Manual”.
TABLE 7-2:OSCILLATOR SELECTION vs.
TYPE OF RESET (CLOCK
SWITCHING ENABLED)
Reset TypeClock Source Determinant
POR
BOR
MCLR
WDTO
SWR
FNOSC[2:0] Configuration bits
(FOSCSEL[2:0])
COSC[2:0] Control bits
(OSCCON[14:12])
DS30010118E-page 82 2016-2020 Microchip Technology Inc.
Page 83
PIC24FJ256GA705 FAMILY
TABLE 7-3:RESET DELAY TIMES FOR VARIOUS DEVICE RESETS
2: TSTARTUP = TVREG.
3: TRST = Internal State Reset Time (2 µs nominal).
4: T
OST = Oscillator Start-up Timer (OST). A 10-bit counter counts 1024 oscillator periods before releasing
the oscillator clock to the system.
5: T
LOCK = PLL Lock Time.
6: TFRC and TLPRC = RC Oscillator Start-up Times.
7: If Two-Speed Start-up is enabled, regardless of the Primary Oscillator selected, the device starts with FRC
so the system clock delay is just T
FRC, and in such cases, FRC start-up time is valid; it switches to the
Primary Oscillator after its respective clock delay.
The oscillator start-up circuitry and its associated delay
timers are not linked to the device Reset delays that
occur at power-up. Some crystal circuits (especially lowfrequency crystals) will have a relatively long start-up
time. Therefore, one or more of the following conditions
is possible after SYSRST
• The oscillator circuit has not begun to oscillate.
• The Oscillator Start-up Timer has not expired (if a
crystal oscillator is used).
• The PLL has not achieved a lock (if PLL is used).
is released:
The device will not begin to execute code until a valid
clock source has been released to the system. Therefore, the oscillator and PLL start-up delays must be
considered when the Reset delay time must be known.
7.4.2FAIL-SAFE CLOCK MONITOR
(FSCM) AND DEVICE RESETS
If the FSCM is enabled, it will begin to monitor the
system clock source when SYSRST
valid clock source is not available at this time, the
device will automatically switch to the FRC Oscillator
and the user can switch to the desired crystal oscillator
in the Trap Service Routine (TSR).
is released. If a
DS30010118E-page 84 2016-2020 Microchip Technology Inc.
Page 85
PIC24FJ256GA705 FAMILY
8.0INTERRUPT CONTROLLER
Note 1: This data sheet summarizes the
features of the PIC24FJ256GA705
family of devices. It is not intended to be
a comprehensive reference source. To
complement the information in this
data sheet, refer to “Interrupts”
(www.microchip.com/DS70000600) in
the “dsPIC33/PIC24 Family Reference Manual”. The information in this data sheet
supersedes the information in the FRM.
2: Some registers and associated bits
described in this section may not be
available on all devices. Refer to
Section 4.0 “Memory Organization” in
this data sheet for device-specific register
and bit information.
The PIC24FJ256GA705 family interrupt controller
reduces the numerous peripheral interrupt request
signals to a single interrupt request signal to the
PIC24FJ256GA705 family CPU.
The interrupt controller has the following features:
• Up to Eight Processor Exceptions and Software
Traps
• Seven User-Selectable Priority Levels
• Interrupt Vector Table (IVT) with a Unique Vector
for Each Interrupt or Exception Source
• Fixed Priority within a Specified User Priority Level
• Fixed Interrupt Entry and Return Latencies
8.1Interrupt Vector Table
8.1.1ALTERNATE INTERRUPT VECTOR
TAB LE
The Alternate Interrupt Vector Table (AIVT) is located
after the IVT, as shown in Figure 8-1. The AIVTEN
(INTCON2[8]) control bit provides access to the AIVT.
If the AIVTEN bit is set, all interrupt and exception
processes will use the alternate vectors instead of the
default vectors. The alternate vectors are organized in
the same manner as the default vectors.
The AIVT supports emulation and debugging efforts by
providing a means to switch between an application,
and a support environment, without requiring the interrupt vectors to be reprogrammed. This feature also
enables switching between applications for evaluation
of different software algorithms at run time. If the AIVT
is not needed, the AIVT should be programmed with
the same addresses used in the IVT.
8.2Reset Sequence
A device Reset is not a true exception because the
interrupt controller is not involved in the Reset process.
The PIC24FJ256GA705 family devices clear their
registers in response to a Reset, which forces the PC
to zero. The device then begins program execution at
location, 0x000000. A GOTO instruction at the Reset
address can redirect program execution to the
appropriate start-up routine.
Note:Any unimplemented or unused vector
locations in the IVT should be
programmed with the address of a default
interrupt handler routine that contains a
RESET instruction.
The PIC24FJ256GA705 family Interrupt Vector Table
(IVT), shown in Figure 8-1, resides in program memory
starting at location, 000004h. The IVT contains six nonmaskable trap vectors and up to 118 sources of
interrupt. In general, each interrupt source has its own
vector. Each interrupt vector contains a 24-bit wide
address. The value programmed into each interrupt
vector location is the starting address of the associated
Interrupt Service Routine (ISR).
Interrupt vectors are prioritized in terms of their natural
priority. This priority is linked to their position in the
vector table. Lower addresses generally have a higher
natural priority. For example, the interrupt associated
with Vector 0 takes priority over interrupts at any other
vector address.
Many useful resources are provided on the main product page of the Microchip website for the devices listed
in this data sheet. This product page, which can be
accessed using this link, contains the latest updates
and additional information.
Note:In the event you are not able to access the
product page using the link above, enter
this URL in your browser:
• All Related “dsPIC33/PIC24 Family Reference Manual” Sections
• Development Tools
8.4Interrupt Control and Status
Registers
PIC24FJ256GA705 family devices implement the
following registers for the interrupt controller:
• INTCON1
• INTCON2
• INTCON4
• IFS0 through IFS7
• IEC0 through IEC7
• IPC0 through ICP29
• INTTREG
8.4.1INTCON1-INTCON4
Global interrupt control functions are controlled from
INTCON1 and INTCON2. INTCON1 contains the
Interrupt Nesting Disable (NSTDIS) bit, as well as the
control and status flags for the processor trap sources.
The INTCON2 register controls global interrupt generation, the external interrupt request signal behavior and
the use of the Alternate Interrupt Vector Table (AIVT).
The INTCON4 register contains the SoftwareGenerated Hard Trap bit (SGHT) and ECC Double-Bit
Error (ECCDBE) trap.
8.4.2IFSx
The IFSx registers maintain all of the interrupt request
flags. Each source of interrupt has a status bit, which is
set by the respective peripherals or external signal, and
is cleared via software.
8.4.3IECx
The IECx registers maintain all of the interrupt enable
bits. These control bits are used to individually enable
interrupts from the peripherals or external signals.
8.4.4IPCx
The IPCx registers are used to set the Interrupt Priority
Level (IPL) for each source of interrupt. Each user
interrupt source can be assigned to one of eight priority
levels.
8.4.5INTTREG
The INTTREG register contains the associated
interrupt vector number and the new CPU Interrupt
Priority Level, which are latched into the Vector
Number bits (VECNUM[7:0]) and Interrupt Priority
Level bits (ILR[3:0]) fields in the INTTREG register. The
new Interrupt Priority Level is the priority of the pending
interrupt.
The interrupt sources are assigned to the IFSx, IECx
and IPCx registers in the same sequence as they are
listed in Table 8-2. For example, the INT0 (External
Interrupt 0) is shown as having Vector Number 8 and a
natural order priority of 0. Thus, the INT0IF bit is found
in IFS0[0], the INT0IE bit in IEC0[0] and the INT0IPx
bits in the first position of IPC0 (IPC0[2:0]).
8.4.6STATUS/CONTROL REGISTERS
Although these registers are not specifically part of
the interrupt control hardware, two of the CPU Control
registers contain bits that control interrupt
functionality. For more information on these registers,
refer to “CPU with Extended Data Space (EDS)”
(www.microchip.com/DS39732) in the “dsPIC33/PIC24Family Reference Manual”.
• The CPU STATUS Register, SR, contains the
IPL[2:0] bits (SR[7:5]). These bits indicate the
current CPU Interrupt Priority Level. The user
software can change the current CPU Interrupt
Priority Level by writing to the IPLx bits.
• The CORCON register contains the IPL3 bit,
which together with the IPL[2:0] bits, also indicates the current CPU Interrupt Priority Level.
IPL3 is a read-only bit so that trap events cannot
be masked by the user software.
All Interrupt registers are described in Register 8-3
through Register 8-6 in the following pages.
DS30010118E-page 90 2016-2020 Microchip Technology Inc.
Page 91
PIC24FJ256GA705 FAMILY
REGISTER 8-1:SR: ALU STATUS REGISTER
(1)
U-0U-0U-0U-0U-0U-0U-0R/W-0
———————DC
bit 15bit 8
R/W-0
IPL2
(3)
(2)
R/W-0
IPL1
(2)
(3)
R/W-0
IPL0
(2)
(3)
R-0R/W-0R/W-0R/W-0R/W-0
RANOVZC
bit 7bit 0
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’= Bit is set‘0’ = Bit is clearedx = Bit is unknown
bit 7-5IPL[2:0]: CPU Interrupt Priority Level Status bits
(2,3)
111 = CPU Interrupt Priority Level is 7 (15); user interrupts are disabled
110 = CPU Interrupt Priority Level is 6 (14)
101 = CPU Interrupt Priority Level is 5 (13)
100 = CPU Interrupt Priority Level is 4 (12)
011 = CPU Interrupt Priority Level is 3 (11)
010 = CPU Interrupt Priority Level is 2 (10)
001 = CPU Interrupt Priority Level is 1 (9)
000 = CPU Interrupt Priority Level is 0 (8)
Note 1: For complete register details, see Register 3-1.
2: The IPL[2:0] Status bits are concatenated with the IPL3 Status bit (CORCON[3]) to form the CPU Interrupt
Priority Level (IPL). The value in parentheses indicates the IPL when IPL3 = 1. User interrupts are
disabled when IPL3 = 1.
3: The IPL[2:0] Status bits are read-only when the NSTDIS bit (INTCON1[15]) = 1.
REGISTER 8-6:INTTREG: INTERRUPT CONTROL AND STATUS REGISTER
R-0U-0R/W-0U-0R-0R-0R-0R-0
CPUIRQ
bit 15bit 8
R-0R-0R-0R-0R-0R-0R-0R-0
bit 7bit 0
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
bit 15CPUIRQ: Interrupt Request from Interrupt Controller to CPU bit
bit 14Unimplemented: Read as ‘0’
bit 13VHOLD: Vector Number Capture Configuration bit
bit 12Unimplemented: Read as ‘0’
bit 11-8ILR[3:0]: New CPU Interrupt Priority Level bits
bit 7-0VECNUM[7:0]: Vector Number of Pending Interrupt bits
—VHOLD—ILR3ILR2ILR1ILR0
VECNUM[7:0]
1 = An interrupt request has occurred but has not yet been Acknowledged by the CPU; this happens
when the CPU priority is higher than the interrupt priority
0 = No interrupt request is unacknowledged
1 = The VECNUMx bits contain the value of the highest priority pending interrupt
0 = The VECNUMx bits contain the value of the last Acknowledged interrupt (i.e., the last interrupt
that has occurred with higher priority than the CPU, even if other interrupts are pending)
1111 = CPU Interrupt Priority Level is 15
•
•
•
0001 = CPU Interrupt Priority Level is 1
0000 = CPU Interrupt Priority Level is 0
11111111 = 255, Reserved; do not use
•
•
•
00001001 = 9, IC1 – Input Capture 1
00001000 = 8, INT0 – External Interrupt 0
00000111 = 7, Reserved; do not use
00000110 = 6, Generic soft error trap
00000101 = 5, Reserved; do not use
00000100 = 4, Math error trap
00000011 = 3, Stack error trap
00000010 = 2, Generic hard trap
00000001 = 1, Address error trap
00000000 = 0, Oscillator fail trap
DS30010118E-page 96 2016-2020 Microchip Technology Inc.
Page 97
PIC24FJ256GA705 FAMILY
PIC24FJ256GA705 Family
Secondary Oscillator
SOSCEN
Enable
Oscillator
SOSCO
SOSCI
WDT, Other Modules
OSCI
OSCO
Primary Oscillator
XT, HS, EC
CPU
Peripherals
RCDIV[2:0]
Timer, CCP, RTCC, CLC, WDT, PWRT
OSCFDIV
SOSC
Clock Control Logic
FSCM
DOZE[14:12]
CLKO
XTPLL, HSPLL
ECPLL,FRCPLL
PLL &
DIV
PLLMODE[3:0]CPDIV[1:0]
PLL
CCP
LPRC
FRC
DIV[14:0]
LPRC
Oscillator
FRCDivider
÷ n
Postscaler
WDT, RTCC, CLC
9.0OSCILLATOR CONFIGURATION
• Software-Controllable Postscaler for Selective
Clocking of CPU for System Power Savings
Note:This data sheet summarizes the features
of this group of PIC24F devices. It is not
intended to be a comprehensive
reference source. For more
information, refer to “Oscillator”
(www.microchip.com/DS39700) in the
“dsPIC33/PIC24 Family Reference
Manual”. The information in this data sheet
• A Fail-Safe Clock Monitor (FSCM) that Detects
Clock Failure and Permits Safe Application
Recovery or Shutdown
• A Separate and Independently Configurable System
Clock Output for Synchronizing External Hardware
A simplified diagram of the oscillator system is shown
in Figure 9-1.
supersedes the information in the FRM.
The oscillator system for the PIC24FJ256GA705 family
devices has the following features:
• An On-Chip PLL Block to provide a Range of
Frequency Options for the System Clock
• Software-Controllable Switching between Various
Clock Sources
The system clock source can be provided by one of
four sources:
• Primary Oscillator (POSC) on the OSCI and
OSCO pins
• Secondary Oscillator (SOSC) on the SOSCI and
SOSCO pins
• Fast Internal RC (FRC) Oscillator
• Low-Power Internal RC (LPRC) Oscillator
The Primary Oscillator and FRC sources have the
option of using the internal PLL block, which can
generate a 4x, 6x or 8x PLL clock. If the PLL is used,
the PLL clocks can then be postscaled, if necessary,
and used as the system clock. Refer to Section 9.5
“Oscillator Modes” for additional information. The
internal FRC provides an 8 MHz clock source.
Each clock source (PRIPLL, FRCPLL, PRI, FRC,
LPRC and SOSC) can be used as an input to an
additional divider, which can then be used to produce a
divided clock source for use as a system clock
(OSCFDIV).
The selected clock source generates the processor
and peripheral clock sources. The processor clock
source is divided by two to produce the internal instruction cycle clock, F
cycle clock is also denoted by F
instruction cycle clock, F
OSCO I/O pin for some operating modes of the Primary
Oscillator.
CY. In this document, the instruction
OSC/2. The internal
OSC/2, can be provided on the
9.2Initial Configuration on POR
The oscillator source (and operating mode) that is used
at a device Power-on Reset event is selected using Configuration bit settings. The Oscillator Configuration bit
settings are located in the Configuration registers in the
program memory (refer to Section 29.1 “Configura-
tion Bits” for further details). The Primary Oscillator
Configuration bits, POSCMD[1:0] (FOSC[1:0]), and the
Oscillator Select Configuration bits, FNOSC[2:0]
(FOSCSEL[2:0]), select the oscillator source that is used
at a Power-on Reset. The OSCFDIV clock source is the
default (unprogrammed) selection; the default input
source to the OSCFDIV divider is the FRC clock source.
Other oscillators may be chosen by programming these
bit locations.
The Configuration bits allow users to choose between
the various Clock modes shown in Table 9-1.
9.2.1CLOCK SWITCHING MODE
CONFIGURATION BITS
The FCKSM[1:0] Configuration bits (FOSC[7:6]) are
used to jointly configure device clock switching and the
Fail-Safe Clock Monitor (FSCM). Clock switching is
enabled only when FCKSM1 is programmed (‘0’). The
FSCM is enabled only when FCKSM[1:0] are both
programmed (‘00’).
DS30010118E-page 98 2016-2020 Microchip Technology Inc.
Page 99
PIC24FJ256GA705 FAMILY
TABLE 9-1:CONFIGURATION BIT VALUES FOR CLOCK SELECTION
Note 1: The input oscillator to the OSCFDIV Clock mode is determined by the RCDIV[2:0] (CLKDIV[10:8) bits. At
POR, the default value selects the FRC module.
2: This is the default Oscillator mode for an unprogrammed (erased) device.
3: OSCO pin function is determined by the OSCIOFCN Configuration bit.
Internal/External111111, 2, 3
Secondary111003
Primary01011
Primary00011
Internal110013
9.3Control Registers
The operation of the oscillator is controlled by five
Special Function Registers:
• OSCCON
•CLKDIV
•OSCTUN
• OSCDIV
•OSCFDIV
The OSCCON register (Register 9-1) is the main con-
trol register for the oscillator. It controls clock source
switching and allows the monitoring of clock sources.
OSCCON is protected by a write lock to prevent
inadvertent clock switches. See Section 9.4 “Clock
Switching Operation” for more information.
The CLKDIV register (Register 9-2) controls the
features associated with Doze mode, as well as the
postscalers for the OSCFDIV Clock mode and the PLL
module.
The OSCTUN register (Register 9-3) allows the user to
fine-tune the FRC Oscillator over a range of
approximately ±1.5%.
The OSCDIV and OSCFDIV registers provide control
for the system oscillator frequency divider.
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
bit 15Unimplemented: Read as ‘0’
bit 14-12COSC[2:0]: Current Oscillator Selection bits
(2)
111 = Oscillator with Frequency Divider (OSCFDIV)
110 = Reserved
101 = Low-Power RC Oscillator (LPRC)
100 = Secondary Oscillator (SOSC)
011 = Primary Oscillator with PLL module (XTPLL, ECPLL)
010 = Primary Oscillator (XT, HS, EC)
001 = Fast RC Oscillator with PLL module (FRCPLL)
000 = Fast RC Oscillator (FRC)
bit 11Unimplemented: Read as ‘0’
(2)
bit 10-8NOSC[2:0]: New Oscillator Selection bits
111 = Oscillator with Frequency Divider (OSCFDIV)
110 = Reserved
101 = Low-Power RC Oscillator (LPRC)
100 = Secondary Oscillator (SOSC)
011 = Primary Oscillator with PLL module (XTPLL, ECPLL)
010 = Primary Oscillator (XT, HS, EC)
001 = Fast RC Oscillator with PLL module (FRCPLL)
000 = Fast RC Oscillator (FRC)
bit 7CLKLOCK: Clock Selection Lock Enable bit
If FSCM is Enabled (FCKSM[1:0] =
00):
1 = Clock and PLL selections are locked
0 = Clock and PLL selections are not locked and may be modified by setting the OSWEN bit
If FSCM is Disabled (FCKSM[1:0] =
1x):
Clock and PLL selections are never locked and may be modified by setting the OSWEN bit.
bit 6IOLOCK: I/O Lock Enable bit
(3)
1 = I/O lock is active
0 = I/O lock is not active
bit 5LOCK: PLL Lock Status bit
(4)
1 = PLL module is in lock or PLL module start-up timer is satisfied
0 = PLL module is out of lock, PLL start-up timer is running or PLL is disabled
Note 1: OSCCON is protected by a write lock to prevent inadvertent clock switches. See Section 9.4 “Clock
Switching Operation” for more information.
2: Reset values for these bits are determined by the FNOSCx Configuration bits.
3: The state of the IOLOCK bit can only be changed once an unlocking sequence has been executed. In
addition, if the IOL1WAY Configuration bit is ‘1’ once the IOLOCK bit is set, it cannot be cleared.
4: This bit also resets to ‘0’ during any valid clock switch or whenever a non-PLL Clock mode is selected.
DS30010118E-page 100 2016-2020 Microchip Technology Inc.
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.