Skip to Main Content Skip to Search
Product Documentation

Code Generation

About Code Generation from Simscape Models

You can use Simulink Coder™ software to generate stand-alone C or C++ code from your Physical Networks models and enhance simulation speed and portability. Certain features of Simulink software also make use of generated or external code. This section explains code-related tasks you can perform with your Simscape models.

Code versions of Simscape models typically require fixed-step Simulink solvers, which are discussed in the Simulink documentation. Some features of Simscape software are restricted when you translate a model into code. See How Simscape Code Generation Differs from Simulink, as well as Limitations.

Related Simulink Code Generation Documentation

Consult Simulink Acceleration modes, Simulink Coder, and xPC Target™ documentation for general information on code generation.

Reasons for Generating Code

Code generation has many purposes and methods. There are two essential rationales:

Using Code-Related Products and Features

With Simulink, Simulink Coder, and xPC Target software, using several code-related technologies, you can link existing code to your models and generate code versions of your models.

Code-Related TaskComponent or Feature
Link existing code written in C or other supported languages to Simulink modelsSimulink S-functions to generate customized blocks
Speed up Simulink simulationsAccelerator mode
Rapid Accelerator mode
Generate stand-alone fixed-step code from Simulink modelsSimulink Coder software
Generate stand-alone variable-step code from Simulink modelsSimulink Coder Rapid Simulation Target (RSim)
Convert Simulink model to code and compile and run it on a target PCSimulink Coder and xPC Target software

How Simscape Code Generation Differs from Simulink

In general, using the code generated from Simscape models is similar to using code generated from regular Simulink models. However, there are certain differences.

Simscape and Simulink Code Generated Separately

Simulink Coder software generates code from the Simscape blocks separately from the Simulink blocks in your model. The generated Simscape code does not pass through model.rtw or the Target Language Compiler. All the code generated from a single model resides in the same directory, however.

Compiler and Processor Architecture Requirements

To generate and execute Simscape code, you must have a compiler and a processor that support:

Although the lcc compiler, which is installed along with MATLAB, is supported, for complex models the generated C-code complexity can exceed the capacity of lcc. MathWorks recommends that you consider using a commercial compiler. For example, Microsoft® Visual Studio® Express is available at no charge and compatible with Simscape software. For details on supported compiler versions, see

http://www.mathworks.com/support/compilers/current_release

Precompiled Libraries Provided for Selected Compilers

Simscape software and its add-on products provide static runtime libraries precompiled for compilers supported by Simulink Coder software. These are the standard UNIX compilers for UNIX operating systems, lcc and Microsoft Visual Studio for 32-bit Windows®, and Microsoft Visual Studio for 64-bit Windows.

For all other compilers, the static runtime libraries needed by code generated from Simscape models are compiled once per model during the code generation build process.

Simscape Code Reuse Not Supported

Reusable subsystems in Simulink reuse code that is generated once from the subsystem. You cannot generate reusable code from subsystems containing Simscape blocks.

Tunable Parameters Not Supported

A tunable parameter is a Simulink run-time parameter that you can change while the simulation is running. Simscape blocks do not support tunable parameters in either simulations or generated code.

Simscape Run-Time Parameter Inlining Override of Global Exceptions

If you choose to enable parameter inlining for code generated from a Simscape model, the software inlines all its run-time parameters. If you choose to make some of the global Simscape block parameters exceptions to inlining, the exceptions are ignored. You can change global tunable parameters only by regenerating code from the model.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS