You are on page 1of 14

Review of PLC software blocks

 
In PLC there are a lot of virtual relays, timers, counters. They all have "a" contacts
- normally open and "b" - normally closed.
 
Entrance (X) and weekend (Y) relays.
 
The main PLC unit contains entrance and weekend relays numbered in the eight-
eighth X000-X007, X010-X017... and Y000-Y007, X010-X017....
The first digit of the designation indicates the block in which the entrance or exit is
located. 0 - main block, 1-7 possible expansion number. For example, in the first
extension, the ins/outs will start with the X100/Y100.
 
Auxiliary relay M
 
Auxiliary relays are not embodied in PLC, receives control only at the information
level, that is from the user program, the PPC management program or on
commands taken through the Modbus interface. The concept of auxiliary relays is
close to the concept of flags or semaphores in high-level programming
languages. Some of the auxiliary relays have the function of energy-independent
storage of their son-in-law, that is, long breaks in the nutrition of PLC will not
violate the conditions established by the program during normal
operation. Auxiliary relays with numbers starting from 8000 have special service
assignments: they allow you to manage the work of PLC and are sources of
information about the performance of the program or the operation of plc in
general for the user's program.
 
Status S
 
This software unit has the same properties as the auxiliary relay, but is used to
control branching in the program.
 
Counter C
 
The counter counts the number of signs of the control signal at its entrance.
Divided into:
         16 bit with positive account direction, range of values 0..32767
         32 bits with positive/negative account direction, range of values
-2,147,483,648..
         high-speed 32-bit with positive/negative account direction, range of values
-2,147,483,648..z2,147,483,647
The first two types of meters are used only for the meter inside the program,
respectively, taking into account the cycle cycle cycle period of 10-50 ms and the
fact that to re-apply the control signal it before it is necessary to remove, the
minimum signal period to the program counters is 20-100 ms or 10-50 Hz for
periodic signals.
The latter type of counters does not depend on the software cycle and has electrical
inputs, which use part of the discrete inputs. The maximum score frequency is 200
kHz. Account modes are possible: easy to increase, with direction and two-phase.
 
Timer T
 
A timer is a counter whose value, if launched, increases every 1, 10 or 100ms of
the user's choice. When the set value is reached, a high level is set on its output.
T100-T199 timers are accumulating. After the control signal disappears at the
entrance, their value is not zeroed and when the control signal is re-fed, they
continue to count down from the same value as they did before the 100ms
outage. The rest of the timers zero their value when the control signal is removed.
 
Data Registers D, FD
 
Registers are designed to store data. The discharge of each register is 16 bits. Two
registers can be combined into a register pair and used as a 32-bit number in
calculations. The numbers in the floating view are stored in the conroller in register
pairs. Registers with prefix D are designed to quickly store the information needed
for the program. Some of them are stored in the controller's RAM, some in RAM,
soaked from the lithium battery. The latter retain their values after the controller is
deactivated.
FD registers have the same properties when reading from them. They are located in
the controller's flash memory, not dependent on any power, but this imposes the
following restrictions:
         The record cannot be done by commands that assume that the result is placed
on the general register. At the same time, these registers are modified in the
same way as regular registers under the Modbus interface.
         enrollment is slower than in the general register
         there is a limit on the number of recording cycles per memory cell
 
Constants K, H
 
Constants will be used as a command argument. Prefix K meets decimal constants,
H meets sixteen-9.
 
Pointers P, I
 
Pointers will be used to indicate where to go when the program is branched. I
prefix pointers are used to indicate the start of interrupting procedures.
 
(tab from 32/42)
 
 
Introduction to LD and IL programming languages
 
The LD language used for the programming of this PLC was originally intended to
describe devices based on relay logic. With the advent of PLC and their
replacement with relay logic, the argument for its adoption as their primary
programming language was that many professionals would not have to
relearn. Using analogies with electrical devices, it will be easy for them to switch
to new equipment. Although this argument is no longer so relevant, because in
PLC often behind this graphic representation there is a program in some more
"habitual" (for people associated with programming) language and execution is
consistent, unlike relay schemes, where all devices work in parallel, which breaks
the analogy, the language of LD is still a tradition.PLC. Its advantage is that a pre-
exercise algorithm that could be implemented in relay logic can be described on it
without using any keywords of the controller programming language, only by
graphic language tools. At the same time, since management systems today are not
limited to discrete signals, in the PLC, the implementation of the LD language in
question allows the integration of the data command, whether mathematical or
related to the shipment or processing of binary data, into the program. In fact, the
entire program for PLC consists of commands in the language of IL (Instruction
List). This transformation occurs when the program is compiled in the LD
language. Specialists who prefer traditional microprocessor programming
languages can immediately write a management program for PLC using the IHL
language mmmocode.
Ld language is the language of rules. Its name is associated with a visual analogy
that occurs when viewing the program on it, with a ladder that has 2 tires and a
crossbar between them. The left tire is associated with a power bus for relays and
electromagnetic actuators. Every crossbar is the rule. The right tyre is the executive
mechanisms, the relays connected to the shared power source bus.
The rule is considered to work if there is at least one way from the imaginary
power source on the left to the executive mechanism on the right, and then the
executive mechanism is given a signal of permission to work.
In the future, when describing programming methods, commands of the cotroller
language will be cited, as well as their graphic and electrical analogies where
applicable.
 
 
 
 
Basic instructions.
 
