MATLAB Answers

Causing steady state error when conveting double (64 bit) data format to single (32 bit) format or run Simulink model on 32 bit processors such as Ti C2000.

3 views (last 30 days)
ebram smith
ebram smith on 14 Sep 2017
Commented: Jakub Vonkomer on 13 Feb 2021
I use Matlab R2017a and Embedded Coder Support Package for Texas Instrument C2000 processors. I designed a validated Phase-Locked Loop (PLL) including a feed-back loop to estimate power grid frequency (50 Hz). The simulation results (the voltage frequency and amplitude) in double format and the results of implemented model on Raspberry Pi 3 including 64 bit processor are correct but when I changed data format to single (32 bit) the frequency and amplitude increased. This steady state error is also visible in the results of implemented model on Launchxl-F28377S that includes a 32 bit DSP, however we do not expect steady state errors in feed-back loops. I think this problem is resulted from numerical errors. The Simulation model and the results of double and single format simulations and implemented model on Launchpad have been attached as a zip file. Should I change the model design (For example using fixed-point design or code programming)? Is it require another (further) setting or special requirements? How can I modify the model to run on this DSP without such errors in the experimental results?
The double format simulation results:
The single format simulation results:
The results of implemented model on DSP:

Answers (1)

Venkatesh Chilapur
Venkatesh Chilapur on 2 Nov 2017
Hi,
Generate code for C2000, code runs on target with 32-bit floating point for the given double in the simulink model. Because double maps to 32-bit floating point for C2000 and "long double" maps to 64bit floating point. Through a workaround by using the "Data type replacement" pane of the configset we can remap "double" to an alias of "long double" to ensure the generated code runs on target with 64bit float. But, this will affect the execution performance badly, So use of double is not recommended unless it is really required.
type cast the my_Double to long double in one header file.
HTH,
Venkatesh C
  1 Comment
Jakub Vonkomer
Jakub Vonkomer on 13 Feb 2021
Hi Venkatesh.
Thank you.
However, even if you define "my_Double" in Matlab like
my_Double=Simulink.AliasType('double');
it just generates something like this in the rtwtypes.h:
typedef my_Double real_T;
where real_T is defined as double, which is 32bit (single) precision on C2000.
Yes, there are ways how to overcome it, e.g. I use a different, manually edited rtwtypes.h, for building the code in CCS, but is there a nice, clean way to force Matlab to generate code where my_Double really is long double (64bit on C2000)? As far as I know, there is no native "long double" type in Matlab.
Best regards,
Jakub

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!