This is one of the most common control methods for systems with a slow and over-damped response where accuracy is not very crucial. A thermal system is one of them. It is quite common to find an on-off control implemented in commercial water heaters. Besides a heating system, an on-off control is also common in a water pump system for delivering water to a tank.

A MATLAB Simulink block, named “Relay”,” is already available for direct implementation of an on-off control with hysteresis.

Fig.1 The anatomy of an on-off control with hysteresis.

Fig.1 The anatomy of an on-off control with hysteresis.

There are four parameters in a relay block.

Fig. 2 The properties of the “Relay” block in Simulink

Fig. 2 The properties of the “Relay” block in Simulink

Implementation of the on-off controller is as follows.

Fig. 3 A Simulink diagram of an on-off control with hysteresis.

Fig. 3 A Simulink diagram of an on-off control with hysteresis.

on_off_2022a.slx

Running the Simulink file above gives us a MAT-file that we can load into MATLAB’s workspace. The first row is the time stamp. The second and the third rows are the applied input to heater-1 and heater-2, respectively. The fourth and the fifth rows are the heater-1 and heater-2 temperatures, respectively. The sixth row is the targeted temperature that must be achieved by the controller.

We provide the following MAT file as an example.

datalog.mat

The following MATLAB script can be used to present the results in a more meaningful manner.

clc
clear 
close all

SWITCH_ON_POINT = 2;
SWITCH_OFF_POINT = -2;

load datalog.mat
datalog = datalog(:, 1:floor(end/2)); % Our data is too long, remove half of it!

t  = datalog(1, :);
u1 = datalog(2, :);
u2 = datalog(3, :);
T1 = datalog(4, :);
T2 = datalog(5, :);
T1_target = datalog(6, :);

% Plot time vs output
figure
hold on
yyaxis left
plot(t, T1_target, 'g')
plot(t, T1)
plot(t, T1_target + SWITCH_ON_POINT, '--k', 'LineWidth', 2)
plot(t, T1_target + SWITCH_OFF_POINT, '--k', 'LineWidth', 2)
ylabel('Output')
xlim([0 t(end)])

% Plot time vs input
yyaxis right
plot(t, u1,'-.', 'LineWidth', 2)
xlabel('Time (s)')
ylabel('Input')
xlim([0 t(end)])

% Plot the hysteresis curve
figure
plot(T1, u1, 'LineWidth', 2)
xlabel('Temperature')
ylabel('Input')
xlim([min(T1)-1 max(T1)+1])
ylim([min(u1)-0.1 max(u1)+0.1])

Fig. 4 The on-off action of the controller and the corresponding output.

Fig. 4 The on-off action of the controller and the corresponding output.

From Fig. 4, we can see that the controller is on when the error is positive and the controller is off when the error is negative. Another interesting behavior is when the controller is off, the temperature still increases for a few moments before it starts to decrease. On the other hand, when the controller is on, the temperature increases almost instantly. Why does such behavior occur?