Products & Services Solutions Academia Support User Community Company

Learn more about Real-Time Workshop   

Simulink Built-In Blocks That Support Code Generation

The following tables summarize Real-Time Workshop and Real-Time Workshop Embedded Coder support for Simulink blocks. There is a table for each block library. For each block, the second column indicates any support notes, which give information about the block for code generation. For more detail, including data types each block supports, in the MATLAB Command Window, type showblockdatatypetable, or consult the block reference pages.

Additional Math and Discrete: Additional Discrete

BlockSupport Notes
Fixed-Point State-SpaceThe Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.
Transfer Fcn Direct Form II
  • The Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.

  • Generated code might rely on memcpy or memset (string.h).

Transfer Fcn Direct Form II Time Varying
Unit Delay Enabled
Unit Delay Enabled External IC
Unit Delay Enabled Resettable
Unit Delay Enabled Resettable External IC
Unit Delay External IC
Unit Delay Resettable
Unit Delay Resettable External IC
Unit Delay With Preview Enabled
Unit Delay With Preview Enabled Resettable
Unit Delay With Preview Enabled Resettable External RV
Unit Delay With Preview Resettable
Unit Delay With Preview Resettable External RV

Additional Math and Discrete: Increment/Decrement

BlockSupport Notes
Decrement Real WorldThe Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.
Decrement Stored Integer
Decrement Time To ZeroSupports code generation.
Decrement To ZeroThe Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.
Increment Real World
Increment Stored Integer

Continuous

BlockSupport Notes
Derivative
  • Consider using the Simulink Model Discretizer to map continuous blocks into discrete equivalents that support code generation. To start the Model Discretizer, select Tools > Control Design > Model Discretizer.

  • Not recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.

Integrator
PID Controller
PID Controller (2DOF)
State-Space
Transfer Fcn
Transport Delay
Variable Time Delay
Variable Transport Delay
Zero-Pole

Discontinuities

BlockSupport Notes
Backlash

Generated code might rely on memcpy or memset (string.h).

Coulomb and Viscous FrictionThe Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.
Dead ZoneSupports code generation.
Dead Zone DynamicThe Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.
Hit CrossingNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
QuantizerSupports code generation.
Rate LimiterCannot use inside a triggered subsystem hierarchy.
Rate Limiter DynamicThe Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.
RelaySupport code generation.
Saturation
Saturation DynamicThe Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.
Wrap To Zero

Discrete

BlockSupport Notes
Difference
  • The Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.

  • Not recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.

Discrete Derivative
  • Generated code might rely on memcpy or memset (string.h).

  • Depends on absolute time when used inside a triggered subsystem hierarchy.

Discrete FilterSupport code generation.
Discrete FIR Filter
PID Controller
  • Generated code might rely on memcpy or memset (string.h).

  • Depends on absolute time when used inside a triggered subsystem hierarchy.

PID Controller (2DOF)
Discrete State-Space

Generated code might rely on memcpy or memset (string.h).

Discrete Transfer Fcn
Discrete Zero-Pole
Discrete-Time IntegratorDepends on absolute time when used inside a triggered subsystem hierarchy.
First-Order HoldNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Integer DelaySupport code generation.
Memory
Tapped Delay
Transfer Fcn First OrderThe Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.
Transfer Fcn Lead or Lag
Transfer Fcn Real Zero
Unit Delay

Generated code might rely on memcpy or memset (string.h).

Zero-Order HoldSupports code generation.

Logic and Bit Operations

BlockSupport Notes
Bit ClearSupport code generation.
Bit Set
Bitwise Operator
Combinatorial Logic
Compare to Constant
Compare to Zero
Detect Change

Generated code might rely on memcpy or memset (string.h).

Detect Decrease
Detect Fall Negative
Detect Fall Nonpositive
Detect Increase
Detect Rise Nonnegative
Detect Rise Positive
Extract BitsSupport code generation.
Interval Test
Interval Test Dynamic
Logical Operator
Relational Operator
Shift Arithmetic

Lookup Tables

BlockSupport Notes
CosineThe Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.
Direct Lookup Table (n-D)Support code generation.
Interpolation Using Prelookup
Lookup Table
Lookup Table (2-D)
Lookup Table (n-D)
Lookup Table Dynamic
Prelookup
SineThe Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.

Math Operations

BlockSupport Notes
AbsSupport code generation.
Add
Algebraic ConstraintIgnored during code generation.
AssignmentSupport code generation.
Bias
Complex to Magnitude-Angle
Complex to Real-Imag
Divide
Dot Product
Gain
Magnitude-Angle to Complex
Math Function (10^u)
Math Function (conj)
Math Function (exp)
Math Function (hermitian)
Math Function (hypot)
Math Function (log)
Math Function (log10)
Math Function (magnitude^2)
Math Function (mod)
Math Function (pow)
Math Function (reciprocal)
Math Function (rem)
Math Function (square)
Math Function (sqrt)
Math Function (1/sqrt)
Math Function (transpose)
Matrix Concatenate
MinMax
MinMax Running Resettable
Permute Dimensions
Polynomial
Product
Product of Elements
Real-Imag to Complex
Reshape
Rounding Function
Sign
Sine Wave Function
  • Does not refer to absolute time when configured for sample-based operation. Depends on absolute time when in time-based operation.

  • Depends on absolute time when used inside a triggered subsystem hierarchy.

