5

I know many of the lower-end PICs have fixed hardware stacks that can become an issue during firmware development. I've recently heard that the PIC24-series (and maybe just anything above PIC18 series) have software-defined stacks? Does that mean they're dynamically allocated while the code is running or is the size just assigned by MPLAB when you compile?

I know this is more of a nuanced question, but I appreciate any help there might be out there. It just doesn't seem to be talked about much on the datasheets or product pages.

tarabyte
  • 3,112
  • 10
  • 43
  • 67

1 Answers1

4

If you look at page 37 of the PIC24F16KA102 data sheet (PDF) (a typical small PIC24 device) you will see a description of the software stack: the W15 register is used as a 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 depicted in Figure 4-4."

Page 70 of the 16-bit MCU and DSC Programmer’s Reference Manual (PDF) has some more information:

"The 16-bit MCU and DSC devices feature a software stack which facilitates function calls and exception handling. W15 is the default Stack Pointer (SP) and after any Reset, it is initialized to 0x0800 (0x1000 for PIC24E and dsPIC33E devices). This ensures that the SP will point to valid RAM and permits stack availability for exceptions, which may occur before the SP is set by the user software. The user may reprogram the SP during initialization to any location within data space."

Trygve Laugstøl
  • 1,410
  • 2
  • 19
  • 28
Leon Heller
  • 38,774
  • 2
  • 60
  • 96
  • "The user may reprogram the SP during initialization to any location within data space" I'm assuming the SP initial location is done by MPLAB during compilation as I'm not going into the assembly or pre-main functions. This doesn't fully answer the question, but it does help. Thank you. – tarabyte Jan 24 '13 at 00:22