MATLAB: TI C2000 code generation generates double data type functions instead of single ones

c2000c99code generationcode replacementsEmbedded Codersimulink

Hi MATLAB!
I have the following problem which I have not solved yet. Currently I am using a F28379D and F28069M Launchpads, but I think my problem is related with C2000 MCUs.
I am using Embedded Coder and TI C2000 Hardware Support package to generate C code from my models. To test the code generation I made the following model:
Simply I am blinking a led, and calculating the sin cos of 1Hz counter. In the Configuration reference the default settings for these Launchpads are the TI C28x Code replacement library and C89/90(ANSI) setting for Standard math library.
After generating the code from this model I got the following for the sin cos functions. It can be see,and thanks to the ANSI math lib, that these are double argument functions, which I don't think are the best chose for a single precision MCU.
TI C28X with C99 extension also is an option for the code generation, but the functions remain double ones.
After this I have tried to switch to C99 (ISO) math library, but this is not supported with none of the TI C28X code replacement libraries.
The only option to eliminate the double precision functions is to select none of the code replacement libraries, and setting the Standard math library to C99.
My question is that, can I use anyway C99 math library to obtain for example sinf() instead if sin(), with one of the C28X Code Replacement libraries or not? Is it worth to use any of the TI C28X Code replacement libraries?

Best Answer

Hi Gergely,
On C2000 devices, double maps to single. I don't think there is any difference between sinf and sin. The result and the execution performance should be identical. My suggestion would be to verify that from your end.
There is an emulated way to create 64-bit floating point variables but you have to declare them as "long double" I don't think TI provides trigonometric functions for long double as they would be computationally expensive.
In general, it is preferable to avoid using the double data type in Simulink as the simulation will mismatch code generation. in the generated code, there is no difference between double and single, they both map to 32-bit single.
I hpoe it helps,
Thanks,
Antonin.