PLC Programming Language - ST1
PLC Programming Language - ST1
Industrial Automation
(Automação de Processos Industriais)
Page 1
IST / DEEC / API Industrial Automation
Syllabus:
Chap. 2 – Introduction to PLCs [2 weeks]
...
...
Chap. 4 - GRAFCET (Sequential Function Chart) [1 week]
Page 2
IST / DEEC / API Chap. 3 - PLCs Programming languages
Page 3
IST / DEEC / API Chap. 3 - PLCs Programming languages
(*
Structured Text Searching for the first element that is not zero in a
table of 32 words (table = words %MW100 till %MW131).
Input:
%M0 works as an enable bit (run search iff %M0 is 1)
%MW100 till %MW131 is the table to search
Output:
%M1 is set to 1/0 if the not zero element was/was-not found
%MW10 is the non-zero value found
%MW11 is the location of the non-zero value
Auxiliary:
%MW99 is the table index
*)
IF %M0 THEN
FOR %MW99:=0 TO 31 DO
IF %MW100[%MW99]<>0 THEN
%MW10:=%MW100[%MW99];
%MW11:=%MW99;
%M1:=TRUE;
EXIT; (* exit the loop *)
ELSE
%M1:=FALSE;
END_IF;
END_FOR;
ELSE
%M1:=FALSE;
END_IF;
Page 4
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
PLC Program = {Sections}, Section = {Sequences}
One sequence is equivalent to one or more rungs in ladder diagram.
Each section can be programmed in Ladder, Instruction List, or Structured Text
Representation of
an ST section:
Structured Text
Basic Instructions
Load
Open contact: contact is active (result is 1)
:= while the control bit is 1.
Close contact: contact is active (result is 1)
:=NOT while the control bit is 0.
Structured Text
Basic Instructions
Store
The result of the logic function activates the coil.
:=
:=NOT The inverse result of the logic function activates the coil.
Structured Text
Basic Instructions
AND
AND of the operand with the result of
AND the previous logical operation.
P
AND of the rising edge with the result
AND(RE...) of the previous logical operation.
Page 8
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Basic Instructions
OR
OR OR of the operand with the result of the previous
logical operation.
Page 9
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Example:
Page 10
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Basic Instructions
XOR
Structured Text
Basic Instructions to Manipulate Bit Tables
Page 12
IST / DEEC / API Chap. 3 - PLCs Programming languages
The instantaneous contacts change state as soon as the timer coil is powered.
The delayed contacts change state at the end of the time delay.
Page 13
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Example:
Page 15
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Temporized Relays
or Timers
Very similar to IL, notice however the missing CAL and the required “;”.
Page 16
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Counters
Some applications...
Page 17
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Again IL and ST are similar, notice however the missing CAL and the required “;”.
Page 19
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing
Page 20
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing
Arithmetic Functions for Words
Page 21
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing
Example:
Arithmetic functions
IF %M0 THEN
%MW0 := %MW10 + 100;
END_IF;
IF %I3.2 THEN
%MW0 := SQRT(%MW10);
END_IF;
IF RE(%I3.3) THEN
INC(%MW100);
END_IF;
Page 22
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing
Example:
Arithmetic functions
IF %M0 THEN
%MW0 := %MW1 + %MW2;
END_IF;
IF %S18 THEN
%MW10 := 32767; RESET %S18;
ELSE
%MW10 := %MW0;
END_IF;
Page 23
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing
Logic Functions
Page 24
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing
Example:
Logic functions
Page 25
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing
Example:
Page 26
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Numerical Processing
Page 27
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Subroutines
Structured Text
JUMP instructions:
Structured Text
Example:
Use of jump instructions
Unity Pro:
Structured Text
Page 31
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
WHILE
Example:
( )
( )
Page 32
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Page 33
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Note: in Unity Pro, both in Structured Text and Instruction List, the
conventional array indexing (e.g. %MW100[%MW1]) is disabled by default. To
enable it, go to the project settings, menu Tools -> Project Settings. See the
grayed region in the next figure:
Page 34
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Halt
Events masking
Page 35
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Page 36
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
• Monostable
• Registers of 256 words (LIFO ou FIFO)
• DRUMs
• Comparators
• Shift-registers
...
• Functions to manipulate floats
• Functions to convert bases and types
Page 37
IST / DEEC / API Chap. 3 - PLCs Programming languages
Structured Text
Numerical Tables
Page 38