LD, LDI, OUT
 
mnemonic graphic designation function Applicable devices
designation
LD (LoaD) ---| |--- loading the state of X, Y, M, S, T, C,
the login or other Dn.m, FDn.m
discrete device,
normally opened
contacts
LDI (LoaD Inverse) ---|/|--- downloading the entry X, Y, M, S, T, C,
state or other discrete Dn.m, FDn.m
device with inversion,
normally closed
contacts
OUT (OUT) ---( )--- A control signal on X, Y, M, S, T, C,
the executive device Dn.m, FDn.m
 
 
The LD command downloads the state of bit devices such as ins, PLC exits,
auxiliary coils, timer outs and counters. When you read the state of the inputs, a
high logical level, as a result of the execution of the command, will be in case the
contacts connected to the input are closed to the general input conductor. The LDI
command will return the logical 1 if the contacts at the entrance are unlocked or
the readable bit is 0.
The OUT command activates the executable mechanism specified in its argument
if the result of the previous operation is logical 1.
 
example:

The program above reads the X0 login state and, if the contacts at that entrance
have been closed, trigger y0. Thus, the X0 entry state is transmitted to Y0 without
alterations. The Y1 exit is transmitted to the inverted X1 entry state. Having been
converted into controller instructions, this program looks like this.
LD X0
OUT Y0
LDI X1
OUT Y1
 
To understand, the result of the LD command is loaded into the battery (the data
storage register in the early microprocessors in which the command arguments
were stored and which retained the result of their execution), and then the OUT
team takes it to the specified port.
 
AND, ANI
 
 
mnemonic graphic function Applicable devices
designation designation
AND (AND) ---| |------| |--- Downloading the entry state X, Y, M, S, T, C,
or other discrete device, Dn.m, FDn.m
applying to the resulting
value and the result of the
previous logical I
command; sequential
connection of normally
opened contacts
ANI (ANd Inverse) ---| |------|/|--- Downloading the entry state X, Y, M, S, T, C,
or other discrete device, Dn.m, FDn.m
applying to the inverted
resulting value and the result
of the previous logical I
command; sequential
connection of normally
opened contacts
 
example:

LD X0
AND X1
OUT Y0
LD X2
ANI X3
OUT Y1
 
When contacted closed, the X0 and X1 inputs will work.
If you have closed contacts at the X2 input and open to X3, the rule that includes
Y1 will work.
 
 
OR, ORI
 
 
mnemonic graphic function Applicable devices
designation designation
OR (OR) ---| |---| Downloading the entry state X, Y, M, S, T, C,
---| |---| or other discrete device, Dn.m, FDn.m
applying to the resulting
value and the result of the
previous logical OR
command. Parallel
connection of normally
opened contacts
ORI (OR Inverse) ---| |---| Downloading the entry state X, Y, M, S, T, C,
---|/|---| or other discrete device, Dn.m, FDn.m
applying to the inverted
resulting value and the result
of the previous logical OR
command. Parallel
connection of normally
opened contacts
 
example:

LD X0
OR X1
OUT Y0
 
The Y0 rule will work when closed contacts at X0 and X1 inputs.
 
 
LDP, LDF, ANP, ANF, ORP, ORF
 
