HDL Coder™ supports both predefined and user-defined System objects for code generation.
System objects provide a design advantage because:
You can save time during design and testing by using existing System object™ components.
You can design and qualify custom System objects for reuse in multiple designs.
You can define your algorithm in a System object once, and reuse multiple instances of it in a single MATLAB design.
This idiom cannot be used with MATLAB functions that have state. For example, if the algorithm has state and requires the use of persistent variables, that function cannot be instantiated multiple times in a design. Instead, you would need to copy and rename the function for each instance.
HDL code that you generate from System objects is modular and more readable.
Predefined System objects that are available with MATLAB®, DSP System Toolbox™, and Communications Toolbox™ are supported for HDL code generation. For a list, see Predefined System Objects Supported for HDL Code Generation.
You can create user-defined System objects for HDL code generation. For an example, see Generate Code for User-Defined System Objects.
The following limitations apply to HDL code generation for all System objects:
Your design can call the step
method only once per
System object.
step
must not be inside a nested conditional
statement, such as a nested loop, if
statement, or
switch
statement.
step
must not be inside a conditional statement that
contains a matrix indexing operation.
A System object must be declared persistent if it has state.
A System object has state when it has a tunable private or public
property, or a property with the DiscreteState
attribute.
You can use the dsp.Delay
System object only in feed-forward delay modeling.
Enumerations are not supported.
Global variables are not supported.
For predefined System Objects, step
is the
only method supported for HDL code generation.
For user-defined System Objects, either the
step
method, or the output
and
update
methods, are supported for HDL code
generation.
Predefined System objects are not supported for HDL code generation from within a MATLAB System block.
In addition to the limitations for all System objects, the following restrictions apply to user-defined System objects for HDL code generation:
In the setupImpl
and resetImpl
methods, if you assign values to properties or variables, the values
must be constants.
If your design uses the output
and
update
methods, it can call each method only once
per System object.
Initial and reset values for properties must be compile-time constant.
User-defined System objects must not be public properties.
A step
method with multiple outputs cannot be called
within a conditional statement.
To learn how to use System objects for HDL code generation, view the MATLAB designs in the following examples: