09-09-2019 01:42 AM
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?
09-09-2019 02:52 AM
my code is like this.
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.
09-09-2019 03:03 AM
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.
09-09-2019 06:41 PM
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.
09-11-2019 12:29 AM
I think instead of:
tt = /65536; tt = +aa; tt = -cc;
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.