2023-01-19 12:57 AM
In the debugger, I see float variables as 9e-39 or similar that is totally wrong.
In the following example the correct value is 615.133911
When passing to int it is 615, as expected.
it may be a wrong configuration of the debugger float number format
How can I solve that?
2023-01-19 01:17 AM
Hola @JLope.11 , it would make more sense to me the issue is in your code.
That ugly 5 factor multiplication is not doing what you thing should be doing.
Maybe an overflow, underflow who knows.
I would split that multiplication step by step and figure out which factor is messing your operation
your_result=factor1;
your_result*=factor2;
your_result*=factor3;
your_result*=factor4;
Did you already tried changing all variables to double type?
2023-01-19 01:46 AM
I think the problem is the debugger viewer format.
I have made:
Vpri_rms2=0.9f;
And in the debugger appeared: 9.00002576e-039
But if I make:
double uu=Vpri_rms2;
The value is correct. I think the debugger display try to show double instead of float.
do I have to work with double instead of float or change something in the debugger viewer setup?
2023-01-19 04:51 AM
SOLVED: the problem was that I configured ADC+DMA to fill double than assigned buffer, so wrote out of the memory.
Now the debugger works fine.
2023-01-20 01:07 PM
Tip: you can multiply with an inverse if you want to avoid division. So you can do *(1.0f/32) instead of hand calculating it first like *0.03125f. To me that makes it more readable and you can remove the comment with 1/32. The compiler will calculate it for you.