Está en la página 1de 42

PLC

programming

7th. Lesson
MISCIT
Typically a PLC system has the basic functional components of processor
PLC system
unit, memory, power supply unit, input/output interface section,
communications interface and the programming device. Figure 1.4 shows
the basic arrangement.

Programming
device Program & data Communications
memory interface

Input Output
inter- Processor inter-
face face

Power supply

Figure 1.4 The PLC system


of the current (Figure 1.11(a)). If the current flows from the output
module to an output load then the output module is referred to as sourcing
(Figure 1.11(b)). With sinking, using the conventional current flow
direction as from positive to negative, an input device supplies current to
Source and sinking
the input module, i.e. the input module is the sink for the current (Figure
1.12(a)). If the current flows to the output module from an output load
then the output module is referred to as sinking (Figure 1.12(b)).

+
Input Input
module module


Input
Output load
(a) device (b)

Figure 1.11 Sourcing

+
Input Input Input
device module module

(a) (b) Output load

Figure 1.12 Sinking

ystems There are two common types of mechanical design for PLC systems; a
single box, and the modular/rack types. The single box type (or, as
I/O Processing
Analogue, i.e. a signal whose size is related to
the size of the quanDty being sensed.
Discrete, i.e. essenDally just an ono signal.
Digital, i.e. a sequence of pulses.
Programs for microprocessor-based systems
have to be loaded into them in machine code,
this being a sequence of binary code numbers
to represent the program instrucDons.
Programming PLC
ladder diagram (LD)
instrucDon list (IL)
sequenDal funcDon chart (SFC)
structured text (ST)
funcDons block diagram (FBD)
Ladder diagrams Programming 81

with electrical power when the switch is closed. The circuit shown i
Figure 5.1(b) is termed a ladder diagram.

Switch L1 L2
L1 Motor M
d.c. input M Switch Motor
L2
Power rails
(a) (b)

Figure 5.1 Ways of drawing the same electrical circuit

With such a diagram the power supply for the circuits is always show
program being clearly denoted, and then promptly resumes at the start
(see Section 4.4). This procedure of going through all the rungs of the
program is termed a cycle. The end rung might be indicated by a
block with the word END or RET for return, since the program
promptly returns to its beginning.

Power flow
Left power rail Right power rail

Rung 1

Rung 2

Rung 3

Rung 4

END End rung

Figure 5.3 Scanning the ladder program


Figure 5.4 shows standard IEC 1131-3 symbols that are used for input
and output devices. Some slight variations occur between the symbols
when used in semi-graphic form and when in full graphic. Note that inputs

Standard IEC 1131


are represented by different symbols representing normally open or
normally closed contacts. The action of the input is equivalent to opening
or closing a switch. Output coils are represented by just one form of
symbol. Further symbols will be introduced in later chapters.

Semi-graphic form Full graphic form

A horizontal link along which


power can flow

Interconnection of horizontal
and vertical power flows

Left-hand power connection


of a ladder rung

Right-hand power connection


of a ladder rung

Normally open contact

Normally closed contact

Output coil: if the power flow


to it is on then the coil state is on

Figure 5.4 Basic symbols

To illustrate the drawing of the rung of a ladder diagram, consider a


To illustrate the drawing of the rung of a ladder diagram, con
situation where the energising of an output device, e.g. a motor, d
Ladder rung
on a normally open start switch being activated by being closed. Th
is thus the switch and the output the motor. Figure 5.5(a) shows the
diagram.
Input Output Input

Output
(a)

Input Output Input

Output

(b)

Figure 5.5 A ladder rung


addresses of each element are appended to its symbol. Thus Figure 5.6
shows how the ladder diagram of Figure 5.5(a) would appear using (a)
Mitsubishi, (b) Siemens, (c) Allen-Bradley, (d) Telemecanique notations
for the addresses. Thus Figure 5.6(a) indicates that this rung of the ladder
program has an input from address X400 and an output to address Y430.
When wiring up the inputs and outputs to the PLC, the relevant ones must
be connected to the input and output terminals with these addresses.
Input Output Input Output
X400 Y430 I0.0 Q2.0

(a) (b)

Input Output Input Output


I:001/01 O:010/01 I0,0 O0,0

(c) (d)

Figure 5.6 Notation: (a) Mitsubishi, (b) Siemens, (c) Allen-Bradley, (d)
Telemecanique

There are many control situations requiring actions to be initiated when a


certain combination of conditions is realised. Thus, for an automatic
ladder diagram starts with | |, a normally open set of contact
input A, to represent switch A and in series with it | |, another
open set of contacts labelled input B, to represent switch B. The

Logic funcDons terminates with O to represent the output. For there to be an ou


input A and input B have to occur, i.e. input A and input B con
to be closed (Figure 5.8(b)). In general:
Programming 85
On a ladder diagram contacts in a horizontal rung, i.e. c
logic gate and the outputs is tabulated in a form series,
known as a truth table.
AND
Thus for the AND gate we have:
represent the logical AND operations.

Input A Input B Output


Inputs Output Input A

A B Input B

0 0 0 (a) Output
0 1 0
(b)
1 0 0
1 1 1 Figure 5.8 AND gate with a ladder diagram rung

A B 5.2.2 OR
Inputs
A Figure 5.9(a)Output
shows an electrical circuit where an output is
Logic
whengate
switch A or B, both normally open, are closed. This des
OR logic
control ANDgate (Figure 5.9(b)) in that input A or input B must
B there to be an output. The truth table is:
Applied voltage
(a) (b)

Figure 5.7 (a) AND circuit, (b) AND logic gate


labelled input A, to represent switch A and in parallel with it | |, norm
open contacts labelled input B, to represent switch B. Either input A
input B have to be closed for the output to be energised (Figure 5.10(
The line then terminates with O to represent the output. In general:

Alternative paths provided by vertical paths from the main rung o


ladder diagram, i.e. paths in parallel, represent logical
operations.

OR Input A Output Input A Output

rollers Input B Input B

Inputs Output
A B (a) (b)

0 0 0 Input A
0 1 1
1 0 1 Input B
1 1 1
Output
(c)
A
Inputs
B
A Figure 5.10 OR gate
Output
Logic gate
control OR
B An example of an OR gate control system is a conveyor b
transporting bottled products to packaging where a deflector plate
(b) activated to deflect bottles into a reject bin if either the weight is
(a) Applied voltage
within certain tolerances or there is no cap on the bottle.
Figure 5.9 (a) OR electrical circuit, (b) OR logic gate

Figure 5.10(a) shows an OR logic gate system on a ladder diagram,


5.2.3 NOT
Figure 5.11(a) shows an electrical circuit controlled by a switch that is
normally closed. When there is an input to the switch, it opens and there is
then no current in the circuit. This illustrates a NOT gate in that there is
an output when there is no input and no output when there is an input
(Figure 5.11(c)). The gate is sometimes referred to as an inverter. The
NOT
truth table is:

Input Output
A
0 1
1 0
A
Input A Output

(b)

(a) Applied voltage


Input A

Output
(c)

Figure 5.11 (a) NOT circuit, (b) NOT logic with a ladder rung, (c) high
A
NOT
A
AND NOT OR
B B
ogrammable Logic Controllers NOT

NAND
(a) (b)
A
NOT
A
Figure 5.12 NAND gate
AND NOT OR

Both the inputs A and BB have to be 0 for there toB be aNOT


1 output. There is
an output when input A and input B are not 1.(b)The combination of these
(a)
gates is termed a NAND gate.
Figure 5.12 NAND gate
Input A Output
Both the inputs A andInput
B have
A to be 0 for there to be a 1 output. There
an output when input A and input B are not 1. The combination of th
gates is termed a NAND gate.
Input B
Input B
Input A Output
Input A
Output
Input B
Input B
Figure 5.13 A NAND gate
A A
NOT
OR NOT
B AND
Programming 89
B
(a) NOT
NOR A (b) A
NOT
OR NOT
Figure 5.14 NOR
B gate AND
B
(a) NOT
Figure 5.15 shows a ladder diagram of a NOR system. When input A
and input B are both not activated, there(b)is a 1 output. When either X400
or X401 are 1 there is a 0 output.
Figure 5.14 NOR gate

Input Figure
A Input5.15
B shows
Outputa ladder diagram
Input A of a NOR system. When input A
and input B are both not activated, there is a 1 output. When either X400
or X401 are 1 there is a 0 output. Input B

Input A Input B Output Input A


Output
Input B
Figure 5.15 NOR gate
When just input B is activated, then the lower branch results in the
being 1. When both input A and input B are activated, there is no o
In this example of a logic gate, input A and input B have two s
contacts in the circuits, one set being normally open and the
normally closed. With PLC programming, each input may have as
Exclusive OR (XOR)
sets of contacts as necessary.

Input A Input B Output


Input A

Input B
Input A Input B

Output

Figure 5.17 XOR gate


An example of a latch circuit is shown in Figure 5.18. When the input
A contacts close, there is an output. However, when there is an output,
another set of contacts associated with the output closes. These contacts
form an OR logic gate system with the input contacts. Thus, even if the
input A opens, the circuit will still maintain the output energised. The only
way to release the output is by operating the normally closed contact B.
Latching
Input A Input B Output

Output

Figure 5.18 Latched circuit

As an illustration of the application of a latching circuit, consider a


motor controlled by stop and start push button switches and for which one
signal light must be illuminated when the power is applied to the motor
and another when it is not applied. Figure 5.19 shows the ladder diagram
with Mitsubishi notation for the addresses.
open in the top rung and third rung, but close in the second rung. Thus
Y431 comes on and Y432 off.
Latching is widely used with start-ups so that the initial switch on of an
application becomes latched on.

s With ladder diagrams, there can be more than one output connected to a
contact. Figure 5.20 shows a ladder program with two output coils. When
MulDple outputs
the input contacts close both the coils give outputs.

Input Output A
Input

ogic Controllers Output A


Output B

Output B
For the ladder rung shown in Figure 5.21, output A occurs when input
A occurs. Output B only occurs when both input A and input B occur.
Input A Output A
Figure 5.20 Ladder rung with two outputs Input A

Input B
Output B
Output A

Input B Output B
Figure 5.21 Ladder rung with two inputs and two outputs

Such an arrangement enables a sequence of outputs to be produced, the


sequence being in the sequence with which contacts are closed. Figure
5.22 illustrates this with the same ladder program in Mitsubishi and
Siemens notations. Outputs A, B and C are switched on as the contacts in
the sequence given by the contacts A, B and C are being closed. Until
input A is closed, none of the other outputs can be switched on. When
input A is closed, output A is switched on. Then, when input B is closed,

Sequenced outputs
output B is switched on. Finally, when input C is closed, output C is
switched on.
Input A Output A Input A Output A
X400 Y430 I0.0 Q2.0

Input B Output B Input B Output B


X401 Y431 I0.1 Q2.1

Input C Output C Input C Output C


X402 Y432 I0.2 Q2.2

(a) (b)

Input A

Input B

Input C

Output A

Output B

Output C
function block in the system shown above it, Timer1. Names of functio
block inputs are shown within the block at the appropriate input an
output points. Cross diagram connectors are used to indicate whe

FuncDons Blocks Diagram


graphical lines would be difficult to draw without cluttering up
complicating a diagram and show where an output at one point is used
an input at another.
Semi-graphic form Full graphic form

Horizontal and vertical lines

function block diagram (FBD) is used for PLC programs


n terms of graphical blocks. It is described as being a graphical
or depicting signal and data flows through blocks, these
Interconnection being
of horizontal
oftware elements. A function block is a program
and verticalinstruction
signal flows unit

en executed, yields one or more output values. Thus a block is


d in the manner shown in Figure 5.23 with the function name
Crossing horizontal and
he box. vertical signal flows

Output
Inputs Function
Blocks with connections

3 Function block
Connectors AV_WEIGHT AV_WEIGHT
C 113-3 standard for drawing such blocks is shown in FigureAV_WEIGHT AV_WEIGHT
Logic gates
96 Programmable Logic Controllers

Input A Input A
Input A Input A
Output Output Input B
Input B & Input B &
Input C Input B
Input C Output

Output
AND function
Input A
Input A Input A Output
Input A Output
>1 Input B
>1 Input B Input B
Input B
Output Output
OR function

Input A
Input A Output Input A
Input A Output
Input B & Input B
>1 Input B
Input C Input B
Input C
Output
Output
NOR function
NAND function

Input A Input A
Input A Output Input A Output
XOR Input B XOR Input B
Input B Input B
Output Output
XOR function XOR function
Programming 97

Output
Input Input Output Input I0.0 Programming
Q2.0 97
I0.0 I0.1 Q2.0 =
Input I0.1 &
Output
Input Input Output Input I0.0 Q2.0
I0.0 I0.1 Q2.0 =
Figure 5.29 Ladder diagram and equivalentInput & diagram
I0.1 block
function

Figure 5.30 shows a ladder diagram involving the output having


contacts acting as an input. The function block diagram equivalent can be
Figure 5.29 Ladder diagram and equivalent function block diagram
shown as a feedback loop.
Figure
Input 5.30 showsOutput
Input a ladder diagram involving the output having
A B Q
contacts acting as an input. The function block diagram equivalent can be
shown as a feedback loop.
>1 Q
A
Input
Output Input Output &
AQ B Q B

>1 Q
A
Output &
Figure 5.30
Q Ladder diagram and equivalent
B function block diagram
Exercice
A signal lamp is required to be switched on if a
pump is running and the pressure is
saDsfactory, or if the lamp test switch is
closed.
instruction may either use or change the value stored in a memory
register. For this, mnemonic codes are used, each code corresponding to
an operator/ladder element. The codes used differ to some extent from

InstrucDons List
manufacturer to manufacturer, though a standard IEC 1131-3 has been
proposed and is being widely adopted. Table 6.1 shows some of the codes
used by manufacturers, and the proposed standard, for instructions used in
this chapter (see later chapters for codes for other functions).

Table 6.1 Instruction code mnemonics

IEC 1131-3 Mitsubishi OMRON Siemens/ Operation Ladder diagram


Operators Telemecanique

LD LD LD A Load operand into Start a rung with open


result register contacts
LDN LDI LD NOT AN Load negative operand Start a rung with closed
into result register contacts
AND AND AND A Boolean AND A series element with open
contacts
ANDN ANI AND NOT AN Boolean AND with A series element with closed
negative operand contacts
OR OR OR O Boolean OR A parallel element with open
contacts
ORN ORI OR NOT ON Boolean OR with A parallel element with
negative operand closed contacts
ST OUT OUT = Store result register An output
into operand
IL, SFC
the Boolean and STAND
operation programming met
performed with
In the first line of the program, LD isresult
the operator,
storedAintheQ,operand, and the to Q.
i.e. outputted
wordsAs at theanends of program lines
illustration of and
the inuse
brackets
of beand
IEC preceded
113-1 andoperators, con
Labels can used to identify various entr
followed by * are comments added to explain what the operation is and
arefollowing:
not part of the program operation as instructions
we will to find later LD
the PLC. forA jumps
is in progra
thus the instruction to load the A intoinstruction
the memoryandregister.
are separated
It can thenfrom it by a colo
later be called on for further operations. The next line of the program has
LD A (*Load A*)
the Boolean operation AND performed with A and B. The last line has the
result storedAND B
in Q, i.e. outputted
PUMP_OK:
to Q. (*AND B*)
LD C
Labels canSTbe used toQ (* entry
identify various Storepoints
result in Q, i.e.
to a program, output to Q*)
useful
as we will find later for jumps in with there and
programs, being
these the instruction
precede the earlier i
instruction and are separated from it PUMP_OK
by a colon. Thusifwe might have: condition is realise
a particular
In the first line of the program, With
LD
the
is the
IEC
operator,
113-1
A the
operators, an
operan
N after
PUMP_OK: LD
words at the ends of program C (* Load C*)
linesif we
andhave:
in brackets and prec
For example,
followed
with bythe
there being * are comments
instruction earlier inadded to explain
the program to jumpwhat
to the operati
are notifpart
PUMP_OK of the
a particular program
condition operation
is realised.
LD Ainstructions
(*LoadtoA*)the PLC.
With the IEC 113-1 operators, an N after it is used to negate its value.
thus the instruction to load the
For example, if we have: ANDN A into B the memory
(*AND register.
NOT B*) It
later be called on for further operations. The next line of the pro
theLD Boolean A operation
(*Load A*) Thusperformed
AND the ANDN with operator inverts
A and the value
B. The last lio
ANDN B (*AND NOT theB*)
result.to Q.
result stored in Q, i.e. outputted
1 The operation is described by a number of separate sequentially
connected states or steps which are represented by rectangular boxes,

SequenDal FuncDons Charts


each representing a particular state of the system being controlled.
The initial step in a program is represented differently to the other
steps, Figure 6.12 shows its representation.

Start Initial step in which the system


is held ready to start

Transition condition

State/step Output

Transition condition

etc.

Stop Final step

Figure 6.12 A state and its transition

2 Each connecting line between states has a horizontal bar representing


the transition condition that has to be realised before the system can
5 Outputs/actions at any state are represented by horizontally linked
boxes and occur when that state has been realised.

As an illustration, Figure 6.13 shows part of an SFC and its equivalent


ladder diagram.

Start
IN 1 OUT 1 Step 0
IN 1 When IN 1 occurs, then
step 0 is realised and
Step 0 OUT 1 OUT 1 occurs

IN 2
Step 1
OUT 1 IN 2 OUT 3
When step 1 has been
Step 1 OUT 2 realised, i.e. OUT 1, and
the transfer condition
IN 3 IN 2, then step 1 is
END realised and OUT 2
End occurs

Figure 6.13 SFC and equivalent ladder diagram


State 1
OUT 0 IN 1 output
State 0 OUT 0

State 2
IN 1 IN 2 IN 3 OUT 0 IN 2 output

State 1 State 2 State 3


State 3

SelecDve branching and parallel branching OUT 1 IN 3 output


State 1 occurs if the transfer
condition IN 1 occurs, but if
IN 2 then state 2 or if IN 3
then state 3

rollers Figure 6.15 Selective branching: the state that follows State 0 will
depend on whether transition IN1, IN2 or IN3 occur.

State 1 State 1
OUT 0 IN 1 output output
OUT 0 IN 1
State 0 OUT 0 OUT 0
State 0

State 2 IN 1 State 2
IN 1 IN 2 IN 3 OUT 0 IN 2 output output

State 1 State 2 State 3


State 1 State 2 State 3
State 3 State 3
OUT 1 IN 3 output output
State 1 occurs if the transfer When IN 0 occurs then
condition IN 1 occurs, but if state 1, state 2 and state 3
IN 2 then state 2 or if IN 3 are all simultaneously
then state 3 realised.

Figure 6.16 Parallel branching states 1, 2 and 3 occur simultaneously


Figure 6.15 Selective branching: the state that follows State 0 will when transition IN 1 occurs.
depend on whether transition IN1, IN2 or IN3 occur.

State 2 Input State 4


State 1 State 2 State 3 output IN 4 output
OUT 0 IN 1 output

State 0 OUT 0 IN 4 IN 5
State 3 Input
IN 1 State 2 output IN 5
output

State 1 State 2 State 3


State 3
output
When IN 0 occurs then
state 1, state 2 and state 3
are all simultaneously
realised.

Convergence state and simultaneous


Figure 6.16 Parallel branching states 1, 2 and 3 occur simultaneously

convergence
when transition IN 1 occurs.

State 2 Input State 4


State 2 State 3 output IN 4 output

IN 4 IN 5
State 3 Input
output IN 5
State 4
IL, SFC and ST programming methods 1

Figure 6.17 Convergence: state 4 follows when either IN 4 or IN5 occur. State 2 Input State 4
State 2 State 3 output IN 4 output

State 3
IN 4 output

State 4
In 0 Out 0

ic Controllers
In 1
given using a ladder diagram, function block diagram, instruction list or
Figurestructured
6.20 Action
text. represented
Thus, where aby a ladder
ladder diagram
diagram is used, the behaviour of the
AcDons
action is shown by the ladder diagram being enclosed within the action
box. boxes
The action
Action are isgenerally
then activated when there
preceded is a powertoflow
by qualifiers into thethe
specify
action box. Figure 6.20 illustrates this.
conditions to exist for the action. In the absence of a qualifier or the
qualifier N, the action is not stored and executed continually while the
In 0
associate state is active. The qualifier P is used for a pulse action that
Out 0
executes only once when a stepInis0 activated. The qualifier D is used for a
time delayed action that only starts after a specified period. The qualifier
L is used for a time In 1
limited action which terminates after a specified
period (Figure 6.21).
Figure 6.20 Action represented by a ladder diagram

Action boxes are generally preceded by qualifiers to specify the


conditions to exist for the action.
L In the absence of a qualifier or the
State 1 Action 1
qualifier N, the action is not
T#5sstored and executed continually while the
associate state isT1active. The qualifier P is used for a pulse action that
executes only once when a step is activated. The qualifier D is used for a
time delayed action that only starts after a specified period. The qualifier
FigureL6.21
is used for a timeoflimited
Illustration action used
a qualifier whichwith
terminates after this
an action, a specified
being a
has (3 InputC) evaluated before its value is used as a divisor so the
second part of the OutputQ statement is 4/(3 2) = 4. Division has
precedence over addition and so the first part of the statement is evaluated
Structured text
before the addition, i.e. 6/3. So we have for OutputQ the value 2 + 1 = 3.

Table 6.2 Structured text operators

Operator Description Precedence

(...) Parenthised (bracketed) expression Highest


Function(...) List of parameters of a function
** Raising to a power
-, NOT Negation, Boolean NOT
*, /, MOD Multiplication, division, modulus
operation
+, - Addition, subtraction
<, >, <=, >= Less than, greater than, less than or
equal to, greater than or equal to
=, <> Equality, inequality
AND, & Boolean AND
XOR Boolean XOR
OR Boolean OR Lowest

Structured text is not case sensitive, thus lower case or capital letters
can be used as is felt necessary to aid clarity. Likewise spaces are not
Gate2 :- Open;
End_IF;

Note that the end of the IF statement has to be indicated. Another


example, using PLC addresses, is:

IF (I:000/00 = 1) THEN
ollers O:001/00 :- 1;
IL, SFC and ST p
ELSE
AT is used to fix the memory location for a variable. Thus we might
O:000/01 = 0;
have: DO
End_IF; Output :- Input;
End_FOR;

CondiDonal statements
Input1 AT %IX100; (*Input1 is located at input memory bit 100*)
So if there is an input to I:000/00 to make it 1 then output O:001/00 is 1,
otherwise it 0. has the output decreasing by 1 each time the in
6.3.1 Conditional statements CASE is used to give the condition that selected statements are to be
decreases by 1.
executed if a particular integer value occurs else some otherWHILE
IF ... THEN ... ELSE is used when selected statements are to be executed selected... DO allows one or more stateme
when certain conditions occur. For example: statements. For example, for temperature control we might have:
particular Boolean expression remains true, e.g

IF (Limit_switch1 AND Workpiece_Present) THEN CASE (Temperature) OF 0 ... 40 ; OutputQ :- 0;


Gate1 :- Open; Furnace_switch :- On; WHILE InputA AND InputB
Gate2 :- Close; 40 ... 100 DO
ELSE Furnace_switch :- Off; OutputQ =: OutputQ + 1;
Gate1 :- Close; ELSE End_WHILE;
Gate2 :- Open; Furnace_switch :- Off;
End_IF; End_CASE; REPEAT ... UNTIL allows one or more sta
repeated whilst a particular Boolean expression
Note that the end of the IF statement has to be indicated. Note,
Anotheras with all conditional statements, the end of the CASE statement
example, using PLC addresses, is: has to be indicated. OutputQ :- 0
REPEAT
IF (I:000/00 = 1) THEN 6.3.2 Iteration statements OutputQ = OutputQ + 1;
O:001/00 :- 1; These are used where it is necessary to repeat one or more statementsUNTILa (Input1 = Off) OR (OutputQ > 5)
ELSE number of times, depending on the state of some variable. The End_REPEAT;
FOR ...
O:000/01 = 0; DO iteration statement allows a set of statements to be repeated
End_IF; 6.3.3 Structured text programs
depending on the value of the iteration integer variable. For example:
Programs have first to define the data types req
So if there is an input to I:000/00 to make it 1 then output O:001/00 is 1, Input :- 10 to 0 BY -1
FOR
otherwise it 0.
TYPE Motor: ( Stopped, Running);
CASE is used to give the condition that selected statements are to be
End_TYPE;
executed if a particular integer value occurs else some other selected
statements. For example, for temperature control we might have:
TYPE Valve: (Open, shut);
End_TYPE;
CASE (Temperature) OF 0 ... 40 ;
Furnace_switch :- On;
TYPE Pressure: REAL; (*The pressure is
40 ... 100
End_TYPE;
Furnace_switch :- Off;
ELSE
Input 2 the trigg
In 2
gives a c
rs after run
Internal
controls for each such output. However, a simpler method isInput 3 anInput 4 relay 2
to use of the PL
internal relay. Figure 7.6 shows such a ladder diagram. The first In rung
3 has In 4 IR 2 stops the
the latch for keeping the internal relay IR 1 on when the start switch gives
a momentary input. The second rung will then switch the power on. The
Rung with second internal relay IR 2 being a
third rung will also switch on and give output Out 2 if input 2Internal
contactsrelay
are 1 trigger o
Output
closed. The third rung will also switch on and give output Out 3IRif 1input 3

ReseDng latch
Out 1
contacts are closed. Thus all the outputs can be switched on when the start Trigger Cycle Trigger
Output Out 1 controlled by the two Trigger
push button is activated. All the outputs will be switched off if the stop input control output
switch is opened. Thus all the outputs are latched by IR 1. internal relays input
Internal 1
relay 2 Trigger
Internal relay
Start Stop IR 1 IR 2 output
Trigger
input Cycle control
Internal relay
IR 1 2
of

Output 1
Internal relay
Out 1 Figure 7.4 Use of two internal relays
(a)
IR 1
Power onoff
Input 1 InternalFigure 7.9 1One-shot
relay 1Output (a) program, (b) facility in
Internal relay Output 2 In 1 IR 1 Out 1
Input for output 2 IR 1 Out 2
Output 2

Internal relay Output 3 Output 1


Input for output 3 IR 1 Out 3 Out 1
Output 3

and so on for further inputs Input 2 Internal relay 1


In 2 IR 1
Figure 7.6 Starting of multiple outputs

If the power supply is cut off from a PLC while it is being used, all the
output relays and internal relays will be turned off. Thus when the power is
output Y430 to be reset, i.e. turned off and latched off. Thus the output
Y430 is on for the time between X400 being momentarily switched on
138 Programmable Logic Controllers
and X401 being momentarily switched on. Between the two rungs
indicated for the set and reset operations, there could be other rungs for
other activities to be carried out, the set rung switching on an output at the
beginning of the sequence and off atWiththe end.the Mitsubishi PLC, the o
activated when the trigger input, say
Input circumstances, M100 would remain
SET coil Y430
X400 were closed. However, if On M100 has b
X400
S Y430 M100 only remains on for Off a fixed p

Input
then goes off, regardless of On X400
X401
bei
X401 RESETt coil Y430 that would be used are LD OffX400, PL

R Y430 operation when the input On goes


Y430from
Off
Figure 7.9(c), X400 is made normall
then the pulse occurs when the i
Figure 7.13 SET and RESET negative-going.
P
The IEC 1131-3 gives standards
(a) The programming instructions for the ladder rungs in the program for
Figure 7.13 are: negative transition-sensing coils
N transition-sensing coil, if the power f
LD X400 output is set on for one ladder r
(b) S Y430 transition-sensing coil, if the power to
(a) Positive
Figure 7.10 Other program rungs are is set on for one ladder rung evaluatio
transition-sensing coil, 7.11, with the input off there is no
8.1 Jump A function often provided with PLCs is the conditional
describe this as:

IF (some condition occurs) THEN


perform some instructions
ELSE
156 Programmable Logic Controllers perform some other instructions.

Jump and call In 1 Jump 1


Such a facility enablesRung 1 programs
If In 1 to be designed such
conditions are met then certain events occur, if they are not
Input 1 Jump events occur. Thus, for example, we might need to design a
Rung 1 if the temperature isRung 2
above 60oC a fan is switched on, an
temperature
In 3 no action
Jump 2 occurs.
Thus, if the appropriate
Rung 3 conditions If In are
3 met, this function
Rung 2 a ladder program to be jumped over. Figure 8.1 illustrates t
manner. When thereRung is an
4
input to In 1, its contacts close
output to the jump relay. This then results in the program
Rung 3
rung in which the jump end occurs, so missing out interm
Rung 5
Jump end rungs. Thus, in this case, when there is an input to Input
Rung 4 jumps toJump
rung 4 and then proceeds with rungs 5, 6, etc. W
2 end
input to Input 1, theRung jump
6 relay is not energised and the
etc. proceeds to rungs 2, 3, etc.
Figure 8.1 Jump Figure 8.2(a) shows the above ladder program in the
Rung 7
Mitsubishi. The jump instruction is denoted by CJP (conditi
the placeJump
to which
1 end the jump occurs is denoted by EJP (end

condition that the jumpRung will


8 occur is then that there is an
When that happens the rungs involving inputs X401 and X4
and the program jumps to continue with the rungs followin
Subroutine Return to main
program
SRET End of subroutine and (b)
return to main program

END End of entire program

SoubrouDnes
ne call with Mitsubishi PLC, (b) jump to subroutine call with Allen-Bradley PLC

Main program prior to call


Input 1
FCx Subroutine block FCx
EN ENO enabled when input to EN

Processing of the block parameters


IN1 OUT Output when IN1 AND IN2

IN2

Return to main program

Figure 8.6 Call to subroutine block with Siemens PLC

Questions 1 to 4 have four answer options: A, B, C or D. Choose the


correct answer from the answer options.
In many
seconds using the internal CPU clock. This chapter shows how cos
timers can be programmed to carry out control tasks. motor or a
interval of
thus have t
9.1 Types of timers PLC manufacturers differ on how timers should be programmed
seconds us
hence how they can be considered. A common approach timers
is to cons
can b
Timer coil timers to behave like relays with coils which when energised result in
closure or opening of contacts
9.1 Types afterofsome
timerspreset time. ThePLC timermanu
is t
Timer contacts treated as an output for a rung with control being exercisedhence over how
pair
Timers contacts elsewhere (Figure 9.1(a)). ThisTimeriscoil
the predominant approach
timers to be u
Time delay in this book. Some treat a timer as a delay block which when inserted
closure or
before activated rung delays signals in that rung
Timerreaching
contacts the output (Figure 9.1(b)).
treated as a
(a)
There are a number of different forms of timers that can contactsbe foundelsw
Timer
PLCs. With small PLCs there is likely to delay
Time be just one form,inthe thison-de
book
timers. These are timers (a)
which come on activated
before after a particular
rungtime de
delays
(Figure 9.2(a)). Off-delay timers are on for a fixed period of There
Timer
time befar
turning off (Figure 9.2(b)). Another type of timer that occurs PLCs. With
is the pu
Time delay before input timer. This timer switches on or off for a fixed period oftimers. The
time (Fig
(b) signal reaches output (Figure 9.2
9.2(c)). Figure 9.3 shows the IEC 1131-3 standard symbols for tim
TON is used to denote on-delay, TOF off-delay. TP turning pulse offtim
Figure 9.1 Treatment of timers Time delay before input timer. This
On-delay is also represented
(b) bysignal
T0 reaches
and off-delay
output
by 0T.
9.2(c)). Fig
TON is u
Figure 9.1 Treatment of timers
Input Input Input On-delay is

Timer Timer Timer


Input Input
output output output
(a) On-delay timer (a) Off-delay timer Timer (c) Pulse timer Timer
output output
Figure 9.2 Timers: (a) on-delay, (b) off-delay, (c) pulse
(a) On-delay timer (a) Off-de
Timers 161

9.2.1 Sequencing
As an illustration of the use of a timer, consider the ladder diagram shown
in Figure 9.5(a). When the input In 1 is on, the output Out 1 is switched
on. The contacts associated with this output then start the timer. The
contacts of the timer will close after the preset time delay, in this case 5.5
s. When this happens, output Out 2 is switched on. Thus, following the
input In 1, Out 1 is switched on and followed 5.5 s later by Out 2. This
illustrates how timed sequence of outputs can be achieved. Figure 9.5(b)
shows the same operation where the format used by the PLC manufacturer

Sequenced outputs
is for the timer to institute a signal delay.

In 1 Out 1 In 1 Out 1

Timer
Out 1 Timer Out 2
Preset Out 1
TON
to 5.5 IN Q

Timer Out 2

Preset to 5.5 s Timers 163


(a) (b)
open. This results in timer 1, in the first rung, being switched off. This
then causes
Figureits
9.5contacts in outputs
Sequenced the second rung to open and switch off timer 2.

ON-OFF cycle Dmer


This results in the timer 2 contacts resuming their normally closed state
and so theFigure
input9.6
to shows two versions
In 1 causes of how
the cycle timers
to start allcan be again.
over used to start three
outputs, e.g. three motors, in sequence following a single start button
being pressed.T1In K5
(a) the timers are programmed as coils, whereas in (b)
In 1
they areT2programmed as delays. When the start push button is pressed
In1
there is an output from internal relay IR1. This latches the start input. It
also starts both the timers, T1 and T2, and motor 1. When the preset time
Time
for
T1 timer 1 hasT2elapsed
K5 then itsT1
contacts
5 sclose and motor 2 starts. When
the preset time for timer 2 has elapsed then its contacts close and motor 3
starts. The three motors are all stopped by pressing the stop push Time
button.
Since this is seen as a complete T2 program, 5 s
the end instruction has been
T1
used. Out 1
Time
9.2.2 Cascaded timers Out 1 5s

Timers can be linked together, the term cascaded is used, to give Time
longer
delay times than are possible with just one timer. Figure 9.7(a) shows the
Figureladder
9.8 On-off
diagramcycle timer
for such an arrangement. Thus we might have timer 1 with
a delay time of 999 s. This timer is started when there is an input to In 1.
after 10 s.

timers Pulse timers are used to produce a fixed duration output from some
initiating input. Figure 9.13(a) shows a ladder diagram for a system that
will give an output from Out 1 for a predetermined fixed length of time
when there is an input to In 1, the timer being one involving a coil. There
are two outputs for the input In 1. When there is an input to In 1, there is
an output from Out 1 and the timer starts. When the predetermined time

Pulse Dmer
has elapsed, the timer contacts open. This switches off the output. Thus
the output remains on for just the time specified by the timer.

In 1 Timer In 1

Time
Timer Out 1 Timer
Closed
contacts
Open
Time
Out 1

(a)
Time
Internal
In 1 Timer relay

TON

Internal
relay Out 1

(b)

Figure 9.13 Pulse-on timer


types. These are down-counters and up-counters. Down-counters count
down from the preset value to zero, i.e. events are subtracted from the set
value. When the counter reaches the zero value, its contacts change state.
Most PLCs offer down counting. Up-counters count from zero up to the
preset value, i.e. events are added until the number reaches the preset
value. When the counter reaches the set value, its contacts change state.
Different PLC manufacturers deal with counters in slightly different
ways. Some count down (CTD), or up (CTU), and reset and treat the
counter as though it is a relay coil and so a rung output. In this way,
Counter counters can be considered to consist of two basic elements: one relay coil
to count input pulses and one to reset the counter, the associated contacts
of the counter being used in other rungs. Figure 10.1(a) illustrates this.
Mitsubishi is an example of this type of manufacturer. Others treat the
counter as an intermediate block in a rung from which signals emanate
when the count is attained. Figure 10.1(b) illustrates this. Siemens is an
example of this type of manufacturer.
Counter Counter Counter Counter

RST RST CTD CTU


CD Q CU Q
Counter Counter
CTD CTU LD PV
Counter Counter
PV CV R CV

Activated when Activated when Output when zero reached Output when set count
zero reached after counting set count reached after after counting down reached after counting
down from set value counting up from zero (b) from set value up from zero
(a)

Figure 10.1 Forms of representation of counters. In (a) RST is reset. In (b), the IEC 1131-3 representation, CD
is count down input, LD is for loading the input, PV is for the preset value, CV the current count value, CU is
count up input, and R is for the reset input.
When the X401 contacts close the output Y430 starts. Also the timer is
need to be of the same data type, e.g. REAL.
started. When the timer accumulated value reaches 5 s then the greater
than or equal to element switches on Y431. When the timer accumulated
value reaches >15 s Sthen the
D greater than or equal to element switches on
Y432. When the timer reaches 25 s then its contacts switch on Y433.
(a)
metic functions Most PLCs provide BCD-to-binary and binary-to-BCD conversions for
Data comparison
GRTuse when the input might be for a thumbwheel switch or the output to a
CMP>R
decimal display. Figure 12.7(a) shows the typical form of instructions for
T4.0.ACC
400 use in such situations and Figure 12.7(b) the form used by Siemens.
IN1
(b) (c) IN2
ArithmeDc foncDons Source
Data handling
BCD_I
Figure 12.4 Greater than comparison: (a) Mitsubishi, (b) Allen-Bradley,
203
BCD S D EN OUT
(c) Figure
Siemens 12.9 shows the basic form of the Siemens instuctions for
IN ENO
Destination
arithmetic functions. With integers the functions avaialble are ADD_1 for
addition, SUB_1 for subtraction,SourceMUL_1 for multiplication
I_BCD and DIV_1
for division with the quotient
BIN as S the Dresult. The arithmetic functions are
EN OUT

ArithmeDc operaDons
executed of there is a 1 at the enable EN input.
Destination
IN ENO

(a) (b)
ADD_1
Figure 12.7 Conversion: (a) BCD-to-binary and binary-to-BCD, (b)
ENinteger-to-BCD
BCD-to-integer and
IN1 OUT
12.3.1 Arithmetic operations
IN2 ENO
Some PLCs are equipped to carry out just the arithmetic operations of

También podría gustarte