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 support@ccsinfo.com

How to reduce the stack

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







How to reduce the stack
PostPosted: Thu Feb 04, 2010 6:43 am     Reply with quote

Hello,

In the FAQ of the CCSINFO Page I have seen that the size of the stack should not exceed 9 if using interrupts.

Quote:
"What are the restrictions on function calls from an interrupt function?

Whenever interrupts are used, the programmer MUST ensure there will be enough stack space. Ensure the size of the stack required by the interrupt plus the size of the stack already used by main() wherever interrupts are enabled is less than 9. This can be seen at the top of the list file. "


if I look in my list file it says "Stack: 11 worst case (4 in main + 7 for interrupts)", so it seems as if I could get some unexpected problems. Further more, if I look in the list file of my bootloader it says "Stack: 4 locations"
Dose this mean that I have up to 15 (11 + 4) in the worst case?

How can I reduce the usage of the stack and is there a possibility to clear the stack after the bootloader jumps to the main program, as I suppose this stack information is not needed any more in the main program and would save the 4.

I am using ccs 4.103 and a PIC18F6722.
Ttelmah
Guest







PostPosted: Thu Feb 04, 2010 9:53 am     Reply with quote

It sounds as if this is a 'FAQ' answer, for a much older chip.
The limit on stack size, is dependant on the processor.
Most of the chips used in the earlier CCS versions, were limited at 8 stack levels (<9)....
Many modern chips allow far more entries (your chip allows 31 levels), and several of the CCS demo programs use more than 9 levels - with interrupts.
There is a balancing act here. You will use the stack,whenever you call a subroutine, which is of reasonable size, and called from multiple points in the code. This costs speed slightly. You can force the code to instead be put 'inline', (by using the inline directive), this gives faster performance, and avoids using the stack, but at a cost in ROM useage.
However, at 11 entries, don't bother. Worry about it if you get up to perhaps 25 levels.

Best Wishes
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