Transforming LD to ST programs

Note the following if you wish to transform your LD program to an ST program:

1. Network with normal output

LD program

ST program code

Remarks

Y0 := X0 AND X1 OR X2 AND NOT X3;
 

Also possible:

IF X0 AND X1 OR X2 AND NOT X3 THEN
	Y0:=TRUE;
ELSE 
	Y0:=FALSE;
END_IF;

Same behavior, but requires more resources.

NOTE

A WHILE loop would cause a scan time error and lead to a watchdog error.

2. Network with a set or reset output

LD program

ST program code

 
IF X0 AND X1 THEN
	Y0 := TRUE;
END_IF;
IF X2 AND NOT X3 THEN
	Y0 := FALSE;
END_IF;
 

3. Network with pulse flag (rising/falling edge)

LD program

ST program code

Remarks

(* rising edge *)
IF	X0 AND NOT X0_Old THEN
	Count:=Count+1;
END_IF;
X0_Old:=X0;
(* falling edge *)
IF	NOT X1 AND X1_Old THEN
	Count:=Count-1;
END_IF;
X1_Old:=X1;

Explicit query of edge detection without function or function block.

Also possible:

(* rising edge *)
R_TRIG_X0( CLK:= X0 );
IF	R_TRIG_X0.Q THEN
	Count:=Count+1;
END_IF;
(* falling edge *)
F_TRIG_X1( CLK:= X1 );
IF	F_TRIG_X1.Q THEN
	Count:=Count-1;
END_IF;

Using R_TRIG or F_TRIG function block instances from the IEC standard library.

Also possible:

(* rising edge *)
IF	DF(X0) THEN
	Count:=Count+1;
END_IF;
(* falling edge *)
IF	DFN(X1)  THEN
	Count:=Count-1;
END_IF;

Using the basic functions DF or DFN.

Modified on: 2019-01-26Feedback on this pagePanasonic hotline