MATLAB: I see an error when generating PLC code about tunable parameter and real32_T/real_T

Simulink PLC Coder

I encounter an error in my model wen generating PLC code
"Simulink block 'Test/TestBlock' that consumes tunable parameter testParameter has datatype real32_T, however the values it contains are of type real_T."
I am using a Simulink.Parameter to specify a signal data type as the following:
testVariable.Value = 0.066;
In the constant block I assign a 'single' data type.

Best Answer

When we check the class of the Simulink Parameter value defined in workspace that it is defaulting to double.
>> class(testVariable.Value)
The output is 'double'.
This means your parameter value is defaulting to double . In this case it is best to define your values of the parameters as:
>> testVariable.Value=single(0.066)
To adjust the data type of the value.
This can be followed by checking:
>>class(testVariable.Value)
MATLAB will tell you that the class is now 'single'.