Float use in CW 10.2

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

Float use in CW 10.2

663 Views
evgenik
Contributor IV

Hi.

I work with K60/K61 MCUs. At this time I added to project float type variables for calculation. But don't all operations are work perfect.

For example:

1)

float Signal = GetValue();     // Signal = 0.6

if(Signal >= 0.5) // this compare not occured never

{

     Signal += 0.1;

}

2)

float Signal = GetValue();     // Signal = 0.6

float Compare = 0.5;

if(Signal >= Compare) // this compare not occured never

{

     Signal += 0.1;

}

In Project Properties->C/C++ Build/Settings// ARM CPU->Floating point selected "Software (default)".

What is a problem with float operations in CW 10.2 with Kinetis?

 

Thanks.

Evgeni.

 

Labels (1)
0 Kudos
3 Replies

346 Views
Monica
Senior Contributor III

Hello Evgeni!

How is the project going going, any breakthroughs? Keep us posted! :smileywink:

Best regards,

Monica.

0 Kudos

346 Views
evgenik
Contributor IV

Hi.

The Freescale in its MCU model description describes the MCU that has FPU (Floating Point Unit) or MCU that work as DSP. For example: MK60FN..... - this MCU has FPU, MK60DN... - this MCU hasn't FPU.

I have demo board MK60DN... therefore I can't use the float as uint8, uint16 or uint32 variables in compare operations. But if I want to use float values I can multiply them with 10 for get the int and perform compare operations. Otherwise no one compare operation will not performe.

Have a good day.

Evgeni.

0 Kudos

346 Views
BlackNight
NXP Employee
NXP Employee

Hi,

Do you mean that the code inside the if is not executed, or that the debugger did not step to that line?

I ask because I have seen cases with compiler optimizations that the debugger did not stepped into the if, but the code was executed well.

So might try stepping with assembly stepping mode.

The other thing to check: are you using prototypes?

Is it like this:

float GetValue(void);

float Signal = GetValue();     // Signal = 0.6

if(Signal >= 0.5) // this compare not occured never

{

     Signal += 0.1;

}

Then, if you have something like this:

float GetValue(void);

void foo(void) {

float Signal = GetValue();     // Signal = 0.6

if(Signal >= 0.5) // this compare not occured never

{

     Signal += 0.1;

}

}

Then the compiler simply could remove the code (as not used/no side effect).


So it would be good if you could post an actual function or more details what you do?



I quickly tried your snippets with CodeWarrior MCU10.3 and gcc, and it works properly for me.


PS: as 0.6 is of type double, it would be good if you would change things to use the 'f' suffix to mark things of type float. E.g.

if (Signal>=0.5f)

0 Kudos