Identify and Programmatically Change and Display HDL Block Parameters

You can follow these guidelines to learn how you can identify block parameters in your design and programmatically update some of the parameters so that the model is compatible for HDL code generation. Each guideline has a severity level that indicates the level of compliance requirements. To learn more, see HDL Modeling Guidelines Severity Levels.

Adjust Sizes of Constant and Gain Blocks for Identifying Parameters

Guideline ID

1.1.11

Severity

Recommended

Description

For Constant blocks and Gain blocks that have significantly large values or use parameter values, the Constant or Gain values may not be visible in the block mask. To increase readability, adjust the size of the block so that the parameter value can be displayed as shown in figure.

Display Parameters that Affect HDL Code Generation

Guideline ID

1.1.12

Severity

Recommended

Description

Certain HDL block properties such as DistributedPipelining and SharingFactor can significantly affect HDL code generation. If the block properties are enabled for a certain block or Subsystem, it is recommended that you annotate the block properties beside that block in the Simulink™ diagram. When you annotate the model, use delimiters such as --HDL-- to separate the annotation from the block name.

For example, open the model hdlcoder_block_annotation_HDL_params.slx.

open_system('hdlcoder_block_annotation_HDL_params')
set_param('hdlcoder_block_annotation_HDL_params','SimulationCommand','Update')

The DUT Subsystem performs a simple multiply-add operation.

open_system('hdlcoder_block_annotation_HDL_params/DUT')

There are HDL block parameters saved on the model. To see the parameters, use the hdlsaveparams function.

hdlsaveparams('hdlcoder_block_annotation_HDL_params/DUT')
%% Set Model 'hdlcoder_block_annotation_HDL_params' HDL parameters
hdlset_param('hdlcoder_block_annotation_HDL_params', 'GenerateCoSimModel', 'ModelSim');
hdlset_param('hdlcoder_block_annotation_HDL_params', 'GenerateValidationModel', 'on');
hdlset_param('hdlcoder_block_annotation_HDL_params', 'HierarchicalDistPipelining', 'on');
hdlset_param('hdlcoder_block_annotation_HDL_params', 'MaskParameterAsGeneric', 'on');
hdlset_param('hdlcoder_block_annotation_HDL_params', 'MinimizeClockEnables', 'on');
hdlset_param('hdlcoder_block_annotation_HDL_params', 'MinimizeIntermediateSignals', 'on');
hdlset_param('hdlcoder_block_annotation_HDL_params', 'OptimizationReport', 'on');
hdlset_param('hdlcoder_block_annotation_HDL_params', 'ResetType', 'Synchronous');
hdlset_param('hdlcoder_block_annotation_HDL_params', 'ResourceReport', 'on');
hdlset_param('hdlcoder_block_annotation_HDL_params', 'TargetLanguage', 'Verilog');
hdlset_param('hdlcoder_block_annotation_HDL_params', 'Traceability', 'on');

% Set SubSystem HDL parameters
hdlset_param('hdlcoder_block_annotation_HDL_params/DUT', 'DistributedPipelining', 'on');
hdlset_param('hdlcoder_block_annotation_HDL_params/DUT', 'InputPipeline', 1);
hdlset_param('hdlcoder_block_annotation_HDL_params/DUT', 'OutputPipeline', 3);

% Set Sum HDL parameters
hdlset_param('hdlcoder_block_annotation_HDL_params/DUT/Add', 'InputPipeline', 1);
hdlset_param('hdlcoder_block_annotation_HDL_params/DUT/Add', 'OutputPipeline', 1);

% Set Product HDL parameters
hdlset_param('hdlcoder_block_annotation_HDL_params/DUT/Product', 'InputPipeline', 2);
hdlset_param('hdlcoder_block_annotation_HDL_params/DUT/Product', 'OutputPipeline', 1);

To annotate the model with the HDL block parameters saved on the model, use the showHdlBlockParams script attached with the example.

showHdlBlockParams('hdlcoder_block_annotation_HDL_params/DUT','on')
Add block annotation for hdlcoder_block_annotation_HDL_params/DUT. 
 ----HDL----\nDistributedPipelining = on\nInputPipeline = 1\nOutputPipeline = 3 


Add block annotation for hdlcoder_block_annotation_HDL_params/DUT/Add. 
 ----HDL----\nInputPipeline = 1\nOutputPipeline = 1 


Add block annotation for hdlcoder_block_annotation_HDL_params/DUT/Product. 
 ----HDL----\nInputPipeline = 2\nOutputPipeline = 1 


open_system('hdlcoder_block_annotation_HDL_params')

open_system('hdlcoder_block_annotation_HDL_params/DUT')

To remove the HDL block parameters annotation from the model, run the showHdlBlockParams set to off.

showHdlBlockParams('hdlcoder_block_annotation_HDL_params/DUT','off')
HDL block annotations for hdlcoder_block_annotation_HDL_params/DUT are removed
HDL block annotations for hdlcoder_block_annotation_HDL_params/DUT/In1 are removed
HDL block annotations for hdlcoder_block_annotation_HDL_params/DUT/In2 are removed
HDL block annotations for hdlcoder_block_annotation_HDL_params/DUT/In3 are removed
HDL block annotations for hdlcoder_block_annotation_HDL_params/DUT/Add are removed
HDL block annotations for hdlcoder_block_annotation_HDL_params/DUT/Product are removed
HDL block annotations for hdlcoder_block_annotation_HDL_params/DUT/Out1 are removed
open_system('hdlcoder_block_annotation_HDL_params')

open_system('hdlcoder_block_annotation_HDL_params/DUT')

Change Block Parameters by Using find_system and set_param

Guideline ID

1.1.13

Severity

Informative

Description

To modify the parameters of certain blocks, you can use the function find_system with the function set_param. For example, this script that detects all Constant blocks with a Sample time of inf and modifies it to -1:

modelname = ‘sfir_fixed’;
open_system (modelname)

% Detect all Constant blocks in the model
blockConstant = find_system(bdroot, 'blocktype', 'Constant')
 
% Detect the Constant blocks with sample time [inf], and change to [-1]
for  n  =  1:numel(blockConstant)
        sTime = get_param(blockConstant{n},'SampleTime') 
        if strcmp(lower(sTime), 'inf')
            set_param(blockConstant{n}, 'SampleTime', '-1')
    end
end

See Also

Functions

Related Topics