Generate DUT Ports for Tunable Parameters
You can use tunable parameters to modify block values during simulation, which enables you to evaluate model performance and test various scenarios. When you generate HDL code with HDL Coder™, tunable parameters are mapped to top-level DUT ports. For each tunable parameter, HDL Coder generates a corresponding DUT port. For more information about tunable parameters, see Tune and Experiment with Block Parameter Values.
You can generate a DUT port for a tunable parameter by using it in one of these blocks:
Chart (Stateflow)
Truth Table (Stateflow)
State Transition Table (Stateflow)
You can place these blocks at any level of the DUT hierarchy, including inside a model reference. If you use a tunable parameter in any other block, HDL Coder generates the parameter as inline code, and it does not map to a DUT port.
You cannot use HDL cosimulation with a DUT that uses tunable parameters in any of these blocks.
Create and Add Tunable Parameters That Maps to DUT ports
You can create a tunable parameter programmatically or by creating a parameter interactively in the Model Explorer. You can define tunable parameters in the base workshop or the model workshop.
Create Tunable Parameter by Using the Model Explorer
You can create a parameter in the base workspace or the model workspace. To create a parameter in the base workspace:
In the Model Explorer Model Hierarchy pane, select
Base Workspace.On the toolbar, click the arrow next to Add Parameter
or Add Signal
. From the drop-down list, select Simulink
Parameter.Model Explorer creates a parameter object in the base workspace. The default name for new parameter objects is
Param.In the StorageClass column of the Contents pane, set StorageClass to
ExportedGlobal.Alternatively, in the Simulink.Parameter pane, click Code Generation tab and set StorageClass to
ExportedGlobal.
Alternatively, in the Simulink.Parameter pane, to create a parameter in the model workspace:
In the Model Explorer Model Hierarchy pane, select
Model Workspace.On the toolbar, click the arrow next to Add Parameter
or Add Signal
. From the drop-down list, select Simulink
Parameter.Model Explorer creates a parameter object in the model workspace. The default name for new parameter objects is
Param.In the StorageClass column of the Contents pane, click the Configure link.
Alternatively in the Simulink.Parameter pane, click Code Generation tab, click Configure in Coder App.
In the Code Mappings pane, click the Parameters tab. Under Model Parameters, set StorageClass to
ExportedGlobal.
Create Tunable Parameter Programmatically
Create a tunable parameter programmatically by creating a
Simulink.Parameter object named myParam and
initialize it to 5. At the command line,
enter:
myParam = Simulink.Parameter;
myParam.Value = 5;
myParam.CoderInfo.StorageClass = 'ExportedGlobal';For more information, see Create Data Objects from Built-In Data Class Package Simulink.
You can define and store tunable parameters in the base workspace or a Simulink® data dictionary. A Simulink data dictionary provides more capabilities. For more information, see What Is a Data Dictionary?.
Add Tunable Parameters to Blocks
The value of a tunable parameter can be either a structure or a scalar data type.
To generate a DUT port for a tunable parameter in HDL code for your Simulink model, use the tunable parameter as the:
Constant value parameter in a Constant block.
Gain parameter in a Gain block.
MATLAB® function argument in a MATLAB Function block.
For more information about using parameter objects, see Use Parameter Objects.
Prerequisites
The Simulink compiled data type must be same for all instances of a tunable parameter. For more information, see Control Block Parameter Data Types.
Simulink blocks that use tunable parameters with the same name must operate at the same data rate.
To generate DUT input ports for tunable parameters in the HDL code, select the Enable HDL DUT input port generation for tunable parameters configuration parameter and clear the Use trigger signal as clock configuration parameter.
Generate Tunable Parameters as DUT Ports in HDL Code
This example shows how to create tunable parameters and generate them as DUT ports in the HDL code. It covers scenarios with Gain blocks inside a model reference, a masked subsystem, and a structure data type used as a tunable parameter.
Create Tunable Parameters
Create four tunable parameters with different values. Enter these commands at the MATLAB® command line:
% Create a tunable parameter, Param1, and initialize it to 5 Param1 = Simulink.Parameter; Param1.Value = 5; Param1.CoderInfo.StorageClass = 'ExportedGlobal'; % Create a tunable parameter, Param2, and initialize it to 8.67 Param2 = Simulink.Parameter; Param2.Value = 8.67; Param2.CoderInfo.StorageClass = 'ExportedGlobal'; % Create a tunable parameter, Param3, of struct type structVar = struct('a', 24.3); Simulink.Bus.createObject(structVar); busType = slBus1; clear slBus1 Param3 = Simulink.Parameter(structVar); Param3.DataType = 'Bus: busType'; Param3.CoderInfo.StorageClass = 'ExportedGlobal'; % Create a tunable parameter, Param4, and initialize it to 3 Param4 = Simulink.Parameter; Param4.Value = 3; Param4.CoderInfo.StorageClass = 'ExportedGlobal';
Load and Open Subsystem
Load and open the hdlcoder_tunable_parameter model.
load_system("hdlcoder_tunable_parameter"); open_system("hdlcoder_tunable_parameter/subsystem_dut"); set_param("hdlcoder_tunable_parameter", "SimulationCommand", "update");

