Course Content
Basic PLC Structured Text Programming Course in CODESYS
About Lesson

// variables
VAR_INPUT
xEnable:BOOL; // decommissioning of control block
rCurrentLevel:REAL; // current liquid level in the tank
rActivationLevel_1:REAL:=2; // activation level for pump1
rDeactivationLevel_1:REAL:=1; // deactivation level for pump1
rActivationLevel_2:REAL:=4; // activation level for pump2
rDeactivationLevel_2:REAL:=3; // deactivation level for pump2
rActivationLevel_3:REAL:=5; // activation level for pump3
rDeactivationLevel_3:REAL:=4; // deactivation level for pump3
END_VAR
VAR_OUTPUT
xPumpStart_1:BOOL; // activate pump no.1
xPumpStart_2:BOOL; // activate pump no.2
xPumpStart_3:BOOL; // activate pump no.3
END_VAR
VAR
rLevelMeters:REAL; // Liquid level in meters
END_VAR

 

// code

// Converting water level to meters
rLevelMeters := rCurrentLevel / 100;
 
IF xEnable THEN
// Filling conditions in automatic mode
IF rLevelMeters >= rActivationLevel_1 THEN
xPumpStart_1 := TRUE;
ELSIF rLevelMeters < rDeactivationLevel_1 THEN
xPumpStart_1 := FALSE;
END_IF
 
IF rLevelMeters >= rActivationLevel_2 THEN
xPumpStart_2 := TRUE; 
ELSIF rLevelMeters < rActivationLevel_2THEN
xPumpStart_2 := FALSE;
END_IF;
 
IF rLevelMeters >= rActivationLevel_3 THEN
xPumpStart_3 := TRUE; 
ELSIF rLevelMeters < rDeactivationLevel_3 THEN
xPumpStart_3 :=FALSE; 
END_IF;
ELSE
xPumpStart_1 := FALSE;
xPumpStart_2 := FALSE;
xPumpStart_3 := FALSE;
 
END_IF
Exercise Files
COD-ST-EN-BASIC FB Pump Control Done.zip
Size: 378.01 KB
COD-ST-EN-BASIC FB Pump Control Template.zip
Size: 330.58 KB
0% Complete