Engee documentation

Switch

Switches the output between the first and third inputs based on the value of the second input.

switch

Description

The Switch block passes the signal from the first or third input depending on the value of the signal on the second input. The first and third inputs are input signals, the second input is a control signal. The condition under which the block passes the signal from the first input to the output is set by the Criteria for passing first input and Threshold parameters.

Ports

Input

Port_1 - first input signal
scalar | vector

The first of two input signals. The block passes either one or the other input signal to the output based on the value of the control signal. The condition under which the block passes the signal from the first input to the output is specified by the Criteria for passing first input and Threshold parameters.

Data types: Float16, Float32, Float64, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Bool, Fixed.

Support for complex numbers: Yes

Port_2 - control signal
scalar | vector

The control signal that the block uses to determine which input should be passed to the output. If the control signal satisfies the conditions specified in Criteria for passing first input, the block passes the first input signal. Otherwise, the block passes the second input signal.

Data types: Float16, Float32, Float64, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Bool, Fixed.

Support for complex numbers: No

Port_3 - second input signal
scalar | vector

The second of two input signals. The block passes either one or the other input signal to the output based on the value of the control signal. The condition under which the block passes the signal from the first input to the output is specified by the Criteria for passing first input and Threshold parameters.

Data types: Float16, Float32, Float64, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Bool, Fixed.

Support for complex numbers: Yes

Output

Port_1 - output signal
scalar | vector

Output signal derived from either the first or the second input signal, depending on the value of the control signal.

Data types: Float16, Float32, Float64, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Bool, Fixed.

Support for complex numbers: Yes

Parameters

Main

Criteria for passing first input - criterion for selecting the passing of the first input signal
u2 > Threshold (by default) | u2 >= Threshold | u2 ~= 0

Select the condition that causes the block to pass the first input signal to the output. If the control input Port_2 satisfies the conditions specified in Criteria for passing first input, the block will pass the first input signal to Port_1. Otherwise, the block will pass the second input signal Port_3. Options for selection:

  • u2 >= Threshold - the control input is greater than or equal to the threshold value;

  • u2 > Threshold - the control input is greater than the threshold value;

  • u2 ~= 0 - the control input is different from zero.

Hint

If the control input is a Boolean signal, use one of the following combinations of condition and threshold value:

  • u2 >= Threshold where the threshold value is 1;

  • u2 > Threshold, where the threshold value is 0;

  • u2 ~= 0.

Otherwise, the Switch block ignores the threshold values and uses a boolean value to route the signal. At a value of 1, the block routes the first input, and at a value of 0, it routes the third input.

Usage in program code

Block parameter

Criteria

Value

u2 >= Threshold | u2 > Threshold | u2 ~= 0

* By default*

u2 > Threshold

*Threshold` is the threshold value used in the criterion
0 (by default) | scalar | vector | matrix | array

The threshold value used in the Criteria for passing first input parameter, which determines which input the block passes to the output.

Dependencies

To use this parameter, set the Criteria for passing first input parameter to u2 >= Threshold or u2 > Threshold.

Usage in program code

Block parameter

threshold

Value

scalar | vector | matrix | array

By default

'0'

Signal Attributes

Require all data port inputs to have the same data type - all data inputs must have the same data type
disabled (by default) | enabled

Enable this parameter so that all data inputs have the same data type.

Usage in program code

Block parameter

InputSameDT

Value

off | on

* By default*

off

Output data type - output data type
Inherit: auto (by default) | Same as first input | Float16 | Float32 | Float64 | Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128 | Fixed point | Bool

Specify the type of output data.

The type can be inherited or specified directly.

Usage in program code

Block parameter

OutDataTypeStr

Values

Inherit: auto (By default) |Same as first input | Float16 | Float32 | Float64 | Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128 | Fixed point | Bool Bool

By default

Inherit: auto

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.

Usage in program code

Block parameter

RndMeth

Value

Ceiling | Convergent | Floor | Nearest | Round | Zero

By default

Floor

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 Int8 (signed, 8-bit integer) is 127.

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 Int8 (signed, 8-bit integer) is 127.

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 Int8, which may cause an unintended result. For example, the result of block 130 (binary code 1000 0010) expressed as Int8, is -126.

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.

Usage in program code

Block parameter

SaturateOnIntegerOverflow

Value

выключено | включено

By default

выключено

Additional options

C code generation: Yes