cancel
Showing results for 
Search instead for 
Did you mean: 

STM32Cubeide debugger displays wrong float values

JLope.11
Associate III

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?

4 REPLIES 4
Javier1
Principal

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?

we dont need to firmware by ourselves, lets talk
JLope.11
Associate III

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?

JLope.11
Associate III

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.

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.

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.