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')

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')

See Also

|

Related Topics