ELSIF: First Match Wins
Part of the Structured Text section of Coddy's PLC Programming journey. Lesson 11 of 17.
An IF can test more than one condition. ELSIF adds another test, and ELSE catches everything left:
IF NOT Low THEN
Heater := FALSE;
ELSIF Temp < 13107 THEN
Heater := TRUE;
ELSIF Temp > 14745 THEN
Heater := FALSE;
END_IF;The PLC tries the conditions from the top and runs only the first one that is TRUE. So put the most important test first: here, never heat an empty tank. Only when there is liquid does it look at the temperature.
Temp is raw: 32767 is 100 °C, so 40 °C is 13107 and 45 °C is 14745. Between the two no arm runs and the heater keeps its state: that gap is the hysteresis.
Challenge
EasyThe starter turns the heater off below Low. Add two ELSIF arms: heater on below 40 °C, off above 45 °C.
Press Run, try it on the machine, then Check.
Try it yourself
// Never heat an empty tank: this test comes first
IF NOT Low THEN
Heater := FALSE;
// add ELSIF arms here: on below 40 °C, off above 45 °C
END_IF;
All lessons in Structured Text
Practice on your own: PLC playground