Generate DUT Ports for Tunable Parameters - MATLAB & Simulink (original) (raw)

Main Content

Tunable parameters that you use to adjust your model behavior during simulation can map to top-level DUT ports in your generated HDL code. HDL Coder™ generates one DUT port per tunable parameter.

You can generate a DUT port for a tunable parameter by using it in one of these blocks:

These blocks with the tunable parameter can be at any level of the DUT hierarchy, including within a model reference.

You cannot use HDL cosimulation with a DUT that uses tunable parameters in any of these blocks. If you use a tunable parameter in a block other than these blocks, code is generated inline and does not map to DUT ports. To use the value of a tunable parameter in a Chart or Truth Table block, see Use Tunable Parameter in Other Blocks.

You can define and store the tunable parameters in the base workspace or a Simulink® data dictionary. However, a Simulink data dictionary provides more capabilities. For details, see What Is a Data Dictionary?.

Prerequisites

To learn more about Simulink compiled data types, see Control Block Parameter Data Types.

Create and Add Tunable Parameter That Maps to DUT Ports

To generate a DUT port for a tunable parameter:

  1. Create a tunable parameter with StorageClass set toExportedGlobal.
    For example, to create a tunable parameter, myParam, and initialize it to 5, at the command line, enter:
    myParam = Simulink.Parameter;
    myParam.Value = 5;
    myParam.CoderInfo.StorageClass = 'ExportedGlobal';
    Create a tunable parameter in Base Workspace using the Model Explorer:
    • Add a Simulink.Parameter by selectingSimulink.Parameter from theAdd menu to the Base Workspace.
    • In the StorageClass column of theContents pane, set StorageClass toExportedGlobal.
    • Alternatively, in the Simulink.Parameter pane, clickCode Generation tab, setStorageClass toExportedGlobal.
      Alternatively, Create a tunable parameter in Model Workspace using the Model Explorer:
    • Add a Simulink.Parameter by selectingSimulink.Parameter from theAdd menu to the Model Workspace.
    • In the StorageClass column of theContents pane, click the Configure link.
    • Alternatively in the Simulink.Parameter pane, clickCode Generation tab, click Configure in Coder App.
    • In the Code Mappings pane, click theParameters tab. Under Model Parameters, set StorageClass toExportedGlobal.
      See Create Data Objects from Built-In Data Class Package Simulink.
  2. In your Simulink design, use the tunable parameter as the:
    • Constant value in a Constant block.
    • Gain parameter in a Gain block.
    • MATLAB® function argument in a MATLAB Function block.

Generated Code

The following VHDL® code is an example of code that HDL Coder generates for a Gain block with its Gain field set to a tunable parameter, myParam. You see that the code generator creates a DUT port and adds a comment to indicate that the port corresponds to a tunable parameter.

ENTITY s IS PORT( In1 : IN std_logic_vector(15 DOWNTO 0); -- sfix16_En5 myParam : IN std_logic_vector(15 DOWNTO 0); -- sfix16_En5 Tunable port Out1 : OUT std_logic_vector(31 DOWNTO 0) -- sfix32_En10 ); END s;

ARCHITECTURE rtl OF s IS

-- Signals SIGNAL myParam_signed : signed(15 DOWNTO 0); -- sfix16_En5 SIGNAL In1_signed : signed(15 DOWNTO 0); -- sfix16_En5 SIGNAL Gain_out1 : signed(31 DOWNTO 0); -- sfix32_En10

BEGIN myParam_signed <= signed(myParam);

In1_signed <= signed(In1);

Gain_out1 <= myParam_signed * In1_signed;

Out1 <= std_logic_vector(Gain_out1);

END rtl;

Limitations

Use Tunable Parameter in Other Blocks

To use the value of a tunable parameter in a Chart or Truth Table block:

  1. Create the tunable parameter and use it in a Constant block.
  2. Add an input port to the block where you want to use the tunable parameter.
  3. Connect the output of the Constant block to the new input port.