K60 usage of mathematical functions

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

K60 usage of mathematical functions

Jump to solution
3,339 Views
guillaumetiffin
Contributor III

Hello,

I'm using MQX 4.0.1 and a kinetis K60.

I'm new on MQX.  And I have some problems.

I'm trying to use mathematical function as pow(), sqrt() etc..

I tyed to include <math.h> butI I can't use the function.

I searched on the forum but I didn't find an answer.

How can I use those functions? Is there somethind to include or to enable?

If there is some other powerfull function in other library can you tell me where I can find it.

Thank you for the answer.

Guillaume

Labels (1)
1 Solution
883 Views
albertovargas
NXP Employee
NXP Employee

Hi,

I found this information on a thread (https://community.freescale.com/message/88204#88204) started by another user:

Floating Point

To get floating point calcs to work, the Compiler tool settings must be changed.

Click on the project in the Project window.

Select Project from the menu:

Properties

Tool Settings->Librarian->Model->c9x

The EWL library has a smaller footprint but doesn’t support floating point calculations.

I hope it helps.

View solution in original post

9 Replies
884 Views
albertovargas
NXP Employee
NXP Employee

Hi,

I found this information on a thread (https://community.freescale.com/message/88204#88204) started by another user:

Floating Point

To get floating point calcs to work, the Compiler tool settings must be changed.

Click on the project in the Project window.

Select Project from the menu:

Properties

Tool Settings->Librarian->Model->c9x

The EWL library has a smaller footprint but doesn’t support floating point calculations.

I hope it helps.

883 Views
MikeJones
Contributor III

I have confirmed that if you are using K70, and you enable the hardware FPU, and you use model c9x, and you don't include math.h, you will see the pow function return 0.0. You must have all three in place or it does not work.

0 Kudos
883 Views
aroste
Contributor IV

Hi all,

I'm facing the same problem.  Latest CW and MQX with a K60, hardware floating point enabled.

I want to use the "asin" function but without success.  In my code I tried that to test the function and I get the following:

angle = asin(0.614);

==> it return angle = -1.000...

Some help?

BR

-stéphan-

0 Kudos
883 Views
guillaumetiffin
Contributor III

Hi Stephan.

Do you have the same problem with the other functions of the math lib or only this one?

I think that there is a function to enable or something like that but I can't find which one.

Regards,

Guillaume

0 Kudos
883 Views
guillaumetiffin
Contributor III

Hello,

I'm sorry to answer so late but I can't answered before.


At first thank you for your answer.

I'm working with the MK60FX512VLQ15. In the project settings, I have the software floating point enable.

When I use floor or ceil for example it still answer 0. I checked that the number in parameters is a float number but it doesn't work.

I don't know if there something to include in bsp or if something is missing.

Thank you for your help.

Guillaume

0 Kudos
883 Views
soledad
NXP Employee
NXP Employee

Hi,

In order to use MQX with floating point math it is necessary to follow the next steps.

1. in user_config.h of bsp project, MQX_INCLUDE_FLOATING_POINT_IO should be defined as 1, if it is not, please changed it and rebuild the bsp and psp project

2. Go to menu project->properties->C/C++ Build->Settings->Librarian and enable int_FP for the print and scan formats of the Ewl model.

3. Add the library #include <stdlib.h> to the project

I hope this helps :smileywink:

Regards

Sol

0 Kudos
883 Views
guillaumetiffin
Contributor III

Hi,

I had a solution from the freescale's support.

The solution is to set change the project properties for all the project (bsp, psp, and so on):

1. set Properties -> C/C++ Build -> Settings -> Librarian -> Model to "c9x"

Then rebuild all the projects

Add in your project file " #include <math.h> before #include <mqx.h> "

0 Kudos
883 Views
Monica
Senior Contributor III

Hello Guillaume Tiffineau,

how's the project going? Any breakthroughs?

Don't forget to keep us posted :smileywink:

Best,

Monica.

0 Kudos
883 Views
djhoop
Contributor II

There could be a number of reasons that this isn't working. You'll need to ensure you have floating point support enabled. This option will depend on which K60 you're using, since some don't come with an FPU. If using CodeWarrior 10, go to Settings->Processor->Floating Point. You may be able to select software or hardware here, depending on your chip. I'm not at my programming computer right now, so I can't verify the procedure.

Also, it is my understanding that the math library only works on floating point variables (float, double, etc.), so it may fail also if you are trying to throw an int at it.  I have a k60 with hardware floating point enabled, and I can use the functions from math.h just fine.

0 Kudos