Select a system target file for a Simulink® model, generate C code for real-time simulation, and view generated files.
The code generator provides model configuration parameters for customizing generated code. Depending on how you use and interact with the generated code, you make configuration
Specify standard library extensions that the code generator uses for math operations. When you generate code for a new model or with a new configuration set object, the code generator uses
Use the code generation template for a new Simulink project. The code generation project template for Simulink Project includes multiple models. The project template also provides
Add files to a new project, set up project shortcuts, generate code, and simulate the harness model. The models in this example demonstrate some principles of Model-Based Design (MBD).
Use the code generator to generate and review code for use in mixed languages and mixed locales.
This model shows ASAP2 data export. ASAP2 is a data definition standard proposed by the Association for Standardization of Automation and Measuring Systems (ASAM).
When you use a MATLAB® structure to specify initialization values for the signal elements in a bus, you can create a tunable global structure in the generated code.
Stateflow and MATLAB Coder can fully define their data definitions, or they can inherit them from Simulink. Data definition capabilities include:
This model illustrates the target-based C API for interfacing signals, parameters, and states in the generated code.
Configure an atomic subsystem for code generation. To specify that a subsystem's code executes as an atomic unit, select the Treat as atomic unit parameter on the block parameters dialog
Generate and optimize the code for a fixed-point air-fuel ratio control system designed with Simulink® and Stateflow®. For a detailed explanation of the model, see sldemo_fuelsys and
You can represent initial conditions for signals and states by creating tunable global variables in the generated code. These variables allow you to restart an application by using initial
How referenced models provide system interface encapsulation and incremental code generation. You can reference one model from another model (one or more times), and all aspects of the
To store multiple independent sets of values for the same block parameters, you can use an array of structures. To switch between the parameter sets, create a variable that acts as an index
As you iteratively develop a model, you capture output signal and state data that model execution generates. You also tune parameter values during execution to observe the effect on the
Create tunable parameter data by representing block parameters as global variables in the generated code.
Create a structure in the generated code. The structure stores parameter data.
When you use a Simulink.Parameter object or a numeric MATLAB variable to set two or more block parameter values, if the block parameters have different data types, you must explicitly
How the generated code stores internal data such as block states.
Apply storage classes to a signal, a block state, and a block parameter in a model.
The RSim target was designed to let you run batch simulations at the fastest possible speed. Using variable-step or fixed-step solvers with RSim combined with the use of a tunable parameter
How the RSim -i option in Simulink® Coder™ lets you use a MAT-file as the input data source for Inport blocks for rapid simulations. The data in such a MAT-file can be presented in any of the
Generate code from a model and produce a Visual Studio Solution. For the base example, see rtwdemo_counter .
Identify required files and interfaces for calling generated code in an external build process.
Simulink® allows you to configure the hardware implementation characteristics of your target system. Failure to do so can result in code that is incorrect or inefficient.
Register and use a toolchain to build an executable. This example uses the Intel® compiler. However, the concepts and programming interface apply for other toolchains. Once you register a
Use the RSim target to run simulations over a range of parameter values. The example uses the Van der Pol oscillator and performs a parameter sweep over a range of initial state values to obtain
Run batch simulations without recompiling the generated code. The example modifies input signal data and model parameters by reading data from a MAT-file. In the first part (steps 1-5), ten
Use the Build Information API and the Post Code Generation Command parameter, PostCodeGenCommand.
Build models by using a batch file, entering commands at the Command Prompt in Windows.
Place external code in generated code by using custom code blocks and model configuration parameters.
Integrate legacy C functions that pass their inputs and outputs by using parameters of a fixed-point data type with the Legacy Code Tool.
Optimize the amount of memory that the code generator allocates for time counters. The example optimizes the memory that stores elapsed time, the interval of time between two events.
Use the Legacy Code Tool to integrate legacy C functions with the block's sample time specified, inherited and parameterized.
Use the Legacy Code Tool to integrate legacy C functions that pass their input arguments by value versus address.
Integrate legacy C++ object methods by using the Legacy Code Tool.
Simulate and generate code for a model that triggers asynchronous events in an example RTOS (VxWorks®) that get passed as input to a referenced model.
Integrate legacy C functions using complex signals with the Legacy Code Tool.
Use the Legacy Code Tool to integrate legacy C functions that pass their output as a return argument.
This model shows the code generated for a multirate discrete-time model configured for single-tasking on a bare-board target (one with no operating system).
This model shows the code generated for a single-rate discrete-time model configured for a bare-board target (one with no operating system).
Integrate legacy C functions with structure arguments that use Simulink® buses with the Legacy Code Tool.
This model shows the differences in the operation modes of the Rate Transition block when used in a multirate, multitasking model. The flexible options for the Rate Transition block allow
Use the Legacy Code Tool to integrate legacy C functions whose arguments have inherited dimensions.
Integrate legacy C functions that use instance-specific persistent memory by using the Legacy Code Tool.
Integrate legacy C functions that implement N-dimensional table lookups by using the Legacy Code Tool.
Use the Legacy Code Tool to integrate legacy C functions that pass their inputs and outputs by using parameters of fixed-point data type.
Simulate and generate code for asynchronous events on a multitasking real-time operating system (VxWorks®). The model shows different techniques for handling asynchronous events
Use the Legacy Code Tool to integrate legacy C functions with multi-dimensional Signals.
Integrate legacy C functions that have start and terminate actions by using the Legacy Code Tool.
This model shows the code generated for a multirate discrete-time model configured for a multitasking bare-board target (one with no operating system).
The data interface of a model is the means by which the model exchanges data (for example, signal values) with other, external models or systems. Customize the data interface of a model to:
Use a configuration reference to select a code generation target for a model reference hierarchy without modifying individual models.
Optimize the generated code by using the memset function to clear the internal storage. When you select the model configuration parameter Use memset to initialize floats and doubles to 0.0,
Use inline invariant signals to optimize the generated code. This optimization transforms symbolic names of invariant signals into constant values.
Optimize generated code by storing logical signals as Boolean data. When you select the model configuration parameter Implement logic signals as Boolean data (vs. double), blocks that
How the code generator combines for loops. The generated code uses for constructs to represent a variety of modeling patterns, such as a matrix signal or Iterator blocks. Using data
Use floating-point multiplication to handle a net slope correction. When converting floating-point data types to fixed-point data types in the generated code, a net slope correction is
How the code generator optimizes generated code by removing code that has no effect on computational results. This optimization:
How the code generator eliminates dead (that is, unused) code paths from generated code. This optimization increases execution speed and conserves ROM and RAM consumption.
How Simulink Coder handles complex signals efficiently. To view the data types of the signals, update the model using Simulation > Update Diagram. Complex signals are represented as
How Simulink® Coder™ optimizes generated code by setting block output that generates vectors to scalars, for blocks such as the Mux, Sum, Gain, and Bus. This optimization reduces stack
Expression folding optimizes code to minimize the computation of intermediate results at block outputs and the storage of such results in temporary buffers or variables. When expression
This model shows a fixed-point version of an acoustic noise canceller.
Optimize the generated code for a model that contains Switch and Multiport Switch blocks. When you select the model configuration parameter Conditional input branch execution, Simulink
This model shows fixed-point code generation in Simulink®, Stateflow®, and MATLAB®.
Optimize the generated code by inlining the numeric values of block parameters. Block parameters include the Gain parameter of a Gain block and the table data and breakpoint sets of an n-D
These examples show how to generate efficient code by configuring a block parameter to use the same data type as a signal that the block operates on.
When you use a parameter object (for example, Simulink.Parameter) to set block parameter values, you can configure the object to appear in the generated code as a tunable global variable. By
Perform parameter tuning and data logging with a Simulink® model running in External mode on ARM Cortex-based VEX Microcontroller targets.
Use Simulink Coder Support Package for ARM Cortex-based VEX Microcontroller to implement both Autonomous mode and Driver mode in the same Simulink model. Autonomous mode, Driver mode and
Use Simulink Coder Support Package for ARM Cortex-based VEX Microcontroller to run a Simulink® model on a VEX microcontroller.
Use Simulink Coder Support Package for ARM Cortex-based VEX Microcontroller to control a servo motor using a digital button on the VEXnet Joystick.
Use Simulink Coder Support Package for ARM Cortex-based VEX Microcontroller to control 2-wheeled tank robot using a VEX wireless controller.
Use Simulink Coder Support Package for ARM Cortex-based VEX Microcontroller to interface the VEX Integrated Encoder Module to the VEX Microcontroller and use the sensor data to control a
Use Simulink Coder Support Package for ARM Cortex-based VEX microcontroller to interface the VEX ultrasonic sensor to the VEX Microcontroller and use the sensor data to control a 4-wheeled
Use Simulink Coder Support Package for ARM Cortex-based VEX Microcontroller to create an application in which a 4-wheeled robot turns by a degree of angle chosen by the user from the options
Use Simulink® models for wireless communication and control between two BBC micro:bit boards.
Develop a Simulink model to implement a Dice Simulation on BBC micro:bit board using the on board Accelerometer sensor and 5x5 LED Matrix.
Use Simulink Coder Support Package for BBC micro:bit to run Simulink® model on a BBC micro:bit.
Use Simulink® models to play musical tunes and a piano with BBC micro:bit.
Use Simulink Coder™ Support Package for BeagleBone® Blue Hardware to run a Simulink® model on a BeagleBone Blue hardware.
Use Simulink Coder Support Package for NXP FRDM-K64F for code verification and validation using External mode.
Use Simulink Coder Support Package for NXP FRDM-K64F Board to run Simulink® model on a FRDM-K64F board.
Use Simulink Coder Support Package for NXP FRDM-K64F Board to configure and read temperature from an NXP FXOS8700CQ sensor which is a I2C based sensor.
Perform MAT-file logging from a Simulink® model on a Micro SD card mounted on NXP FRDM-K64F board.
Use Simulink Coder Support Package for NXP FRDM-KL25Z Board to control a servo motor connected to FRDM-TFC Shield.
Use Simulink Coder Support Package for NXP FRDM-KL25Z Board to run Simulink® model on a NXP FRDM-KL25Z board.
Use Simulink Coder Support Package for NXP FRDM-KL25Z for code verification and validation using External mode.
Use Simulink Coder Support Package for NXP FRDM-KL25Z Board for code verification and validation using PIL. To run this model you need to have Embedded Coder Toolbox.
Tune the parameters and monitor the signals of an algorithm running on STMicroelectronics Nucleo Board.
Use Simulink® Coder Support Package for STMicroelectronics Nucleo board to enable and write to/ read from an SPI based EEPROM.
Use Simulink Coder Support Package for STMicroelectronics Nucleo Boards for code verification and validation using PIL. The PIL feature requires Embedded Coder product.
Demonstrates how to use the Simulink Coder Support Package for STMicroelectronics Nucleo Boards to run a Simulink® model on an STMicroelectronics Nucleo board.
Demonstrates how to use the Simulink Coder Support Package for STMicroelectronics Nucleo Boards to run a Simulink® model on an STMicroelectronics Nucleo board to brighten up and dims down
Use Simulink® Coder Support Package for STMicroelectronics Nucleo Boards to configure and read data from an I2C based sensors.
Avnet created MiniZed™ to help designers get started with the Xilinx® single-core Zynq® 7Z007S SoC. The Avnet MiniZed Support Package for Simulink makes it easy to program the board using C
Run a processor in the loop (PIL) Simulation using the Target for TI HERCULES™ RM48 MCUs package.
Run a processor in the loop (PIL) Simulation using the Target for TI HERCULES™ RM48 MCUs package.
Copyright (C) 2012-2014 Texas Instruments Incorporated - http://www.ti.com/
This function performs simple checks on the preferences configured by the function TI_HERCULES_RM48_setup(). These checks are limited to confirmation that paths and certain
This function must be customized and then executed before the target support package for TI RM48 MCUs will run properly. Note: if you are viewing the abbreviated form of this help through the