You are on page 1of 45

PLC programming

-1

)(Program
PLC .
, :
)(Graphical
) :(LAD - Ladder Diagram
.
) :(FBD - Function Block Diagram



.
) :(SFC Sequential Function Chart
).(Grafcet

):(Textual
) :(IL - Instructions List
, .
) :(ST Structured Text
, .
-2

)(LAD - Ladder Diagram



) (.
,
)( )( , .

LAD
.
) (rung

.
,

.

.

-3

IEC
IEC standard LAD symbols

) :(NO-Normally open contact


) (1 ).(0
) :(NC-Normally closed contact
) (0 ).(1
):(Positive transition contact
) (0
).(1
):(Negative transition contact
) (1
).(0
) :(Coil .
) :(Negated coil
.

-4

IEC
IEC standard LAD symbols

M
-5

) :(Set coil ) (1
) (1
.
) :(Reset coil ) (0
) (0
.
) :(Positive transition coil
) (1 )(0
) (1 .
) :(Negative transition coil
) (1 )(1
) (0 .
) :(Memory coil
.

)(IL - Instructions List


,
) ,(Assembly Language IEC
) (Operator


) (Operand .
,
,
:


Operator Operand
Comment
LD
)* count (* count
SUB
1
)* 1 *(
NE
0
)* (* 0
JMP
)* loop (* label
-6

Label
loop

)(FBD - Function Block Diagram


,
,
,
).(CSF - Control System Flowchart

-7

)SFC - Sequential Function

(Chart


).(Grafcet
) (Steps.
) (Initial step
.

).(Control action
) (qualifier
,
.
) (Transition condition

-8

) (qualifiers

N
S

Non-stored
Set

R
L
D
P
-9

:.
Reset

Time Limited
Time Delayed
Pulse

:.

:.

:.

:.
:.

)SFC - Sequential Function

(Chart


Initial step
)(Transition condition 1

)(Control action 2
Ex: out2=off


Second step

)(Transition condition 3
)(Control action 3
Ex: out3=on
-10


Third step

Control flow direction

)(Transition condition 2

)(Control action1
Ex: out1=on


First step

)(ST Structured Text


) ,(Pascal Language
ICE :
:
IF .. ELSE .. THEN, CASE, FOR, REPEAT, WHILE
: ) ADD ,(+ ) SUB ,(-
) MUL *( , ) DIV .(/
,AND, OR, NOT : .XOR
: ) GT >( ,
) GE =>( , ) LT <( , ) LE <=( ,
) NE ><(.
) (Statements );(.

-11


PROGRAM program_name
VAR_ INPUT
)* *(
END_VAR
VAR_OUTPUT
)* *(
END_VAR
VAR
)* *(
END_VAR
)* *(
END_PROGRAM

-12

v1

volt
(.)integer
v1
v2
-13

.)integer

(:

.
volt:
.
volt:

VAR
;v1 : INT
END_VAR

TYPE
;volt : INT
END_TYPE
VAR
;v1 : volt
;v2 : volt
END_VAR


temp
volt

t1
v1
.250

-14

TYPE
).
integer

(:
;)temp : INT(-10..50
).
integer

