Extended Data Space (EDS) on a 16-bit PIC® MCU

Last modified by Microchip on 2023/11/10 11:07

Certain PIC24 MCUs and dsPIC® Digital Signal Controller (DSC) have Extended Data Space (EDS), which gives the device the ability to map additional memory to the upper 32 kilobytes of data memory space. EDS devices are able to map extended internal data RAM, external RAM connected through the Parallel Master Port, or blocks of Flash program memory to the upper 32 kB of data memory space.

Please consult the datasheet of the part you are using to ensure EDS is available. Accessing Flash program memory for devices without EDS can be accomplished using Program Space Visibility (PSV).

The two registers used to control EDS access are:

  • DSRPAG EDS Read Page Register
  • DSWPAG EDS Write Page Register

The value stored in the EDS registers determines which blocks of memory are mapped into address 0x8000 - 0xFFFF.

DSRPAGDSWPAGAddress Referenced
in the Instruction
Effective AddressNotes
0x00000x00000x0000 - 0x7FFE0x0000 - 0x7FFFEData Memory
0x00000x00000x8000 - 0xFFFEInvalidAddress Trap Occurs

Diagram of Extended Data Space Memory

DSRPAGDSWPAGAddress Referenced
in the Instruction
Effective AddressNotes
0x00010x00010x8000 - 0xFFFE0x008000 - 0x00FFFEExtended Data Memory
0x00020x00020x8000 - 0xFFFE0x010000 - 0x017FFEExtended Data Memory
 …. 
0x01FF0x01FF0x8000 - 0xFFFE0xFF8000 - 0xFFFFFEExtended Data Memory

Diagram of Lower 16-bits of Program Memory Mapping into EDS

DSRPAGDSWPAGAddress Referenced
in the Instruction
Effective AddressNotes
0x0200n/a0x8000 - 0xFFFE0x000000 - 0x00FFFElower 16-bit of PM
 …. 
0x02FFn/a0x8000 - 0xFFFE0x7F8000 - 0x7FFFFElower 16-bit of PM

Diagram of Upper 8-bits of Program Memory Mapping into EDS

DSRPAGDSWPAGAddress Referenced
in the Instruction
Effective AddressNotes
0x0300n/a0x8001 - 0xFFFF0x000001 - 0x00FFFFUpper 8-bits of PM
 …. 
0x03FFn/a0x8001 - 0xFFFF0x7F8001 - 0x7FFFFFUpper 8-bits of PM

Back to top

Example

The PIC24FJ256DA210 has 96 kB of data memory. Addresses 0 - 30 K are accessed by the operand contained in the instruction and with DSRPAG/DSWPAG set to 0. Memory in addresses above 30 K can be accessed through the EDS window with DSRPAG and DSWPAG set to the appropriate page value.

Diagram of Accessing Upper RAM using DSRPAG/DSWPAG

Back to top

Putting Variables in EDS

The EDS registers are typically controlled by MPLAB® XC16 compiler directives. Variables are placed into EDS using the space or address attribute.

  • __attribute ((address(0xxxx))) will cause the compiler to place a variable at a particular address. The address may be within the virtual address space of extended data memory (0x0800 - 0x0178FE on the PIC24FJ256DA210), or within the typical data memory (0x0800 - 0x7FFE).
  • __attribute ((eds)) causes a variable to be placed in the EDS at an address selected by the compiler.

Back to top

Accessing EDS Variables

The __eds__ qualifier is used in conjunction with the EDS or address attribute. The compiler will ensure the appropriate values are loaded in PSRPAG and PSWPAG before accessing variables defined with __eds__ qualifier.

Diagram of Extended Data Space Memory

MPLAB XC16 compiler will create a 32-bit pointer when the __eds__ qualifier is used during a pointer's declaration. 32-bit EDS qualified pointers are capable of being loaded with the virtual address of any operand. For the PIC24FJ256DA210, the virtual address for memory ranges from 0x0800 to 0x178FE (with all addresses above 0x8000 located in EDS memory). When accessing any variable with through an __eds__ qualified pointer, the compiler will ensure the appropriate values are loaded into PSRPAG and PSWPAG.

The following code example shows how variables can be placed into EDS. The example also shows how the program can use a pointer to access the EDS memory, thus leaving all register manipulations to the compiler.

Diagram of Extended Data Space Memory

After the previous code has been run, the MPLAB X IDE's Watches window shows the following values. Note the value 0xABCD has been placed into the EDS memory location of eds_var.

Diagram of Extended Data Space Memory

Back to top

Learn More

Back to top