Main Content

Recommended Block Parameter Settings of Multiport Switch Block for Numeric and Enumerated Types

Guideline ID

2.3.2

Severity

Recommended

Description

To switch multiple input signals in your model for HDL code generation, you can use Switch, Multiport Switch, and Index Vector blocks. The Index Vector block is equivalent to the Multiport Switch block that has Number of data terminals set to 1.

You can use numeric and enumerated data types for the Multiport Switch block. When using numeric data types, in the Block Parameters dialog box of the Multiport Switch block, set Data Port Order to Zero-based contiguous and Data port for default case to Last data port. When number of input signals is a power of two, the Zero-based contiguous mode minimizes the number of bits of the control port.

For an example that uses Multiport Switch block with numeric types, open the model hdlcoder_multiport_switch_numeric.

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

The DUT subsystem contains a Multiport Switch block and an Index Vector block.

open_system('hdlcoder_multiport_switch_numeric/DUT')

To generate HDL code for the DUT, run the makehdl function.

makehdl('hdlcoder_multiport_switch_numeric/DUT')
### Working on the model <a href="matlab:open_system('hdlcoder_multiport_switch_numeric')">hdlcoder_multiport_switch_numeric</a>
### Generating HDL for <a href="matlab:open_system('hdlcoder_multiport_switch_numeric/DUT')">hdlcoder_multiport_switch_numeric/DUT</a>
### Using the config set for model <a href="matlab:configset.showParameterGroup('hdlcoder_multiport_switch_numeric', { 'HDL Code Generation' } )">hdlcoder_multiport_switch_numeric</a> for HDL code generation parameters.
### Running HDL checks on the model 'hdlcoder_multiport_switch_numeric'.
### Begin compilation of the model 'hdlcoder_multiport_switch_numeric'...
### Working on the model 'hdlcoder_multiport_switch_numeric'...
### Working on... <a href="matlab:configset.internal.open('hdlcoder_multiport_switch_numeric', 'GenerateModel')">GenerateModel</a>
### Begin model generation 'gm_hdlcoder_multiport_switch_numeric'...
### Copying DUT to the generated model....
### Model generation complete.
### Generated model saved at <a href="matlab:open_system('hdlsrc/hdlcoder_multiport_switch_numeric/gm_hdlcoder_multiport_switch_numeric.slx')">hdlsrc/hdlcoder_multiport_switch_numeric/gm_hdlcoder_multiport_switch_numeric.slx</a>
### Begin Verilog Code Generation for 'hdlcoder_multiport_switch_numeric'.
### Working on hdlcoder_multiport_switch_numeric/DUT as hdlsrc/hdlcoder_multiport_switch_numeric/DUT.v.
### Code Generation for 'hdlcoder_multiport_switch_numeric' completed.
### Generating HTML files for code generation report at <a href="matlab:hdlcoder.report.openDdg('/tmp/Bdoc24b_2725827_3882109/tp31cd77df/hdlcoder-ex69164871/hdlsrc/hdlcoder_multiport_switch_numeric/html/hdlcoder_multiport_switch_numeric_codegen_rpt.html')">hdlcoder_multiport_switch_numeric_codegen_rpt.html</a>
### Creating HDL Code Generation Check Report file:///tmp/Bdoc24b_2725827_3882109/tp31cd77df/hdlcoder-ex69164871/hdlsrc/hdlcoder_multiport_switch_numeric/DUT_report.html
### HDL check for 'hdlcoder_multiport_switch_numeric' complete with 0 errors, 0 warnings, and 0 messages.
### HDL code generation complete.

When you use enumerated types as input to the Multiport Switch, set Data Port Order to Specify Indices. You define the enumeration class in a MATLAB® file. When you use the default case, set the Default case diagnostic to Warning or None.

For an example that uses Multiport Switch block with enumerated types, open the model hdlcoder_multiport_switch_enum. This code shows the enumerated class defined in MATLAB.

classdef BasicColors < Simulink.IntEnumType
    
  enumeration
    Red(0)
    Yellow(1)
    Blue(2)
  end
  
  methods (Static)
    function retVal = getDefaultValue()
      retVal = BasicColors.Blue;
    end
  end
  
end

Open the model hdlcoder_multiport_switch_enum.

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

The DUT subsystem contains two Multiport Switch blocks. The second Multiport Switch block has Data Port Order set to Specify Indices.

open_system('hdlcoder_multiport_switch_enum/DUT')

To generate HDL code for the DUT, run the makehdl function.

makehdl('hdlcoder_multiport_switch_enum/DUT')
### Working on the model <a href="matlab:open_system('hdlcoder_multiport_switch_enum')">hdlcoder_multiport_switch_enum</a>
### Generating HDL for <a href="matlab:open_system('hdlcoder_multiport_switch_enum/DUT')">hdlcoder_multiport_switch_enum/DUT</a>
### Using the config set for model <a href="matlab:configset.showParameterGroup('hdlcoder_multiport_switch_enum', { 'HDL Code Generation' } )">hdlcoder_multiport_switch_enum</a> for HDL code generation parameters.
### Running HDL checks on the model 'hdlcoder_multiport_switch_enum'.
### Begin compilation of the model 'hdlcoder_multiport_switch_enum'...
### Begin compilation of the model 'hdlcoder_multiport_switch_enum'...
### Working on the model 'hdlcoder_multiport_switch_enum'...
### Working on... <a href="matlab:configset.internal.open('hdlcoder_multiport_switch_enum', 'GenerateModel')">GenerateModel</a>
### Begin model generation 'gm_hdlcoder_multiport_switch_enum'...
### Copying DUT to the generated model....
### Model generation complete.
### Generated model saved at <a href="matlab:open_system('hdlsrc/hdlcoder_multiport_switch_enum/gm_hdlcoder_multiport_switch_enum.slx')">hdlsrc/hdlcoder_multiport_switch_enum/gm_hdlcoder_multiport_switch_enum.slx</a>
### Begin VHDL Code Generation for 'hdlcoder_multiport_switch_enum'.
### Working on hdlcoder_multiport_switch_enum/DUT as hdlsrc/hdlcoder_multiport_switch_enum/DUT.vhd.
### Generating package file hdlsrc/hdlcoder_multiport_switch_enum/DUT_pkg.vhd.
### Code Generation for 'hdlcoder_multiport_switch_enum' completed.
### Generating HTML files for code generation report at <a href="matlab:hdlcoder.report.openDdg('/tmp/Bdoc24b_2725827_3882109/tp31cd77df/hdlcoder-ex69164871/hdlsrc/hdlcoder_multiport_switch_enum/html/hdlcoder_multiport_switch_enum_codegen_rpt.html')">hdlcoder_multiport_switch_enum_codegen_rpt.html</a>
### Creating HDL Code Generation Check Report file:///tmp/Bdoc24b_2725827_3882109/tp31cd77df/hdlcoder-ex69164871/hdlsrc/hdlcoder_multiport_switch_enum/DUT_report.html
### HDL check for 'hdlcoder_multiport_switch_enum' complete with 0 errors, 0 warnings, and 0 messages.
### HDL code generation complete.

See Also

|

Related Topics