(:
;)volt : INT(180..250
END_TYPE
VAR

.50
10temp
:
;t1 : temp
180

volt:
;v1 : volt
END_VAR


AT %
I0.3
Q0.4


.0

3:

.0

4:

.I0.3
.Q0.4

-15

PROGRAM test
VAR
;AT %I0.3 : BOOL
;AT %Q0.4 : BOOL
END_VAR
;LD %I0.3
;ST %Q0.4
END_PROGRAM
PROGRAM test
VAR
;in1 AT %I0.3 : BOOL
;out1 AT %Q0.4 : BOOL
END_VAR
;LD in1
;ST out1
END_PROGRAM


FUNCTION_BLOCK function_name
VAR_ INPUT
)* *(
END_VAR
VAR_OUTPUT
)* *(
END_VAR
VAR
)* *(
END_VAR
)* *(
END_FUNCTION_BLOCK

-16

IF..THEN..ELSE
IF <Boolean expression is true> THEN <Statements>
ELSE
<Statements>
END_IF

IF a > 100 THEN redlight =:ON;


ELSEIF a > 50 THEN yellowlight := ON;
ELSE
greenlight := ON;
END_IF

-17

CASE
CASE <integer expression> OF
<list1>: <Statements>
<list2>: <Statements>
.
ELSE
<Statements>
END_CASE
CASE dial-setting OF
1: x := 10;
2: x := 15;
3: x := 18;
4,5: x := 20;
ELSE
x := 30;
END_CASE

-18

FOR .. DO
FOR <index> =: <start> TO <finish> BY <increment> DO
<Statements>
END_FOR

FOR I =: 0 TO 100 BY 1 DO
light[I] =: ON;
END_FOR

-19

WHILE .. DO
WHILE <Boolean expression is true> DO
<Statements>
END_WHILE

I := 0;
WHILE I =< 100 DO
light[I] := ON;
I := I+1;
END_WHILE

-20

REPEAT .. UNTIL
REPEAT
<Statements>
UNTIL <Boolean expression is true>
END_REPEAT

I := 0;
REPEAT
light[I] := ON;
I := I+1;
UNTIL I > 100
END_REPEAT

-21

(PLC Addressing modes

-22

)(Absolute Addressing
:
:Address Identifier :
I
T

Q.)Input

( :
C.)Timer

(:

M .)Output

(:
.)Counter
(:

.)Memory
(:

) :(Memory Location
.

-23

0 4

)(Absolute Addressing
:
Immediate Addressing

27+
()L +27
Direct Addressing
I0.0

AND

()A I0.0
Indirect Addressing
(])A I[MD3

-24

AND

MD3

)(Symbolic Addressing


,
) (Symbol Editor
.
Q4.0 ,MOTOR_ON

-25

)(Numerical Systems

-26

-27

-28

PLC

-29


Basic Functions

-30

)(AND gate
Q0.0 I0.0 I0.1 ,
.
LAD

IL
I0.0
I0.1
Q0.0

-31

LD
A
=

FBD

)(OR gate
Q0.0 I0.0 I0.1
, .
LAD

IL
I0.0
I0.1
Q0.0

-32

LD
O
=

FBD

)(NOT gate
Q0.0 I0.0.
LAD

IL
I0.0
Q0.0

-33

LD
NOT
=

FBD

)(NAND gate
Q0.0 I0.0 I0.1 ,
.
LAD

IL
I0.0
I0.1
Q0.0
-34

LD
A
NOT
=

FBD

)(NOR gate
Q0.0 I0.0 I0.1
, .
LAD

IL
I0.0
I0.1
Q0.0
-35

LD
O
NOT
=

FBD


Advanced Functions

-36

)(Timers
PLC
, ,

.

-37

)(Pulse Timer
.PT
IN ) (1 Q
) (1 .PT

IN
PT
Q
ET

-38

:.

.:
:.
:.

)(On-delay Timer
) (1 IN
) (1 .PT
IN ) (0 Q
).(0

IN
PT
Q
ET

-39

:.

.:
:.
:.

)(Off-delay Timer
) (0 IN
) (0 .PT
IN ) (1 Q
).(1

IN
PT
Q
ET

-40

:.

.:
:.
:.

)(Counters
PLC ,
.
.
.

-41

)(Up counter
CU ) (0
) (1
PV Q ).(1
R ).(0

:.
CU
:.
R

.:
PV
Q:.
:.
CV

-42


FUNCTION-BLOCK ctu
VAR_ INPUT
cu : BOOL R_TRIG;
(* )*
r : BOOL;
pv : INT;
END_VAR
VAR_OUTPUT
q : BOOL;
cv : INT;
END_VAR
IF r THEN cv := 0;
ELSEIF cu THEN
cv := cv+1;
END_IF
q := (cv >= pv);
END_FUNCTION_BLOCK
-43

)(Down counter
CD ) (0
) (1 PV
Q ).(1
LD ).(PV

:.
CD
:.
LD

.:
PV
Q:.
:.
CV

-44

)(Up-down counter
CU ) (0 )(1

PV QU ).(1
CD ) (0 )(1
QD
).(1

CU
CD
R
LD
PV
QU
QD
CV

-45

:.
:.
:.
:.

.:
:.
:.
:.