Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Stack usage

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
dongags5

Bascom Member



Joined: 02 May 2005
Posts: 108
Location: Melbourne Australia

australia.gif
PostPosted: Tue Jun 24, 2014 4:16 am    Post subject: Stack usage Reply with quote

In most of my programs which are fairly small - I use the demo version, I don't use any stack directives and this does not seem to be a problem. If a program lacks these directives does the compiler allocate default values for the micro used?

I use mainly the ATMega8535, ATMega8515 and ATTiny2313. I know that I should be entering these directives but I haven't seen any simple way of calculating the various stack requirements i.e.
$hwstack = 48
$swstack = 32
$framesize = 32

Maybe I should make an effort to properly understand this fully but a lazy way out is to start with some safe values - any suggestions?
Thanks in anticipation of a reply.

Don


(BASCOM-AVR version : 2 0 7 5 , Latest : 2.0.7.7 )
Back to top
View user's profile
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 586
Location: Cleveland, OH

usa.gif
PostPosted: Tue Jun 24, 2014 4:50 am    Post subject: Reply with quote

In the Bascom IDE, under the Options tab, under Chip, one sees "default" values for the HW Stack, SW Stack, and Framespace.

If you omit the compiler directives from your program then I believe the above values come into play.

I always include the instructions in the code, that way there is no question as to what the values were.

I agree, it is hard to know what the values should be.

If you aren't tight on memory you can always increase them a bit.

If you are getting a very difficult to track down bug it is often worth increasing them, to see if the bug is suddenly resolved, and was due to one of them being undersized, and other memory having been overwritten.

JC
Back to top
View user's profile Visit poster's website
six1

Bascom Expert



Joined: 27 Feb 2009
Posts: 553

germany.gif
PostPosted: Tue Jun 24, 2014 7:57 am    Post subject: Reply with quote

Hi,
have a look at older Thread:

http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=10649&highlight=stack

one hint:
if micro doesn't have enough ram for testing with stackcheck, you also can make use of biger micro for getting values for stack... and set these values in tiny micro.

regards, michael

_________________
For technical reasons, the signature is on the back of this message.
Back to top
View user's profile
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Tue Jun 24, 2014 9:10 am    Post subject: Reply with quote

Quote:
I haven't seen any simple way of calculating the various stack requirements i.e.
$hwstack = 48
$swstack = 32
$framesize = 32


I use this calculation:

$hwstack = SRAM_bytes / 8
$swstack = SRAM_bytes / 16
$framesize = SRAM_bytes / 16

So the stacks take 1/4 of SRAM.

For example Atmega8 has 1OOO bytes SRAM:
$hwstack = 128
$swstack = 64
$framesize = 64
768 bytes remain for global variables.

I do not say it is an ideal way, but I think it will work in most cases.
Back to top
View user's profile
dongags5

Bascom Member



Joined: 02 May 2005
Posts: 108
Location: Melbourne Australia

australia.gif
PostPosted: Tue Jun 24, 2014 1:41 pm    Post subject: Reply with quote

Thanks guys for the very helpful responses.
I have now got a much clearer picture of what can be done and I now know what needs to be addressed in the various components of stack size to fix any future concerns in this area. However, as my programs are limited in size due to the demo version, I may not need to change the default values - if at all! Maybe if I get the paid version and embark on more complex programs then a good feel for stack sizes will become far more important. I notice that there is a pretty comprehensive explanation of stack in the Bascom helpfile.
cheers
Don

Very Happy
Back to top
View user's profile
Arera

Bascom Member



Joined: 23 Sep 2007
Posts: 386
Location: Wuppertal, Germany

germany.gif
PostPosted: Wed Jun 25, 2014 2:01 pm    Post subject: Reply with quote

@Visovian
You are quite creative, respect!

Cheers, Marc
Back to top
View user's profile
six1

Bascom Expert



Joined: 27 Feb 2009
Posts: 553

germany.gif
PostPosted: Thu Jun 26, 2014 7:47 am    Post subject: Reply with quote

Hi Visovian,
if you use functions, then your way it is not the best...
I think it will be better to check, what will be needed or what's in use.

regards, michael

_________________
For technical reasons, the signature is on the back of this message.
Back to top
View user's profile
sentinel

Bascom Member



Joined: 02 Feb 2009
Posts: 141
Location: Tasmania

australia.gif
PostPosted: Thu Jul 17, 2014 5:28 am    Post subject: Reply with quote

I am also having problems that I believe are related to stack overwrite.
I have searched in the forum, but can't find an answer to this question: Is the unallocated portion of SRAM used by the micro-controller for other tasks?

Put another way, can you allocate too much SRAM to the stack, or can it be completely allocated to stack without problem?

I am using an ATmega88 which has 1k SRAM with HW stack of 100, SW stack of 120 and Frame size of 120
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Thu Jul 17, 2014 11:50 am    Post subject: Reply with quote

Hello sentinel

You should be ok with those values.
What does the report say you have in ram used & left ?
Bascom will tell you if you run out of ram.

What problem are you having?

If you look at my 32x8 clock module you will see I used almost every bit of memory the Mega 8 had ram, eeprom & flash

Regards Paul
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
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
You cannot attach files in this forum
You cannot download files in this forum