Hi Ralph,

Using GOSUB to call a sub-routine that returns to the calling routine with a GOTO VS a RETURN eats up your stack since there is no RETURN instruction to POP the return address back from the stack. You end up with stack over-flow.

On the 16F series you have an 8 level deep stack, and once it's filled up, it starts being over-written (circular type buffer) by further return addresses pushed onto the stack from top-to-bottom.

While your program may or may not work on a 16F part when doing this, it can still cause trouble depending on how many consecutive calls you have before returns start (referred to as nesting) popping addresses back off the stack.

You have return addresses being pushed onto the stack by PBP library functions + your own code. With the 16F's circular type stack buffer, you're getting by with the boo-boo because return addresses are still being pushed on the stack (simply overwritting previous contents), and all's well if you're not nesting calls too deep.

One the 18F parts you have a 31 level stack, BUT, it's not the circular type buffer like you have with the 16F. Once you get to location 31 the 32nd return address simply overwrites location 31,
and it's sit & spin at location 31 from there on.

I.E. you're now stuck at the last stack level, and nothing else can be pushed onto the stack leaving you with only "1" stack position where a return address is stashed to any caller.

Your program gets shot-off into la-la land somewhere, and goes haywire. Basically, it goes like splat...;o]

>>forces a lock-up of the 18F252 after 29 successful loops<<

That's why the above happens. You're OK until you hit that magic number on the 18F.

TIP:
You can use the STVREN config bit on the 18F series to help you find bugs like this, and force a device reset on stack overflow/underflow conditions.