December 21, 2022

#147 - PLC Programming Patterns in LAD and ST

There is a very good source of PLC programming design patterns in Ladder Diagram (LD). In this post, my intent is to convert them to Structured Text (ST) language.

1) Sealed-in Coil with Fault:

LD:

ST:

    K1 := S1 OR (K1 AND NOT S2);

2) Start/Stop/Run:

LD:

ST:

    K1 := (S1 OR K1) AND NOT S2;

3) Set/Reset:

LD:

ST:

            IF S1 AND NOT S2 THEN                 K1 := TRUE;

            IF S2 THEN                 K1 := FALSE;

4) Flashing Light:

LD:


ST:

    TON1(IN:= NOT TON2.Q, PT:= T#1000ms);     TON2(IN:= TON1.Q, PT:= T#2000ms); K1 := TON1.Q;

5) Debounce Digital Input:

LD:

ST:

    TON1(IN:= S1, PT:= T#100ms);     TOF1(IN:= S1, PT:= T#100ms); K1 := TON1.Q OR (K1 AND TOF1.Q);

6) Mode selection HOA:

LD:

ST:

AUTO := (S1 OR AUTO) AND NOT S2; MAN := NOT AUTO;

7) Mission -> Step -> 5 Rung:

a) Mission: Higher level program selection (e.g. CIP, Production)

ST:

NO_PRG := NOT PRG_1 AND NOT PRG_2; PRG_1 := AUTO AND ((NO_PRG AND PRG_1.START) OR PRG_1) AND NOT PRG_1.DONE; PRG_2 := AUTO AND ((NO_PRG AND NOT PRG_1 AND PRG_2.START) OR PRG_2) AND NOT PRG_2.DONE;

b) Sequence Step: (e.g. Mixing, Dosing)

Example: Step1: Mixing Step2: Dosing Step Status: Complete, In Progress Others: Sequence Start, Complete, Transition OK, Init OK

ST:

STEP_1.Complete := SEQ.Start AND (Transition_OK OR STEP_1.Complete); STEP_1.InProgress := SEQ.Start AND NOT STEP_1.Complete; STEP_2.Complete := STEP_1.Complete AND (Transition_OK OR STEP_2.Complete); STEP_2.InProgress := STEP_1.Complete AND NOT STEP_2.Complete); SEQ.Complete := STEP_2.Complete;

c) 5 Rung:

ST:

Trigger := From_SEQ; SAFE_OK := ESTOP_OK AND NOT TIMEOUT_FAULT; Command := ((Auto_Mode AND Trigger) OR (Man_Mode AND Selector) OR Command) AND SAFE_OK AND NOT In_Position; In_Position := Sensor; TON1 (IN:=Command AND NOT In_Position, PT:=1000ms); Timeout := TON1.Q OR (Timeout AND NOT Fault_Reset);

No comments:

Post a Comment