Use the Simulink® Report Generator with Simulink® Coder™ to automatically generate documentation for a model and its generated code.
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
Generate code for a control algorithm model, integrate the generated code with an existing system, and validate simulation and executable results.
Use Eclipse™ and Cygwin™, a free software integration development environment (IDE) and free compiler, for the examples Build Integrated Code Outside the Simulink Environment and Test
Add comments to numerous types of objects in Simulink® and Stateflow®.
Reuse previously generated code by creating a cross-release software-in-the-loop (SIL) block and incorporating the block within an integration model. For more information about the
Embedded Coder® provides three levels of control for parentheses in the generated code.
Validate generated code by using system-level S-functions or by running the code in an external environment.
Specify signals, states, and parameters for inclusion in generated code.
Customize generated identifiers by specifying the Identifier format control parameters on the Code Generation > Symbols pane in the Configuration Parameters dialog box.
Call existing, external functions from a simulation or from the generated code by using the Legacy Code Tool.
This model shows the code generated for a Simulink model containing a MATLAB script.
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
Use code generation templates to add custom code banners, rearrange data and functions, and insert additional code segments and documentation into generated code files.
Learn how characteristics of generated code and RAM/ROM data affect the RAM/ROM metric.
Apply uniform naming rules for Simulink® data objects, including signals, parameters, and data store memory variables.
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.
Develop and use code replacement libraries to replace function and operators in generated code. Code replacement is a technique to change the code that the code generator produces for
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
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.
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
Create and name a fixed-point data type in generated code. You can use the name of the type to specify parameter and signal data types throughout a model and in generated code.
Generate code that interfaces with legacy code by using specialized get and set functions to access data.
Associate subsystems in a model with function names and files.
How the generated code stores internal data such as block states.
Configure the generated code to use a data type name (typedef) that you specify.
Apply the custom storage class GetSet to nonvirtual bus signals and structure parameters in a model.
Apply storage classes to a signal, a block state, and a block parameter in a model.
To integrate the generated code with your own external code, you can configure data items in a model, such as signal lines and block parameters, to appear in the generated code as global
Customize the interface of C++ code that you generate from a model and want to call from C or C++ code. To call the C++ code from C code, you encapsulate the C++ class interface in the generated
Configure a model so that the code generator produces a custom interface for the step (execution) entry-point function.
How the generated code initializes signal, state, and parameter data.
This model shows user-defined types, consisting of numeric and alias types. Numeric types allow you to define abstract numeric types, which is particularly useful for fixed-point types.
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.
Configure a model such that the code generator produces an example main program that you can customize for deployment on bare-board target hardware (has no operating system). When you
Place external code in generated code by using custom code blocks and model configuration parameters.
Generate code for an air-fuel ratio control system designed with Simulink® and Stateflow®.
Use Simulink® variant subsystems to generate C preprocessor conditionals that control which child subsystem of the variant subsystem is active in the generated code produced by the
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.
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
Use the Legacy Code Tool to integrate legacy C functions with the block's sample time specified, inherited and parameterized.
Integrate legacy C++ object methods by using the Legacy Code Tool.
Use the Legacy Code Tool to integrate legacy C functions that pass their input arguments by value versus address.
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.
This model shows code generation for a single-rate discrete-time model configured for a bare-board target (one with no operating system).
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).
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.
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
The code generator optimizes generated code for vector signal assignments by trying to replace for loop controlled element assignments and memcpy function calls with pointer
Generate optimized code that reads from and writes to global variables less frequently.
If your model has the optimal parameter settings for removing data copies, you might be able to remove additional data copies by using Simulink.Signal objects to specify buffer reuse. After
Optimize the generated code by packing Boolean data into bitfields. When you select the model configuration parameter Pack Boolean data into bitfields, Embedded Coder® packs the Boolean
You can reuse buffers for matrices that have different sizes and shapes. In the Configuration Parameters dialog box, you enable this optimization by selecting Reuse buffers of different
Optimize generated code by removing code that protects against division by zero and overflows in division INT_MIN/-1 operations for integers and fixed-point data. If you are sure that
How the code generator optimizes fixed-point operations by replacing expensive division operations with highly efficient product operations. This optimization improves execution
Test numerical equivalence between model components and production code that you generate from the components by using software-in-the-loop (SIL) and processor-in-the-loop (PIL)
Create a target connectivity configuration by using target connectivity APIs. With a target connectivity configuration, you can run PIL simulations on custom embedded hardware.
Implement a communication channel for processor-in-the-loop (PIL) simulation.
If Simulink® Coverage™ is installed, you can collect code coverage metrics during a software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulation - see
Configure and run normal, software-in-the-loop (SIL), and processor-in-the-loop (PIL) simulations, and compare results.
The basic workflow and key APIs for generating C code from a motor control algorithm, and for verifying its compiled behavior and execution time. You will use Processor-in-the-loop (PIL)
Link generated code to model element requirements. Using configuration parameters, you can specify whether to include requirement descriptions as comments in the generated code.
Use Embedded Coder™ Support Package for ARM Cortex-A Processors for real-time execution profiling of generated code.
Use Embedded Coder Support Package for ARM Cortex-A Processors to run a Simulink® models on an ARM Cortex-A9 emulator.
Use Embedded Coder Support Package for ARM Cortex-A Processors for code verification and validation using PIL and External Mode.
Use Embedded Coder® Support Package for ARM Cortex-M™ Processors for code verification and validation using PIL.
Use the Embedded Coder™ Support Package for ARM Cortex-R Processors for real-time execution profiling of generated code. The hardware being used in this example is the Texas Instruments™
Use Embedded Coder™ Support Package for ARM® Cortex®-R Processors to verify and validate code using PIL and external mode. The hardware used in this example is the Texas Instruments™
Generate AUTOSAR-compliant C code and export AUTOSAR XML ( arxml ) descriptions from a Simulink® model.
Simulate AUTOSAR component calls to Basic Software memory and diagnostic services using reference implementations
Use Simulink® models, subsystems, and functions to model AUTOSAR atomic software components and their runnable entities (runnables).
Create Simulink® representation of AUTOSAR component imported from AUTOSAR authoring tool arxml file
Develop AUTOSAR components by implementing behavior algorithms, simulating components and compositions, and generating component code
Use Embedded Coder® Support Package for BeagleBone Black™ Hardware for code verification and validation using PIL and External Mode features.
Use the ALSA Audio Playback block from the BeagleBone Black™ block library to implement a parametric audio equalizer algorithm on BeagleBone Black hardware.
Use Embedded Coder Support Package for BeagleBone Black™ Hardware to run a Simulink® models on BeagleBone Black hardware.
Use the V4L2 Video Capture and the SDL Video Display blocks from the BeagleBone Black block library to implement an image inversion algorithm with a Simulink® model, and to run the model on
Use Embedded Coder Support Package for BeagleBone Black Hardware for Processor-in-the-Loop (PIL) verification of MATLAB® functions on hardware.
Use Embedded Coder™ Support Package for Intel® SoC Devices for real-time execution profiling of generated code.
Use Embedded Coder Support Package for Altera® SoC Platform to run a Simulink® model on an Intel SoC FPGA hardware.
Demonstrates how to use the Embedded Coder Support Package for STMicroelectronics Discovery Boards to run a Simulink® model on an STMicroelectronics STM32F4-Discovery,
Use Embedded Coder Support Package for STM32 Discovery Boards to run on the STM32F746G Discovery Board to send and receive UDP and TCP messages.
Use code replacement libraries for ARM Cortex-M processors to generate optimized code for the STMicroelectronics STM32F4-Discovery board.
Use Embedded Coder Support Package for STMicroelectronics Discovery Boards for Processor-in-the-Loop (PIL) verification of MATLAB® functions.
Use the GPIO blocks in the STMicroelectronics STM32F4-Discovery library to control the push-button and the LED's on the STMicroelectronics STM32F4-Discovery board.
Model the ITU-T G.729 Voice Activity Detector (VAD) algorithm and run it on the ARM® Cortex-M based STMicroelectronics® STM32 Discovery boards.
Use Embedded Coder Support Package for STMicroelectronics Discovery Boards for code verification and validation using PIL and External mode.
Model asynchronous scheduling using the Hardware Interrupt block for the STMicroelectronics STM32F4-Discovery board.
Model a three band parametric equalizer algorithm and run it on the ARM® Cortex M based STMicroelectronics® STM32 Discovery boards.
Use Embedded Coder Support Package for Texas Instruments C2000 Concerto processors ARM Cortex M3 core for code verification and validation using External mode.
In this example, you will learn how to configure a simple Simulink model to generate code for ARM and C28x cores of Concerto F28M3x processors and run the generated code on the board to
Control the speed of a three-phase Permanent Magnet Synchronous Motor in a closed-loop fashion via Field-Oriented Control using the C28x peripherals and DMC library blocks.
Use Embedded Coder Support Package for Texas Instruments C2000 Concerto processors to send and receive UDP and TCP messages using the ARM Cortex-M3 core of F28M3x Concerto processor.
Use Embedded Coder Support Package for Texas Instruments C2000 Concerto processor for code verification and validation using PIL.
Use the c28x peripherals and Hardware Interrupt blocks to control the real-time execution of Simulink® function-call subsystems in an asynchronous fashion.
Use the C28035 LIN Receive, LIN Transmit, and PWM blocks to generate a pulse waveform.
Model a controller for the DC/DC buck converter using the Embedded Coder Support Package for Texas Instruments® C2000 Processors. The model runs on a TI F28377S or F28379D Launchpad
Create a real-time executable for a Texas Instruments F28335 embedded target. You will build upon the algorithm specified in the example
Use Embedded Coder Support Package for Texas Instruments C2000 processor for code verification and validation using PIL.
Perform parameter tuning and data logging with a Simulink® model running in External mode on the Texas Instruments™ C2000 targets. See Embedded Coder Support Package for Texas Instruments
Use the Control Law Accelerator (CLA) available on some of the TI Piccolo processors.
Use Embedded Coder™ Support Package for Texas Instruments C2000 Processors and Embedded Coder Support Package for Texas Instruments C2000 F28M3x Concerto Processors for real-time
Simulate a Permanent Magnet Synchronous Machine model from SimPowerSystems™ toolbox using C28x peripherals and DMC library blocks.
Use the IPC blocks to communicate between the two CPUs of Texas Instruments™ Delfino F2837xD using Simulink® models.
Control the speed of a three-phase Permanent Magnet Synchronous Motor in a closed-loop fashion via Field-Oriented Control (FOC)using the C28x peripherals and DMC library blocks.
Use the CAN Calibration Protocol (CCP) block to monitor model signals and tune parameter values in the application code running on the target hardware. You can use either External mode or a
Use the ADC and PWM blocks. In the generated code, changes in the voltage of the ADC input alter the duty cycle of the PWM output. The period of the PWM waveform remains constant. This example
Model a controller and implement it on a Xilinx® Zynq™-7000 All Programmable SoC target. This example is based on a ZedBoard using an Analog Devices motor control FMC board. Note that if you do
Communicate with the FPGA IP core on the Zynq hardware using AXI4®-Lite protocol. AXI4 (Advanced eXtensible Interface 4) is an ARM® standard.
Configure the VxWorks® 7 operating system, generate code from a Simulink® model and run the executable on the Zynq hardware.
Generate code from a Simulink® model and run the executable on the Zynq hardware.
Send data using the UDP Ethernet protocol from a Simulink® model running on Zynq hardware to another model running on the host computer.
Use Embedded Coder™ Support Package for ARM Cortex-A® Processors for code verification and validation using PIL and External Mode.
Develop and use code replacement libraries to replace function and operators in generated code. Code replacement is a technique to change the code that the code generator produces for
Configure default data and function code generation for example model rtwdemo_configdefaults .The example uses the default mapping programming interface to specify code generation