Multiport Switch
Selects the output signal based on the control signal.
|
|
|
Description
The Multiport Switch block determines which of several inputs to the block goes to the output, depending on the value of the signal on the first input. The first input is called the control input and the others are called data inputs. The value of the control input determines which input data is passed to the output.
The table below shows how the block interprets the control signal and determines which input signal will be passed to the output.
Control input |
Rounding |
Setting data port numbering |
Block behaviour during simulation |
|
---|---|---|---|---|
Indexing for data input selection |
Out of range condition |
|||
Integer value |
No |
|
Numbering from zero |
The signal at the control input is less than |
|
Numbering from one |
The signal at the control input is less than |
||
|
User-defined numbering |
The signal at the control input does not match any data input number. |
||
Non-integer value |
The unit truncates the value to an integer by rounding towards zero. |
|
Numbering from zero |
The rounded value of the input signal is less than |
|
Numbering from one |
The rounded value of the input signal is less than |
||
|
Custom numbering |
The rounded value of the input signal does not correspond to any data input number. |
Multiport Switch configured as an Index Vector block
Index Vector is a special configuration of the Multiport Switch block in which only one data input is specified and the control input is counted from zero. The output of the block is the element of the input vector whose index corresponds to the control input. For example, if the input vector is [18 15 17 10]
and the control input is 3
, then the element of the vector numbered 3
(starting from zero) equal to 10
becomes the output value.
To configure the Multiport Switch block to operate as an Index Vector block, set the Number of data ports to 1
and the Data port order to Zero-based contiguous
.
How the block handles out-of-range control input
If the control signal is an integer and its value is less than typemax(Int)
, it is taken out of range if it does not match any data input number. If the control signal is not an integer, its value is taken to be outside the valid range if the rounded value does not match any data port index. In both cases the block behaviour depends on the settings Data port for default case and Diagnostic for default case.
If the value of the control signal is greater than typemax(Int) , the block converts the input value to an integer.
|
Simulation behaviour
The following behaviour applies only to the simulation of the model.
Data port for default case |
Diagnostic for default case |
|
---|---|---|
No |
Error |
|
|
The last data input is used and no warnings or errors appear. |
An error message appears and the simulation stops. |
|
The optional data input labelled |
An error message appears and simulation stops. |
Code generation behaviour
The following behaviour applies to code generation from the model.
Data port for default case |
Diagnostic for default case |
|
---|---|---|
No |
Error |
|
|
The last data input is being used. |
The last data input is being used. |
|
The optional data input labelled |
The optional data input labelled |
Rules defining the block behaviour
The number of data inputs is specified by the Number of data ports parameter.
-
If you set Number of data ports to
1
, the block behaves as a Selector block, not as a Multiport Switch block. -
If you set the Number of data ports to be greater than
1
, the block behaves as a Multiport Switch. The block output represents an input signal whose number corresponds to the value of the control input. If at least one of the input signals is a vector, the block output is a vector. In this case, the block extends any scalar input parameters to vectors. -
If all input signals are scalar, the output signal is also scalar.
Assumptions and limitations
-
If the input signals of a block are buses, their structure on the different ports (names, types, and dimensions) must be completely the same. To ensure that the output bus has the same structure regardless of which input bus the block chooses, it is forbidden to mix buses with regular signals.
-
To work with buses, the Number of data ports must be at least 2.
-
For buses, the control signal must be a scalar.
Ports
Input
Port_1 - control signal
scalar
| vector
| matrix
A control signal that determines which of the input signals goes to the output.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, UInt128
, Bool
, Fixed
.
1 - first input signal
scalar
| vector
| matrix
| bus
First data input as a scalar, vector, matrix, array or bus.
-
If all input signals are scalars, the output signal is also a scalar.
-
If at least one of the input signals is a vector, the output of the block is a vector. In this case, the block extends any scalar input signals to vectors.
Dependencies
To work with buses, the value of Number of data ports must be ≥ 2.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, UInt128
, Bool
, Fixed
.
2 - second input signal
scalar
| vector
| matrix
| bus
Second data input as scalar, vector, matrix, array or bus.
-
If all input signals are scalars, the output signal is also a scalar.
-
If at least one of the input signals is a vector, the output of the block is a vector. In this case, the block extends any scalar input signals to vectors.
Dependencies
For bus operation, the Number of data ports must be ≥ 2.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, UInt128
, Bool
, Fixed
.
N - n-th input signal
scalar
| vector
| matrix
| bus
Nth data input as scalar, vector, matrix, array or bus.
-
If all input signals are scalars, the output signal is also a scalar.
-
If at least one of the input signals is a vector, the output of the block is a vector. In this case, the block extends any scalar input signals to vectors.
Dependencies
For bus operation, the Number of data ports must be ≥ 2.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, UInt128
, Bool
, Fixed
.
* - data input for control signal value out of range
scalar
| vector
| matrix
| bus
Input data port for an out-of-range control signal value as a scalar, vector, matrix, array or bus.
All signals on the data inputs can be of any data type that Engee supports.
Dependencies
To create an additional input data port for an out-of-range control signal value, set the Data port for default case parameter to Additional data port
. When you set Data port for default case to Last data port
, the block uses the last data port for output when the control signal value does not match any data port indices.
For bus operation, the value of Number of data ports must be ≥ 2.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, UInt128
, Bool
, Fixed
.
Output
Port_1 - selected input signal corresponding to the value of the control signal
scalar
| vector
| matrix
| bus
The unit outputs one of the input signals selected according to the value of the control signal. The output signal has the same dimensions as the corresponding input signal. The data type of the output is the data type of the input port, which requires the largest amount of memory.
Dependencies
For bus operation, the Number of data ports must be ≥ 2.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, UInt128
, Bool
, Fixed
.
Parameters
Data port order - type of data port numbering
One-based contiguous
| Zero-based contiguous
| Specify indices
Specifies the data port numbering type.
-
Zero-based contiguous
- the block starts counting input ports from zero. This is the by default value for the Index Vector block. -
One-based contiguous
- the block starts counting input ports from one. This is the by default value for the Multiport Switch block. -
Specify indices
- the block uses arbitrary numbering of data ports.
Dependencies
-
Selecting
Zero-based contiguous
orOne-based contiguous
enables the Number of data ports parameter. -
Selecting
Specify indices
includes the Data port indices parameter.
Block parameter |
|
Value |
|
By default |
|
Number of data ports - number of data input ports
1
| 3
| an integer from 1 to 65535
.
Specifies the number of data ports. The total number of input ports is the number you specify, plus one for the control signal input port and plus one more if you set Data port for default case to Additional data port
.
Dependencies
To use this parameter, set the Data port order parameter to Zero-based contiguous
or One-based contiguous
.
Block parameter |
|
Value |
|
By default |
|
Data port indices - array of indices for data ports
[1,2,3] (By default)
| `array of indices'.
Specifies an array of indices for data inputs. The block icon will change to match the data port indices you specify.
Dependencies
The parameter is available if Data port order is set to Specify indices
.
Block parameter |
|
Value |
|
By default |
|
Data port for default case - input port in case of control signal value out of range
Last data port (by default)
| Additional data port
Specifies whether to use the last data port in case of an out-of-range control signal value or to use an optional port. An asterisk (*) next to the port name indicates the port that the block uses when the control input value does not match any data port index.
-
Last data port
- the block uses the last data port for output when the control signal value does not match any data port index. -
Additional data port
- the block uses the optional data port for output when the control signal value does not match any data port index.
If you set this parameter to Additional data port and Number of data ports is 3, the number of input ports in the block is 5. The first input is the control port, the next three inputs are data ports, and the fifth input is the by default port in case the control signal value is out of range.
|
Block parameter |
|
Value |
|
By default |
|
Diagnostic for default case - diagnostic action
Error (By default)
| None
Specifies the diagnostic action to take if the control port value does not match any of the data port indices. Options include:
-
None
- the system takes no action. -
Error
- the simulation stops and an error is displayed. In this case Data port for default case is used only for code generation, not simulation.
Block parameter |
|
Values |
|
By default |
|
Signal Attributes
Output data type - output data type
Inherit: auto (by default)
| Float64
| Float32
| Int8
| UInt8
| Int16
| UInt16
| Int32
| UInt32
| Int64
| UInt64
| Int128
| UInt128
| Fixed-point
Specify the type of output data. You can specify:
-
Inherit: auto
data type inheritance. -
An inherited data type, such as
Float32
. -
Fixed-point data type
Fixed-point
.
Block parameter |
|
Values |
|
By default |
|
Output fixed-point type - fixed-point output data type
Fixed{Int16, 0} (By default)
| description of the fixed-point data type
Specify the fixed-point output data type.
Dependencies
This parameter appears when Fixed-point
is selected for Output data type.
Block parameter |
|
Values |
|
By default |
|
Integer rounding mode - rounding mode for fixed point operations
Floor (by default)
| Ceiling
| Convergent
| Nearest
| Round
| | Zero
Select the rounding mode for fixed point operations. You can select:
-
Floor
- rounds both positive and negative numbers downwards (towards negative infinity). -
Ceiling
- rounds both positive and negative numbers upwards (towards positive infinity). -
Convergent
- rounds a number to the nearest representable value. If the fractional part of a number ends in 5, the number is rounded to the nearest even integer. -
Nearest
- rounds the number to the nearest representable value. If the fractional part of the number ends in 5, the number is rounded upwards (towards positive infinity). -
Round
- rounds the number to the nearest representable value. If the fractional part of a number ends in 5, positive numbers are rounded upwards (towards positive infinity) and negative numbers are rounded downwards (towards negative infinity).
-
Zero
- rounds the number towards zero.
The block parameters are always rounded to the nearest representable value.
Block parameter |
|
Value |
|
By default |
|
Saturate on integer overflow - saturation to integer on overflow
выключено (by default)
| включено
A checkbox which, when selected, uses saturation arithmetic for integers and fixed-point numbers: when an overflow occurs, the result is automatically replaced by the maximum possible (modulo) value for the data type.
Action | Rationale | Effect on overflow | Example |
---|---|---|---|
The checkbox Saturate on integer overflow is checked (enabled). |
Overflow is possible for your model and you want the generated code to have an explicit overflow protection. |
If an overflow occurs, the result is automatically replaced by the maximum possible (modulo) value for the data type. |
The maximum value that can be represented by the data type Any result of a block operation that exceeds this maximum value results in an 8-bit integer overflow. When checked, the block output is saturated to 127. Similarly, the block output is saturated at a minimum output value of -128. |
The Saturate on integer overflow checkbox is unchecked (disabled). |
You want to optimise the efficiency of your generated code. You want to avoid over-determining how the block handles out-of-range signals. |
Overflows are carried in an appropriate value that can be represented by a data type. |
The maximum value that can be represented by the data type Any result of a block operation that exceeds this maximum value results in an 8-bit integer overflow. If the check box is unchecked, software interprets the value causing the overflow as |
When you select this check box, saturation is applied to all internal operations in the block, not just the input/output data or the result.
Block parameter |
|
Value |
|
By default |
|
Require all data port inputs to have the same data type - require data ports to have the same data type
disabled (by default)
| enabled
Select to require all data port inputs to have the same data type.
Block parameter |
|
Value |
|
* By default* |
|