PLC SCL keeping variable true

Viewed 44

So I am writing a PLC code in SCL language and I am wondering about this thing:

I have a tank with an inlet and a pump for flow out. The pump should only run after the level in the tank goes beyond a level, lets say 10 meters. And it should keep going until the tank level goes down to 4 meters.

Not sure if I should use more IF statements or maybe a WHILE statement?. Problem is, how to keep the pump going after the level has gone under 10 meters but not yet reached 4 meters?

This code would probably not be useful:

IF (TankLevel > 10) THEN
      StartPump := TRUE;
END_IF;

Any help is appreciated.

3 Answers

Just add the following:

IF (TankLevel < 4) THEN
      StartPump := FALSE;
END_IF;

Add an elsif

IF (TankLevel > 10) THEN
    StartPump := TRUE;
ELSIF (TankLevel < 4) THEN
    StartPump := FALSE;
END_IF;

A PLC program is basically one big while loop, so this can be checked every few milliseconds.

Another option, although this is more suited to ladder logic:

StartPump := ( (TankLevel > 10) OR StartPump ) AND NOT (TankLevel < 4);

The StartPump bit will be "latched" at 10m until it is released at 4m.

Related