CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

stack

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

stack
PostPosted: Wed Jun 14, 2006 12:51 am     Reply with quote

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
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: stack
PostPosted: Wed Jun 14, 2006 1:27 am     Reply with quote

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!!
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Jun 14, 2006 12:04 pm     Reply with quote

You could also use a state machine inside a while loop. When the timer0 interrupts, change states.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 14, 2006 12:22 pm     Reply with quote

I also felt that the program structure could probably be changed, and
then this problem would not be an issue.

Look at various threads in the forum that show how to do multitasking:
http://www.ccsinfo.com/forum/viewtopic.php?t=17189&highlight=multitasking
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

clearing the stack
PostPosted: Wed Jun 14, 2006 11:36 pm     Reply with quote

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
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Jun 15, 2006 6:18 am     Reply with quote

What PIC??
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

stack
PostPosted: Thu Jun 15, 2006 10:28 pm     Reply with quote

The micro is 18F252
Joseph
Ttelmah
Guest







PostPosted: Fri Jun 16, 2006 3:17 am     Reply with quote

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
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Jun 16, 2006 6:48 am     Reply with quote

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.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

stack
PostPosted: Sat Jun 17, 2006 7:45 am     Reply with quote

tahks for the answers, realy helpfull
joseph
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group