Why do I get an error regarding tunable parameter and real32_T/real_T when generating PLC code?

2 views (last 30 days)
I encounter the following error in my model when generating PLC code using MATLAB R2018b through R2019b:
Simulink block 'MyModel/TestBlock' that consumes tunable parameter Param1 has datatype real32_T, however
the values it contains are of type real_T.
Or from R2020a:
Invalid data type. The 'MyModel/TestBlock' block that consumes tunable parameter Param1 expects real32_T
datatype. However the parameter values are of type real_T. Use a typed expression, such as single(21.1)
to set the value property of the parameter.
My parameter 'Param1' already has been defined to have 'single' data type.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 9 Aug 2022
Edited: MathWorks Support Team on 9 Aug 2022
This is an expected conformance check performed by Simulink PLC Coder. It occurs because there is a mismatch between the specified data type 'single' (real32_T) and the provided value which defaults to 'double' (real_T) in MATLAB/Simulink.
If the parameter is a Simulink.Parameter, define the value as shown below and verify the data type of the value:
>> testVariable.Value=single(1.234)
>> class(testVariable.Value)
ans =
    'single'
If the parameter is defined in a Data Dictionary, make sure to explicitly cast the value of the parameter to single as shown below:

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!