Hello srd,
here's a quick an dirty idea.
You have to check values for level calculation, percentages of valve opening and
to think about what happens to valve set value if water surface doing waves!
Pay attention to the change in the manipulated variable at the range limits. If these can change rapidly, the valve opening degree will also change rapidly.
So the solution is not ready, yet. Do the commissioning very carefully. No guaranty to correct function.
//Calculate water level in cm
LS01 (
EN := ,
I1 := IA05, //read water level
X1 := 819, //Inc @ 4 mA
Y1 := 400, //short distance -> water level 400 cm
X2 := 3440, //Inc @ ~13 mA (400 cm) CHECK @ EMPTY TANK!!!
Y2 := 0, // long distance -> water level 0 cm
QV => //water level in cm
);
//Set analogue output for valve depending on water level
CASE LS01QV OF
0..100: QA05:=1638; //water level 0..100 cm -> valve 25% open
101..200: QA05:=2457; //water level 101..200 cm -> valve 50% open
201..300: QA05:=3276; //water level 101..300 cm -> valve 75% open
301..400: QA05:=4095; //water level 301..400 cm -> valve 100% open
ELSE
;
END_CASE;