Slider GainSupport code generation.
Squeeze
Subtract
Sum
Sum of Elements
Trigonometric FunctionFunctions asinh, acosh, and atanh are not supported by all compilers. If you use a compiler that does not support the functions, the Real-Time Workshop software issues a warning message for the block and the generated code fails to link.
Unary MinusSupport code generation.
Vector Concatenate
Weighted Sample Time Math

Model Verification

BlockSupport Notes
AssertionSupports code generation.
Check Discrete Gradient

Not recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.

Check Dynamic GapSupport code generation.
Check Dynamic Lower Bound
Check Dynamic Range
Check Dynamic Upper Bound
Check Input ResolutionNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Check Static Gap
Check Static Lower Bound
Check Static Range
Check Static Upper Bound

Model-Wide Utilities

BlockSupport Notes
Block Support TableIgnored during code generation.
DocBlockUses the template symbol you specify for the RTW Embedded Coder Flag block parameter to add comments to generated code. Requires a Real-Time Workshop Embedded Coder license. For more information, see Using a Simulink DocBlock to Add a Comment.
Model InfoIgnored during code generation.
Time-Based Linearization
Trigger-Based Linearization

Ports & Subsystems

BlockSupport Notes
Atomic SubsystemSupport code generation.
CodeReuse Subsystem
Configurable Subsystem
Enable
Enabled Subsystem
Enabled and Triggered Subsystem
For Iterator Subsystem
Function-Call Generator
Function-Call Subsystem
If
If Action Subsystem
Model
Subsystem
Switch Case
Switch Case Action Subsystem
Triggered Subsystem
While Iterator Subsystem

Signal Attributes

BlockSupport Notes
Bus to VectorSupport code generation.
Data Type Conversion
Data Type Conversion Inherited
Data Type Duplicate
Data Type Propagation
Data Type Scaling Strip
ICNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
ProbeSupports code generation.
Rate Transition
  • Generated code might rely on memcpy or memset (string.h).

  • Cannot use inside a triggered subsystem hierarchy.

Signal ConversionSupport code generation.
Signal Specification
Weighted Sample Time
Width

Signal Routing

BlockSupport Notes
Bus AssignmentSupport code generation.
Bus Creator
Bus Selector
Data Store Memory
Data Store Read
Data Store Write
Demux
Environment ControllerNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
FromSupport code generation.
Goto
Goto Tag Visibility
Index Vector
Manual SwitchNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
MergeWhen multiple signals connected to a Merge block have a non-Auto storage class, all non-Auto signals connected to that block must be identically labeled and have the same storage class. When Merge blocks connect directly to one another, these rules apply to all signals connected to Merge blocks in the group.
Multiport SwitchSupport code generation.
Mux
Selector
Switch

Generated code might rely on memcpy or memset (string.h).

Sinks

BlockSupport Notes
DisplayIgnored for code generation.
Floating Scope
Outport (Out1) Supports code generation.
ScopeIgnored for code generation.
Stop Simulation
  • Not recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.

  • Generated code stops executing when the stop condition is true.

TerminatorSupports code generation.
To FileNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
To WorkspaceIgnored for code generation.
XY Graph

Sources

BlockSupport Notes
Band-Limited White NoiseCannot use inside a triggered subsystem hierarchy.
Chirp SignalNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Clock
ConstantSupports code generation.
Counter Free-RunningNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Counter Limited
  • The Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.

  • Not recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.

Digital ClockNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Enumerated ConstantSupports code generation.
From FileIgnored for code generation.
From Workspace
GroundSupport code generation.
Inport (In1)
Pulse GeneratorCannot use inside a triggered subsystem hierarchy. Does not refer to absolute time when configured for sample-based operation. Depends on absolute time when in time-based operation.
RampNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Random NumberSupports code generation.
Repeating Sequence
  • Not recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.

  • Consider using the Repeating Sequence Stair or Repeating Sequence Interpolated block instead.

Repeating Sequence Interpolated
  • The Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.

  • Cannot use inside a triggered subsystem hierarchy.

Repeating Sequence StairThe Real-Time Workshop software does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.
Signal BuilderNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Signal Generator
Sine Wave
  • Depends on absolute time when used inside a triggered subsystem hierarchy.

  • Does not refer to absolute time when configured for sample-based operation. Depends on absolute time when in time-based operation.

StepNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally correct and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Uniform Random NumberSupports code generation.

User-Defined

BlockSupport Notes
Embedded MATLAB FunctionSupport code generation.
Fcn
Level-2 M-File S-FunctionIgnored during code generation.
MATLAB FcnConsider using the Embedded MATLAB Function block instead.
S-FunctionS-functions that call into MATLAB are not supported for code generation. See User-Created Block Considerations for advice on generating optimized user-defined blocks.
S-Function Builder

  


Related Products & Applications

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

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