12.1 Address Spaces

The 16-bit devices are a combination of traditional PIC® Microcontroller (MCU) features (peripherals, Harvard architecture, RISC) and new DSP capabilities (dsPIC DSC devices). These devices have two distinct memory regions:

  • Program Memory - contains executable code and optionally constant data.
  • Data Memory - contains external variables, static variables, the system stack and file registers. Data memory consists of near data, which is memory in the first 8 KB of the data memory space and far data, which is in the upper 56 KB of data memory space.

Although the program and data memory regions are distinctly separate, the dsPIC and PIC24 families of processors contain hardware support for accessing data from within program Flash using a hardware feature that is commonly called Program Space Visibility (PSV). More detail about how PSV works can be found in device data sheets or Family Reference Manuals. See sections Variables In Data Space Memory and PSV Usage with Interrupt Service Routines.

Briefly, the architecture allows the mapping of one 32K page of Flash into the upper 32K of the data address space via the Special Function Register (SFR) PSVPAG. Devices that support Extended Data Space (EDS) map using the DSRPAG register instead. It is also possible to map Flash and other areas, see section Extended Data Space Access.

By default the compiler only supports direct access to one single PSV page, referred to as the auto_psv space. In this model, 16-bit data pointers can be used. However, on larger devices this can make it difficult to manage large amounts of constant data stored in Flash.

The extensions presented here allow the definition of a variable as being a ‘managed’ PSV variable. This means that the compiler will manipulate both the offset (within a PSV page) and the page itself. As a consequence, data pointers must be 32 bits. The compiler will probably generate more instructions than the single PSV page model, but that is the price being paid to buy more flexibility and shorter coding time to access larger amounts of data in Flash.