10.07.2015 Views

pic24fj128ga010 family - Microchip

pic24fj128ga010 family - Microchip

pic24fj128ga010 family - Microchip

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PIC24FJ128GA010 FAMILY3.2.5 SOFTWARE STACKIn addition to its use as a working register, the W15 registerin PIC24F devices is also used as a SoftwareStack Pointer. The pointer always points to the firstavailable free word and grows from lower to higheraddresses. It pre-decrements for stack pops andpost-increments for stack pushes, as shown inFigure 3-4. Note that for a PC push during any CALLinstruction, the MSB of the PC is zero-extended beforethe push, ensuring that the MSB is always clear.Note:The Stack Pointer Limit register (SPLIM) associatedwith the Stack Pointer sets an upper address boundaryfor the stack. SPLIM is uninitialized at Reset. As is thecase for the Stack Pointer, SPLIM is forced to ‘0’because all stack operations must be word-aligned.Whenever an EA is generated using W15 as a sourceor destination pointer, the resulting address is comparedwith the value in SPLIM. If the contents of theStack Pointer (W15) and the SPLIM register are equaland a push operation is performed, a stack error trapwill not occur. The stack error trap will occur on asubsequent push operation. Thus, for example, if it isdesirable to cause a stack error trap when the stackgrows beyond address 2000h in RAM, initialize theSPLIM with the value, 1FFEh.Similarly, a Stack Pointer underflow (stack error) trap isgenerated when the Stack Pointer address is found tobe less than 0800h. This prevents the stack frominterfering with the Special Function Register (SFR)space.A write to the SPLIM register should not be immediatelyfollowed by an indirect read operation using W15.FIGURE 3-4:0000hStack Grows TowardsHigher AddressA PC push during exception processingwill concatenate the SRL register to theMSB of the PC prior to the push.15PC000000000 PCCALL STACK FRAME0W15 (before CALL)W15 (after CALL)POP : [--W15]PUSH : [W15++]3.3 Interfacing Program and DataMemory SpacesThe PIC24F architecture uses a 24-bit wide programspace and 16-bit wide data space. The architecture isalso a modified Harvard scheme, meaning that datacan also be present in the program space. To use thisdata successfully, it must be accessed in a way thatpreserves the alignment of information in both spaces.Aside from normal execution, the PIC24F architectureprovides two methods by which program space can beaccessed during operation:• Using table instructions to access individual bytesor words anywhere in the program space• Remapping a portion of the program space intothe data space (Program Space Visibility)Table instructions allow an application to read or writeto small areas of the program memory. This makes themethod ideal for accessing data tables that need to beupdated from time to time. It also allows access to allbytes of the program word. The remapping methodallows an application to access a large block of data ona read-only basis, which is ideal for look ups from alarge table of static data. It can only access the leastsignificant word of the program word.3.3.1 ADDRESSING PROGRAM SPACESince the address ranges for the data and programspaces are 16 and 24 bits, respectively, a method isneeded to create a 23-bit or 24-bit program addressfrom 16-bit data registers. The solution depends on theinterface method to be used.For table operations, the 8-bit Table Page register(TBLPAG) is used to define a 32K word region withinthe program space. This is concatenated with a 16-bitEA to arrive at a full 24-bit program space address. Inthis format, the Most Significant bit of TBLPAG is usedto determine if the operation occurs in the user memory(TBLPAG = 0) or the configuration memory(TBLPAG = 1).For remapping operations, the 8-bit Program SpaceVisibility register (PSVPAG) is used to define a16K word page in the program space. When the MostSignificant bit of the EA is ‘1’, PSVPAG is concatenatedwith the lower 15 bits of the EA to form a 23-bit programspace address. Unlike table operations, this limitsremapping operations strictly to the user memory area.Table 3-31 and Figure 3-5 show how the program EA iscreated for table operations and remapping accessesfrom the data EA. Here, P refers to a programspace word, whereas D refers to a data spaceword.DS39747E-page 42© 2009 <strong>Microchip</strong> Technology Inc.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!