Note the following details of the code protection feature on Microchip devices:
•Microchip products meet the specification contained in their particular Microchip Data Sheet.
•Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•Microchip is willing to work with the customer who is concerned about the integrity of their code.
•Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED,
WRITTEN OR ORAL, STATUTORY OR OTHERWISE,
RELATED TO THE INFORMATION, INCLUDING BUT NOT
LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE,
MERCHANTABILITY OR FITNESS FOR PURPOSE.
Microchip disclaims all liability arising from this information and
its use. Use of Microchip devices in life support and/or safety
applications is entirely at the buyer’s risk, and the buyer agrees
to defend, indemnify and hold harmless Microchip from any and
all damages, claims, suits, or expenses resulting from such
use. No licenses are conveyed, implicitly or otherwise, under
any Microchip intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, K
EELOQ, microID, MPLAB, PIC, PICmicro, PICSTART,
PRO MATE, PowerSmart, rfPIC and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, Migratable Memory, MXDEV, MXLAB,
SEEVAL, SmartSensor and The Embedded Control Solutions
Company are registered trademarks of Microchip Technology
Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, dsPICDEM,
dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR,
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial
Programming, ICSP, ICEPIC, Linear Active Thermistor,
MPASM, MPLIB, MPLINK, MPSIM, PICkit, PICDEM,
PICDEM.net, PICLAB, PICtail, PowerCal, PowerInfo,
PowerMate, PowerTool, REAL ICE, rfLAB, rfPICDEM, Select
Mode, Smart Serial, SmartTel, Total Endurance, UNI/O,
WiperLock and Zena are trademarks of Microchip Technology
Incorporated in the U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
Microchip received ISO/TS-16949:2002 quality system certification for
its worldwide headquarters, design and wafer fabrication facilities in
Chandler and Tempe, Arizona and Mountain View, California in
October 2003. The Company’s quality system processes and
procedures are for its PICmicro
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
4.0Flash Program Memory.............................................................................................................................................................. 45
8.0Power-Saving Features .............................................................................................................................................................. 97
22.0 Comparator Voltage Reference................................................................................................................................................ 177
23.0 Special Features ...................................................................................................................................................................... 179
24.0 Instruction Set Summary .......................................................................................................................................................... 189
25.0 Development Support............................................................................................................................................................... 197
Index ................................................................................................................................................................................................. 221
The Microchip Web Site..................................................................................................................................................................... 225
Customer Change Notification Service .............................................................................................................................................. 225
Customer Support .............................................................................................................................................................................. 225
Product Identification System ............................................................................................................................................................ 227
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 or fax the Reader Response Form in the back of this data sheet to (480) 792-4150. We
welcome your feedback.
Most Current Data Sheet
To obtain the most up-to-date version of this data sheet, please register at our Worldwide Web site at:
http://www.microchip.com
You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page.
The last character of the literature number is the version number, (e.g., DS30000A is version A of document DS30000).
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current
devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision
of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Microchip’s Worldwide Web site; http://www.microchip.com
• Your local Microchip sales office (see last page)
When contacting a sales office, please specify which device, revision of silicon and data sheet (include literature number) you are
using.
Customer Notification System
Register on our web site at www.microchip.com to receive the most current information on all of our products.
This document contains device specific information for
the following devices:
• PIC24FJ64GA006
• PIC24FJ64GA008
• PIC24FJ64GA010
• PIC24FJ96GA006
• PIC24FJ96GA008
• PIC24FJ96GA010
• PIC24FJ128GA006
• PIC24FJ128GA008
• PIC24FJ128GA010
This family introduces a new line of Microchip devices:
a 16-bit RISC microcontroller family with a broad
peripheral feature set and enhanced computational
performance. The PIC24FJ128GA family offers a new
migration option for those high-performance applications which may be outgrowing their 8-bit platforms, but
don’t require the numerical processing power of a
digital signal processor.
1.1Core Features
1.1.116-BIT ARCHITECTURE
Central to all PIC24 devices is the 16-bit modified
Harvard architecture, first introduced with Microchip’s
dsPIC® digital signal controllers. The PIC24 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 8 Mbytes (program
space) and 64 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
All of the devices in the PIC24FJ128GA family incorporate a range of features that can significantly reduce
power consumption during operation. Key items
include:
• On-the-Fly Clock Switching: The device clock
can be changed under software control to the
Timer1 source or the internal low-power RC
oscillator during operation, allowing the user to
incorporate power-saving ideas into their software
designs.
• Doze Mode Operation: When timing-sensitive
applications, such as serial communications,
require the uninterrupted operation of peripherals,
the CPU clock speed can be selectively reduced,
allowing incremental power savings without
missing a beat.
• Instruction-Based Power-Saving Modes: The
microcontroller can suspend all operations, or
selectively shut down its core while leaving its
peripherals active, with a single instruction in
software.
1.1.3OSCILLATOR OPTIONS AND
FEATURES
All of the devices in the PIC24FJ128GA family offer five
different oscillator options, allowing users a range of
choices in developing application hardware. These
include:
• Two Crystal modes, using crystals or ceramic
resonators.
• Two External Clock modes, offering the option of
a divide-by-2 clock output.
• A Fast Internal Oscillator (FRC) with a nominal
8 MHz output, which can also be divided under
software control to provide clock speeds as low as
31 kHz.
• A Phase Lock Loop (PLL) frequency multiplier,
available to the external oscillator modes and the
FRC oscillator, which allows clock speeds of up to
32 MHz.
• A separate internal RC oscillator (LPRC) with a
fixed 31 kHz output, which provides a low-power
option for timing-insensitive applications.
The internal oscillator block also provides a stable reference source for the Fail-Safe Clock Monitor. 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.
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 to the next larger
device. This is true when moving between devices with
the same pin count, or even jumping from 64-pin to
80-pin to 100-pin devices.
The PIC24 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 select a
Microchip device.
1.2Other Special Features
• Communications: The PIC24FJ128GA family
incorporates a range of serial communication
peripherals to handle a range of application
requirements. All devices are equipped with two
independent UARTs with built-in IrDA
encoder/decoders. There are also two independent SPI modules, and two independent I
modules that support both Master and Slave
modes of operation.
• Parallel Master/Enhanced Parallel Slave Port:
One of the general purpose I/O ports can be
reconfigured for enhanced parallel data communications. In this mode, the port can be configured
for both master and slave operations, and
supports 8-bit and 16-bit data transfers with up to
16 external address lines in Master modes.
• Real-Time Clock/Calendar: 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.
• 10-Bit A/D Converter: This module incorporates
programmable acquisition time, allowing for a
channel to be selected and a conversion to be
initiated without waiting for a sampling period, as
well as faster sampling speeds.
2
C
1.3Details on Individual Family
Members
Devices in the PIC24FJ128GA family are available in
64-pin, 80-pin and 100-pin packages. The general
block diagram for all devices is shown in Figure 1-1.
The devices are differentiated from each other in two
ways:
1. Flash program memory (64 Kbytes for
PIC24FJ64GA devices, 96 Kbytes for
PIC24FJ96GA devices and 128 Kbytes for
PIC24FJ128GA devices).
2.Available I/O pins and ports (53 pins on 6 ports
for 64-pin devices, 69 pins on 7 ports for 80-pin
devices and 84 pins on 7 ports for 100-pin
devices).
All other features for devices in this family are identical.
These are summarized in Table 1-1.
A list of the pin features available on the
PIC24FJ128GA family devices, sorted by function, is
shown in Table 1-2. 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
the data sheet. Multiplexed features are sorted by the
priority given to a feature, with the highest priority
peripheral being listed first.
The PIC24 CPU has a 16-bit (data) modified Harvard
architecture with an enhanced instruction set, and a
23-bit instruction word with a variable length opcode
field. The Program Counter (PC) is 24 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.
PIC24 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 16th working register (W15) operates as
a software Stack Pointer for interrupts and calls.
The upper 32 Kbytes of the data space memory map
can optionally be mapped into program space at any
16K word boundary defined by the 8-bit Program
Space Visibility Page (PSVPAG) register. The program
to data space mapping feature lets any instruction
access program space as if it were data space.
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.
The core supports Inherent (no operand), Relative,
Literal, Memory Direct and three groups of addressing
modes. All modes support Register Direct and various
Register Indirect modes. Each group offers up to 7
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 (that is, A + B = C) to be
executed in a single cycle.
A high-speed 17-bit by 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 by 16-bit or
8-bit by 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 PIC24 has a vectored exception scheme with up
to 8 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 2-1.
2.1Programmer’s Model
The programmer’s model for the PIC24 is shown in
Figure 2-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 Table 2-1. All registers associated with the
programmer’s model are memory mapped.
1 = A carry-out from the 4th 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-5IPL2:IPL0: CPU Interrupt Priority Level Status bits
111 = CPU interrupt priority level is 7 (15). User interrupts 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: The IPL Status bits are read-only when NSTDIS (INTCON1<15>) = 1.
2: The IPL bits are concatenated with the IPL3 bit (CORCON<3>) to form the CPU interrupt priority
level. The value in parentheses indicates the IPL when IPL3 = 1.
bit 4RA: REPEAT Loop Active bit
1 = REPEAT loop in progress
0 = REPEAT loop not in progress
bit 3N: ALU Negative bit
1 = Result was negative
0 = Result was non-negative (zero or positive)
bit 2OV: ALU Overflow bit
1 = Overflow occurred for signed (2’s complement) arithmetic in this arithmetic operation
0 = No overflow has occurred
bit 1Z: ALU Zero bit
1 = An operation which effects the Z bit has set it at some time in the past
0 = The most recent operation which effects the Z bit has cleared it (i.e., a non-zero result)
bit 0C: ALU Carry/Borrow
1 = A carry-out from the Most Significant bit of the result occurred
0 = No carry-out from the Most Significant bit of the result occurred
R/W-0
IPL1
bit
(2)
(1)
R/W-0
IPL0
(2)
(1)
R-0R/W-0R/W-0R/W-0R/W-0
RANOVZC
(2)
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 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
Note:User interrupts are disabled when IPL3 = 1.
bit 2PSV: Program Space Visibility in Data Space Enable bit
1 = Program space visible in data space
0 = Program space not visible in data space
bit 1-0Unimplemented: Read as ‘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
2.3Arithmetic Logic Unit (ALU)
The PIC24 ALU is 16 bits wide and is capable of addition, subtraction, bit shifts and logic operations. Unless
otherwise mentioned, arithmetic operations are 2’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.
and Digit Borrow bits, respectively,
The PIC24 CPU incorporates hardware support for
both multiplication and division. This includes a dedicated hardware multiplier and support hardware for
16-bit divisor division.
2.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:
The divide block supports 32-bit/16-bit and 16-bit/16-bit
signed and unsigned integer divide operation 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. 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
(m+1):Wm) for the 32-bit dividend. The divide algo-
(W
rithm 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.
2.3.3MULTI-BIT SHIFT SUPPORT
The PIC24 ALU supports both single-bit and
single-cycle, multi-bit arithmetic and logic shifts.
Multi-bit 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
multi-bit 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 below in Table 2-2.
TABLE 2-2:INSTRUCTIONS THAT USE THE SINGLE AND MULTI-BIT SHIFT OPERATION
InstructionDescription
ASRArithmetic shift right source register by one bit.
ASRFArithmetic shift right the content of the register by one bit.
ASRWArithmetic shift right source register by up to 15 bits, value held in the W register referenced
within instruction.
ASRKArithmetic shift right source register up to 15 bits. Shift value is literal.
SLShift left source register by one bit.
SLFShift left the content of the file register by one bit.
SLWShift left source register by up to 15 bits, value held in the W register referenced instruction.
SLKShift left source register up to 15 bits. Shift value is literal.
LSRLogical shift right source register by one bit.
LSRFLogical shift right the content of the register by one bit.
LSRWLogical shift right source register by up to 15 bits, value held in the W register referenced
within instruction.
LSRKLogical shift right source register up to 15 bits. Shift value is literal.
As Harvard architecture devices, PIC24 microcontrollers feature separate program and data memory
spaces and busses. This architecture also allows the
direct access of program memory from the data space
during code execution.
3.1Program Address Space
The program address memory space of
PIC24FJ128GA 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 3.3 “InterfacingProgram 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 Device ID sections of the
configuration memory space.
The program memory space is organized in word
addressable 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 3-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.
3.1.2HARD MEMORY VECTORS
All PIC24 devices reserve the addresses between
00000h 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 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.
PIC24 devices also have two interrupt vector tables,
located from 000004h to 0000FFh and 000100h to
0001FFh. These vector tables allow each of the many
device interrupt sources to be handled by separate
ISRs. A more detailed discussion of the interrupt vector
tables is provided in Section 6.1 “Interrupt VectorTabl e”.
3.1.3FLASH CONFIGURATION WORDS
In PIC24FJ128GA family devices, the top two words of
on-chip program memory are reserved for configuration information. On device Reset, the configuration
information is copied into the appropriate Configuration
registers. The addresses of the Flash Configuration
Word for devices in the PIC24FJ128GA family are
shown in Table 3-1. Their location in the memory map
is shown with the other memory vectors in Figure 3-1.
The Configuration Words in program memory are a
compact format. The actual Configuration bits are
mapped in several different registers in the configuration memory space. Their order in the Flash Configuration Words do not reflect a corresponding arrangement
in the configuration space. Additional details on the
device Configuration Words are provided in
The PIC24 core has a separate 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 3-3.
All Effective Addresses (EAs) in the data memory
space are 16 bits wide, and point to bytes within the
data space. This gives a data space address range of
64 Kbytes, or 32K words. The lower half of the data
memory space (that is, when EA<15> = 0) is used for
implemented memory addresses, while the upper half
(EA<15> = 1) is reserved for the Program Space Visibility area (see Section 3.3.3 “Reading Data fromProgram Memory Using Program Space Visibility”).
PIC24FJ128GA family devices implement a total of
8 Kbytes of data memory. Should an EA point to a location outside of this area, an all zero word or byte will be
returned.
3.2.1DATA SPACE WIDTH
The data memory space is organized in byte addressable, 16-bit wide blocks. Data is aligned in data
memory and registers as 16-bit words, but all data
space EAs resolve to bytes. The Least Significant
Bytes of each word have even addresses, while the
Most Significant Bytes have odd addresses.
FIGURE 3-3:DATA SPACE MEMORY MAP FOR PIC24FJ128GA FAMILY DEVICES
To maintain backward compatibility with PICmicro
devices and improve data space memory usage efficiency, the PIC24 instruction set supports both word
and byte operations. As a consequence of byte accessibility, all effective address 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
Least Significant Byte. The Most Significant Byte is not
modified.
A sign-extend instruction (SE) 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.
3.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.
3.2.4SFR 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 PIC24 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 SFRs are actually implemented, is
shown in Table 3-2. Each implemented area indicates
a 32-byte region where at least one address is implemented as an SFR. A complete listing of implemented
SFRs, including their addresses, is shown in Tables 3-3
through 3-30.
Legend:— = unimplemented, read as ‘0’. Reset values are shown in hexadecimal.
TABLE 3-29:NVM REGISTER MAP
Note 1:Reset value shown is for POR only. Value on other Reset states is dependent on the state of memory write or erase operations at the time of Reset.
In addition to its use as a working register, the W15 register in PIC24 devices is also used as a software Stack
Pointer. 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-increments for
stack pushes, as shown in Figure 3-4. Note that for a
PC push during any CALL instruction, 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 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’
because 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.
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 Special Function Register (SFR)
space.
A write to the SPLIM register should not be immediately
followed by an indirect read operation using W15.
FIGURE 3-4:CALL STACK FRAME
0000h
Stack Grows Towards
000000000
Higher Address
PC<15:0>
PC<22:16>
<Free Word>
015
W15 (before CALL)
W15 (after CALL)
POP : [--W15]
PUSH : [W15++]
3.3Interfacing Program and Data
Memory Spaces
The PIC24 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 this
data successfully, it must be accessed in a way that
preserves the alignment of information in both spaces.
Aside from normal execution, the PIC24 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.
3.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 Page 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 Most Significant bit of TBLPAG is 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 8-bit Program Space
Visibility register (PSVPAG) is used to define a
16K word page in the program space. When the Most
Significant bit of the EA is ‘1’, PSVPAG is concatenated
with the lower 15 bits of the EA to form a 23-bit program
space address. Unlike table operations, this limits
remapping operations strictly to the user memory area.
Table 3-31 and Figure 3-5 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.
3.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 8 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>)
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’.
to a data address (D<15: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 explained in Section 4.0 “FlashProgram Memory”.
For all table operations, the area of program memory
space to be accessed is determined by the Table Page
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 and only
then, in implemented areas such as the
Device ID. Table write operations are not
allowed.
FIGURE 3-6:ACCESSING PROGRAM MEMORY WITH TABLE INSTRUCTIONS
Program Space
TBLPAG
02
23150
000000h
020000h
030000h
800000h
00000000
00000000
00000000
00000000
‘Phantom’ Byte
TBLRDH.B (Wn<0> = 0)
TBLRDL.B (Wn<0> = 1)
TBLRDL.B (Wn<0> = 0)
TBLRDL.W
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.
3.3.3READING DATA FROM PROGRAM
MEMORY USING PROGRAM
SPACE VISIBILITY
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
if the Most Significant bit of the data space EA is ‘1’ and
program space visibility is enabled by setting the PSV
bit in the Core Control register (CORCON<2>). The
location of the program memory space to be mapped
into the data space is determined by the Program
Space Visibility Page register (PSVPAG). This 8-bit
register defines any one of 256 possible pages of
16K words in program space. In effect, PSVPAG functions as the upper 8 bits of the program memory
address, with the 15 bits of the EA functioning as the
lower bits. Note that by incrementing the PC by 2 for
each program memory word, the lower 15 bits of data
space addresses directly map to the lower 15 bits in the
corresponding program space addresses.
Data reads to this area add an additional cycle to the
instruction being executed, since two program memory
fetches are required.
Although each data space address, 8000h and higher,
maps directly into a corresponding program memory
address (see Figure 3-7), only the lower 16 bits of the
24-bit program word are used to contain the data. The
upper 8 bits of any program space locations used as
data should be programmed with ‘1111 1111’ or
‘0000 0000’ to force a NOP. This prevents possible
issues should the area of code ever be accidentally
executed.
Note:PSV access is temporarily disabled during
table reads/writes.
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.
FIGURE 3-7:PROGRAM SPACE VISIBILITY OPERATION
When CORCON<2> = 1 and EA<15> = 1:
Program Space
PSVPAG
02
The data in the page
designated by
PSVPAG is mapped
into the upper half of
the data memory
space....
23150
000000h
010000h
018000h
800000h
Data Space
PSV Area
0000h
8000h
FFFFh
Data EA<14:0>
...while the lower 15
bits of the EA specify
an exact address
within the PSV area.
This corresponds
exactly to the same
lower 15 bits of the
actual program space
address.
of this group of PIC24FJ devices. It is not
intended to be a comprehensive reference
source.
The PIC24FJ128GA family of devices contains internal
Flash program memory for storing and executing application code. The memory is readable, writable and
erasable during normal operation over the entire V
range.
Flash memory can be programmed in two ways:
1.In-Circuit Serial Programming (ICSP)
2.Run-Time Self-Programming (RTSP)
ICSP allows a PIC24FJ128GA family device to be serially programmed while in the end application circuit.
This is simply done with two lines for Programming
Clock and Programming Data (which are named PGCx
and PGDx, respectively), and three other lines for
power (V
DD), ground (VSS) 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 64 instructions (192 bytes) at a time, and erase program memory
in blocks of 512 instructions (1536 bytes) at a time.
4.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 bits<7:0> of the TBLPAG register and the
Effective Address (EA) from a W register specified in
the table instruction, as shown in Figure 4-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 PIC24 Flash program memory array is organized
into rows of 64 instructions or 192 bytes. RTSP allows
the user to erase blocks of eight rows (512 instructions)
at a time, and to program one row at a time. The 8-row
erase blocks and single-row write blocks are edgealigned, from the beginning of program memory, on
boundaries of 1536 bytes and 192 bytes, respectively.
The program memory implements holding buffers that
can contain 64 instructions of programming data. Prior
to the actual programming operation, the write data
must be loaded into the buffers in sequential order. The
instructions words loaded must always be from a group
of 64 boundaries.
The basic sequence for RTSP programming is to set up
a Table Pointer, then do a series of TBLWT instructions
to load the buffers. Programming is performed by setting the control bits in the NVMCON register. A total of
64 TBLWTL and TBLWTH instructions are required to
load the instructions.
All of the table write operations are single-word writes
(2 instruction cycles), because only the buffers are written. A programming cycle is required for programming
each row.
4.3Control Registers
There are two SFRs used to read and write the
program Flash memory: NVMCON and NVMKEY.
The NVMCON register (Register 4-1) controls which
blocks are to be erased, which memory type is to be
programmed and the start of the programming cycle.
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 4.4 “Programming
Operations” for further details.
4.4Programming Operations
A complete programming sequence is necessary for
programming or erasing the internal Flash in RTSP
mode. A programming operation is nominally 4 ms in
duration and 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.
1 = An improper program or erase sequence attempt or termination has occurred (bit is set automatically
on any set attempt of the WR bit)
0 = The program or erase operation completed normally
bit 12-7Unimplemented: Read as ‘0’
bit 6ERASE: Erase/Program Enable bit
1 = Perform the erase operation specified by NVMOP3:NVMOP0 on the next WR command
0 = Perform the program operation specified by NVMOP3:NVMOP0 on the next WR command
bit 5-4Unimplemented: Read as ‘0’
bit 3-0NVMOP3:NVMOP0: NVM Operation Select bits
1111 = Memory bulk erase operation (ERASE = 1) or no operation (ERASE = 0)
0010 = Memory row erase operation (ERASE = 1) or no operation (ERASE = 0)
0001 = Memory row program operation (ERASE = 0) or no operation (ERASE = 1)
(2)
(1)
(2)
NVMOP2
R/W-0
(1)
(2)
R/W-0
NVMOP1
(1)
(2)
R/W-0
NVMOP0
(1)
(2)
Note 1: These bits can only be reset on POR.
2: All other combinations of NVMOP3:NVMOP0 are unimplemented.
Legend:
R = Readable bitW = Writable bitSO = Settable-Only bit U = Unimplemented bit
-n = Value at Reset‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
4.4.1PROGRAMMING ALGORITHM FOR
FLASH PROGRAM MEMORY
The user can program one row of program Flash 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
(512 instructions) and store in data RAM.
2.Update the program data in RAM with the
desired new data.
3.Erase the block (see Example 4-1):
a)Set the NVMOP bits (NVMCOM<3:0>) to
‘0010’ to configure for block erase. Set the
ERASE (NVMCOM<6>) and WREN
(NVMCOM<14>) bits.
b)Write the starting address of the block to be
erased into the TBLPAG and W registers.
c)Write 55h to NVMKEY.
d)Write AAh to NVMKEY.
e)Set the WR bit (NVMCOM<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.Write the first 64 instructions from data RAM into
the program memory buffers (see Example 4-2).
5.Write the program block to Flash memory:
a)Set the NVMOP bits to ‘0001’ to configure
for row programming. Clear the ERASE bit
and 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 mem-
ory is done, the WR bit is cleared automati-
cally.
6.Repeat steps 4 and 5, using the next available
64 instructions from the block in data RAM by
incrementing the value in TBLPAG, until all
512 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 4-3.
EXAMPLE 4-1:ERASING A PROGRAM MEMORY BLOCK
; Set up NVMCON for block erase operation
MOV#0x4042, W0;
; Init pointer to row to be ERASED
MOVW0, NVMCON; Initialize NVMCON
MOV#tblpage(PROG_ADDR), W0;
MOVW0, TBLPAG; Initialize PM Page Boundary SFR
MOV#tbloffset(PROG_ADDR), W0; Initialize in-page EA[15:0] pointer
TBLWTL W0, [W0] ; Set base address of erase block
DISI#5; Block all interrupts with priority <7
; for next 5 instructions
MOV#0x55, W0
MOVW0, NVMKEY ; Write the 55 key
MOV #0xAA, W1 ;
MOVW1, NVMKEY ; Write the AA key
BSETNVMCON, #WR; Start the erase sequence
NOP ; Insert two NOPs after the erase
NOP; command is asserted
; Set up a pointer to the first program memory location to be written
; program memory selected, and writes enabled
; Perform the TBLWT instructions to write the latches
; 0th_program_word
; 1st_program_word
; 2nd_program_word
; 63rd_program_word
MOV#0x4001, W0;
MOVW0, NVMCON; Initialize NVMCON
MOV#0x0000, W0;
MOVW0, TBLPAG; Initialize PM Page Boundary SFR
MOV#0x6000, W0; An example program memory address
MOV#LOW_WORD_0, W2;
MOV#HIGH_BYTE_0, W3;
TBLWTLW2, [W0]; Write PM low word into program latch
TBLWTHW3, [W0++]; Write PM high byte into program latch
MOV#LOW_WORD_1, W2;
MOV#HIGH_BYTE_1, W3 ;
TBLWTLW2, [W0]; Write PM low word into program latch
TBLWTHW3, [W0++] ; Write PM high byte into program latch
[W0] ; Write PM low word into program latch
[W0++]; Write PM high byte into program latch
[W0] ; Write PM low word into program latch
[W0++]; Write PM high byte into program latch
EXAMPLE 4-3:INITIATING A PROGRAMMING SEQUENCE
DISI#5; Block all interrupts with priority <7
MOV#0x55, W0
MOVW0, NVMKEY ; Write the 55 key
MOV #0xAA, W1 ;
MOVW1, NVMKEY ; Write the AA key
BSETNVMCON, #WR; Start the erase sequence
NOP ; Insert two NOPs after the
NOP; erase command is asserted
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
: Pin Reset
•SWR: RESET Instruction
• WDT: Watchdog Timer Reset
• BOR: Brown-out 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 5-1.
Any active source of Reset will make the SYSRST
nal 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.
FIGURE 5-1:RESET SYSTEM BLOCK DIAGRAM
RESET
Instruction
. The
sig-
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 5-1). A POR will clear all bits except for
the BOR and POR bits (RCON<1:0>), 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 manual.
Note:The status bits in the RCON register
should be cleared after they are read so
that the next RCON register value after a
device Reset will be meaningful.
1 = A Trap Conflict Reset has occurred
0 = A Trap Conflict Reset has not occurred
bit 14IOPUWR: Illegal Opcode or Uninitialized W Access Reset Flag bit
1 = An illegal opcode detection, an illegal address mode, or uninitialized W register used as an Address
Pointer caused a Reset
0 = An illegal opcode or uninitialized W Reset has not occurred
bit 13-10 Unimplemented: Read as ‘0’
bit 9CM: Configuration Word Mismatch Reset Flag bit
1 = A Configuration Word Mismatch Reset has occurred
0 = A Configuration Word Mismatch Reset has not occurred
bit 8VREGS: Voltage Regulator Standby Enable bit
1 = Regulator remains active during Sleep
0 = Regulator goes to standby during Sleep
bit 7EXTR: External Reset (MCLR
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 = A RESET instruction has been executed
0 = A RESET instruction has not been executed
bit 5SWDTEN: Software Enable/Disable of WDT bit
1 = WDT is enabled
0 = WDT is disabled
Note:If the FWDTEN Configuration bit is ‘1’ (unprogrammed), the WDT is always enabled, regardless
of the SWDTEN bit setting.
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 = Device has been in Sleep mode
0 = Device has not been in Sleep mode
bit 2IDLE: Wake-up From Idle Flag bit
1 = Device was in Idle mode
0 = Device was not in Idle mode
bit 1BOR: Brown-out Reset Flag bit
1 = A Brown-out Reset has occurred. Note that BOR is also set after Power-on Reset.
0 = A Brown-out Reset has not occurred
bit 0POR: Power-on Reset Flag bit
1 = A Power-up Reset has occurred
0 = A Power-up Reset has not occurred
Note: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.
————CMVREGS
) Pin bit
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
IOPR (RCON<14>)Illegal opcode or uninitialized W register accessPOR
EXTR (RCON<7>)MCLR
SWR (RCON<6>)RESET instructionPOR
WDTO (RCON<4>)WDT time-outPWRSAV instruction, POR
SLEEP (RCON<3>)PWRSAV #SLEEP instructionPOR
IDLE (RCON<2>)PWRSAV #IDLE instructionPOR
BOR (RCON<1>)POR, BOR—
POR (RCON<0>)POR—
Note: All Reset flag bits may be set or cleared by the user software.
ResetPOR
5.1Clock Source Selection at Reset
If clock switching is enabled, the system clock source
at device Reset is chosen as shown in Table 5-2. If
clock switching is disabled, the system clock source is
always selected according to the oscillator Configuration bits. Refer to 7.0 “Oscillator Configuration” for
further details.
TABLE 5-2:OSCILLATOR SELECTION vs.
TYPE OF RESET (CLOCK
SWITCHING ENABLED)
Reset TypeClock Source Determinant
POROscillator Configuration Bits
BOR
MCLR
WDTR
SWR
(FNOSC2:FNOSC0)
COSC Control bits
(OSCCON<14:12>)
5.2Device Reset Times
The Reset times for various types of device Reset are
summarized in Table 5-3. Note that the system Reset
signal, SYSRST, is released after the POR and PWRT
delay times expire.
The time that 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 FSCM delay determines the time at which the
FSCM begins to monitor the system clock source after
the SYSRST
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
low-frequency 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).
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.
is released:
5.2.2FAIL-SAFE CLOCK MONITOR
(FSCM) AND DEVICE RESETS
If the FSCM is enabled, it will begin to monitor the system clock source when SYSRST
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.
5.2.2.1FSCM Delay for Crystal and PLL
Clock Sources
When the system clock source is provided by a crystal
oscillator and/or the PLL, a small delay, T
automatically be inserted after the POR and PWRT
delay times. The FSCM will not begin to monitor the
system clock source until this delay expires. The FSCM
delay time is nominally 100 μs and provides additional
time for the oscillator and/or PLL to stabilize. In most
cases, the FSCM delay will prevent an oscillator failure
trap at a device Reset when the PWRT is disabled.
FSCM, will
5.3Special Function Register Reset
States
Most of the Special Function Registers (SFRs) associated with the PIC24 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 oscillator Configuration bits in the FOSC
Device Configuration register (see Table 5-2). The
RCFGCAL and EECON1 registers are only affected by
a POR.
The PIC24 interrupt controller reduces the numerous
peripheral interrupt request signals to a single interrupt
request signal to the PIC24 CPU. It has the following
features:
• Up to 8 processor exceptions and software traps
• 7 user-selectable priority levels
• Interrupt Vector Table (IVT) with up to 118 vectors
• A unique vector for each interrupt or exception
source
• Fixed priority within a specified user priority level
• Alternate Interrupt Vector Table (AIVT) for debug
support
• Fixed interrupt entry and return latencies
6.1Interrupt Vector Table
The Interrupt Vector Table (IVT) is shown in Figure 6-1.
The IVT resides in program memory, starting at location
000004h. The IVT contains 126 vectors, consisting of 8
non-maskable trap vectors, plus 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 is linked to their position in the vector table.
All other things being equal, lower addresses have a
higher natural priority. For example, the interrupt associated with vector 0 will take priority over interrupts at
any other vector address.
PIC24FJ128GA family devices implement nonmaskable traps and unique interrupts. These are
summarized in Table 6-1 and Table 6-2.
6.1.1ALTERNATE INTERRUPT VECTOR
TAB LE
The Alternate Interrupt Vector Table (AIVT) is located
after the IVT as shown in Figure 6-1. Access to the
AIVT is provided by the ALTIVT control bit
(INTCON2<15>). If the ALTIVT 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
The PIC24FJ128GA family devices implement a total
of 28 registers for the interrupt controller:
• INTCON1
• INTCON2
• IFS0 through IFS4
• IEC0 through IEC4
• IPC0 through IPC14, and IPC16
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 the external interrupt
request signal behavior and the use of the Alternate
Interrupt Vector Table.
The IFS 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.
The IEC registers maintain all of the interrupt enable
bits. These control bits are used to individually enable
interrupts from the peripherals or external signals.
The IPC registers are used to set the interrupt priority
level for each source of interrupt. Each user interrupt
source can be assigned to one of eight priority levels.
The interrupt sources are assigned to the IFSx, IECx
and IPCx registers in the same sequence that they are
listed in Table 6-2. For example, the INT0 (External
Interrupt 0) is shown as having a vector number and a
natural order priority of 0. Thus, the INT0IF status bit is
found in IFS0<0>, the enable bit in IEC0<0> and the
priority bits in the first position of IPC0 (IPC0<2:0>).
Although they are not specifically part of the interrupt
control hardware, two of the CPU control registers contain bits that control interrupt functionality. The CPU
STATUS register (SR) contains the IPL2:IPL0 bits
(SR<7:5>). These indicate the current CPU interrupt
priority level. The user may change the current CPU
priority level by writing to the IPL bits.
The CORCON register contains the IPL3 bit, which
together with IPL2:IPL0, also indicates the current CPU
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 6-1
through Register 6-30, in the following pages.
bit 7-5IPL2:IPL0: CPU Interrupt Priority Level Status bits
111 = CPU interrupt priority level is 7 (15). User interrupts 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: The IPL bits are concatenated with the IPL3 bit (CORCON<3>) to form the CPU interrupt priority
level. The value in parentheses indicates the IPL if IPL3 = 1.
2: The IPL Status bits are read-only when NSTDIS (INTCON1<15>) = 1.
.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
(1,2)
REGISTER 6-2:CORCON: CORE CONTROL REGISTER
Upper Byte:
U-0U-0U-0U-0U-0U-0U-0U-0
————————
bit 15bit 8
Lower Byte:
U-0U-0U-0U-0R/C-0R/W-0U-0U-0
————IPL3
bit 7bit 0
bit 3IPL3: CPU Interrupt Priority Level Status bit
1 = CPU interrupt priority level is greater than 7; peripheral interrupts are disabled
0 = CPU interrupt priority level is 7 or less
Note 1: The IPL3 bit is concatenated with the IPL2:IPL0 bits (SR<7:5>) to form the CPU interrupt priority
level.
.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
1.Set the NSTDIS Control bit (INTCON1<15>) if
nested interrupts are not desired.
2.Select the user-assigned priority level for the
interrupt source by writing the control bits in the
appropriate IPCx Control register. The priority
level will depend on the specific application and
type of interrupt source. If multiple priority levels
are not desired, the IPCx register control bits for
all enabled interrupt sources may be
programmed to the same non-zero value.
Note:At a device Reset, the IPC registers are
initialized, such that all user interrupt
sources are assigned to priority level 4.
3.Clear the interrupt flag status bit associated with
the peripheral in the associated IFSx Status
register.
4.Enable the interrupt source by setting the interrupt enable control bit associated with the
source in the appropriate IECx Control register.
6.4.2INTERRUPT SERVICE ROUTINE
The method that is used to declare an ISR and initialize
the IVT with the correct vector address will depend on
the programming language (i.e., ‘C’ or assembler) and
the language development toolsuite that is used to
develop the application. In general, the user must clear
the interrupt flag in the appropriate IFSx register for the
source of interrupt that the ISR handles. Otherwise, the
ISR will be re-entered immediately after exiting the routine. If the ISR is coded in assembly language, it must
be terminated using a RETFIE instruction to unstack
the saved PC value, SRL value and old CPU priority
level.
6.4.3TRAP SERVICE ROUTINE
A Trap Service Routine (TSR) is coded like an ISR,
except that the appropriate trap status flag in the
INTCON1 register must be cleared to avoid re-entry
into the TSR.
6.4.4INTERRUPT DISABLE
All user interrupts can be disabled using the following
procedure:
1.Push the current SR value onto the software
stack using the PUSH instruction.
2.Force the CPU to priority level 7 by inclusive
ORing the value OEh with SRL.
To enable user interrupts, the POP instruction may be
used to restore the previous SR value.
Note that only user interrupts with a priority level of 7 or
less can be disabled. Trap sources (level 8-15) cannot
be disabled.
The DISI instruction provides a convenient way to disable interrupts of priority levels 1-6 for a fixed period of
time. Level 7 interrupt sources are not disabled by the
DISI instruction.
of this group of PIC24FJ devices. It is not
intended to be a comprehensive reference
source.
The oscillator system for PIC24FJ128GA family
devices has the following features:
• A total of four external and internal oscillator options
as clock sources, providing 11 different clock modes
• On-chip 4x PLL to boost internal operating frequency
on select internal and external oscillator sources
• Software-controllable switching between various
clock sources
• Software-controllable postscaler for selective
clocking of CPU for system power savings
• A Fail-Safe Clock Monitor (FSCM) that detects
clock failure and permits safe application recovery
or shutdown
A simplified diagram of the oscillator system is shown
in Figure 7-1.
FIGURE 7-1:PIC24FJ128GA FAMILY CLOCK DIAGRAM
PIC24FJ128GA Family
Secondary Oscillator
SOSCO
SOSCEN
SOSCI
Enable
Oscillator
7.1CPU Clocking Scheme
The system clock source can be provided by one of
four sources:
• Primary Oscillator (POSC) on the OSC1 and
OSC2 pins
• Secondary Oscillator (SOSC) on the SOSCI and
SOSCO pins
• Fast Internal RC (FRC) Oscillator
• Low-Power Internal RC (LPRC) Oscillator
Clock Source Option
The primary oscillator and FRC sources have the
option of using the internal 4x PLL. The frequency of
the FRC clock source can optionally be reduced by the
programmable clock divider. 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
document, the instruction cycle clock is also denoted
by F
OSC/2. The internal instruction cycle clock, FOSC/2,
can be provided on the OSC2 I/O pin for some
operating modes of the primary oscillator.
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 23.1 “Configuration Bits” for further
details.) The Primary Oscillator Configuration bits,
POSCMD1:POSCMD0 (Configuration Word 2<1:0>),
and the Initial Oscillator Select Configuration bits,
FNOSC2:FNOSC0 (Configuration Word 2<10:8>),
select the oscillator source that is used at a Power-on
Reset. The FRC primary oscillator with postscaler
(FRCDIV) is the default (unprogrammed) selection.
The secondary oscillator, or one of the internal
oscillators, may be chosen by programming these bit
locations.
The Configuration bits allow users to choose between
the various clock modes, shown in Table 7-1.
7.2.1CLOCK SWITCHING MODE
CONFIGURATION BITS
The FCKSM Configuration bits (Configuration Word 2<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 FCKSM1:FCKSM0 are
both programmed (‘00’).
TABLE 7-1:CONFIGURATION BIT VALUES FOR CLOCK SELECTION
Oscillator ModeOscillator Source
Fast RC Oscillator with Postscaler
(FRCDIV)
(Reserved)Internal001101
Low-Power RC Oscillator (LPRC)Internal001011
Secondary (Timer1) Oscillator
(SOSC)
Primary Oscillator (HS) with PLL
Module (HSPLL)
Primary Oscillator (XT) with PLL
Module (ECPLL)
Primary Oscillator (EC) with PLL
Module (XTPLL)
Primary Oscillator (HS)Primary10010
Primary Oscillator (XT)Primary01010
Primary Oscillator (EC)Primary00010
Fast RC Oscillator with PLL Module
(FRCPLL)
Fast RC Oscillator (FRC)Internal000001
Note 1:OSC2 pin function is determined by the OSCIOFNC Configuration bit.
2:This is the default oscillator mode for an unprogrammed (erased) device.
Internal00111 1, 2
Secondary001001
Primary10011
Primary01011
Primary00011
Internal000011
POSCMD1:
POSCMD0
FNOSC2:
FNOSC0
Note
7.3Control Registers
The operation of the oscillator is controlled by three
Special Function Registers:
• OSCCON
•CLKDIV
•OSCTUN
The OSCCON register (Register 7-1) is the main control register for the oscillator. It controls clock source
switching, and allows the monitoring of clock sources.
The Clock Divider register (Register 7-2) controls the
features associated with Doze mode, as well as the
postscaler for the FRC oscillator.
The FRC Oscillator Tune register (Register 7-3) allows
the user to fine tune the FRC oscillator over a range of
approximately ±12%. Each bit increment or decrement
changes the factory calibrated frequency of the FRC
oscillator by a fixed amount.
PIC24FJ128GA FAMILY
REGISTER 7-1:OSCCON: OSCILLATOR CONTROL REGISTER
Upper Byte:
U-0R-0R-0R-0U-0R/W-x
—COSC2COSC1COSC0—NOSC2NOSC1NOSC0
bit 15bit 8
(1)
R/W-x
(1)
R/W-x
(1)
Lower Byte:
R/SO-0U-0R-0
CLKLOCK
bit 7bit 0
bit 15Unimplemented: Read as ‘0’
bit 14-12 COSC2:COSC0: Current Oscillator Selection bits
111 = Fast RC Oscillator with Postscaler (FRCDIV)
110 = Reserved
101 = Low-Power RC Oscillator (LPRC)
100 = Secondary Oscillator (SOSC)
011 = Primary Oscillator with PLL module (HSPLL, ECPLL)
010 = Primary Oscillator (XT, HS, EC)
001 = Fast RC Oscillator with postscaler and PLL module (FRCPLL)
000 = Fast RC Oscillator (FRC)
bit 11Unimplemented: Read as ‘0’
bit 10-8NOSC2:NOSC0: New Oscillator Selection bits
111 = Fast RC Oscillator with Postscaler (FRCDIV)
110 = Reserved
101 = Low-Power RC Oscillator (LPRC)
100 = Secondary Oscillator (SOSC)
011 = Primary Oscillator with PLL module (HSPLL, ECPLL)
010 = Primary Oscillator (XT, HS, EC)
001 = Fast RC Oscillator with postscaler and PLL module (FRCPLL)
000 = Fast RC Oscillator (FRC)
bit 7CLKLOCK: Clock Selection Lock Enabled bit
If FSCM is enabled (FCKSM1 =
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 (FCKSM1 = 0):
Clock and PLL selections are never locked and may be modified by setting the OSWEN bit.
bit 6Unimplemented: Read as ‘0’
bit 5LOCK: PLL Lock Status bit
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
bit 4Unimplemented: Read as ‘0’
bit 3CF: Clock Fail Detect bit
1 = FSCM has detected a clock failure
0 = No clock failure has been detected
bit 2Unimplemented: Read as ‘0’
bit 1SOSCEN: 32 kHz Secondary Oscillator (SOSC) Enable bit
1 = Enable secondary oscillator
0 = Disable secondary oscillator
bit 0OSWEN: Oscillator Switch Enable bit
1 = Initiate an oscillator switch to clock source specified by NOSC2:NOSC0 bits
0 = Oscillator switch is complete
Note 1: Reset values for these bits are determined by the FNOSC Configuration bits.
2: Also resets to ‘0’ during any valid clock switch, or whenever a non-PLL Clock mode is selected.
—LOCK—CF—SOSCENOSWEN
1):
(2)
U-0R/CO-0U-0R/W-0R/W-0
Legend:U = Unimplemented bit, read as ‘0’
R = Readable bitW = Writable bitCO = Clear-Only bitSO = Set-Only bit
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
000000 = Center frequency, oscillator is running at factory calibrated frequency
111111 =
•
•
•
100001 =
100000 = Minimum frequency deviation
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
7.4Clock Switching Operation
With few limitations, applications are free to switch
between any of the four clock sources (POSC, SOSC,
FRC and LPRC) under software control and at any
time. To limit the possible side effects that could result
from this flexibility, PIC24 devices have a safeguard
lock built into the switching process.
Note:Primary Oscillator mode has three
different submodes (XT, HS and EC)
which are determined by the POSCMD
Configuration bits. While an application
can switch to and from Primary Oscillator
mode in software, it cannot switch
between the different primary submodes
without reprogramming the device.
7.4.1ENABLING CLOCK SWITCHING
To enable clock switching, the FCKSM1 Configuration
bit in the Configuration register must be programmed to
‘0’. (Refer to Section 23.1 “Configuration Bits” for
further details.) If the FCKSM1 Configuration bit is
unprogrammed (‘1’), the clock switching function and
Fail-Safe Clock Monitor function are disabled. This is
the default setting.
The NOSC control bits (OSCCON<10:8>) do not
control the clock selection when clock switching is disabled. However, the COSC bits (OSCCON<14:12>)
will reflect the clock source selected by the FNOSC
Configuration bits.
The OSWEN control bit (OSCCON<0>) has no effect
when clock switching is disabled. It is held at ‘0’ at all
times.
At a minimum, performing a clock switch requires this
basic sequence:
1.If desired, read the COSC bits
(OSCCON<14:12>), to determine the current
oscillator source.
2.Perform the unlock sequence to allow a write to
the OSCCON register high byte.
3.Write the appropriate value to the NOSC control
bits (OSCCON<10:8>) for the new oscillator
source.
4.Perform the unlock sequence to allow a write to
the OSCCON register low byte.
5.Set the OSWEN bit to initiate the oscillator
switch.
Once the basic sequence is completed, the system
clock hardware responds automatically as follows:
1.The clock switching hardware compares the
COSC status bits with the new value of the
NOSC control bits. If they are the same, then the
clock switch is a redundant operation. In this
case, the OSWEN bit is cleared automatically
and the clock switch is aborted.
2.If a valid clock switch has been initiated, the
LOCK (OSCCON<5>) and CF (OSCCON<3>)
status bits are cleared.
3.The new oscillator is turned on by the hardware
if it is not currently running. If a crystal oscillator
must be turned on, the hardware will wait until
the OST expires. If the new source is using the
PLL, then the hardware waits until a PLL lock is
detected (LOCK = 1).
4.The hardware waits for 10 clock cycles from the
new clock source and then performs the clock
switch.
5.The hardware clears the OSWEN bit to indicate a
successful clock transition. In addition, the NOSC
bit values are transferred to the COSC status bits.
6.The old clock source is turned off at this time,
with the exception of LPRC (if WDT or FSCM
are enabled) or SOSC (if SOSCEN remains
set).
Note 1: The processor will continue to execute
code throughout the clock switching
sequence. Timing sensitive code should
not be executed during this time.
2: Direct clock switches between any
Primary Oscillator mode with PLL and
FRCPLL mode are not permitted. This
applies to clock switches in either direction. In these instances, the application
must switch to FRC mode as a transition
clock source between the two PLL
modes.
A recommended code sequence for a clock switch
includes the following:
1.Disable interrupts during the OSCCON register
unlock and write sequence.
2.Execute the unlock sequence for the OSCCON
high byte, by writing 78h and 9Ah to
OSCCON<15:8> in two back-to-back
instructions.
3.Write new oscillator source to the NOSC control
bits in the instruction immediately following the
unlock sequence.
4.Execute the unlock sequence for the OSCCON
low byte by writing 46h and 57h to
OSCCON<7:0> in two back-to-back instructions.
5.Set the OSWEN bit in the instruction immediately
following the unlock sequence.
6.Continue to execute code that is not clock
sensitive (optional).
7.Invoke an appropriate amount of software delay
(cycle counting) to allow the selected oscillator
and/or PLL to start and stabilize.
8.Check to see if OSWEN is ‘0’. If it is, the switch
was successful. If OSWEN is still set, then
check the LOCK bit to determine cause of
failure.
The core sequence for unlocking the OSCCON register
and initiating a clock switch is shown in Example 7-1.
of this group of PIC24FJ devices. It is not
intended to be a comprehensive reference
source.
The PIC24FJ128GA family of devices provide the ability
to manage power consumption by selectively managing
clocking to the CPU and the peripherals. In general, a
lower clock frequency and a reduction in the number of
circuits being clocked constitutes lower consumed
power. All PIC24F devices manage power consumption
in four different ways:
• Clock frequency
• Instruction-based Sleep and Idle modes
• Software-controlled Doze mode
• Selective peripheral control in software
Combinations of these methods can be used to selectively tailor an application’s power consumption, while
still maintaining critical application features, such as
timing sensitive communications.
8.1Clock Frequency and Clock
Switching
PIC24F devices allow for a wide range of clock
frequencies to be selected under application control. If
the system clock configuration is not locked, users can
choose low-power or high-precision oscillators by simply
changing the NOSC Configuration bits. The process of
changing a system clock during operation, as well as
limitations to the process, are discussed in more detail in
Section 7.0 “Oscillator Configuration”.
8.2Instruction-Based Power-Saving
Modes
PIC24F devices have two special power-saving modes
that are entered through the execution of a special
PWRSAV instruction. Sleep mode stops clock operation
and halts all code execution; Idle mode halts the CPU
and code execution, but allows peripheral modules to
continue operation. The assembly syntax of the
PWRSAV instruction is shown in Example 8-1.
Note:SLEEP_MODE and IDLE_MODE are con-
stants defined in the assembler include
file for the selected device.
Sleep and Idle modes can be exited as a result of an
enabled interrupt, WDT time-out or a device Reset.
When the device exits these modes, it is said to
“wake-up”.
8.2.1SLEEP MODE
Sleep mode has these features:
• The system clock source is shut down. If an
on-chip oscillator is used, it is turned off.
• The device current consumption will be reduced
to a minimum provided that no I/O pin is sourcing
current.
• The Fail-Safe Clock Monitor does not operate
during Sleep mode since the system clock source
is disabled.
• The LPRC clock will continue to run in Sleep
mode if the WDT is enabled.
• The WDT, if enabled, is automatically cleared
prior to entering Sleep mode.
• Some device features or peripherals may
continue to operate in Sleep mode. This includes
items such as the input change notification on the
I/O ports, or peripherals that use an external clock
input. Any peripheral that requires the system
clock source for its operation will be disabled in
Sleep mode.
The device will wake-up from Sleep mode on any of the
these events:
• On any interrupt source that is individually
enabled
• On any form of device Reset
• On a WDT time-out
On wake-up from Sleep, the processor will restart with
the same clock source that was active when Sleep
mode was entered.
EXAMPLE 8-1:PWRSAV INSTRUCTION SYNTAX
PWRSAV#SLEEP_MODE; Put the device into SLEEP mode
PWRSAV#IDLE_MODE; Put the device into IDLE mode
• The system clock source remains active. By
default, all peripheral modules continue to operate
normally from the system clock source, but can
also be selectively disabled (see Section 8.4 “Selective Peripheral Module Control”).
• If the WDT or FSCM is enabled, the LPRC will
also remain active.
The device will wake from Idle mode on any of these
events:
• Any interrupt that is individually enabled.
• Any device Reset.
• A WDT time-out.
On wake-up from Idle, the clock is re-applied to the
CPU and instruction execution begins immediately,
starting with the instruction following the PWRSAV
instruction, or the first instruction in the ISR.
8.2.3INTERRUPTS COINCIDENT WITH
POWER SAVE INSTRUCTIONS
Any interrupt that coincides with the execution of a
PWRSAV instruction will be held off until entry into Sleep
or Idle mode has completed. The device will then
wake-up from Sleep or Idle mode.
8.3Doze Mode
Generally, changing clock speed and invoking one of
the power-saving modes are the preferred strategies
for reducing power consumption. There may be circumstances, however, where this is not practical. For
example, it may be necessary for an application to
maintain uninterrupted synchronous communication,
even while it is doing nothing else. Reducing system
clock speed may introduce communication errors,
while using a power-saving mode may stop
communications completely.
Doze mode is a simple and effective alternative method
to reduce power consumption while the device is still
executing code. In this mode, the system clock continues to operate from the same source and at the same
speed. Peripheral modules continue to be clocked at the
same speed, while the CPU clock speed is reduced.
Synchronization between the two clock domains is
maintained, allowing the peripherals to access the SFRs
while the CPU executes code at a slower rate.
Doze mode is enabled by setting the DOZEN bit
(CLKDIV<11>). The ratio between peripheral and core
clock speed is determined by the DOZE2:DOZE0 bits
(CLKDIV<14:12>). There are eight possible
configurations, from 1:1 to 1:256, with 1:1 being the
default.
It is also possible to use Doze mode to selectively
reduce power consumption in event driven applications. This allows clock sensitive functions, such as
synchronous communications, to continue without
interruption while the CPU idles, waiting for something
to invoke an interrupt routine. Enabling the automatic
return to full-speed CPU operation on interrupts is
enabled by setting the ROI bit (CLKDIV<15>). By
default, interrupt events have no effect on Doze mode
operation.
8.4Selective Peripheral Module
Control
Idle and Doze modes allow users to substantially
reduce power consumption by slowing or stopping the
CPU clock. Even so, peripheral modules still remain
clocked and thus consume power. There may be cases
where the application needs what these modes do not
provide: the allocation of power resources to CPU
processing with minimal power consumption from the
peripherals.
PIC24F devices address this requirement by allowing
peripheral modules to be selectively disabled, reducing
or eliminating their power consumption. This can be
done with two control bits:
• The Peripheral Enable bit, generically named
“XXXEN”, located in the module’s main control
SFR.
• The Peripheral Module Disable (PMD) bit, generi-
cally named “XXXMD”, located in one of the PMD
control registers.
Both bits have similar functions in enabling or disabling
its associated module. Setting the PMD bit for a module
disables all clock sources to that module, reducing its
power consumption to an absolute minimum. In this
state, the control and status registers associated with the
peripheral will also be disabled, so writes to those registers will have no effect and read values will be invalid.
Many peripheral modules have a corresponding PMD
bit.
In contrast, disabling a module by clearing its XXXEN
bit disables its functionality, but leaves its registers
available to be read and written to. Power consumption
is reduced, but not by as much as the PMD bit does.
Most peripheral modules have an enable bit;
exceptions include Capture, Compare and RTCC.
To achieve more selective power savings, peripheral
modules can also be selectively disabled when the
device enters Idle mode. This is done through the
control bit of the generic name format “XXXIDL”. By
default, all modules that can operate during Idle mode
will do so. Using the disable on Idle feature allows further reduction of power consumption during Idle mode,
enhancing power savings for extremely critical power
applications.