View previous topic :: View next topic |
Author |
Message |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
stack |
Posted: Wed Jun 14, 2006 12:51 am |
|
|
I am using timer0 as a time-out indicator, to stop "while" functions and begin others. I don't want to go back to the same "while" after the interrupt.
that make the stack full after a certain time.
I would like to clear the stack. It is posible ? or have some other technics
not to fill the stack when not returning to the same place.
In assembler is simple, calls go back to the next line, so no stack overflow problems.
Joseph |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
Re: stack |
Posted: Wed Jun 14, 2006 1:27 am |
|
|
gjs_rsdi wrote: | I am using timer0 as a time-out indicator, to stop "while" functions and begin others. I don't want to go back to the same "while" after the interrupt.
that make the stack full after a certain time.
I would like to clear the stack. It is posible ? or have some other technics
not to fill the stack when not returning to the same place.
In assembler is simple, calls go back to the next line, so no stack overflow problems.
Joseph |
There may be an easier way. In the while loop conditional test include a test to ensure timer0 interrupt flag is clear. If set, the timer has expired. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Jun 14, 2006 12:04 pm |
|
|
You could also use a state machine inside a while loop. When the timer0 interrupts, change states. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
clearing the stack |
Posted: Wed Jun 14, 2006 11:36 pm |
|
|
Thanks for the answers
my program is a multitasking one and it works O.K. also with the hardware. The reset problem I solved by NOSTVREN in the fuses.
My program should go to an other place if time-out occured and not executing the "while".
In any case, my question remain "it is posible to clear the stack, not by reset?"
Joseph |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Jun 15, 2006 6:18 am |
|
|
What PIC?? |
|
![](templates/subSilver/images/spacer.gif) |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
stack |
Posted: Thu Jun 15, 2006 10:28 pm |
|
|
The micro is 18F252
Joseph |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Fri Jun 16, 2006 3:17 am |
|
|
It really does sound 'messy'. Overriding the stack, to my mind reflects the possibility of quite dangerous programming. However it is do-able. All you need to do, is reset the stack _pointer_. Values left 'in' the stack, do not matter. The '0' stack address has no RAM, and allways contains 0, so setting the pointer back to zero, effectively resets the stack, and will also clear error conditions if present.
Code: |
#byte STKPTR=0xFFC
#define clear_stack() STKPTR=0
|
clear_stack();
Will clear the stack (only on 18 chips).
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Jun 16, 2006 6:48 am |
|
|
For PIC18's you can do as RJ pointed out to reset the pointer but there are ASM instructions 'POP' and 'PUSH' which allow you to remove addresses from the stack as well as put addresses on the stack. |
|
![](templates/subSilver/images/spacer.gif) |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
stack |
Posted: Sat Jun 17, 2006 7:45 am |
|
|
tahks for the answers, realy helpfull
joseph |
|
![](templates/subSilver/images/spacer.gif) |
|