The model contains a subsystem named subsystem_dut. The subsystem_dut subsystem includes these subsystems and blocks:
model_reference: A model reference that references theref_subsystem, which contains a Gain block,gain2, with its Gain parameter set toParam2.subsystem_struct: A subsystem that contains a Gain block,gain3, with its Gain parameter set toParam3.a.subsystem_mask: A masked subsystem that contains a Gain block,gain4, with its Gain parameter set toParam4.gain1: A Gain block with its Gain parameter set toParam1.
Generate HDL Code
Generate code for the hdlcoder_tunable_parameter subsystem.
makehdl("hdlcoder_tunable_parameter/subsystem_dut");### Working on the model hdlcoder_tunable_parameter ### Generating HDL for hdlcoder_tunable_parameter/subsystem_dut ### Using the config set for model hdlcoder_tunable_parameter for HDL code generation parameters. ### Running HDL checks on the model 'hdlcoder_tunable_parameter'. ### Begin compilation of the model 'hdlcoder_tunable_parameter'... ### Working on the model 'ref_subsystem'... ### Working on the model 'hdlcoder_tunable_parameter'... ### The code generation and optimization options you have chosen have introduced additional pipeline delays. ### The delay balancing feature has automatically inserted matching delays for compensation. ### The DUT requires an initial pipeline setup latency. Each output port experiences these additional delays. ### Output port 1: 28 cycles. ### Output port 2: 28 cycles. ### Working on... GenerateModel ### Begin model generation 'gm_ref_subsystem'... ### Rendering DUT with optimization related changes (IO, Area, Pipelining)... ### Model generation complete. ### Generated model saved at hdlsrc/hdlcoder_tunable_parameter/ref_subsystem/gm_ref_subsystem.slx ### Begin model generation 'gm_hdlcoder_tunable_parameter'... ### Rendering DUT with optimization related changes (IO, Area, Pipelining)... ### Model generation complete. ### Generated model saved at hdlsrc/hdlcoder_tunable_parameter/gm_hdlcoder_tunable_parameter.slx ### Begin VHDL Code Generation for 'ref_subsystem'. ### Begin VHDL Code Generation for 'hdlcoder_tunable_parameter'. ### Working on ref_subsystem as hdlsrc/hdlcoder_tunable_parameter/ref_subsystem/ref_subsystem_ref_subsystem.vhd. ### Code Generation for 'ref_subsystem' completed. ### Generating HTML files for code generation report at index.html ### Working on hdlcoder_tunable_parameter/subsystem_dut/subsystem_mask/nfp_mul_double as hdlsrc/hdlcoder_tunable_parameter/nfp_mul_double.vhd. ### Working on hdlcoder_tunable_parameter/subsystem_dut/subsystem_mask as hdlsrc/hdlcoder_tunable_parameter/subsystem_mask.vhd. ### Working on hdlcoder_tunable_parameter/subsystem_dut/subsystem_struct as hdlsrc/hdlcoder_tunable_parameter/subsystem_struct.vhd. ### Working on hdlcoder_tunable_parameter/subsystem_dut/nfp_add_double as hdlsrc/hdlcoder_tunable_parameter/nfp_add_double.vhd. ### Working on hdlcoder_tunable_parameter/subsystem_dut as hdlsrc/hdlcoder_tunable_parameter/subsystem_dut.vhd. ### Generating package file hdlsrc/hdlcoder_tunable_parameter/subsystem_dut_pkg.vhd. ### Code Generation for 'hdlcoder_tunable_parameter' completed. ### Generating HTML files for code generation report at index.html ### Creating HDL Code Generation Check Report subsystem_dut_report.html ### HDL check for 'hdlcoder_tunable_parameter' complete with 0 errors, 0 warnings, and 0 messages. ### Creating HDL Code Generation Check Report ref_subsystem_report.html ### HDL check for 'ref_subsystem' complete with 0 errors, 0 warnings, and 0 messages. ### HDL code generation complete.
HDL Coder™ generates VHDL® code for the subsystem_dut subsystem and generate one DUT port for each tunable parameter. This code snippet shows that the Param1, Param2, Param3.a, and Param4 tunable parameters are generated as DUT ports. The comments indicate that each port corresponds to a tunable parameter.

Limitations
When you use test point or tunable parameters in the IP core workflow, the DUT must be a subsystem level DUT, not the top-level model or model reference DUT.
You can set the value of a tunable parameter to a structure or a scalar data type. Complex, enumerated, and matrix types, as well as mathematical expression are not supported.
You cannot set the value of a block parameter to an expression that includes tunable parameters.
Use Tunable Parameter in Chart, Truth Table, or State Transition Table Block
To use the value of a tunable parameter in a Chart, Truth Table, or State Transition Table block:
Create the tunable parameter and use it in a Constant block.
Add an input port to the block where you want to use the tunable parameter.
Connect the output of the Constant block to the new input port.