cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
xilinx_chenzimu
Visitor
Visitor
481 Views
Registered: ‎09-09-2019

Variables are cleared during operation

I use the zu3cg chip. The FreeRTOS is running on the A53 processor.when the processor operate the double type variable, sometimes the variable becomes zero. why?

0 Kudos
9 Replies
471 Views
Registered: ‎07-23-2019

There are many reasons for that, you will have to specify more.

0 Kudos
xilinx_chenzimu
Visitor
Visitor
461 Views
Registered: ‎09-09-2019

my code is like this.

void function()

{

    double tt;

    unsigned int aa = 1;

    unsigned int bb = 2;

    unsigned int cc = 3;

    tt = /65536;

    tt = +aa;

    tt = -cc;

}

the function is running in a FreeROTS task. And the FreeRTOS will process a interrupt from FPGA, the interrupt's period is 0.5millisecond. Sometimes the tt will become zero during the operation. Can you list some reasons that may refer to the problem? I will try to fix.

0 Kudos
446 Views
Registered: ‎07-23-2019

 

now you can get some help.

First, I'm not sure with FreeRTOS if you need to declare tt static.... I guess not, otherwise all variables should be...

Second, what is tt = /65536? Should it be tt /= 65536?

Third, software is dumber than the dumber programmer (a personal principle). You are adding ints to doubles. Please cast your ints to double.

My guess is in that cryptic (to me) line    tt =/ 65536   you are dividing your value (are you?) but for some reason it does an integer division, so any value below 65k becomes a zero. Extra type casts won't harm. You can force a type to a constant, like     (double)65536.

 

0 Kudos
acidka
Visitor
Visitor
432 Views
Registered: ‎08-01-2017

Have you thought that can be because you just do some operations with this variable and don't use it anywhere?

0 Kudos
xilinx_chenzimu
Visitor
Visitor
405 Views
Registered: ‎09-09-2019

Thanks for your help.

first, i tryed that, define the tt static. But it not work.

second, i am sorry about that. I made a mistake. It should be tt /= 65536. 

third, i will try this method. Cast the ints to double.

0 Kudos
xilinx_chenzimu
Visitor
Visitor
403 Views
Registered: ‎09-09-2019

thanks for your help.

I wrote the function that is not complicated compared with my real program. The program uses the variable.

0 Kudos
xilinx_chenzimu
Visitor
Visitor
381 Views
Registered: ‎09-09-2019

I cast the int to double. But, it still don't work. 

Could you list other reasons that may cause this problem?

Thank you very much.

0 Kudos
371 Views
Registered: ‎07-23-2019

I think instead of:

    tt = /65536;
    tt = +aa;
    tt = -cc;

you mean:

    tt /= (double)65536;

    tt += aa;

    tt -= cc;

Other reason I can think of for tt to be zero is if where you look at it is casted to an int. Because of the values of aa and cc and the division, tt is a small number.

0 Kudos
367 Views
Registered: ‎07-23-2019

For example, if you use something like:

printf("tt = %i\n", tt);

instead of %d or %f

0 Kudos