Combine multiple signals into single signal
Simulink / Commonly Used Blocks
Simulink / Signal Routing
HDL Coder / Commonly Used Blocks
HDL Coder / Signal Routing
The Switch block passes through the first input or the third input signal based on the value of the second input. The first and third inputs are data input. The second input is a control input. Specify the condition under which the block passes the first input by using the Criteria for passing first input and Threshold parameters.
The Switch block is a bus-capable block. The data inputs can be virtual or nonvirtual bus signals subject to the following restrictions:
All the buses must be equivalent (same hierarchy with identical names and attributes for all elements).
All signals in a nonvirtual bus input to a Switch block must have the same sample time. The requirement holds even if the elements of the associated bus object specify inherited sample times.
You can use a Rate Transition block to change the sample time of an individual signal, or of all signals in a bus. See Modify Sample Times for Nonvirtual Buses and Bus-Capable Blocks for more information.
You can use an array of buses as an input signal to a Switch block. For details about defining and using an array of buses, see Combine Buses into an Array of Buses. When using an array of buses, set the Threshold parameter to a scalar value.
If the data inputs to the Switch block are buses, the element
names of both buses must be the same. Using the same element names ensures that
the output bus has the same element names no matter which input bus the block
selects. To ensure that your model meets this requirement, use a bus object to
define the buses and set the Element name mismatch
diagnostic to error
. See Connectivity Diagnostics Overview for more information.
Port_1
— First data input signalFirst of two data inputs. The block propagates either the first or second data input to the output. The block selects which input to pass based on the control input. Specify the condition for the control input to pass the first input using the Criteria for passing first input and Threshold parameters.
Data Types: single
| double
| half
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
| bus
Port_2
— Control input signalControl signal the block uses to determine whether to pass the first or second data input to the output. If the control input meets the condition set in the Criteria for passing first input parameter, then the block passes the first data input. Otherwise, the block passes the second data input.
Data Types: single
| double
| half
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
| bus
Port_3
— Second data input signalSecond of two data inputs. The block propagates either the first or second data input to the output. The block selects which input to pass based on the control input. Specify the condition for the control input to pass the first or second input using the Criteria for passing first input and Threshold parameters.
Data Types: single
| double
| half
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
| bus
Port_1
— Output signalOutput signal propagated from either the first or second input signal, based on the control signal value.
Data Types: single
| double
| half
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
| bus
Criteria for passing first input
— Selection criteria to pass first data inputu2 >= Threshold
(default) | u2 > Threshold
| u2 ~= 0
Select the condition under which the block passes the first data
input. If the control input meets the condition set in the
Criteria for passing first input parameter, the
block passes the first input. Otherwise, the block passes the second
data input signal from input Port_3
.
u2 >= Threshold
Checks whether the control input is greater than or equal to the threshold value.
u2 > Threshold
Checks whether the control input is greater than the threshold value.
u2 ~=0
Checks whether the control input is nonzero.
Note
The Switch block does not support
u2 ~=0
mode for
enumerated data types.
When the control input is a Boolean signal, use one of these combinations of condition and threshold value:
u2 >= Threshold
, where the
threshold value equals 1
u2 > Threshold
, where the
threshold value equals 0
u2 ~=0
Otherwise, the Switch block ignores threshold values and uses the Boolean value for signal routing. For a value of 1, the block passes the first input, and for a value of 0, the block passes the third input. A warning message that describes this behavior also appears in the MATLAB® Command Window.
Block Parameter:
Criteria |
Type: character vector |
Value:
'u2 >= Threshold' | 'u2 >
Threshold' | 'u2 ~=0' |
Default:
'u2 >= Threshold' |
Threshold
— Threshold used in criteria0
(default) | scalar
Assign the threshold used in the Criteria for passing first input that determines which input the block passes to the output. Threshold must be greater than Output minimum and less than Output maximum.
To specify a nonscalar threshold, use brackets. For example, the following entries are valid:
[1 4 8 12]
[MyColors.Red, MyColors.Blue]
Setting Criteria for passing first input to
u2 ~=0
disables this
parameter.
Block Parameter:
Threshold |
Type: character vector |
Value:
'off' | 'on' |
Default:
'off'
|
Enable zero-crossing detection
— Enable zero-crossing detectionon
(default) | BooleanSelect to enable zero-crossing detection. For more information, see Zero-Crossing Detection.
Block Parameter:
ZeroCross |
Type: character vector, string |
Values: 'off' |
'on' |
Default: 'on' |
Click the Show data type assistant
button to display the Data Type Assistant,
which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant.
Require all data port inputs to have the same data type
— Require data ports to have the same data typeoff
(default) | on
Require all data inputs to have the same data type.
Block Parameter:
InputSameDT |
Type: character vector |
Value: |
Default:
'0' |
Output minimum
— Minimum output value for range checking[]
(default) | scalarLower value of the output range that Simulink® checks.
Simulink uses the minimum to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters) for some blocks.
Simulation range checking (see Specify Signal Ranges and Enable Simulation Range Checking).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Note
Output minimum does not saturate or clip the actual output signal. Use the Saturation block instead.
Block Parameter:
OutMin |
Type: character vector |
Values: '[ ]' |
scalar |
Default: '[ ]' |
Output maximum
— Maximum output value for range checking[]
(default) | scalarUpper value of the output range that Simulink checks.
Simulink uses the maximum value to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters) for some blocks.
Simulation range checking (see Specify Signal Ranges and Enable Simulation Range Checking).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Note
Output maximum does not saturate or clip the actual output signal. Use the Saturation block instead.
Block Parameter:
OutMax |
Type: character vector |
Values: '[ ]' |
scalar |
Default: '[ ]' |
Output data type
— Output data typeInherit: Inherit via internal
rule
(default) | Inherit: Inherit via back
propagation
| double
| single
| half
| int8
| uint8
| int16
| uint16
| int32
| uint32
| int64
| uint64
| fixdt(1,16)
| fixdt(1,16,0)
| fixdt(1,16,2^0,0)
| string
| Enum: <class name>
| <data type expression>
Specify the output data type.
Inherit: Inherit via internal
rule
Uses the following rules to determine the output data type.
Data Type of First Input Port | Output Data Type |
---|---|
Has a larger positive range than the third input port | Inherited from the first input port |
Has the same positive range as the third input port | Inherited from the third input port |
Has a smaller positive range than the third input port |
Inherit: Inherit via back
propagation
Uses data type of the driving block.
double
Specifies output data type is
double
.
single
Specifies output data type is
single
.
half
Specifies output data type is
half
.
int8
Specifies output data type is
int8
.
uint8
Specifies output data type is
uint8
.
int16
Specifies output data type is
int16
.
uint16
Specifies output data type is
uint16
.
int32
Specifies output data type is
int32
.
uint32
Specifies output data type is
uint32
.
int64
Specifies output data type is
int64
.
uint64
Specifies output data type is
uint64
.
fixdt(1,16,0)
Specifies output data type is fixed point
fixdt(1,16,0)
.
fixdt(1,16,2^0,0)
Specifies output data type is fixed point
fixdt(1,16,2^0,0)
.
Enum: <class name>
Uses an enumerated data type, for example,
Enum: BasicColors
.
string
Specifies output data type is string.
<data type expression>
Uses a data type object, for example,
Simulink.NumericType
.
When the output is of enumerated type, both data inputs should use the same enumerated type as the output.
Block Parameter:
OutDataTypeStr |
Type: character vector |
Values: 'Inherit: Inherit via internal
rule | 'Inherit: Inherit via back
propagation' | 'double' |
'single' | 'half' |
'int8' | 'uint8' |
'int16' | 'uint16' ,
'int32' | 'uint32' |
'int64' | 'uint64' |
'fixdt(1,16)' |
'fixdt(1,16,0)' |
'fixdt(1,16,2^0,0)' | Enum:
<class name> | 'string' |
'<data type expression>' |
Default: 'Inherit:
Inherit via internal rule' |
Lock data type settings against changes by the fixed-point tools
— Prevent fixed-point tools from overriding data typesoff
(default) | on
Select this parameter to prevent the fixed-point tools from overriding the data types you specify on this block. For more information, see Lock the Output Data Type Setting (Fixed-Point Designer).
Block Parameter: LockScale |
Type: character vector |
Values: 'off' | 'on' |
Default: 'off' |
Integer rounding mode
— Specify the rounding mode for fixed-point operationsFloor
(default) | Ceiling
| Convergent
| Nearest
| Round
| Simplest
| Zero
Choose one of these rounding modes.
Ceiling
Rounds both positive and negative numbers
toward positive infinity. Equivalent to the
MATLAB
ceil
function.
Convergent
Rounds number to the nearest representable
value. If a tie occurs, rounds to the nearest even
integer. Equivalent to the Fixed-Point Designer™
convergent
function.
Floor
Rounds both positive and negative numbers
toward negative infinity. Equivalent to the
MATLAB
floor
function.
Nearest
Rounds number to the nearest representable
value. If a tie occurs, rounds toward positive
infinity. Equivalent to the Fixed-Point Designer
nearest
function.
Round
Rounds number to the nearest representable
value. If a tie occurs, rounds positive numbers
toward positive infinity and rounds negative
numbers toward negative infinity. Equivalent to
the Fixed-Point Designer
round
function.
Simplest
Automatically chooses between round toward floor and round toward zero to generate rounding code that is as efficient as possible.
Zero
Rounds number toward zero. Equivalent to the
MATLAB
fix
function.
Block Parameter:
RndMeth |
Type: character vector |
Values:
'Ceiling' |
'Convergent' |
'Floor' |
'Nearest' |
'Round' |
'Simplest' |
'Zero' |
Default:
'Floor' |
For more information, see Rounding (Fixed-Point Designer).
Saturate on integer overflow
— Method of overflow actionoff
(default) | on
Specify whether overflows saturate or wrap.
off
— Overflows wrap to the appropriate value that the data type can represent.
For example, the number 130 does not fit in a signed 8-bit integer and wraps to -126.
on
— Overflows saturate to either the minimum or maximum value that the data type can represent.
For example, an overflow associated with a signed 8-bit integer can saturate to -128 or 127.
Tip
Consider selecting this check box when your model has a possible overflow and you want explicit saturation protection in the generated code.
Consider clearing this check box when you want to optimize efficiency of your generated code.
Clearing this check box also helps you to avoid overspecifying how a block handles out-of-range signals. For more information, see Troubleshoot Signal Range Errors.
When you select this check box, saturation applies to every internal operation on the block, not just the output or result.
In general, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.
Block Parameter: SaturateOnIntegerOverflow |
Type: character vector |
Values: 'off' | 'on' |
Default: 'off' |
Allow different data input sizes
— Allow different data input sizesoff
(default) | on
Select this check box to allow input signals with different sizes. The block propagates the input signal size to the output signal. If the two data inputs are variable-size signals, the maximum size of the signals can be equal or different.
Block Parameter:
AllowDiffInputSizes
|
Type: character vector |
Value:
'on' | 'off' |
Default:
'off'
|
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
Generated code relies on memcpy
or memset
functions (string.h) under certain conditions.
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.
This block has a single, default HDL architecture.
ConstrainedOutputPipeline | Number of registers to place at
the outputs by moving existing delays within your design. Distributed
pipelining does not redistribute these registers. The default is
|
InputPipeline | Number of input pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is
|
OutputPipeline | Number of output pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is
|
This block supports code generation for complex signals.