plaasjaapie - 2006-12-23

As you know I was recently having troubles getting what should have been workable code running on the 16F877A to work properly.  When I shifted over to a pin-compatable 18F chip things worked find. 

I posted my observations on a PIC chat group run by fellow Oshonsoft BASIC users and this very illuminating post came back...

*********************************************************************************************

Unfortunately there is no stack overflow trap on the 16F, and once the stack
is full it simply wraps around, overwriting the first entry and so on (=
very unpredictable results). There is no means of viewing the stack pointer,
or the stack contents themselves (as far as I'm aware), and no
overflow/underflow status bits.

My method is to try to avoid using call's from within interrupts altogether,
and ensure that "interrupt within interrupt" can never occur. Hence
interrupts are only one deep on the stack. Then I know I have plenty of
stack space left over for the main program, and usually as I don't go more
than four or five deep on the stack I'm safe.

Obviously, this approach is fine in assembly, but not so easy to achieve
when compiling from a higher level language...

On the 18F it's easy as there are stack overflow/underflow bits, the stack
itself (to an extent) and the stack pointer can be read, so its easy to trap
a stack error, and if needs be it can be indicated with a spare i/o port and
LED during the troubleshooting.

Daren.

*********************************************************************************************

I don't know if I am the only one who is that inexperienced with the ins and outs of PIC programming, so I thought that I'd post the post.