MATLAB: Do I get a ‘floating-point support’ error when Generating code for a S-function in Real-Time Workshop Embedded Coder 5.4 (R2009b)

Embedded Coder

I have written a C MEX S-function and I want to generate integer only code for a model with this S-function.
When generating code, I get the following error :
The parameter 'P1' of block 'reprod/engine_speed' is a floating point type. Consider changing the data type or selecting the 'support floating point numbers' option on the Configuration Parameters > Real-Time Workshop > Interface page.

Best Answer

This error is thrown when generating code for an integer model that contains a S-function with a double precision parameter that is defined as tunable and when the 'support floating point numbers' option on the Configuration Parameters > Real-Time Workshop > Interface page is not enabled.
The parameter 'P1' of block 'ExampleModel1/ExampleSFunction' is a floating point type. Consider changing the data type or selecting the 'support floating point numbers' option on the Configuration Parameters > Real-Time Workshop > Interface page.
By default, the s-function parameters are set to be tunable unless you specify that you don’t want them to be tunable using the following macro:
 
ssSetSFcnParamTunable(S, 0, SS_PRM_NOT_TUNABLE);
You can find relevant information in the documentation page titled "Make a block parameter tunable"
If you define a parameter as tunable, you will be able to change the value during simulation and run-time of the generated code and therefore the parameter will be included in the generated code. If the value is double and the rest of the model is integer, the parameter will need to be cast to integer in the generated code. The ‘floating-point support error’ is indicating that this parameter is double and that you should either turn on floating-point support or convert the parameter to integer. In this case, integer-only code and a non-tunable parameter are preferred, so changing the s-function parameter to not tunable resolves this issue.
Please see the link below for more information on support of floating-point numbers.