Switch output between two constants
The Relay block allows its output to switch between two specified values. When the relay is on, it remains on until the input drops below the value of the Switch off point parameter. When the relay is off, it remains off until the input exceeds the value of the Switch on point parameter. The block accepts one input and generates one output.
The Switch on point value must be greater than or equal to the Switch off point. Specifying a Switch on point value greater than the Switch off point models hysteresis, whereas specifying equal values models a switch with a threshold at that value.
The Relay block accepts signals of the following data types:
Enumerated (output only)
If Output when on or Output when off is an enumerated value, both must be of the same enumerated type as the output.
For more information, see Data Types Supported by Simulink in the Simulink® documentation.
The Main pane of the Relay block dialog box appears as follows:
The "on" threshold for the relay. The Switch on point parameter is converted to the input data type offline using round-to-nearest and saturation.
The "off" threshold for the relay. The Switch off point parameter is converted to the input data type offline using round-to-nearest and saturation.
The output when the relay is on.
The output when the relay is off.
Specify whether the block performs sample- or frame-based processing. You can select one of the following options:
Elements as channels (sample based) — Treat each element of the input as a separate channel (sample-based processing).
Columns as channels (frame based) — Treat each column of the input as a separate channel (frame-based processing).
Note: Frame-based processing requires a DSP System Toolbox™ license.
For more information, see Sample- and Frame-Based Concepts in the DSP System Toolbox documentation.
Inherited — Inherit the processing mode from the input signal and delay the input accordingly. You can identify whether the input signal is sample or frame based by looking at the signal line. Simulink represents sample-based signals with a single line and frame-based signals with a double line.
Use Input processing to specify whether the block performs sample- or frame-based processing. The block accepts frame-based signals for the input u. All other input signals must be sample based.
|Input Signal u||Input Processing Mode||Block Works?|
|Sample based||Sample based||Yes|
|Frame based||No, produces an error|
|Sample based||Frame based||Yes|
For more information about these two processing modes, see Sample- and Frame-Based Concepts in the DSP System Toolbox documentation.
Select to enable zero-crossing detection. For more information, see Zero-Crossing Detection.
Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See Specify Sample Time in the Simulink documentation for more information.
The Signal Attributes pane of the Relay block dialog box appears as follows:
Specify the minimum value that the block should output. The default value is  (unspecified). Simulink software uses this value to perform:
Specify the maximum value that the block should output. The default value is  (unspecified). Simulink software uses this value to perform:
Specify the output data type. You can set it to:
A rule that inherits a data type, for example, Inherit: Inherit via back propagation
The name of a built-in data type, for example, single
The name of a data type object, for example, a Simulink.NumericType object
An expression that evaluates to a data type, for example, fixdt(1,16,0)
An enumerated data type, for example, Enum:BasicColors
In this case, Output when on and Output when off must be of the same enumerated type.
Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Output data type parameter.
See Specify Block Output Data Types for more information.
Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor. For more information, see Use Lock Output Data Type Setting.
The Relay block appears in the Thermostat subsystem.
The thermostat allows fluctuations of 5 degrees Fahrenheit above or below the desired room temperature. If air temperature drops below 65 degrees Fahrenheit, the thermostat turns on the heater. The Relay block outputs a value of 1 to turn on the heater and a value of 0 to turn off the heater.