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

Stack Size PIC24

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



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Stack Size PIC24
PostPosted: Fri Jun 17, 2016 6:28 pm     Reply with quote

Currently my project .lst file is reporting:

ROM used: 48916 bytes (56%)
Largest free fragment is 22520
RAM used: 6134 (75%) at main() level
6383 (78%) worst case
Stack used: 348 locations (42 in main + 306 for interrupts)
Stack size: 512

It's a PIC24FJ128GA306 and has 8K RAM.

With a Stack Size of 512 how does it look ? Just how more stack usage is possible ?

Can the compiler really predict every scenario as it appears to be doing !

Should I increase the stack size ?
guy



Joined: 21 Oct 2005
Posts: 291

View user's profile Send private message Visit poster's website

PostPosted: Sat Jun 18, 2016 2:33 am     Reply with quote

I have a large project with a similar PIC - 24FJ64GA308 .
I ran into random resets which had to do with the printf() function. This is known to take up a lot of stack (due to floating point conversions done inside printf). The following solved it: #BUILD(STACK = 0x200) so apparently it was a stack issue which was not noted by the compiler during Build.
I understand you are already working with a 512 byte stack.

To answer your question, from my experience the compiler doesn't know exactly how much stack it would take up so it's better to have a safe margin and look out for bugs and phenomena that smell like Stack Overflow. There is also the Stack Overflow fuse (I don't remember the exact name) that handles this.
temtronic



Joined: 01 Jul 2010
Posts: 9163
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jun 18, 2016 5:24 am     Reply with quote

While I don't use that PIC... my 'gut' feeling is to increase the stack to 1024.
There always seems to be a lot of stack related queries here.

A lot of your STACK(90%) is used for interrupts, so adding one or two more ISRs ...and.. poof...PIC stops working ! You still have enough 'main RAM' to assign to the STACK.
Try it, see what happens. if your program needs more RAM, THEN reduce the STACK to say 768 (nice binary number...).

As for HOW the compiler predicts.... it has a very good crystal ball !

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19338

View user's profile Send private message

PostPosted: Sat Jun 18, 2016 11:55 am     Reply with quote

I wouldn't go so far as 1024. Seems a bit 'OTT'. Smile

The calculated figure is always pretty reasonable, except for certain things. In particular, CCS doesn't always seem to 'know' the stack used by the printf. I think it uses some form of dynamic allocation, based on the actual values involved. So some numbers (particularly some float values), can result in 'extra' stack being used, beyond what is 'expected'. The '42 in main', sounds suspiciously small to me. You can get stack overflow, at a size of 256, with a main 'saying' it only uses about 100 bytes, if you printf several float values. I've developed a 'rule' of running the stack to 256 greater than the figure the compiler says is being used, and (touch wood), so far have not seen a stack overflow, with it set like this. So I'd suggest taking the stack to 640, as a compromise between wasting space, and leaving a margin....
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Thanks for all the replies
PostPosted: Sat Jun 18, 2016 3:21 pm     Reply with quote

I was having graphics issues, and these started after adding totally unrelated code.

I ended up with stack at 768 and that fixed the graphics problem.

Thanks again for all the good advice.
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