View previous topic :: View next topic |
Author |
Message |
dongags5
Joined: 02 May 2005 Posts: 108 Location: Melbourne Australia
|
Posted: Tue Jun 24, 2014 4:16 am Post subject: Stack usage |
|
|
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 |
|
|
JC
Joined: 15 Dec 2007 Posts: 584 Location: Cleveland, OH
|
Posted: Tue Jun 24, 2014 4:50 am Post subject: |
|
|
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 |
|
|
six1
Joined: 27 Feb 2009 Posts: 553
|
|
Back to top |
|
|
Visovian
Joined: 31 Oct 2007 Posts: 584 Location: Czech
|
Posted: Tue Jun 24, 2014 9:10 am Post subject: |
|
|
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 |
|
|
dongags5
Joined: 02 May 2005 Posts: 108 Location: Melbourne Australia
|
Posted: Tue Jun 24, 2014 1:41 pm Post subject: |
|
|
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
|
|
Back to top |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Wed Jun 25, 2014 2:01 pm Post subject: |
|
|
@Visovian
You are quite creative, respect!
Cheers, Marc |
|
Back to top |
|
|
six1
Joined: 27 Feb 2009 Posts: 553
|
Posted: Thu Jun 26, 2014 7:47 am Post subject: |
|
|
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 |
|
|
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
Posted: Thu Jul 17, 2014 5:28 am Post subject: |
|
|
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 |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Thu Jul 17, 2014 11:50 am Post subject: |
|
|
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 |
|
|
|