The stack on the PICmicro is a circular buffer. An overflow will simply overwrite the oldest entry on the stack. You will simply loose the ability to return to the top level calling function. This can be considered a "feature" If you ever decide to "soft reset" your application you can simply "decide" that the stack is empty and continue to run from where you are. Of course the down side is when you overflow the stack inadvertantly. Debugging this can be challenging. There are three methods. 1) Using an ICE2000 set it to break on stack overflow. This costs money due to the price of the ICE2000. 2) Use the simulator and break on stack overflow. This can be difficult to do depending on how your code simulates. Some code requires specific external stimuli that is difficult to do on the simulator. 3) Print your code and count the calls to determine how deep they go. Then determine what happens on interrupt. Does your interrupt service routine make a call to another function? Your interrupt will consume at least 1 stack position so make sure you never call more than 7 other functions without returning. Good Luck. On Sunday, October 12, 2003, at 07:17 PM, David VanHorn wrote: > At 08:40 AM 10/13/2003 +0800, TAN WH wrote: > >> Hi, may someone please explain this to me. >> >> I am suspecting that there is a stack overflow in my PIC16F877. So I >> would >> like to know what will happen to a PIC when a stack overflow occur. > > Overflow is when you store one more item on the stack than there's > space for. > That item won't be stored. > When you pop the stack, you won't get what you think you're getting, > and from there, everything pretty much goes to hell. > > Stack underflow is similar, when you pop one more item than you pushed. > You should get a copy of the first item that was pushed, then as above. > > In either case, the results are bad, and pretty much unrecoverable, > except for a reset. > > A stack crash is when your stack in ram collides with data in ram. > The results are again, unpredictable, but almost always fatal. > > -- > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body