The LDP command returns the result of detecting a positive drop at the entrance,
specified as an argument. That is, if in the previous cycle of the program execution
(scan) the specified entry gave a low level, and in the current high - the result of
execution - a high level. It follows that the high level as a result of the performance
of this command will be maintained during one scan, as the next scan will not be
sufficient to detect a positive difference, because from the point of view of the next
scan in the previous one there was already a high level and a positive difference
can not occur.
LDF returns the result of detecting a negative drop at the entrance in the same way.
From previous descriptions of commands, such as AND, it is clear that when they
are executed, it is essentially first the loading of the state of the specified entry, as
if it was made by the LD command, and then the application of the appropriate
logical operation. Logical function commands, whose mmmocode ends on P and F,
load the state specified in the entry arguments, as would be the case with LDP and
LDF commands, respectively.
 
 
mnemonic graphic function Applicable devices
designation designation
LDP (LoaD Pulse) p up detecting a positive drop at X, Y, M, S, T, C,
the entrance Dn.m, FDn.m
LDP (LoaD Fall) page down detection of a negative drop X, Y, M, S, T, C,
at the entrance Dn.m, FDn.m
ANP (ANd Pulse)   detection of a positive drop X, Y, M, S, T, C,
at the entrance, the Dn.m, FDn.m
application to the result and
the result of the previous
command of the logical
function of AND
ANF (ANd Fall)   detection of a negative drop X, Y, M, S, T, C,
at the entrance, the indence Dn.m, FDn.m
to the result and the result
of the previous command of
logical function AND
ORP (OR Pulse)   detection of a positive drop X, Y, M, S, T, C,
at the entrance, the Dn.m, FDn.m
application to the result and
the result of the previous
command of the logical
function of OR
ORF (OR Fall)   detection of a negative drop X, Y, M, S, T, C,
at the entrance, the Dn.m, FDn.m
innuation to the result and
the result of the previous
command of the logical
function of OR
 
 
PLS, PLF, SET, RST, ALT
 
These 4 commands are designed to be put into bit devices.
PLS displays a high logical level within 1 scan, if the rule for this instruction did
not work for the specified output in the previous scan, which is the result of the
previous instruction - 0.
PLS displays a low logical level for 1 scan, if the rule for this instruction did not
work for the specified output in the previous scan, which is the result of the
previous instruction - 0.
SET sets the state of the specified output permanently in a high state until it is
replaced by another command, even after the expiration of the rule that triggers the
SET command.
RST places the state of the specified output permanently in a high state until it is
replaced by another command, even after the expiration of the rule that triggers the
RST command.
ALT replaces the output of the specified exit to the opposite and leaves it
permanent, until the change by another instruction. Caution should be exercised in
applying this instruction. If the rule for this instruction is valid from any long-
standing signals, the change of state on the specified output will be made in each
scan until the rule ceases to function. Therefore, it is usually advisable to preface
this instruction, such as that which detects a difference.
 
mnemonic designation graphic designation Applicable devices
PLS (PuLSe) No Y, M, S, T, C,
Dn.m, FDn.m
PLF (PuLse Fall) No Y, M, S, T, C,
Dn.m, FDn.m
SET (SET) ---(S)--- Y, M, S, T, C,
Dn.m, FDn.m
RST (ReSeT) ---(R)--- Y, M, S, T, C,
Dn.m, FDn.m
ALT (ALTernate) No Y, M, S, T, C,
Dn.m, FDn.m
 
 
Applied instructions
type designation function
  CJ conditional jump
CALL Calling a routine
subroutine SRET Return from the routine
STL Start a disconnected section of code
STLE End of the code section that's being disconnected
SET Turn on the code section
Turn off the section of code without disabling the
ST
current
FOR The beginning of the FOR-NEXT cycle
NEXT End of the FOR-NEXT cycle
FEND The first end of the program
LD= LD Truth If (S1) (S2)
LD> LD Truth if (S1) > (S2)
LD< LD Truth If (S1) < (S2)
LD<> LD Truth if(S1)≠ (S2)
LD<= LD Truth if(S1)≤ (S2)
LD>= LD Truth if(S1)≥ (S2)
AND= AND the truth if(S1) (S2)
AND> AND truth if(S1)>(S2)
AND< AND truth if(S1)< (S2)
Compariso
AND<> AND truth if(S1)≠(S2)
n of data
AND<= AND truth if(S1)≤ (S2)
AND>= AND truth if(S1)≥(S2)
OR= OR Truth if(S1) (S2)
OR> OR Truth if(S1)> (S2)
OR< OR Truth if(S1)< (S2)
OR<> OR Truth if(S1)≠ (S2)
OR<= OR Truth if(S1)≤ (S2)
OR>= OR Truth if(S1)≥ (S2)
MOV Copy value into one register
BMOV Copy value into multiple registers
FMOV Fill move
Copy FWRT Record in Flash Memory
content MSET Turning on the zone
ZRST Turning off the zone
SWAP Senior 8 words change with junior 8 grades
XCH permutation
ADD addition
SUB subtraction
MUL multiplication
DIV division
INC increment
Data DEC decrement
operations MEAN average
WAND The word "I"
WOR The word "OR"
WXOR The word "Excluding or"
CML supplement
NEG negative
     
     
 
