IST / DEEC / ACSDC
MEEC 2007-2008
Industrial Automation
(Automao (A t d de P Processos I Industriais) d t i i)
PLCs Programming Languages Structured Text
http://www.isr.ist.utl.pt/~pjcro/courses/api0708/api0708.html
Prof. Paulo Jorge Oliveira pjcro @ isr.ist.utl.pt Tel: 21 8418053 ou 2053 (internal)
API P. Oliveira Page 1
IST / DEEC / ACSDC
Industrial Automation
Syllabus:
Chap. 2 Introduction to PLCs [2 weeks] ... Chap. 3 PLCs Programming Languages [2 weeks] Standard languages (IEC-1131-3): Ladder Diagram; Instruction List, and Structured Text. Software development resources. ... Chap. 4 - GRAFCET (Sequential Function Chart) [1 week]
API
P. Oliveira
Page 2
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
PLCs Programming Languages (IEC 11311131-3) Ladder Diagram Structured Text
If %I1.0 THEN %Q2.1 := TRUE ELSE %Q2.2 := FALSE END_IF
Instruction List
LD AND ANDN OR ST %M12 %I1.0 %I1.1 %M10 %Q2.0
Sequential Function Chart (GRAFCET) 1
(1) m
2
(2) b
Right
3
(3) p
Load
4
(2) a
Left
API
P. Oliveira
Page 3
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Linguagens de programao de PLCs (IEC 11311131-3) Ladder Diagram Structured Text
If %I1.0 THEN %Q2.1 := TRUE ELSE %Q2.2 := FALSE END_IF
Instruction List
LD AND ANDN OR ST %M12 %I1.0 %I1.1 %M10 %Q2.0
Sequential Function Chart (GRAFCET) 1
(1) m
2
(2) b
Direita
3
(3) p
Carrega
4
(2) a
Esquerda
API
P. Oliveira
Page 4
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
API
P. Oliveira
Page 5
Chap. 3 - PLCs Programming languages
Structured Text A section of the program is composed by sequences O sequence i One is equivalent i l t to t a section ti in i ladder l dd diagram di (one or more rangs).
Legend: 1 label 2 comments 3 instructions
- unique identifier (%Li, i=0...999) - augments legibility (* limited to 256 bytes *)
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text Basic Instructions
Load
:= :=NOT :=RE :=FE
P
Open contact: contact is active (result is 1) while the control bit is 1. Close contact: contacto is active (result is 1) while the control bit is 0. Contact in the rising edge: contact is active during a scan cycle where the control bit has a rising edge. edge Contact in the falling edge: contact is active during a scan cycle where the control bit has a falling edge.
API
P. Oliveira
Page 7
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text Basic Instructions
Store
:= :=NOT SET RESET
S
The result of the logic function activates the coil. The inverse result of the logic function activates the coil. The result of the logic function energizes the relay (sets the latch). latch) The result of the logic function de-energizes the relay (resets the latch)..
API
P. Oliveira
Page 8
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text Basic Instructions
AND
AND AND(NOT...) AND(RE...) AND(FE...)
P
AND of the operand with the result of the previous logical operation. AND of the operand with the inverted result of the previous logical operation. AND of the rising edge with the result of the previous logical operation. operation AND of the falling edge with the result of the previous logical operation.
API
P. Oliveira
Page 9
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text Basic Instructions
OR
OR OR(NOT...) OR(RE...) OR(FE...)
N
OR of the operand with the result of the previous logical operation. OR of the operand with the inverted result of the previous logical operation. OR of the rising edge with the result of the previous logical operation. OR of the falling edge with the result of the previous logical operation.
API
P. Oliveira
Page 10
Chap. 3 - PLCs Programming languages
Structured Text
Example:
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text Basic Instructions
XOR
API
P. Oliveira
Page 12
Chap. 3 - PLCs Programming languages
Structured Text Basic Instructions to Manipulate Bit Tables
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text Temporized Relays or Timers
API
P. Oliveira
Page 14
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text Temporized Relays or Timers
%TMi IN
MODE: TON TB: 1mn TM.P: 9999 MODIF: Y
Characteristics:
Identifier: Input: Mode: %TMi IN TON TOFF TP TB 0..63 in the TSX37 to activate On delay Off delay Monostable 1mn (def.), 1s, 100ms, 10ms
Time basis: Q
Programmed value: %TMi.P 0...9999 (def.) period=TB*TMi.P Actual value: %TMi.V 0...TMi.P (can be real or tested) Modifiable: Y/N can be modified from the console
P. Oliveira Page 15
API
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text Rels temporizados Ou Timers
IF %I1.1 THEN START %TM1; END_IF; %Q2.3 := %TM1.Q
API P. Oliveira Page 16
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Example:
API
P. Oliveira
Page 17
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text Counters
Some applications...
API
P. Oliveira
Page 18
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text Characteristics: Counters
Identifier: Value progr.: Value Actual: %Ci R S
CP: 9999 MODIF: Y
%Ci %Ci.P %Ci.V Y/N
0..31 in the TSX37 0...9999 (def.) 0...Ci.P (only to be read) can be modified from the console Reset Ci.V=0 Preset Ci.V=Ci.P Count Up Count Down Overrun %Ci.E=1 %Ci.V=0->9999 Done %Ci.D=1 %Ci.V=Ci.P Full %Ci.F=1 %Ci.V=9999->0
P. Oliveira Page 19
E D F
Modifiable:
Inputs:
CU CD
R S CU CD E D F
Outputs:
API
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text Counters
Example:
IF %I1.1 THEN RESET %C8; END IF; END_IF; IF (%I1.2 AND %M0) THEN UP %C8; END_IF; %Q2.0 := %C8.D;
API
P. Oliveira
Page 20
10
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing
Algebraic and Logic Functions
API
P. Oliveira
Page 21
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing Arithmetic Functions for Words
API
P. Oliveira
Page 22
11
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing E Example: l Arithmetic functions IF %M0 THEN %MW0 := %MW10 + 100; END_IF; IF %I3.2 THEN %MW0 := SQRT(%MW10); SQRT(%MW10) END_IF; IF RE %I3.3 THEN INC %MW100; END_IF;
API P. Oliveira Page 23
Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing E Example: l Arithmetic functions
IF %M0 THEN %MW0 := %MW1 + %MW2; END_IF; IF %S18 THEN %MW10 := 32767; RESET %S18; Use of a system variable: ELSE %MW10 := %MW0; END_IF; %S18 flag de overflow
12
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing Logic Functions
API
P. Oliveira
Page 25
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing E Example: l Logic functions
API
P. Oliveira
Page 26
13
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing E Example: l Numeric Tables Manipulation
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing P i iti on the Priorities th execution ti of f the th operations ti
API
P. Oliveira
Page 28
14
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Structures for Control of Flux S b ti Subroutines Call and Return
API
P. Oliveira
Page 29
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Structures for Control of Flux JUMP i instructions: t ti Conditional and unconditional
API
P. Oliveira
Page 30
15
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Structures for Control of Flux E Example: l Use of jump instructions Attention to: INFINITE LOOPS ... It is not a good style of programming!... Does not improove the legibility of the proposed solution.
API P. Oliveira Page 31
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Structures for Control of Flux IF ... THEN ... ELSE ...
16
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Structures for Control of Flux WHILE
Example:
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Structures for Control of Flux
REPEAT ... UNTIL FOR ... DO
EXIT to abort the execution of a st6ructured flux control instruction
Example:
17
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Structures for Control of Flux H lt Halt
Stops all processes! Events masking
API
P. Oliveira
Page 35
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Data and time related instructions
API
P. Oliveira
Page 36
18
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
There are other advanced instrauctions (see manual) Monostable Registers of 256 words (LIFO ou FIFO) DRUMs Comparators Shift-registers ... Functions to manipulate floats Functions to convert bases and types
IST / DEEC / ACSDC
Chap. 3 - PLCs Programming languages
Structured Text
Numerical Tables
API
P. Oliveira
Page 38
19