problem in stack in MC68HC908LK24

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

problem in stack in MC68HC908LK24

921 Views
abdallah
Contributor I

we have aproblem in stack of MC68HC908LK24. we have reached nearly RAM size of controller and we have stack size about 0x80. in some functions while they return back to calling function the controller resets due to illegal address or illegal opcode.when we remove many variables from ram and increase stack size these problems disappear.the compiler doesn't give any warning about reaching stack size problem.we use codeworrior version 3.0 

 

so what can i do to save stack size at 0x80 and don't have problems?

and i want to roughly calculate guaranteed minimum stack size of our application.

Labels (1)
0 Kudos
2 Replies

276 Views
peg
Senior Contributor IV

Hello and welcome to the fora, abdallah.

 

Unfortunately there is one or both of two problems here. You have written your code in a very inefficient way or you chose the wrong device to implement your project in.

 

The only way to run a safe stack with a very limited size is to ensure your stack allocated variables and your depth of function calls/subroutine nesting is limited to within that size. You need to be wary of interrupts occurring on top of this as well.

 

There are many discussions here on this forum about measuring the required stack depth. Basically it involves programming some kind of pattern into the memory used by the stack. running the code and excercising it to use all of the functions in all possible scenarios and then checking how much of the patterned memory has been overwritten.

 

Good Luck!

 

0 Kudos

276 Views
bigmac
Specialist III

Hello,

 

You have allocated one sixth of the total RAM capacity to the stack.  Intuitively, this seems a little low.  This implies that you either have a very large requirement for global and static variables, or much of the RAM is unallocated.

 

Examine the project map file to ascertain your global variable requirement.  Also note that zero page RAM is probably unused. unless you explicitly allocate variables within this region.  Also ascertain the the memory allocation for the stack.  Any available memory above the stack is probably not utilised.

 

Are you using floating point operations and floating point variables? These will substantially increase the RAM requirement, and should be avoided if possible.

 

Regards,

Mac

 

0 Kudos