PROGRAMMING
There are several language methods applied to PLC programming.
Logical diagrams
List of Instructions
Ladder logic
High-level language
However, they all rely on Boolean Algebra developed in 1849.
by George Boole and is used to develop logical statements, given
which generate true (1) or false (0) orders of logic
combinational of Boolean Algebra. However, the logical operations
basics allow for the performance of a good number of functions of
industrial applications, there are other situations that cannot be resolved
they directly relate to logical operations and it is here that it becomes necessary
the programming languages, specific to each team and manufacturer, being
possible the translation of one type of program to another.
CONCEPTS OF BOOLEAN ALGEBRA
The definitions and properties of Boolean algebra is a topic that can
develop extensively in courses specifically dedicated to the topic, without
We will present their main developments that allow for their application.
to the programming of PLCs
a) Allowed values in Boolean Algebra: 0, 1 the physical interpretation of
these two values correspond to situations open, closed; on,
off; drives, does not drive; etc.
b) Logical variables: A, B, X, Y, etc. can only take these two.
values.
c) The permitted operations: AND, (·); Boolean product X = A · B
OR, ( + ); Boolean sum X=A+B
NOT, ( ); Boolean complement. X = A
d) A logical or boolean function corresponds to a set of variables.
boolean values related by boolean operations
Y = e·(a·b + c·d)
e) Logical or Boolean operations comply with postulates and laws
Associative property of addition and boolean multiplication.
a+(b+c)=(a+b)+c a · ( b· c ) = ( a · b ) · c
Commutative property of addition and Boolean multiplication.
a+b=b+aa·b=b·a
Distributive property of the product with respect to addition.
a·(b+c)=(a·b)+(a·c)
Distributive property of addition over multiplication.
a + (b · c) = (a + b) · (a + c)
Law of absorption.
a+a·b=a a·(a+b)=a
Morgan's Law
(a + b + c + d + ....... ) = a · b · c · d · .........
(a · b · c · d ........) = a + b + c + d + .......
f) Logical operations can be represented in truth tables.
a + b = c a ·b = c a = a
0 0 0 0 0 0 0 1
0 1 1 0 1 0 1 0
1 0 1 1 0 0
1 1 1 1 1 1
g) Boolean algebra can be symbolically represented by
logic gates, semiconductor devices that perform an operation
logic. Thus we find AND (Y), OR (O), NOT (inverter)
a a
c c
b b a a
h) A combinational circuit, made of gates, can be implemented
interconnecting logic gates.
a
e = (a+b) * (c+d)
b
c
d
Considering that a high percentage of industrial applications are of
logical operations (parties, stops, alarms, counts, timing,
comparisons) it is appropriate to use some form of programming that
consider Boolean algebra as the basis for the structuring of language.
of programming.
Let's assume there is a pool from which water is extracted with the operation
from a pump, a manual switch (HS-1) is used for starting and
pump stop. The pool has a level switch. The pump does not
it can be activated, it doesn't work, if there is not enough level in the pool. Without
embargo, in an emergency situation it is desirable to be able to operate using the
water reserve that is under the LSL switch for that there is a
auxiliary switch HS-2 that enables this operation.
Physical element Variable If it is worth 0 If it is worth 1
Level switch a Lower the switch. Level above the
LSL Open switch switch
Closed switch
HS-1 Switch b Stop the bomb by opening Start the pump close the
the switch switch.
HS-2 switch c Normal operation, Operate the pump when the
emergency closed switch switch indicates that there is none
water
Closed switch
bomb d Not working It works
Truth table of the logical function 0 normal operation (SW open)
c 1 bomb opera when SW
a b a+c b d = (a + c)b there is no water (SW closed)
0 0 0 0 0 0 does not work
d
0 1 1 0 0 1 works
1 0 1 0 0
1 1 1 0 0
0 0 0 1 0
0 1 1 1 1
1 0 1 1 1
1 1 1 1 1
0 low level (open SW)
a
1 on level (closed SW)
0 stop pump (SW open)
b
1 start pump (SW closed)
OPERATIONS FOR THE IMPLEMENTATION OF INDUSTRIAL APPLICATIONS.
The development of industrial applications requires operations that go
beyond those corresponding to those supplied by Boolean algebra, thus the
the total possible operations we can carry out can be grouped into:
Basic Operations
Timers and counters
Arithmetic operations
Comparators
Data transfer
Control of program flow.
Basic operations correspond to logical operations and their derivatives: AND;
OR; NOT or their derivatives NAND, NOR; OREX, etc.
Timers and Counters, Allow activating and deactivating devices after
fulfill a specific condition of time or event count. The
Timers and Counters are functionally similar. They can be combined.
boolean variables with non-boolean variables. The Timer inputs are
the boolean variable is not boolean when the preset time is not boolean.
The basic timer is activated in response to a closed input contact.
It will time for a defined period and will close the output contact at the end.
period.
A B
Timer
t
Other timers are implemented based on the basic timer, so
we found the following types, among others:
Delayed Start Timer
In this timer, the change from 0 to 1 at the input marks the start of the period of
timing, t, at the end of it the output changes from 0 to 1 and remains in that state
until the input returns to 0
A
t
B
Delayed Termination Timer
In this timer, the change from 0 to 1 at the input triggers a change from 0 to 1.
At the output, when the input changes from 1 to 0, it starts the timing period.
t, at the end of which it enables the output to change from 1 to 0
t
A
Pulse-activated timer
In this timer, the change from 0 to 1 of the input starts a change from 0 to 1 of
the output, the timing starts simultaneously, t, the input can change from
1a 0, however the output will only change from 1 to 0 when the time is up.
assigned timing.
Arithmetic operations often need to be performed.
among the signals placed at the PLC inputs. Depending on the potential
the team includes operations of addition, subtraction, multiplication, and division, in the
small teams. While in the larger teams there are operations of
Logarithms, square roots, trigonometric functions, it is evident that these
operations will have non-boolean operands and results.
The Comparators perform the operation between two variables and correspond
mainly to: Equal to (=); greater than (>), and less than (<). The result of the
operation is boolean
Data Transfer used mainly to transfer data within the
PLC memory.
The Program Flow Control acts on how the execution is being carried out.
there are instructions such as:
Start and end marks of the program
Conditional and unconditional jumps
Calls to subroutines.
-etc.
PRESENTATION OF PROGRAMS USED IN INDUSTRIAL APPLICATIONS
To describe the form that programs written in various languages have, one
present the following example.
There is a pool from which water is extracted by starting and stopping.
of a bomb.
HS Manual Switch
I Enclavement
LLL Low-level indicator light
LLLL Very low level light indicator
LSL Switch for low signal
LSLL Switch for very low level
LT Level transmitter
The pump starts from a HS-1 button and will stop from another HS-2 button.
There is low-level signaling LLL (pool level below safety level),
it obtains from a level transmitter LT whose signal is used for a level indication,
outside of the PLC.
For the protection of the pump, it will turn off if the level of the tank is below the
LSLL level switch that indicates very low level, simultaneously a chain is triggered.
very low level luminous indication LLLL. It is necessary to turn off automatically
because the pump cannot operate without liquid.
For HS-2, a normally closed switch is used, which is closed when not pressed; for HS-1...
use a normally open switch, open when not pressed
The LSLL switch will be a type NA open contact when the switch is off.
energized by the water level. Closed when the level is above the limit
specified.
The pump will be powered when the output Y1 is powered or in state 1 and
turned off otherwise.
LOGICAL DIAGRAMS
Programming using logical diagrams is a derivation of the language of
gates, the nomenclature used has been standardized (DIN 40.700/40.719, ISA
S5.2)
Physical element Variable If it is worth 0 If it is worth 1
Level Transmitter LT Analog variable (0-1m)
Level switch LSLL Open: Closed
Contact NA Level below Level On Switch
LSLL switch LSLL
Low level indicator LLL Off On.
Level above the fixing Lower level than set for
for alarm (100 mm.) alarm (100 mm.)
Very low indicator LLLL Off. On.
level Level above the Level under the switch
LSLL switch LSLL
Start button HS-1 Open. Closed.
Without pressing. Pressed.
Stop button HS-2 Open. Closed.
Pressed. Without pressing.
Bomb Y1 Off. On
The ISA S5.2 standard 'Binary Logic Diagrams for Process Operations'
contains recommendations for the implementation of sequences and interlocks
used for starts, stops, alarms, etc. Their symbolism is independent of
system used for its implementation (Mechanical, electrical, digital, hydraulic, etc.)
The symbolism used is in accordance with the ISA S5.1 standard 'Instrumentation
Symbols and Identification
FUNCTION SYMBOL DEFINITION
Y (AND) A The logical output D exists (1) if and only if the
logical inputs A, B, and C exist (1)
B A D
C
A
O (OR) The logical output D exists (1) if and only if one or
B OR D more than the logical inputs A, B, or C exist
C (1)
NO (NOT) A B
The logical output B exists (1) if and only if the
logical input A does not exist. (0)
TIMER The continuous existence of the logical input A
AT THE START DI during a time t causes the output
A B
Delayed t logic B exists after time t.
B ceases to exist when A ceases to exist.
TIMER The existence of the logical input A causes the
END A
DT
B
existence of logical output B.
DELAYED t B ceases to exist after a while
continues that A has ceased to exist.
TIMER The existence of the logical input A,
ACTIVATED FOR regardless of its subsequent status,
PO
PULSE A
t
B make logical output B exist
immediately. B exists for the time t and
then disappears.
MEMORY The logical output C exists as soon as there exists the
FLIP -FLOP entry logic A. C exists
A S C
regardless of the state of A, do
R
B
that B exists. Once B exists, C ceases,
regardless of the subsequent state of
B. until A exists.
The solution to the presented problem using logical diagrams is shown in the
next figure.
LIST OF INSTRUCTIONS
The programming language that uses a list of instructions derives from Algebra of
Boole and other instructions that allow representing timings, counters,
data movements in memory, etc.
Each instruction consists of a MNEMONIC (abbreviation that represents a function)
and it can have one or more arguments (variables that act as inputs to the
function.
AND dir, END, >= dir
As an element to store the result, use an auxiliary register that is loaded
through a special instruction or with the recently executed one. The record
auxiliary can store boolean and non-boolean values.
An instruction with an argument does not use the auxiliary as an argument.
The instructions of two arguments (AND; OR) use the first argument for this
registration, although it depends on the manufacturer. The representation of the mnemonics
(abbreviations) may vary by manufacturer (initials or if it is in uppercase or
lowercase)
Some of the most common ones are presented in the following list:
STR dir Load the content of the auxiliary register
AND dir Perform an And operation and enter the contents of dir and auxiliary reg
The result is stored in the auxiliary register.
OR dir Perform an OR operation between the content of dir and auxiliary reg
The result is saved in the auxiliary register.
OUT dir Copy the auxiliary record content to dir
NOT Invert the auxiliary register, the 0s become 1s and the 1s become 0s
dir Perform the 'greater than or equal to' operation between dir and auxiliary register.
The result is saved in the auxiliary register.
< = dir Perform the 'less than or equal' operation between dir and auxiliary register.
The result is stored in the auxiliary register.
END End of program.
The program that corresponds to the initially posed example and using the
Instructions defined in the previous list turn out to be the following.
STR LT LT variable is not boolean converted to a numeric range of 0 and
1024 stores the converted value in the auxiliary register.
< = 100 Compare auxiliary record with 100 it will be 0 if the level is above and
it will be 1 if the level is below 100, result is stored in
auxiliary record
OUT LLL Copy value auxiliary record the address LLL if it is 0 contact of
exit remains open, light off. If it is 1 contact of
exit closes, light turns on
STR HS-1 The value of HS-1 is stored in auxiliary register (0 not pressed; 1 pressed)
OR Y1 perform logical OR operation between auxiliary register and value Y1
result is stored in auxiliary record. If one of them is 1 then
store a 1 if both are zeros, store a zero.
AND HS-2 Perform a logical AND operation between the auxiliary register and the value
HS-2 the result is stored in auxiliary register. If one of them
if 0, store a 0; if both are 1, store a 1.
AND LSLL
OUT Y1 Store a 1 in the Y1 register when the CPU reads this register
send the value to the output card the output contact is
it will close and the pump will start to operate.
STR LSLL Load the LSLL value into the auxiliary register.
NOT The content of the auxiliary register is inverted.
OUT LLLL
END End of program, the program restarts from the beginning.
According to the program, the output Y1 will be activated when the conditions are met.
simultaneously the following three conditions.
HS-2 = 1 (HS-2 switch not pressed)
0
HS-1 = 1 (HS-1 switch pressed) or Y1 is equal to 1 (Register Y1 is activated).
Condition for Y1 to remain activated once HS-1 is released.
Ladder Logic
Programming using ladder logic or ladder diagrams is based on logic.
contact used by the electrician to connect the relays, which through
graphic symbols carry out logical operations in addition to timing,
counters and activations of external elements in addition to other operations
necessary for the development of an application.
The basic elements of programming are NC or NO contacts and coils (NO,
normally open or NC, normally closed) the normal state of a contact
corresponds to the contact position unenergized
The basic symbolism of a language is shown in the following table.
Contact NA
NC Contact
( )
Bobbin
TON Timer of
Delayed start
TOF Timer of
Delayed term
RTO Timer, with hold.
Actuated by pulse
CTU Increasing counter
CMD Comparator
For the implementation of a program in scale diagram, it is assumed that a line
The program is connected to a pair of power supply lines a, b.
a b
B1 = X1AND X3 )
X1X3 B1
a b
----------- )---
B2= X1OR X2 X1 B2
X2
The coil of the actuator element is the last element that is placed in the line and
represents the element of final action
The contact diagram is presented in its desenergized state and process plant.
empty.
a b
CMP
1
LT<100
LLL
HS-1
2 BOMB
LSLL
BOMB
3 BOMB
LSLL
4 LLLL
AUX
HIGH-LEVEL LANGUAGES
High-level languages, besides being used in intelligent models, are useful for
write subroutines in PLC that use other languages such as ladder logic.
In some languages in ladder logic, instructions called BOX are inserted.
that when activated execute subroutines written in languages similar to C, Pascal, Basic.
Their applications are aimed at applications that require intensive capacity.
calculation. They are suitable for high complexity programs, it is not usual in
programming of relative simplicity, like that of our example, however of
make it is shown in the following list.
10 REM 'Variable declaration'
20 DECLARE HS-1, HS-2, LSLL, LLLL
BOOLEAN
30 DECLARE LT = WORD
40 REM Reading field variables
50 DIN HS-1, HS-2, LSLL
60 AIN LT
70 REM Program
80 LLL = CMP < (LT, 100)
90 BOMBA = AND (HS-2, AND (LSLL, OR (HS-1, BOMBA)))
100 LLLL = NOT (LSLL)
110 REM Writing field variables
120 BOMB, LLL, LLLL
130 END
STRUCTURED PROGRAMMING
High-level languages, particularly structured programming languages, are useful.
in applications of high complexity, aims to facilitate understanding and the
design of the developed programs
Structured programming is a set of elements that support each other.
they constitute a whole, of which they are members and not parts, forming a totality and
not a sum. The members are characterized by their independence, their articulation in
the total form and its solidarity.
It consists of breaking down a job into several independent tasks,
self-contained and easy to understand. Each one is designed separately in some
described language. A master program defines how tasks are run and controls the
set.
Each manufacturer defines its own version of its structured languages