TI C2000 code generation generates double data type functions instead of single ones
11 views (last 30 days)
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?
Antonin on 5 Mar 2019
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,
More Answers (1)
Venkatesh Chilapur on 5 Mar 2019
Please note that the CRL we support are meant to be used for fixed point math. These CRL's don't support float operations.
The reason error pop's up for C99 extension is because the TI compiler is not fully ready to support this extension. Here is a link on the C99 support in TI compilers.
For float, the TI Math libraries support the implementation of the float operations.
However, you may need to have CRL and C99 extension in the same application. For this, we can provide a p-code file that can help overcome the error.
The attached "rtwTargetInfo.p" file from zip can be replaced at path:
'C:\ProgramData\MATLAB\SupportPackages\R20xxy\toolbox\target\supportpackages\tic2000_base\crl' after taking backup of old file.
You also need to add the compiler flag --c99 to enable support for C99 constructs. Please note, there could be implications of enabling the C99 option and could cause compiler issues like error or warning. So please enable this option with care.