MATLAB: Does the function name change when I build the subsystem with Real-Time Workshop Embedded Coder

changecompileembeddedEmbedded Coderfunctionnamerealsimulinksimulink codertargettimeworkshop

When I use Real-Time Workshop Embedded Coder to right-click build a subsystem, the corresponding function is named "MyFnc_Start" instead of "MyFnc" in the generated C code.

Best Answer

This code generation behavior results from the "Sample time" parameter setting for a Constant block. When you set a Constant block's "Sample time" parameter to 'inf', Real-Time Workshop Embedded Coder assumes that the value of the Constant block cannot change and generates the start function "MyFnc_Start". If you set the "Sample time" parameter to '-1' (inherited), the coder assumes the value must be checked for each time step and generates functions for each time step, including "MyFnc" function.
To work around this issue, do the following:
1. Double click a Constant block to access the block parameters.
2. Change the setting of "Sample time" from 'inf' to '-1' (inherit sample time).
3. Click OK.
4. Repeat steps 1 to 3 for any remaining Constant blocks.
5. Rebuild the subsystem.