(Next at the beginning of each description should follow a sign with features, I will
give an example as I see them, but I will not put, otherwise if you need to remake
for some aesthetic or typographical purposes - will have to redo everything.)
 
Anyway, here's the concept:
 
ADD addition operation applicable in
devices
16 bit: ADD 32 bit: DADD XC1, XC3, XC5
 
Apply to blocks:
Source 1
K/H DX DY DM DS TD CD D FD
Source 2
K/H DX DY DM DS TD CD D FD
destination (or recipient)
    DY DM DS TD CD D  
 
 
 
CJ - Condition Jump - Conditional Transition
 
Valid argument: Pointer - P
Valid argument boundaries: P0-P9999
 
The execution of the instruction causes the program to switch to the instruction
following the pointer specified in the argument, provided that the previous
instruction returned a high level.
In practice, the instructions reduce the duration of the scan, avoid repeated
exposure to the same devices, and change the behavior of the device depending on
its mode of operation.
 
(rice from 75/85)
 
The above program shows that there are two rules for influencing Y0. At the same
time, the first Y0 rule will only be considered when the X0 input is low.
The instruction does not move from one STLE instruction to another.
CALL - call subroutine, SRET - subroutine return - call and return from routine
 
Acceptable argument for CALL: Pointer - P
Valid argument boundaries: P0-P9999
 
(rice from 76/86)
 
The CALL instruction triggers a shift to the routine that the pointer indicates in the
argument, provided that the previous instruction returned a high level. The SRET
instruction returns program execution control to the instruction following the last
CALL statement.
In this example, the routine between the P10 and the SRET is performed at a high
level at the X0 input. The FEND instruction shows the end of the core program's
body, and the END shows the whole program.
 
SET, ST, STL, STLE - Thread Management
Acceptable argument for SET, ST, STL: status - S
 
These 4 instructions allow you to create and manage software flows. In the text of
the program, the beginning of the stream is denoted by the STL instruction, and
ended with the STLE instruction.
Then, in order to allow the thread to be executed, you must execute set or ST
instructions with an argument pointing to the flow number. The difference between
them is that SET stops the flow from which it is executed. You can ban the thread
from running with the RST instruction, with an argument pointing to the flow.
 
(rice from 77/87)
 
Keep in mind that once the flow is complete, the timers they use, as well as the
registers used by the PLS, PLF instructions, are zeroed.
 
 
 
FOR-NEXT Cycle
Arguments :DX、DY、DM、DS、T、C、D、FD、K
 
The first is the instruction between the FOR-NEXT instruction for a while
(depending on the size of the data inside the loop), then the NEXT instruction is
followed.
M0
FOR K5
M1
FOR K6

INC D0 [A]

NEXT
M3 [C]
FOR K7

INC D1 [B]

NEXT

NEXT

1) Each FOR instruction should end with THE NEXT instruction.


2) Between FOR-NEXT instructions LDP and LDF act one external cycle. When
the M0 coil state changes its state from 0 to 1 and M1 changes its state from 0 to 1,
cycle A is performed 6 times
3) When the M0 and M3 coils change their state from 0 to 1, cycle B will run
5/7/35 times
4) If there are many cycles, the scan cycle will be long
5) If the NEXT instruction is in front of FOR,or no NEXT,or NEXT is after
the FENG block, , END,or THEnumber of NEXT does not equal FOR - this will
lead to an error
6) Between FOR - NEXT is not allowed to place CJ blocks, also it applies
to STL, , FOR - NEXT should be used paired
 
 
FEND and END
Arguments - no
 
The FEND block is used to indicate the end of the main program and the start of
the sub-programme blocks (streams).
- If the CALL instruction is in the program after the FEND instruction, there
should be an SRETinstruction. )
- After following the CALL instruction and before SRET is followed, if the
FEND is followed or FEND is followed after the FOR instruction is performed and
before following THE NEXT - this situation will cause an error
- If you use the FEND instruction, the end of the program should end
with END,if FEND is not used - the use of END is not necessary.
 
 
Write values in registers and install/reset coils
 
Blocks of this section are similar in function, they write in registers some value, if
it is coils, then recorded (coil is installed) in 0 or 1. Data can be entered into single
registers as well as register blocks.
 
MOV  Block
Arguments - DX、DY、DM、DS、T、C、D、FD、K

S· D·
X0
MOV K10 D10

In this code, when the X0 coil is triggered, register Dwill be enteredto 10 (the


value is automatically converted to binary code).
 
It is also possible to write down 2 words at once:
DMOV D0 D10 (D1,D0)→(D11,D10)
(C235 текущее значение)→(D21,D20)

DMOV C235 D20


f

You might also like