local varibales notlisted

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

local varibales notlisted

Jump to solution
615 Views
Cram
Contributor III

Dear all,

 

I never faced this problem before so I'm a little bit lost.

 

MCU: S9S08QD4

CW=6V1

 

I'm debbuging a new code just adquiring some signals from the ADCH0 and ADCH1, called Vbat and Vshunt, as follows:

 

void adquisition(void){

 

 

unsigned int contcicles=0, limit=0,Vbat=0;

unsigned int Vshunt=0;

 

           ....

           

            Vbat=getValorAD(0);

 

            Vshunt=getValorAD(1);

 

 

       ....

 

}

 

When debbuging the code and reach this function all the local variable are listed expect for Vshunt, if I declare it as global variable it works perfectly, (data adquired is correct so Hw is working fine). What is going on? Anybody faced it before?

 

I'm using the startup code generated for the wizard (start08.c)

 

BR

 

MarC

 

 

Labels (1)
0 Kudos
1 Solution
515 Views
CrasyCat
Specialist III

Hello

This is due to optimization, Local variables are kept into registers and if they are not used anymore later on in the function, their value is not copied over to the stack.

In order to get the value of the local variable copied to its stack location you can

  1. Add a read access to this local variable further down in the function code.
  2. Define the variable as volatile.
  3. Define the variable as static local
  4. Define the variable as global

Note that all these solutions will make it easier to debug your code, but will generate additional code, which will increase execution time..So it could bea good idea to implement that only for the debug configuration of your target.

CrasyCat

View solution in original post

0 Kudos
2 Replies
516 Views
CrasyCat
Specialist III

Hello

This is due to optimization, Local variables are kept into registers and if they are not used anymore later on in the function, their value is not copied over to the stack.

In order to get the value of the local variable copied to its stack location you can

  1. Add a read access to this local variable further down in the function code.
  2. Define the variable as volatile.
  3. Define the variable as static local
  4. Define the variable as global

Note that all these solutions will make it easier to debug your code, but will generate additional code, which will increase execution time..So it could bea good idea to implement that only for the debug configuration of your target.

CrasyCat

0 Kudos
515 Views
Cram
Contributor III

Thanks Catherine for you statment.

I tested it with static unsigned int, and works it helps a lot during the debug process.

BR

0 Kudos