5
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ How is this not directly and clearly answered in the datasheet right where you'd expect to find it? \$\endgroup\$ – Olin Lathrop Jan 20 '13 at 21:04
4
\$\begingroup\$

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."

\$\endgroup\$
  • \$\begingroup\$ "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. \$\endgroup\$ – tarabyte Jan 24 '13 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.