changing in global variable value -  MC9S08GB60

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

changing in global variable value -  MC9S08GB60

1,453 Views
santhu
Contributor I
hi,
 
I'm using HCS08 family controller(MC9S08GB60).In the code i'm using some global variables like x,y,z.The values of global variable changes as required.But while executing following statement (mathematical) the values of global variable changes to unknown value.The statement is as below
 
 a=(unsigned long int)((vtg_r_max1 * vtg_r_max1)+(vtg_y_max1 * vtg_y_max1)+(vtg_r_max1 * vtg_y_max1));
              
 b=(unsigned long int)((vtg_y_max1 * vtg_y_max1)+(vtg_b_max1 * vtg_b_max1)+(vtg_y_max1 * vtg_b_max1));
              
 c=(unsigned long int)((vtg_b_max1 * vtg_b_max1)+(vtg_r_max1 * vtg_r_max1)+(vtg_b_max1 * vtg_r_max1));
              
The above statement is just in the form of (a2+b2+ab).And the global variable x,y,z have no relationship with this expression.
 
Can you suggest me the sollution for changes in global variable value upon executing each expression.
 
With regards
        santhu
 
 
Added p/n to subject.
 


Message Edited by NLFSJ on 2008-07-24 07:28 AM
Labels (1)
0 Kudos
3 Replies

267 Views
bigmac
Specialist III
Hello Santhu
 
It is possible that the stack is over-writing the global variables.  Are the variables in question located immediately below the stack allocation?  The map file for the project should provide this information.  With the calculations using long variables, the stack requirements could be extensive, and exceed the size you have allowed.
 
Try increasing the stack size to see whether this helps.
 
Regards,
Mac
 
0 Kudos

267 Views
santhu
Contributor I
hi Mac,
 
   Thanks for your suggestion.And now my code working properly.I increased my stack size from 50 to 100. While answering me,you used below words.
 
 With the calculations using long variables, the stack requirements could be extensive, and exceed the size you have allowed.
 
 Can you tell me what you mean by calculation using long variable.Is there is any calculation for increasing stack size.What is the max value we can give for stack in 8 bit controller of 64k.
 
With regards
         santhu
0 Kudos

267 Views
eckhard
Contributor V
Hello,

Codewarrior keeps local Variables on the Stack, so by using long, much stack space is used ( 4 Bytes for each long variable ). The max value for the stack size is given by the RAM size. For gte GB60 this is 4 KB.
You can use Stacktop instead of Stacksize to put the Stack to the Top of the RAM area.

Eckhard.
0 Kudos