DEMO9S08QG8 weird problem in debug???!!!

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

DEMO9S08QG8 weird problem in debug???!!!

1,410 Views
urlreader
Contributor I
Hi,

I'm using DEMO9S08QG8 for a project, however, this is the first time I use freescale. When I use the codewarrior to debug the firmware, I have a weird problem.

Below it is the code, the declare of varaibles are:
================================
int DL = 10, L = 10; // L and DL are constant
int DL2;
int dataX[10];
================================

Then, in the firmware, I need calculate some variables:

================================
DL2 = DL / 2;
D_X = 0, D_Y = 0, D_Z = 0;
for (i = L-1; i>=L - DL2; i--){
D_X = D_X + (dataX[i]-dataX[(int)(L-DL2)]) * (dataX[i]-dataX[(int)(L-DL2)]); //*****
}
================================

i loops from 9 to 5, when i=9, everything seems ok. but when i=8, suddenly, DL2 changed value to 0. DL2 is a constant although it is declared as 'int' only. It is not used in any other places in the firmware. Because of this, the calculation is wrong. dataX's value is small, 0 or 1, so, it is not overflow problem

So, I changed the code to :

================================
DL2 = DL / 2;
D_X = 0, D_Y = 0, D_Z = L - DL2;
for (i = L-1; i>=D_Z; i--){
D_Y = dataX[i]-dataX[(int)(L-DL2)];
D_Y = D_Y * D_Y;
D_X = D_X + D_Y;
}
================================

Then seems ok, DL2's value doesn't change. But I'm worrying about something else changed but I didn't notice. So, what can cause this problem? How to fix this? Anyone has any ideas? Really need some help.

thanks

urlreader
Labels (1)
0 Kudos
3 Replies

376 Views
CompilerGuru
NXP Employee
NXP Employee
variables changing suddenly are often stack overflow problems, I would watch how close the SP gets to your DL2 variable.
Try to increase the STACK_SIZE in the prm file.

In general I would use more unsigned char's and not int's for the 8 bit HCS08 CPU if all the possible values fit.

Daniel
0 Kudos

376 Views
urlreader
Contributor I
thanks. I changed stacksize, and it seems ok now.

in my firmware, I need collect data from sensors, and then do some calculation. some of the calculations have to be float. what value is reasonable for the stacksize? Or I can set it as high as I want? any other suggestions?

I never used freescale and codewarrior before.



thanks

urlreader
0 Kudos

376 Views
bigmac
Specialist III
Hello urlreader,
 
With the QG8 device, the maximum RAM available is only 512 bytes. This must be apportioned to both the global and static variables used by the program, and to the stack.
 
However, the CW debugger does not give any warning should overflow of the allocated stack size occur during operation of the program.  So you will need to conduct some tests (during simulation) to positively determine the lower boundary of stack usage by your program, and then make sure there is some additional margin allowed.  This margin will perhaps allow for the servicing of additional interrupts that were not previously simulated, and for subsequent alterations to the program.
 
Make sure the globals are allocated, starting from the lowest RAM address (within zero page), and ensure that the stack commences at the highest RAM address.  This will maximize the available stack size.  This may require some experimentation with the PRM file settings.  Also minimize the number of different RAM sections used by your code.
 
These precautions can potentially be relaxed for MCUs with substantially more RAM available.
 
Regards,
Mac
 
0 Kudos