Searching \ for 'Stack depth insufficient' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=stack+depth+insufficient
Search entire site for: 'Stack depth insufficient'.

Truncated match.
PICList Thread
'Stack depth insufficient'
1995\02\07@080731 by Byron A Jeff

flavicon
face
>
> Hi Folks,
>
> Can you help ...
>
> I am writting some stuff for the PIC 16C55 (because I need that number of IO
> pins AND I got one as part of the PIC-START Kit).
>
> I like to write structured code with subroutines. But .... the stack is
> only 2 deep on this device.
>
> I want to have the main loop calling the sub sections, the sub sections
calling
> sub-sub sections and in turn they can call device routines, which call delays
> etc etc.
>
> Any ideas/tricks/tips to get over having only a 2 deep stack?

There's no easy way to do it with the 16C5X series chips. This is the reason
that the 16C[71|84|64|74] have 8 level stacks and the 17C42 has a 16 level
stack.

Honestly I'm annoyed that all the PICs stacks are not addressible. It precludes
the possibility of having clean co-routines or multitasking. While not
inportant for a 16C54 a 17C42 could certainly benefit from it.

Anyway back to your problem. Simply put you'll have to restructure. You'll
have to manage your own stack and use computed GOTOs (by writing the PCL
register) to get the desired result.

OK I'm looking at the Data Book and here is the relevant section
(16C5X Data Sheet section 4.3)

---------------------------
d) If PC is the destination in any instruction (e.g. MOVWF PC, ADDWV PC etc.)
then the computed 8 bit result will be loaded into the lower 8 bits of the
program counter. The ninth bit of PC will be cleared.
---------------------------

What this means is that the "return" address must be in the first 256 words
(because the 9th bit is cleared). GOTO can jump directly to any instruction.

So an instruction sequence something like this:

;------------------------------------------------------
saveret: ds  1

; Note that this part needs to be in the first 256 words.
Caller:  movlw retadr
        movwf saveret
        goto  sub
retadr:  ; Life goes on from here.

; Somewhere later in the code. Can be anywhere
sub:     ; Do the subrouting work.
        movf  saveret,w     ; Setup for the return
        movwf pc            ; Do the return
;------------------------------------------------------

Will do the job. You can even simulate a call/return stack with a stack
pointer to do multiple level calling.

Anyway it's a pain in the butt. To be honest from the cursory description
of you application it's probably a bit much for a 16C55. A 16C64 would
probably be more appropriate.

Hope this helps,

Any other comments?

BAJ

More... (looser matching)
- Last day of these posts
- In 1995 , 1996 only
- Today
- New search...