(* TANK RECIPE SELECT WITH POINTERS - Structured Text *) (* Tank Fill scene, simulator v1.133+, linked as the only scene at offset 0. *) (* AX1 = tank level in counts 0-4095 (4-20 mA transmitter on a 4-20 mA card) *) (* X3 Start PB X4 Stop PB (N.C.) X5 E-Stop (N.C.) X6 Auto/Manual (ON=Auto) *) (* MANUAL: X7 = recipe A, X8 = recipe B, X9 = recipe C *) (* X10 Overflow float Y1 Inlet valve Y2 Drain pump Y3 Alarm Y4 Mixer *) (* Same registers as the ladder example: D1 recipe number 0-2, *) (* D2/D3 pointers, D10/D11 working setpoints, D20 level %, *) (* D100-D102 fill % table, D110-D112 drain-to % table. *) VAR RecipeOK : BOOL; (* recipe number is inside the tables *) Running : BOOL; Filling : BOOL; Draining : BOOL; END_VAR (* Load both recipe tables on the first scan *) IF SB3 THEN D[100] := 50; D[101] := 65; D[102] := 80; (* fill to, % *) D[110] := 40; D[111] := 30; D[112] := 25; (* drain to, % *) END_IF; (* Recipe select - only in MANUAL, so a recipe never changes mid-cycle *) IF NOT X6 THEN IF X7 THEN D[1] := 0; END_IF; IF X8 THEN D[1] := 1; END_IF; IF X9 THEN D[1] := 2; END_IF; END_IF; (* Fetch through pointers. In ST an index outside D[1]-D[4000] stops the *) (* PLC, so check the recipe number before using it as an index. *) RecipeOK := (D[1] >= 0) AND (D[1] <= 2); IF RecipeOK THEN D[2] := 100 + D[1]; (* fill pointer *) D[3] := 110 + D[1]; (* drain pointer *) D[10] := D[D[2]]; (* ladder: MOV D[D2] -> D10 *) D[11] := D[D[3]]; (* ladder: MOV D[D3] -> D11 *) END_IF; (* Level in whole percent - the SCL formula written out *) D[20] := REAL_TO_INT(INT_TO_REAL(AX1) * 100.0 / 4095.0); (* Auto run: Start seals in; Stop, E-Stop, Manual or a bad recipe drop it *) Running := (X3 OR Running) AND X4 AND X5 AND X6 AND RecipeOK; (* Fill to D10, drain to D11 - the recipe's dead band *) IF Running AND D[20] >= D[10] THEN Draining := TRUE; END_IF; IF D[20] <= D[11] OR NOT Running THEN Draining := FALSE; END_IF; Filling := Running AND NOT Draining AND D[20] < D[10]; (* Outputs *) Y1 := Filling AND NOT X10; (* inlet, blocked by overflow float *) Y2 := Draining; (* drain pump *) Y4 := Running AND D[20] > 30; (* mixer only when the blades are covered *) Y3 := X10 OR NOT RecipeOK; (* overflow or bad recipe number *)