Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Sleep, Call Stack & Software Reset

Status
Not open for further replies.

Dan East

New Member
I'm using Sleep to "turn off" the PIC. When an interrupt turns it back on it continues program execution following the sleep call. However I want to reset the PIC when it wakes up. So currently I'm just jumping to my initialization routine and all is well. I do have one concern, and that is the call stack. The sleep may be called from within subroutine(s), thus the call stack is dirty after my "reset".

So finally here are my questions.

Is it okay to just let the stack overflow since I don't need the elements that are pushed off of the bottom?

Is there a way to clear the stack without using return / retlw?

Can a PIC be reset via software?

Thanks!

Dan East
 
Which PIC family are you working with?

To answer your questions under the PIC16 family:

Is it okay to just let the stack overflow since I don't need the elements that are pushed off of the bottom?

The stack pointer will overflow and wrap around to the start. This does not pose any problem if you use stack only up to 8 calls deep.

Is there a way to clear the stack without using return / retlw?

None and IMO not needed.

Can a PIC be reset via software?

No way that I know of except enabling the watchdog timer. But You can't have that enabled while using sleep.

To answer your questions under the PIC18 family:

Is it okay to just let the stack overflow since I don't need the elements that are pushed off of the bottom?

A stack underflow or overflow can trigger a reset.

Is there a way to clear the stack without using return / retlw?

The STKPTR register is accessable and can be cleared by software.

Can a PIC be reset via software?

The RESET instruction is available.
 
Thanks for the info! I'm using PIC12 and PIC16 family PICs. So I'll just let the stack overflow.

Dan East
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top