MATLAB Answers

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

34 ビュー (過去 30 日間)
Gergely Szabó
Gergely Szabó 2019 年 3 月 4 日
Commented: Gergely Szabó 2019 年 9 月 23 日
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?

  0 件のコメント

サインイン to comment.

採用された回答

Antonin
Antonin 2019 年 3 月 5 日
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.

  1 件のコメント

Gergely Szabó
Gergely Szabó 2019 年 9 月 23 日
Thank You!
You are absolutely right!

サインイン to comment.

More Answers (1)

Venkatesh Chilapur
Venkatesh Chilapur 2019 年 3 月 5 日
Hi,
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.
Regards,
Venkatesh C

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。


Translated by