Function Return and Variable Disappear

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

Function Return and Variable Disappear

870 Views
HarryHirn
Contributor I

Hi

 

i got a problem getting me crazy :smileywink:

 

i got a function:

 

 

float FUNCTIONS_convolution(uint16_t x[], uint16_t y[]){     uint8_t i = 0;  float x_bar = 0.00;  float y_bar = 0.00;  float sigma_x = 0.0;  float sigma_y = 0.0;  float sigma_xy = 0.0;  float rho = 0.0;  ...  some crazy calculations   ...  sigma_xy = (sigma_xy / 9.0);  rho = (sigma_xy / (sigma_x * sigma_y));    return rho;}

 

 

and i call it from my main function with:

 

 

/* Write your local variable definition here */  uint16_t x[10] = {1,2,3,4,5,6,7,8,9,10};  uint16_t y[10] = {1,2,3,4,5,6,7,8,9,10};  float convolution = 0.0;  float temp = 0.0;    /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/  PE_low_level_init();  /*** End of Processor Expert internal initialization.                    ***/  /* Write your code here */    ...  some initialisation stuff  ...    while(1){        if(process == CONVOLUTION)    {      convolution = FUNCTIONS_convolution(x, y);            temp = 2*convolution;            if(temp <= convolution)      {        FUNCTIONS_usb_send_byte('O');      }            process = IDLE;    }      }

 

now my problem is that in my function the calculations are done up to the last few lines...

sigma_xy has a value, but it keeps it value even after division.

after that rho is not calculated and stepping in the tru time simulator skips the calculation and return value.

in the simulator (P&E Debugger, software running on hardware) the variables rho, convolution and temp are not shown.

the if case is not correct, its just a tryout to tell the compiler that i need that variables :smileywink:

whats wrong and how can i tell the compiler not to cut my variables away :smileywink:

 

im using codewarrior 4.7

 

Compiler throws a warning: C12056: SP debug info incorrect because of optimization or inline assembler

 

im not using inline assembler, maybe from the includet math.h?

Labels (1)
0 Kudos
2 Replies

337 Views
Lundin
Senior Contributor IV

I think the SP debug warning comes from the IDE. For each C file in your project you need to click the little green bug in the project browser, to enable debug info.

 

If that didn't solve the problem, it sounds like an optimization issue. When debugging, declare variables as volatile to prevent optimization.

 

 

 

0 Kudos

337 Views
HarryHirn
Contributor I

i think i posted in the wrong subforum, maybe someone could move me to the codewarrior topic... :smileywink:

0 Kudos