100% found this document useful (1 vote)
257 views91 pages

PLC Programming & Applications

Uploaded by

hericonan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (1 vote)
257 views91 pages

PLC Programming & Applications

Uploaded by

hericonan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 91

“PROGRAMMABLE LOGIC CONTROLLER

(PLC) :
PROGRAMMING & APPLICATIONS”

AUTHORS:
NORAZILA BINTI MD POSDZI
TAN EE CHIN

i
DISCLAIMER

All Rights Reserved


No part of this eBook may be reproduced or transmitted
in any form or by any means, electronic or photocopy,
mechanical, recording, or any information storage and
retrieval system without permission in writing from the
publisher.

The publisher and author have made every effort to


prepare this eBook. This effort includes development,
research and testing of theory to determine its
effectiveness. However, all content in this eBook is
intended for educational purposes only.

Copyright © First Edition 2021

e ISBN 978-967-2421-35-1

Published by

Politeknik Ungku Omar


Jalan Raja Musa Mahadi
31400 Ipoh, Perak

ii
PREFACE

Alhamdulillah

The PROGRAMMABLE LOGIC CONTROLLER (PLC) :


PROGRAMMING & APPLICATIONS is specially written as a
guide note for students from the Department of Electrical
Engineering, Polytechnic Malaysia who take the PLC &
Automation course. PLC & Automation in polytechnics is a
course offered to diploma students in electrical and
electronics. This eBook was created in accordance with the
syllabus provided by the Curriculum Development Division
of the Polytechnic Department.

Hopefully, this eBook will make it easier for users to learn


PLC programming and any feedback for the future is
welcome.

iii
SYNOPSIS
The PROGRAMMABLE LOGIC CONTROLLER (PLC) :
PROGRAMMING & APPLICATIONS is specially written for a
course in PLC & Automation. The main objective in writing is
to guide student understand about PLC System and how to
design PLC Programming based on OMRON PLC such as
CPM2A or CPM1A type.

This eBook consists of five chapters, namely:


Chapter 1 : PLC Programming
Chapter 2: Basic Logic Instruction Set
Chapter 3: Timer & Counter Instruction Set
Chapter 4: Special Instruction Set
Chapter 5: Application PLC Programming

This eBook focuses on the basic PLC system, PLC


programming and PLC instruction set. Besides that, method
for design simple PLC programming using a ladder diagram
and instruction list (mnemonic code) are also exposed. Each
sub-topic in this book is also accompanied by a self-
assessment to evaluate the student learning outcomes.

iv
ABOUT THE AUTHORS

NORAZILA BINTI MD POSDZI


is a lecturer in Department
of Electrical Engineering,
Polytechnic Ungku Omar,
Ipoh since 2016 and
Polytechic Kuching Sarawak
since 2009. She obtained a
Bachelor’s Degree in
Electronics Engineering
(Industrial Electronic)
(Hons), UTeM, Melaka.

TAN EE CHIN is a lecturer in


Department of Electrical
Engineering, Polytechnic
Ungku Omar, Ipoh since
1999. She obtained a
Bachelor’s Degree of
Science in Electronic
Engineering (Control),
UTHM, Johor.

v
CONTENT
1.0 PLC PROGRAMMING
1 Ladder Diagram (LD)
Instruction List
Structure Text
Function Block Diagram (FBD)
Sequential Function Chart (SFC)
Reflection Question

2.0 BASIC LOGIC INSTRUCTION SET


20 LOAD / LOAD NOT
AND / AND NOT
OR / OR NOT
AND LOAD
OR LOAD
OUT, END, No operation
Reflection Question
3.0 TIMER & COUNTER INSTRUCTION SET
36 Timer Instruction Set
Counter Instruction Set
Reflection Question

4.0 SPECIAL INSTRUCTION SET


45 Holding Circuit
SET/RESET
KEEP
DIFU / DIFD
INTERLOCK / INTERLOCK CLEAR
JUMP / JUMP END
Reflection Question

5.0 APPLICATION PLC PROGRAMMING


65 Three Phase Motor Direct Control by using PLC
Three Phase Motor Forward-reverse Rotation Control by
using PLC
Pedestrian Crossing Traffic Light Control System
A Conveyor Dispatching System
Part Sorting for Assembled Material
Reflection Question

83 REFERENCE

vi
1.0 PLC
PROGRAMMING

Understand PLC programming system

1. Ladder Diagram (LD)


2. Instruction List
3. Structure Text
4. Function Block Diagram (FBD)
5. Sequential Function Chart (SFC)

1
PLC PROGRAMMING SYSTEM

WHAT IS
PLC PROGRAMMING?

PLC programming is an important activity that involves planning


and developing programs to implement control applications
based on the desired situation.

When designing a PLC program, as a programmer must know the


type of PLC programming language to be used.

PLC programming uses a


programming language
that is easy to use and
learn by beginner.

2
PLC PROGRAMMING SYSTEM

Generally, at the international level each industry will use a


different PLC programming language based on the type of PLC.

IEC 1131-3 is a global standard for control programming languages


in PLCs. PLC programming languages are divided into two
categories: text languages and graphic languages. The following
is a list of PLC programming languages specified by this standard.

Programming Languages

Text Languages Graphic Languages


Mnemonic Code Ladder Diagram
(Instruction List)

Graphic
Languages
Sequential
Function Chart
(SFC)

Text Languages Graphic Languages


Structured Text Function Block Diagram
(FBD)

3
PLC PROGRAMMING SYSTEM

LADDER DIAGRAM
Ladder diagram are a type of programming language that uses
graphic methods to write control instructions.

It is the most used and best choice language for PLC programming.
This language is very similar for all PLC manufacturers.

+ve -ve
NO NC output
Rung

Input Condition

Power line

Figure 1.1 - Ladder Diagram

The ladder diagram has vertical lines on the right and left. It
represents for positive (+ve) and negative (-ve) power lines, as
shown in Figure 1.1.

The horizontal line that connects the bus bar is called a Rung, and
it is where the switching elements Normally Open (NO), Normally
Closed (NC) and OUTPUT are placed. Basically, a ladder diagram
consists of a set of rungs in which each rung represents a single
line with a specific function.

4
PLC PROGRAMMING SYSTEM

LADDER DIAGRAM
Ladder Diagram is kind of graphical programming language that
evolved from the the relay control wiring circuit diagram. Figure
1.2(a) and Figure 1.2(b) shows the difference between wiring
diagram and ladder diagram concept.

SW 1 (0000) SW 2 (0001)

+ L1 (1000)
24V

Figure 1.2 (a) - Wiring Diagram

+ -
0001 0002 1000

Figure 1.2 (b) - Ladder Diagram

Writing this program is


similar to that of drawing
a switching circuit.

5
PLC PROGRAMMING SYSTEM

LADDER DIAGRAM FEATURES

1 Power flow is from left to right (from +ve to –ve)

+ve SW1 SW2 Lamp -ve


0000 0001 1000

Current flow
Left rail

The output on the right can not be connected directly to the


2 left.

+ve Lamp -ve


1000

Wrong

There must be at least one input for each rung.


+ve SW1 Lamp -ve
0000 1000

3 Each rung contains at least one output.

+ve SW1 SW2 Lamp -ve


0000 0001 1000

At least
one output

6
PLC PROGRAMMING SYSTEM

LADDER DIAGRAM FEATURES

Contact input cannot be placed on the right side of the


4 output.

+ve SW1 Lamp SW2 -ve


0000 1000 0001
Wrong

Output must connect to a right rail.


+ve SW1 SW2 Lamp -ve
0000 0001 1000

Right rail

5 Multiple loads cannot be connected in series.

+ve SW1 SW2 Lamp 1 Lamp 2 -ve


0000 0001 1000 1001
Wrong

Multiple loads must be connected in parallel.


+ve SW1 SW2 -ve
0000 0001 1000

Output
connect
1001
in parallel

7
PLC PROGRAMMING SYSTEM

LADDER DIAGRAM FEATURES

Each output in the programmed can only be used once and


6 cannot be repeated.

+ve SW1 SW2 Lamp 1 -ve


0001 0002 1001

Output
Lamp 2
1002
can be
used once

Multiple input can be used in the programmed


+ve SW1 SW1 Lamp 1 -ve
0000 0001 1001

SW1 SW2 Lamp 2


0001 0002 1002

7 Output address can be used as input address

+ve Lamp 1 SW2 Lamp 2 -ve


1001 0001 1002

Input address cannot be used as an output address.


+ve SW1 SW2 SW3 -ve
0001 0002 0003
Wrong

8
PLC PROGRAMMING SYSTEM

MNEMONIC CODE
Mnemonic Code (Instruction List) is a PLC programming language
that uses statement lists. It is used to programmed the PLC by
entering data and instructions through the Programming Console.
Figure 1.3 show the instruction list operations for this
programming.

Instruction List Operations

* LOAD (LD) instruction


* AND instruction
* OR instruction
* Output (OUT) instruction
* END (FUN) instruction
* NOT instruction
* AND LD instruction
* OR LD instruction

Figure 1.3

Mnemonic code is the second step after creating a ladder diagram.


The ladder diagram cannot be read by the Programming Console.
As a result, the Ladder Diagram should be converted to mnemonic
code that contains the same information as the Ladder Diagram
and can be typed directly into the Programming Console.

9
PLC PROGRAMMING SYSTEM

MNEMONIC CODE
A mnemonic code is an instruction keyword, usually an
abbreviation of the actual name of the instruction.

Table 1.1 - Mnemonic Code


ADDRESS INSTRUCTION DATA
0000 LD 0001
0001 OR 0002
0002 AND 0003
0003 OUT 1001
0004 TIM 000
#050
0005 FUN (01)

Referring to the mnemonic code in Table 1.1, it consists of three


column of table, namely:

Address Instruction: Operand/Data:


Consists of a The sequence Implementation of
four-bit number that must be the data input and
sequence, followed in order output process. In
referred to as to complete the other words, the
the memory task using the value of the data
address. instruction list. processed by the
instruction.

10
PLC PROGRAMMING SYSTEM

MNEMONIC CODE
EXAMPLE OF MNEMONIC CODE

The basic elements of a mnemonic code (instruction list) program


from a ladder diagram as shown Figure 1.4 (a) and Figure 1.4 (b):

+ -
0001 0002 1000

0003

END

Figure 1.4 (a) - Ladder Diagram (LD)

ADDRESS INSTRUCTION DATA


0000 LD 0001
0001 OR NOT 0003
0002 AND 0002
0003 OUT 1000
0004 FUN (01)

Figure 1.4 (b) - Mnemonic Code

The steps to write the mnemonic code could be found on page 25.

11
PLC PROGRAMMING SYSTEM

STRUCTURED TEXT
Structured text (ST) is a high-level text language, such as BASIC, C,
or PASCAL, that has been specifically developed for industrial
control applications such as process automation. It is used to
implement complex procedures that are difficult to express in
graphical languages.

Structured text is an extremely flexible programming language for


writing control algorithms. ST programming can be written in any
text editor and are easy to programmed, debug, test, and
understand. Therefore, it is ideal for complex mathematical,
algorithmic or decision-making tasks.

Benefits of Structured Text:

Programs run as fast and efficient as ladder diagram.

Programmers can easily learn structured


01 text programming.

Programs can be created in any text


02 editor.

Programs run as fast and efficient as


03 ladder diagram.

12
PLC PROGRAMMING SYSTEM

STRUCTURED TEXT
Structured text makes use of statements to specify what should
be executed.

Figure 1.5 (a) and Figure 1.5 (b) illustrates how structured text and
ladder diagram programming can both be used to produce the
same logical output.

EXAMPLE OF STRUCTURED TEXT


The light will turn on when one of the following two circuit
condition is present:
• Switch 1 and Switch 2 switches are both closed.
• Switch 3 is closed and Switch 4 switch is open.

+ -
Switch 1 Switch 2 Lamp

Switch 3 Switch 4

Figure 1.5 (a) - Ladder Diagram (LD)

IF Switch_1 AND Switch_2 THEN


LAMP := 1;
ELSEIF Switch_3 AND NOT Switch_4 THEN
LAMP := 1;
END_IF;

Figure 1.5 (b) - Structured Text (ST)

13
PLC PROGRAMMING SYSTEM

FUNCTION BLOCK DIAGRAM


Function block diagram (FBD) is used for PLC programming that
use block graphs. It is a graphical language used to describe signal
and data flow within a block.

The main concept of a functional block diagram is data flow. It is


most useful in applications involving high information or data flow
between control components, such as process control.

A1 Q1

A1 OR
A2 Q1
A2

A1 Q1
A1 OR
Q1
A2 A2

Figure 1.6 - Ladder Diagram to Function Block Diagram

Function blocks are connected to form a circuit that meets a


control requirement. The block function type name, such as OR is
displayed in the block as shown in Figure 1.6. Function blocks can
have standard functions like logic gates, counters, or timers.

14
PLC PROGRAMMING SYSTEM

FUNCTION BLOCK DIAGRAM


The main concept is the data flow, which starts with the inputs
and continues through the blocks to generate the output.

EXAMPLE OF FUNCTION BLOCK DIAGRAM


Figure 1.7 (a) and Figure 1.7 (b) shows an example between of
a function block diagram and ladder diagram.

+ -
A1 A2 Q1

Q1

Figure 1.7 (a) - Ladder Diagram (LD)

OR
A1 AND
Q1
A2

Figure 1.7 (b) - Function Block Diagram (FBD)

15
PLC PROGRAMMING SYSTEM

SEQUENTIAL FUNCTION CHART

Sequence Function Chart (SFC) is also a graphical programming


language for PLC used mainly for sequential processes whereby
the process can be divided into many sequential steps. These are
like flowcharts, but this method is different because it does not
have to follow a single path through the flowchart. Figure 1.8
shows a concept of sequential function chart (SFC).

Start

Transition 1
Action

Step Output

Transition 2

Transition xx

Stop

Figure 1.8 - Sequential Function Chart (SFC)

SFC programming uses a graphical interface to organize program.


The three main components of an SFC are steps, actions and
transitions. A step is a system function, like a mechanical process
and transition is the condition needs to be fulfilled before the
process can move from one step to another step.

16
PLC PROGRAMMING SYSTEM

SEQUENTIAL FUNCTION CHART


For each design using SFC, two requirements must be followed:

• There should be a transition condition between two steps.


• A step should always be between two transitions.

EXAMPLE OF SEQUENTIAL FUNCTION CHART PROGRAM


Figure 1.9 (a) and Figure 1.9 (b) shows an example between of a
sequential function chart and ladder diagram program.

+ Switch -
Start Red Lamp Start

Switch Start
Sensor 1 Red Lamp Green Lamp
Step 1 Red Lamp

Sensor 1
END
Step 2 Green Lamp

Figure 1.9 (a) - Ladder


Diagram End

Figure 1.9 (b) - Sequential


Function Chart

17
PLC PROGRAMMING SYSTEM

INPUT / OUTPUT PORT ADDRESS


In order to create the ladder diagram and mnemonic code, all
external input and output devices to be connected to the PLC
must be identified. In the figure below, input and output data
values are described.

Output Data
Input Data
0000 ~ 0011 1000 ~ 1007

{
{

1st digit 3rd & 4th


1st digit
is ‘1’ to digits
is ‘0’ to 3rd & 4th represents represent
represents digits output output bit
input data represent data 2nd digit on the PLC
2nd digit input bit on
represents
represents the PLC
channel
channel

For example, for the Omron PLC CPM2A shown in the Figure
1.10, the input terminals are numbered from 0000 to 0011 (12
inputs), and the output terminals are numbered from 1000 to
1007 (8 output).

In this E-book, All


explanations are referred
to OMRON PLC type
CPM2A

Figure 1.10 – Omron PLC


CPM2A

18
PLC PROGRAMMING SYSTEM

REFLECTION QUESTION
1. List FIVE (5) standard PLC programming languages.

2. Based on the ladder diagram below, explain the error found in the
diagram.
+ -
0001 0002 1001 1000

1000
1001

0001 0003 1000 1000

3. Explain the structure of the following PLC programming language:


(a) Function Block Diagram
(b) Sequential Function Chart

4. Convert the structured text below to PLC ladder diagram.


IF PB1_1 AND PB_2 THEN
LAMP := 1;
ELSEIF PB_3 THEN
LAMP := 1;
END_IF;

5. Mnemonic code consists of three column namely __________,


__________and ____________.

6. What is rung in PLC ladder diagram?

19
2.0 BASIC LOGIC
INSTRUCTION SET

Understand basic logic instruction set

1. LOAD / LOAD NOT


2. AND / AND NOT
3. OR / OR NOT
4. AND LOAD
5. OR LOAD
6. OUT
7. END
8. No operation

20
BASIC LOGIC INSTRUCTION SET

LOAD (LD)
▪ LD is the starting instruction for the logic line of the program.
▪ LD is use when a rung starts with the Normally Open (NO)
condition on the left power line.

0001
Address Instruction Data
0000 LD 0001

Ladder Diagram Mnemonic Code

LOAD NOT (LD NOT)


▪ LD NOT is the starting instruction for the logic line of the
program.
▪ LD NOT is use when a rung starts with the Normally Closed
(NC) condition on the left power line.

0001
Address Instruction Data
0000 LD NOT 0001

Ladder Diagram Mnemonic Code

21
BASIC LOGIC INSTRUCTION SET

OUT
▪ OUT instructions are used to control the coil output.
▪ OUT is connected to a right power line in the Normally Open
(NO) condition.

+ -
0001 1000 Address Instruction Data
0000 LD 0001
0001 OUT 1000

Ladder Diagram Mnemonic Code

Output 1000 will remain ON as long as Input 0001 is ON. When


0001 changes to OFF, 1000 also changes to OFF.

OUT NOT
▪ OUT NOT instructions are used to control the coil output.
▪ OUT NOT is connected to a right power line in the Normally
Closed (NC) condition.

+ 0001
-
1000 Address Instruction Data
0000 LD 0001
0001 OUT NOT 1000
Ladder Diagram Mnemonic Code

Output 1000 will remain ON as long as Input 0001 is OFF.


When 0001 changes to ON, 1000 changes to OFF.

22
BASIC LOGIC INSTRUCTION SET

AND
AND instructions is used to connect two or more input with a
Normally Open (NO) condition in serial.

+ -
0001 0002 1000 Address Instruction Data
0000 LD 0001
0001 AND 0002
0002 OUT 1000
AND
Mnemonic Code
Ladder Diagram

When both inputs 0001 and 0002 are turned on, the output 1000
will also be turned on.

AND NOT
AND NOT instructions is used to connect two or more input with
a Normally Closed (NC) condition in serial.

+ -
0001 0002 1000 Address Instruction Data
0000 LD 0001
0001 AND NOT 0002
0002 OUT 1000
AND NOT
Ladder Diagram Mnemonic Code

When the inputs 0001 is turned ON and 0002 is turned OFF, the
output 1000 will be turned on.

23
BASIC LOGIC INSTRUCTION SET

OR
OR instructions is used to connect two or more input with a
Normally Open (NO) condition in parallel.

+ -
0001 1000 Address Instruction Data
0000 LD 0001
0002 0001 OR 0002
0002 OUT 1000
OR Mnemonic Code
Ladder Diagram
When any of the inputs 0001 or 0002 are turned on, the output
1000 will also be turned on.

OR NOT
OR NOT instructions is used to connect two or more input with a
Normally Closed (NC) condition in parallel.

+ -
0001 1000 Address Instruction Data
0000 LD 0001
0002 0001 OR NOT 0002
0002 OUT 1000
OR NOT
Mnemonic Code
Ladder Diagram

When the input 0001 is turned on or 0002 is turned off, the


output 1000 will be turned on. The input 0002 is NC, so the output
remains on until 0002 is turned on or 0001 is turned off.

24
BASIC LOGIC INSTRUCTION SET

END
END instruction is used to indicate the end program.
It is the last instruction of a program. The program cannot be
executed without an END instruction. For OMRON PLCs, the
END instruction is FUN (01).

+ -
0001 1000
Address Instruction Data
0000 LD 0001

END
0001 OUT 1000
0002 FUN (01)

Ladder Diagram Mnemonic Code

NO OPERATION (NOP)
NOP instruction will display on the PLC programming console
screen when the PLC programming is deleted from the PLC's
memory.

These instructions have no symbols for a ladder diagram and


will not perform any operations.

25
BASIC LOGIC INSTRUCTION SET

HOW TO WRITE MNEMONIC CODE?


Convert from ladder diagram program to Mnemonic Code
1st contact is
NC, start with STEP 5
LD NOT + 0003 -
0001 0002 1000
STEP 1 1st rung
0004 STEP 6 Use OUT
STEP 2 instruction
Next, refer STEP 4
to contact
in parallel Next, go to
0005 STEP 3 serial for AND
instruction
1st contact
is NO, start
with LD 0006 STEP 8 1001
STEP 7 2nd rung
Use OUT NOT
STEP 9 END of program instruction
END used FUN (01)

Address Instruction Data STEP


0000 LD NOT 0001 1
0001 OR 0004 2
0002 OR NOT 0005 3
0003 AND 0002 4
0004 AND NOT 0003 5
0005 OUT 1000 6
0006 LD 0006 7
0007 OUT NOT 1001 8
0008 FUN (01) 9

26
BASIC LOGIC INSTRUCTION SET

AND LOAD (AND LD)


The AND LD instruction is used to connect two parallel
instruction blocks that are connected in series.

LD 1 LD 2
+ -
0001 0002 1000

0003 0004

Parallel block

+ -
LD 1 LD 2 1000 Ladder diagrams can
be simplified into
series connections.

Address Instruction Data


0000 LD 0001
LD 1
0001 OR 0003
0002 LD 0002
LD 2
0003 OR 0004
0004 AND LD -
0005 OUT 1000

27
BASIC LOGIC INSTRUCTION SET

AND LOAD (AND LD)


AND LD instruction must be used if the serial block before the
parallel block.

EXAMPLE 1

+ - Address Instruction Data


0001 0002 1000
0000 LD 0001
0001 LD 0002
0003
0002 OR 0003
0003 AND LD -
0004 OUT 1000
Connect two block
using AND LD

A parallel block in front of a serial block can be connected using


AND connection.

EXAMPLE 2

+ - Address Instruction Data


0001 0002 0004 1000
0000 LD 0001
0001 LD 0002
0003
0002 OR 0003
0003 AND LD -
0004 AND 0004
Connect two Next, connect
block using using AND 0005 OUT 1000
AND LD instruction only

28
BASIC LOGIC INSTRUCTION SET

OR LOAD (OR LD)


The OR LD instruction is used to connect two series instruction
blocks that are connected in parallel.

+ -
LD 1
0001 0002 1000

series
0003 0004 block

LD 2

+ -
LD1 1000
Ladder diagrams can
LD2 be simplified into
series connections.

Address Instruction Data


0000 LD 0001
LD 1
0001 AND 0003
0002 LD 0002
LD 2
0003 AND 0004
0004 OR LD -
0005 OUT 1000

29
BASIC LOGIC INSTRUCTION SET

OR LOAD (OR LD)


OR LD instruction is used if a single contact is connected to a
serial block in parallel

EXAMPLE
+ - Address Instruction Data
0001 0002 1000
0000 LD 0001
0001 LD 0003
0003 0004 Connect two
block using 0002 AND 0004
OR LD 0003 OR LD -
0004 AND 0002
0005 OUT 1000

COMBINATION AND LD & OR LD


The example programming using AND LD and OR LD instruction

Connect two block


using AND LD
Address Instruction Data
0000 LD 0001
+ -
0001 0002 1000 0001 OR 0003
0002 LD 0002
0003 0004 0005 0003 LD 0004
0004 AND 0005
0005 OR LD -
Connect using Connect two 0006 AND LD -
OR instruction block using
only OR LD 0007 OUT 1000

30
BASIC LOGIC INSTRUCTION SET

TEMPORARY RELAYS (TR)


Temporary Relays (TR) are used for temporary storage of a
program instructions. The program instruction found in a ladder
diagram that has a special branch point as shown in Figure 2.1.
The TR instruction are used for mnemonics code only.

TR instructions contain 8 bits of data and have addresses ranging


from TR0 to TR07. TR can be used as many times as required and
the number address must be the same at the same branch point.

Use AND
+ OUT instruction -
0001 0002 1000
TR0

0003 0004 0005 1001

LD
TR0 Branch Point

Figure 2.1 – Special branch point for the use of TR

▪ TR instruction can only be used with the OUT and LD


instructions.
▪ The OUT TR instruction should be used at the first branch
point.
▪ The LD TR instruction is used after the second row of the
branch point.
▪ The first instruction after OUT TR or LD TR instruction must
be connected with the AND instruction.

31
BASIC LOGIC INSTRUCTION SET

This is a simple example of using the TR instruction:

EXAMPLE 1 When a branch point with a separate input is


connected to an output.
OUT Address Instruction Data
+ TR0 - 0000 LD 0001
0001 0002 1000
0001 OUT TR0
0002 AND 0002
0003 1001 0003 OUT 1000
LD
0004 LD TR0
TR0
0005 AND 0003
0006 OUT 1001

EXAMPLE 2 When a branch point without a separate input


is connected to an output.
OUT
+ TR0 - Address Instruction Data
0001 0002 1000 0000 LD 0001
0001 OUT TR0
0002 AND 0002
1001
LD 0003 OUT 1000
TR0 0004 LD TR0
0006 OUT 1001

EXAMPLE 3
TR instruction is not required when there are no contact input
after the branch point in the first row of the instruction block.

+ -
0001 1000
ADDRESS INSTRUCTION DATA
0000 LD 0001
0002 1001 0001 OUT 1000
TR is not 0002 AND 0002
required
0003 OUT 1001

32
BASIC LOGIC INSTRUCTION SET

DESIGN OF CONTROL SYSTEMS


USING PLC

STEP 1:
Determine the machine
sequence of operation
By drawing flowchart to
show the sequence of STEP 2:
operation Assignment of
inputs and outputs
Identify the input and
STEP 3:
output device in the
Writing of the program system
Write the ladder diagram
program by following the
control system sequence of
operation as determined by STEP 4:
step one. Programming into
PLC memory
Through console or
STEP 5: computer by using CX
Running the system programmer software
Test run the system thoroughly
until it is safe to operate by
anyone.

33
BASIC LOGIC INSTRUCTION SET

EXAMPLE OF CONTROL SYSTEMS


DESIGN USING PLC

Design the following sequences:


A DC motor should operate continuously when the Start button,
S1, is pressed and only turn off when the Stop button, S2, is
pressed.

STEP 1: Determine the STEP 2: Assignment of


process sequence inputs and outputs

The activity The sequence Input Devices Description

S1 ; ON DC Motor, M1 ; 0001 S1
ON 0002 S2
S2 ; ON DC Motor, M1 ;
OFF Output Devices Description

Can also use the flow chart as 1001 M1


a reference

STEP 3: Writing of the STEP 4 : Write Mnemonic


program Code if Programming into PLC
by using Console
+ -
0001 0002 1001
Address Instruction Data
1001
0000 LD 0001
0001 OR 1001
0002 AND NOT 0002
0003 OUT 1001
END
0004 FUN (01)

Ladder Diagram can be programmed by


using CX programmer software (OMRON)
34
BASIC LOGIC INSTRUCTION SET

REFLECTION QUESTION
1. Explain the difference between the instruction AND and AND NOT
instruction with the aid of a ladder diagram.

2. List the steps to design control system using PLC Programming.

3. Explain the function of AND LD and OR LD.

4. Explain the operation of the ladder diagram below.

+ -
0001 0002 1001

0003

0004 0002 1002

5. Convert the ladder diagram below to mnemonic code.


+ -
0001 0002 0005 1001

0003 0004

0006 1002

END

6. Explain temporary relays (TR) and give one example of using the
instruction?

35
3.0 TIMER & COUNTER
INSTRUCTION SET

Understand TIMER & COUNTER


Instruction Set

1. Timer Instruction Set


2. Counter Instruction Set

36
TIMER INSTRUCTION SET

TIMER INSTUCTION SET


A timer (TIM) is an internal PLC instruction used to delay time for
input and output signals. The instructions that require numbers
TIM (N) and the set value (SV) as shown in Figure 3.1.

TIM
N N: Timer Number
Input Condition
SV SV: Set Value

Figure 3.1 – Timer Instruction Set

The range of numbers (N) for TIM is from 000 to 255, while the
setting range of set values (SV) for the TIM is the BCD between
#0000 to #9999.

TIM operates a timer with 1 pulse scan time is 0.1s. For example,
if timer be set to 5 seconds, then the set value (SV) is #0050.

0000
TIM TIM 000 is used

This contact turns 000 Set value is #100


on TIM000 #100 0.1s → 1 pulse
10s → 100 pulse
This value will
decrease until zero

Timer is activated when the input condition is turns ON, and


it will be reset to the set value (SV) when the input condition
is OFF.

37
TIMER INSTRUCTION SET

APPLICATION OF TIMER PROGRAM (ON DELAY)

Example
Lamp 1 will turn ON after 5 second when switch 1 is turned ON.
Draw a ladder diagram and mnemonic code.

+ Switch 1 -
0001 TIM Address Instruction Data
000
#050 0000 LD 0001
0001 TIM 000
Lamp 1
TIM 000 1000 #050
0002 LD TIM000
0003 OUT 1000

After 5 seconds contact TIM000 will


change to NC and the lamp will turn ON.

Example 2
When switch 1 is turned ON, the TIM000 timer is triggered after
10 seconds. Then, lamp 1 will be turned ON and lamp 2 will be
turned OFF. Draw a ladder diagram and timing diagram.

+ Switch 1 -
0001 TIM
000 0001
#100
sec
Lamp 1 T000
TIM 000 1000 10s
1000
Lamp 2
TIM 000 1001
1001

After 10 seconds contact TIM000 will


change to NO and lamp 2 will turn OFF.

38
TIMER INSTRUCTION SET

APPLICATION OF TIMER PROGRAM (OFF DELAY)

The OFF delay timer circuit can be implemented using ON delay


timer circuit.

Example
When switch is turned ON, the lamp will turn ON. As long as
switch is ON, the timer will not be active. When switch is turned
OFF, the timer will start to trigger. After 5 seconds, the lamp will
turn OFF.

+ Switch Lamp - Address Instruction Data


0001 TIM000 1001
0000 LD 0001
0001 OR 1001
1001
0002 AND NOT TIM000
Switch 0003 OUT 1001
1001 0001 TIM 0004 LD 1001
000 0005 AND NOT 0001
#050 0006 TIM 000
END #050
0007 FUN (01)

0001 The timer will start to


sec
trigger if the switch is
turned OFF.
T000
5s
The lamp will only turn
1000 OFF after a delay of time.

ON delay timer is a timer that is triggered when the input switch


is turned ON. While OFF delay timer is a timer that is triggered
when the input switch is turned OFF. There is a delay before the
output is turned ON or OFF.

39
TIMER INSTRUCTION SET

LIGHT FLICKER CIRCUIT USING TIMER PROGRAM


A light flicker circuit is a circuit that causes the lights to turn ON
and OFF alternately. In this program, two timers are required.
One is used to determine the ON time, while the other one is for
the OFF time.
Address Instruction Data
+ Switch Lamp -
0001 TIM000 1001 0000 LD 0001
0001 OUT TR0
0002 AND NOT TIM000
reset timer 0003 OUT 1001
TIM001 TIM 0004 LD TR0
000 0005 AND NOT TIM001
#200
0006 TIM 000
TIM000 TIM #200
001 0007 LD TIM000
#100 0008 TIM 001
#100
END
0009 FUN (01)

Timing diagram illustrates a system's input/output status.


SW
When 0001 turns OFF the circuit
SWITCH
0001 will stop flickering the lamp.
OFF OFF

TIM000 begin to count for 20s


TIM000 after 0001 turns ON (Lamp ON).
20s TIM001 begin to count for 10s
TIM001 after T000 is activated (Lamp
turns OFF) .
NC 30s
To allow the lamp to turn ON
TIM000
and turns OFF after 20s.
NO To allow the T001 to start
TIM000
counting the time after 20s.
NC To reset both timers after 30s
TIM001
and repeat itself.
LAMP
1001 Lamp to turn ON for 20s and
turns OFF for 10s alternately.

40
COUNTER INSTRUCTION SET

COUNTER INSTUCTION SET


A counter (CNT) is an internal PLC instruction used to count
pulses. The instructions that require numbers CNT (N) and the set
value (SV). The counter have two input condition with a clock
pulse (CP) and reset input (R) as shown in Figure 3.2.

CP
CNT
Input N: Timer Number
R
N
Condition
SV SV: Set Value

Figure 3.2 – Counter Instruction Set

The range of numbers (N) for CNT is from 000 to 255, while the
setting range of set values (SV) for the CNT is the BCD between
#0000 to #9999. Counter and timer cannot use the same range
of numbers (N) in a program.
0000
CP need to
switch from CNT CNT 000 is used
OFF to ON 000
0001 Set a value to count
#010 This value will
To reset SV
of counter decrease by 1.

Each time input CP (0000) is switched from OFF to ON, the


counter's set value decreases by one. Once it reaches zero, the
counter will operate. The counter will reset if input R (0001) is
ON. The counter can not count the transition condition at CP
when R is ON. The counter can start to count the input at CP after
R is turned OFF.

41
COUNTER INSTRUCTION SET

APPLICATION OF COUNTER PROGRAM


Example 1
Lamp 1 will turn OFF after Switch 1 is turned ON by 5 times.
Switch 2 will reset the counter and lamp will turn ON again. Draw
a ladder diagram and mnemonic code.
+ Switch 1 -
0001 Address Instruction Data
CNT 0000 LD 0001
Switch 2 000
0002 0001 LD 0002
#005
0003 CNT 000
Lamp 1 #005
CNT000 1001 0004 LD NOT CNT000
0005 OUT 1001

Contact CNT000 will change to NO and the lamp 1 will


turn OFF after the counter has been counted 5 times.

Example 2
Draw a timing diagram and ladder diagram that will activate a
pilot lamp after a sensor detects the presence of 3 products. The
pilot lamp will deactivate after switch reset is pressed.

+ Sensor - Sensor
0001 0001
CNT
Switch 000
0002 CNT000
#003
Lamp
Pilot lamp 1001
CNT000 1001
Reset
0002

Contact CNT000 will change to NC and


the pilot lamp will turn ON after the Timing Diagram
counter has been counted 3 times.

42
COUNTER INSTRUCTION SET

SIMPLE APPLICATION USING TIMER AND COUNTER

Example
When push button 1 (PB1) is pressed for 4 times, the Lamp 1 will
be ON. When Lamp 1 is ON, TIM001 will be activated and, after 5
seconds, Lamp 2 will be ON. Push Button 2 (PB2) is used to reset
the counter. Draw a ladder diagram and timing diagram for the
system.
+ PB1 -
0001
CNT
PB2 000
0002
#004

CNT000 1001
Lamp 1

CNT000 TIM
001
#050
TIM001 1002
Lamp 2

END

PB1
0001 After PB1 has been activated four
sec times, CNT000 will be triggered,
Lamp 1 and Lamp 1 will be turn ON.
1001

At the same time, TIM001 begins


TIM001 to count for 5 seconds, and after
5s TIM001 is activated, Lamp 2 turns
Lamp 2 ON.
1002

PB2 Lamp 1 and lamp 2 will remain ON


0002 until PB2 is pressed.

43
TIMER & COUNTER INSTRUCTION SET

REFLECTION QUESTION
1. State the range of numbers that can be used to identify a
timer (TIM) and counter (CNT).

2. Draw a ladder diagram that a pilot lamp will turn ON after 10


seconds when switch 1 is turned ON.

3. What is the difference between a ON delay and a OFF delay


timer circuit?

4. Explain the counter instruction set in PLC programming using


appropriate diagrams.

5. Draw a ladder diagram that will turn ON a motor after a


toggle switch is closed. The motor should stop automatically
after two minutes, while the toggle switch is still closed.

6. Determine the SV values of timer and counter to have a delay


time of 6 hours.

7. A pilot lamp will turn ON after sensor detects a presence of


12 objects. The system can be reset after push button is
pressed or after a time delay of one minutes. Draw a ladder
diagram and write out the mnemonic code for this operation.

44
4.0 SPECIAL
INSTRUCTION SET

Understand Special PLC Instruction Set

1. HOLDING CIRCUIT
2. SET/RESET
3. KEEP
4. DIFU / DIFD
5. INTERLOCK / INTERLOCK CLEAR
6. JUMP / JUMP END

45
SPECIAL INSTRUCTION SET

To understand the special instructions of the PLC program, firstly


we must know about the internal relay (IR).

INTERNAL RELAY (IR)


Internal Relay (IR) is one bit memory device. If the program is
used with IR, this bit stores the data and maintains an ON or OFF
status regardless of whether the input set is ON or OFF.

IR is an imaginary programmed relay that has coils and contacts


but is not connected to a real output (relay). So, internal relay
cannot have addresses that start with the data ‘10’.

For the OMRON PLC CPM2A, the bit data for IR addresses are:

20000 to 23115 (928 bits)

IR can be used in other special instruction sets such as KEEP, SET


and RSET, DIFU, DIFD. These instructions are used to control ON
and OFF state output bits in the IR. Figure 4.1 shows the ladder
diagram using holding circuit with internal relay (IR).
set reset
+ 0000 0001 200.00 -
coil
IR 200 is used in
200.00 the holding circuit

contact

Figure 4.1 – Internal Relay (IR)

All PLCs have IR, however the internal numbering scheme work
bit for them depends on the PLC model.

46
SPECIAL INSTRUCTION SET

HOLDING CIRCUIT (LATCH)


Holding Circuit is used as a latch. It is used to keep the status of
the specified bit based on two input conditions. These two input
conditions are indicated by the symbols S and R as shown in
Figure 4.2. S is the set input and R is the reset input.

+ Set Reset Bit -


coil Operand Bit can use
Bit from output bit or
internal relay (IR)
contact

Figure 4.2 – Holding Circuit

APPLICATION OF HOLDING CIRCUIT


PB1 PB2 IR
+ 0000 0001 - 0000
200.00
1
200.00
200.00
LAMP 1000
200.00 1000
2 0001

When push button 1 (0000) is momentarily pressed (ON then


OFF), output IR 200 is energized. Because of IR 200 output is
held by a latching, it will remain ON even if 0000 is turned OFF.
This condition will also cause the output Lamp (1000) to remain
turned ON.

When push button 2 (0001) is pressed, the internal relay of the


IR 200 is deenergized and the IR 200 is turned OFF. As a result,
the lamp (1000) will also be turned OFF.
47
SPECIAL INSTRUCTION SET

EXAMPLE 1
When the start button is pressed and released, a motor will rotate,
and the conveyor will move to bring out the product. The sensor
will count 12 products and inserting it into the box as shown in
Figure 4.3. Then, the motor will be stopped the process.

+ -
Start Motor
0000 CNT000 1000

1000

Sensor
1000 0001
Figure 4.3 CNT
CNT000 000
#012

END

EXAMPLE 2
Design PLC ladder diagram by using Holding Circuit to implement
the timing diagram shown in Figure 4.4:
+ Start Stop IR
-
0000 0001 200

200

200 TIM
000
#150
TIM000 1000
Lamp 1
Figure 4.4 1001
Lamp 2

END

48
SPECIAL INSTRUCTION SET

EXAMPLE 3
Design PLC ladder diagram by using Holding Circuit to implement
the timing diagram as shown in Figure 4.5:

Figure 4.5
+ Start IR
-
0000 TIM002 200.00
Address Instruction Data
0000 LD 0000
200.00 0001 OR 200.00
0002 AND NOT TIM002
200.00 TIM 0003 OUT 200.00
000 0004 LD 200.00
#100 0005 TIM 000
TIM000 1000 #100
Lamp 0006 AND NOT TIM000
Sensor
0002 0007 OUT 1000
TIM000
0008 LD 0002
CNT 0009 AND TIM000
TIM002 001 0010 LD TIM002
#002
0011 CNT 001
CNT001 #002
TIM
0012 LD CNT001
002
#200 0013 TIM 002
#200
1001
0014 OUT 1001
Motor
0015 FUN(01)
END

49
SPECIAL INSTRUCTION SET

SET/RESET
SET and RESET are optional instructions that can be used to keep
the output. The SET instruction will turn ON the operand bit (B)
when the input condition is ON, and it stays ON even when the
input condition is OFF. RSET will turn OFF the operand bit when
the input condition is ON. Figure 4.6 shows the Set and Reset
instruction using ladder diagram program.
+ -
Set Bit operand (B) may
SET
consist of data output
B
or internal relay (IR)
Reset RSET Set and Reset must
B used a same data
Input Condition

Figure 4.6 – SET and RESET instruction

APPLICATION OF SET/RESET
When PB1 (0001) is momentarily pressed, SET IR 200.00 is
energized and it will remain ON even if PB1 is turned OFF. This
condition keeps the output Lamp 1 (1001) is turned ON. When
PB2 (0002) is pressed, the RSET IR 200.00 is turned OFF. As a
result, the lamp (1001) will also be turned OFF.
+ PB1 -
0001
SET 0001
200.00
PB2
200.00
0002 RSET
200.00
1001
Lamp 1
200.00 1001
0002

50
SPECIAL INSTRUCTION SET

Example 1
By using the SET/RESET instruction, create a ladder diagram that will
light up a pilot lamp after 5 second the push button start (PB1) is
pressed. Then, after pushing a push button stop (PB2), the lights will
be turned off.
+ PB_1 -
0001
SET
200.00
PB_1
0002
RSET
200.00
200.00 TIM
000
#50
TIM000 1001
Pilot Lamp

END

Example 2
Design PLC ladder diagram by using SET and RESET instruction to
implement the timing diagram as shown in Figure 4.7:
+ PB_1 -
0001
SET
200.00
TIM000
RSET
200.00

200.00 TIM
000
#80
Figure 4.7
200.00 1001
Lamp 1

1002
Lamp 2
END

51
SPECIAL INSTRUCTION SET

KEEP
The KEEP instruction is another optional instruction that can also
be used to maintain the output. KEEP instruction is used to keep
a status bit operation based on two input conditions.
These two input conditions are indicated by set (S) and reset (R)
as shown in Figure 4.8. Bit operand (B) may consist of data output
or internal relay (IR).

Set

Input KEEP
Condition Reset
B B : Data Output / IR

Figure 4.8 – KEEP instruction

When S is in the ON state, the operation of the KEEP instruction


will be ON and remain ON until reset, regardless of whether Set
is ON or OFF. When Reset is in the ON state, the operation of
KEEP instruction is OFF.

APPLICATION OF KEEP INSTRUCTION


KEEP functions in almost the same way as a holding circuit and
the SET/RSET instruction.
+ PB1 -
0001 0001

PB2 KEEP 200.00


0002 200.00
1001
Lamp 1
200.00 1001
0002

52
SPECIAL INSTRUCTION SET

Example 1
Design a ladder diagram by using the KEEP instruction. The DC
motor will run automatically after 10 second the push button start
(PB1) is pressed. Then, after pushing a push button stop (PB2), the
DC motor will stop.
+ PB_1 -
0001

PB_1 KEEP
0002 200.00

200.00 TIM
000
#100
TIM000 1001
DC Motor

END

Example 2
Design PLC ladder diagram by using KEEP instruction to implement
the timing diagram as shown in Figure 4.9:
+ PB_1 -
0001

KEEP
TIM000 200.00

200.00 TIM
000
#100
Figure 4.9 200.00 1001
Lamp 1

1002
Lamp 2

END

53
SPECIAL INSTRUCTION SET

EXAMPLE PROGRAM : HOLDING CIRCUIT AND KEEP


Refer to the figure 4.10, it shows the system connection to control
the traffic light. When start push button (PB1) is pressed, red light
will turn ON for 5 seconds. After that, green light will turn ON for 10
seconds and red light will turn OFF. The operation will repeat
simultaneously until stop push button (PB2) is pressed to stop the
operation. Construct this sequence using PLC ladder diagram.

PB1 PB2
The ladder diagram below
5 sec
shows two types of
10 sec programming design that
can be used in this
situation.
Figure 4.10
+ -
+ Start Stop IR
- Start
0000 0001 200.00 0000
or
KEEP
200.00 0001 200.00

200.00 TIM001 Red


TIM 200.00 TIM000 1000
000
#50
TIM000 200.00 TIM001 TIM
TIM
000
001
#050
#100
Green
Red
200.00 TIM000 1000 TIM000 TIM001 1000

Green TIM000
TIM000 1001 TIM
001
#100
END END

54
SPECIAL INSTRUCTION SET

EXAMPLE PROGRAM : KEEP AND SET/RSET


In the final round of the polytechnic quiz competition, two
students from the different polytechnics will compete against each
other as shown in figure 4.11. If one of them presses the button
faster, the desk light will remain on for 10 seconds until turning off.
Those who press the button too late, their lights will not turn on.
Draw the ladder diagram by using KEEP and SET / RSET instruction.

Player 1
Player 2

Figure 4.11
KEEP instruction SET/RESET instruction
+ - + Lamp
-
PB_Player 1 Lamp PB_Player 1
0000 1001 Player 1 Player 1
0000 1001
SET
KEEP 1000
TIM000 1000 or TIM000
RSET
1000
PB_Player 2 Lamp Lamp
0001 1000 Player 2 PB_Player 2
Player 2
0001 1000
SET
KEEP
TIM000 1001
1001 TIM000
RSET
1001
1000 TIM 1000
000 TIM
#100 000
1001
1001 #100

END END

55
SPECIAL INSTRUCTION SET

DIFFERENTIATE UP (DIFU) AND


DIFFERENTIATE DOWN (DIFD)
The Differentiate UP (DIFU) and Differentiate Down (DIFD)
instruction are a special instruction that will turn ON the output
in a very short time.

DIFU instructions will turn ON the bit when the input condition
changes from OFF to ON (rising edge). When the input is turned
ON, it is used to perform operations that require only one scan
cycle. Figure 4.12 shows the ladder diagram and timing diagram
for DIFU instruction.
+ -
Input Input
DIFU
B DIFU
bit
Input Condition
B : Operand bit IR 1 scan

Figure 4.12 - DIFU instruction

DIFD instructions will turn ON the bit when the input condition
changes from ON to OFF (falling edge). When the signal is
turned OFF, it is used to perform operations that require only
one scan cycle. Figure 4.13 shows the ladder diagram and timing
diagram for DIFD instruction.
+ -
Input Input
DIFD
B DIFD
bit
Input Condition
B : Operand bit IR 1 scan

Figure 4.13 – DIFD instruction

56
SPECIAL INSTRUCTION SET

APPLICATION EXAMPLE OF DIFU & DIFD


+ -
Switch 1 SW 1
0000 0000
DIFU
200.00 DIFU
Lamp 1 200.00
200.00 1001
LAMP 1 1 scan
1001 OFF OFF
Switch 2
0001
DIFD
201.00 SW 2
0001
Lamp 2
201.00 1002 DIFD
201.00
1 scan
END LAMP 2
1002 OFF OFF

Based on the timing above, it shows the process output cannot be seen
because the lamp will be ON within a very short time and then OFF.
+ -
Switch 1 Address Instruction Data
0000
DIFU 0000 LD 0000
200.00
0001 DIFU 200.00
200.00 1001 0002 LD 200.00
Lamp 1 0003 OR 1001
0004 OUT 1001
1001
0005 LD 0001
0006 DIFD 201.00
Switch 2 0007 LD 201.00
0001
DIFD 0008 OR 1002
201.00 0009 OUT 1002
201.00 1002
Lamp 2 To solve the above problem, use
1002 the holding circuit concept to
ensure that both lamps are always
turned ON.
END

57
SPECIAL INSTRUCTION SET

APPLICATION EXAMPLE OF DIFU


When the push button is pressed and released, motor will turn
ON. Then, conveyor will move to carry out the box and stop after
a limit switch detects the next box as shown in Figure 4.14. This
process will be repeated by an operator in verify the quality of the
product in the box. Draw a ladder diagram for the system.
+ Push -
Button Motor
0001 200.00 1001

1001

Limit
Switch
0001
DIFU
200.00

END
Figure 4.14

APPLICATION EXAMPLE OF DIFD


Design PLC ladder diagram by using DIFD to implement the timing
diagram shown in Figure 4.15:
+ -
Sensor
0001
DIFD
200.00
200.00
CNT
Sw Reset 000
0002
#003
Figure 4.15 Motor
CNT000 1001

END

58
SPECIAL INSTRUCTION SET

INTERLOCK / INTERLOCK CLEAR


The interlock (IL) and interlock clear (ILC) instructions are used to
lock or skip all output conditions between IL and ILC when the
input condition for IL is turned OFF. If IL is turned ON, no lock and
skipping occur. IL and ILC must be used together as shown in
Figure 4.16.
Input
Input IL (02)
Condition

ILC (03)

Figure 4.16 – Interlock & Interlock Clear Instruction

APPLICATION OF IL AND ILC


When input 0000 is turned OFF, output 1001 that is between IL
and ILC will be skipped and will not function. Then, when input
0001 is turned ON only output 1002 it will be turned ON because
it is outside the interlock range.
Now, when input 0000 is turned ON, all outputs that are between
IL and ILC can execute normally, so output 1001 will be turned
ON when switch 0001 is turned ON. Next, when input 0000 is
turned OFF again, output 1001 will be turned OFF or reset.
+ -
0000 IL / ILC
IL 0000

0001 1001
0001

1001
ILC
1002
0001 1002
1002 is out of range of IL and
it will be controlled by 0001
59
SPECIAL INSTRUCTION SET

INTERLOCK / INTERLOCK CLEAR


IL may be used many times in a row in the programme and should
be ended by ILC. ILCs should not be used unless at least one IL is
provided. The ladder diagram and mnemonic code in Figure 4.17
represents IL being used twice with one ILC.
+ 0000 -
IL Address Instruction Data
0000 LD 0000
0001 TIM 0001 IL
000 0002 LD 0001
#050 0003 TIM 000
TIM000 1001 #050
0004 LD TIM000
0002 0005 OUT 1001
IL 0006 LD 0002
0003 1002 0007 IL
0008 LD 0003
0009 OUT 1002
0004
0010 LD 0004
CNT
0011 LD 0005
0005 001
#005 0012 CNT 001
#005
ILC 0013 ILC

Figure 4.17 – Application of IL being used twice with one ILC.

When input 0000 for 1st IL is turned ON and 0002 for 2nd IL is
turned OFF, TIM000 will be activated for 5 seconds and output
1001 will be turned ON but CNT001 will not be changed and
output 1002 will be turned OFF.
When 0000 and 0002 for both ILs are ON, the program between
the 1st IL and the ILC will execute normally.
Next, when both of ILs are turned OFF again, TIM000 will be reset
and outputs 1001 and 1002 will be turned OFF but CNT001 will
not change. CNT001 will not reset when input 0005 is turned ON.

60
SPECIAL INSTRUCTION SET

JUMP / JUMP END


The Jump (JMP) and Jump End (JME) instructions can be used to
skip all output conditions between JMP and JME when the input
condition for JMP is turned OFF. If JMP is turned ON all program
can execute normally. Although this instruction is very similar to
Interlock (IL), but the JMP instruction will retain or not changed
the status of all its outputs after JMP is turned OFF. Figure 4.18
shows the JMP and JME instruction.
Input
JMP
Input #1
Condition #Jump Number
JME can be from 0 – 99
#1 (depend type of PLC)

Figure 4.18 – Jump and Jump End Instruction

APPLICATION OF JMP AND JME


When input 0000 is turned OFF, output 1001 that is between JMP
and JME will be skipped. Then, when input 0001 is turned ON only
output 1002 it will be turned ON because it is outside the JMP
range. Now, when input 0000 is turned ON, all outputs that are
between JMP and JME can execute normally, so output 1001 will
be turned ON when switch 0001 is turned ON. Next, when input
0000 is turned OFF again, it will move to the JME instruction
without changing the status of output 1001.
+ -
0000 JMP/JME
JMP 0000
#1
0001 1001
0001

JME 1001
#1
0001 1002 1002
1002 is out of range of JMP

61
SPECIAL INSTRUCTION SET

JUMP / JUMP END


The following ladder diagram is similar to the Interlock (IL)
example, except that it uses JUMP instruction. The ladder diagram
and mnemonic code in Figure 4.19 represents JMP being used
twice with one JME.
+ 0000 -
JMP Address Instruction Data
#1
0000 LD 0000
0001 TIM 0001 JMP #1
000 0002 LD 0001
#050 0003 TIM 000
TIM000 1001 #050
0004 LD TIM000
0002 0005 OUT 1001
JMP
#1 0006 LD 0002
0003 1002 0007 JMP #1
0008 LD 0003
0009 OUT 1002
0004
0010 LD 0004
CNT
001 0011 LD 0005
0005
#005 0012 CNT 001
#005
JME
0013 JME #1
#1

Figure 4.19 – Application of JMP being used twice with one JME.

When input 0000 for 1st JMP is turned ON and 0002 for 2nd JMP is
turned OFF, TIM000 will be activated for 5 seconds and output
1001 will be turned ON but CNT001 will not be changed and
output 1002 will remain as current value.
When 0000 and 0002 for both JMP are ON, the program between
the 1st JMP and the JME will execute normally.
Next, when both of JMP are turned OFF again. All the output
relay, timer or counter remain unchanged.

62
SPECIAL INSTRUCTION SET

REFLECTION QUESTION
1. Explain the function of internal relay (IR) instruction using a
ladder diagram and mnemonic code.

2. Based on the Figure 4.20, what happen to a circuit when push


button 1 (0000) is turned ON and then, the push button 1 is
turned OFF.
Lamp
+ Push Button 1 Push Button 2
1001 -
0000 0001

1001

3. By using KEEP instruction set, draw the PLC ladder diagram


based on the timing diagram shown in Figure 4.21.

Figure 4.21

4. Explain the operation of SET and RESET by referring to Figure


4.22.
+ PB1 -
0001 SET
1000
PB2
0002 RSET
1000
Figure 4.22

63
SPECIAL INSTRUCTION SET

REFLECTION QUESTION
5. Design PLC ladder diagram by using KEEP and DIFD
instruction to implement the timing diagram as shown in
Figure 4.23.

Figure 4.23

6. Explain the difference between DIFD and DIFU instruction.

7. Both IL and JMP instruction are to skip a section of instruction


when they turn OFF. What are the differences between these
two instructions when they are executed.

64
5.0 APPLICATION
PLC PROGRAMMING

Application PLC Programming

1. Three Phase Motor Direct Control by


using PLC
2. Three Phase Motor Forward-reverse
Rotation Control By Using PLC
3. Pedestrian Crossing Traffic Light Control
System
4. A Conveyor Dispatching System
5. Part Sorting For Assembled Material

65
APPLICATION 1 : PLC PROGRAMMING

THREE PHASE MOTOR DIRECT CONTROL


BY USING PLC
3 phase motor can be controlled by PLC through a 3 phase
contactor (K1) as in figure 5.1. The contactor contacts are closed
when it is energized by applying 240V ac across its’ coil . A normally
open (N.O) push button switch is used to start the motor and a
normally close (N.C) switch is used to stop the motor.

START

To K1
STOP PLC coil

Figure 5.1 – 3 phase motor controlled using contactor


To write a control program for this process, we need to assign
input and output terminal addresses to the input and output
devices. Assuming that OMRON CPM2A is used, table 5.1 shows
the assignment of PLC terminal address to device.

Table 5.1 – Input Output assignment


Device Type PLC Terminal Address

Start Switch (N.O) Input 0000 or (0.00)

Stop Switch (N.C) Input 0001 or (0.01)


Contactor Coil K1 Output 1000 or (10.00)

Since momentarily switch is used to start the motor, a holding or


latching circuit is needed for the motor to be in the energized
state even after the push button is released. To realise it, a
internal relay bit or the output bit itself can be used to a
accomplish the purpose as is shown in the ladder diagram 1 and 2.

66
APPLICATION 1 : PLC PROGRAMMING

Holding Circuit using Internal Relay


Referring to Figure 5.2, when start switch is pushed, bit 200.00 is
activated through the start and the stop switches (stop contact is
close because a N.C type is used for stop switch). The 2 associated
contact of bit 200.00 will turn ON; one to hold the circuit in rung 1,
another to drive the output as shown in rung 2.
When the stop button is pressed, its’ contact 0001 opens to
disconnect the flow of current to 200.00. The associated contacts
of this bit thus open to release the latching action in rung 1 and
deactivate the output 1000 in rung 2.

+ Start
0000
Stop
0001
IR
200.00 -
1
Used NO contact
200.00
if using NC Switch
Contactor
200.00 1000
2

Figure 5.2 – Ladder Diagram 1

Holding Circuit using the Output Bit


Figure 5.3 shows the ladder diagram of another control by using
the output bit associated contact itself as holding circuit.
Start Stop Contactor
+ 0000 0001 1000 - Used the
output bit

1000

Figure 5.3 – Ladder Diagram 2


67
APPLICATION 2 : PLC PROGRAMMING

THREE PHASE MOTOR FORWARD-REVERSE


ROTATION CONTROL BY USING PLC
Referring to figure 5.4, to have forward rotation, the R,Y and B lines
are connected to motor terminals 1,2 and 3 respectively through
contactor K1. To reverse the rotation, R,Y and B are connected to
terminals 2, 1 and 3 respectively through contactor K2.
The control system for this process has 3 inputs and 2 output
devices as shown in figure 5.4. 3 push button switches for stop,
forward and reverse and 2 contactor coil K1 and K2.

STOP
To K1
FWD coil
PLC

REV To K2
coil

Figure 5.4 – Three Phase Motor Forward-reverse Rotation Control

Table 5.2 shows the assignment of PLC terminals addresses to


input and output devices.
Table 5.2 – Input Output assignment
Device Type PLC Terminal Address

Stop Switch (N.C) Input 0001

Forward (N.O) Input 0002

Reverse (N.O) Input 0003


Contactor Coil K1 Output 1000

Contactor Coil K2 Output 1001

68
APPLICATION 2 : PLC PROGRAMMING

Explanation based on the ladder diagram control


program for the system.

Referring to the ladder diagram in Figure 5.5,


• Initially no contactor coil is energized, motor is in stop mode. When
the forward button is pushed, K1 coil is energized through the stop
switch (N.C), the FWD switch and the K2 associated normally close
contact to run the motor in forward direction. Once K1 is energized,
its associated contact in FWD rung will hold the circuit after FWD
button is released.
• The associated contact of K1 in the REV rung is open because K1 is
active is to prevent the energization of K2 coil if the REV button is
accidentally pushed.
• The change the direction of motor rotation we need to stop the
motor first, before we push the respective button.
• The operation of rotate the motor in reverse direction is similar to
the forward action accept that the REV button is pushed, and K2 coil
is energized instead of K1.

+ Stop Forward K1 Coil -


0001 0002 1001 1000

1000

Reverse K2 Coil
0003 1000 1001

1001

END

Figure 5.5 – Ladder Diagram

69
APPLICATION 3 : PLC PROGRAMMING

PEDESTRIAN CROSSING TRAFFIC LIGHT CONTROL


SYSTEM
Figure 5.6 shows a pedestrian crossing system which operates as
followed:
• When PLC is set to run mode, the Green light for car traffic and the
Red light for pedestrian crossing are turned ON. It remains ON until
the pedestrian crossing button is pressed and released.
• After a delay of 15 seconds, the Yellow light for car traffic turns ON
and the Green light turns OFF. The pedestrian light remains Red.
• After another 5 seconds, car traffic light turns Red light. At the
same time the pedestrian Green light turns ON for 5 second and
flickers 5 times (ON for 1 second and OFF for another 2 second )
and then Red light for car traffic remains ON.
• This condition remains for 2 seconds and then car traffic light turns
Green light, and the pedestrian light remains Red light. The process
will repeat when the button is pressed again.
• The button will only effective when the car traffic light is Green.
The summarized of the process operation as shown in Table 5.3.

Push
Button

Figure 5.6 - Pedestrian Crossing System


70
APPLICATION 3 : PLC PROGRAMMING

Table 5.3 - Summarized the process operation


Pedestrian Traffic
Car Traffic Light
Light Time Delay
State
(Sec)
Green Yellow Red Green Red

Initial State ON OFF OFF OFF ON


Button
ON OFF OFF OFF ON 15
Pressed
After 15s OFF ON OFF OFF ON 5

After 5s OFF OFF ON ON OFF 5


5 times (off
After 5s OFF OFF ON FLICKER OFF
2s on 1s)
After
OFF OFF ON OFF ON 2
Flicker
Wait for
After 2s ON OFF OFF OFF ON button
press

Table 5.4 shows the input and output devices for the system
and the assignment of PLC terminals to the devices.

Table 5.4 – Input Output assignment


PLC Input Output PLC Output
Input Device
Terminal Devices Terminal
Push Button NO 0000 Red Car 1000
Yellow Car 1001
Green Car 1002
Red
1003
Pedestrian
Green
1004
Pedestrian

71
APPLICATION 3 : PLC PROGRAMMING

Figure 5.7 and Figure 5.8 shows the ladder diagram control program
for the system.
In the initial condition, the Green light for the car traffic light is
turned ON by TIM000 contact (NC contact) at rung 5 and the Red
light for the pedestrian is turned ON by TM001 contact (NC contact)
at rung 6.

+ PB IR - At rung 0, once the


0000 TIM006 200.00
Pedestrian push button is
0
200.00 pressed, TIM000 at rung 1
starts to operate. After 15
200.00 TIM seconds, its associated
1 Green 000
Car #150
contact TIM000 opens to
TIM000 turns OFF car Green traffic
TIM
Yellow
001
light at rung 5 and turn ON
Car
#050 the Yellow light at rung 7.
TIM001
TIM
Red
Car
002 In the same time, it also
#050
Red_Car Flicker activates TIM001 at rung 1. 5
TIM002 CNT005 TIM004 seconds after TIM001
TIM
2 003 activation, its’ associated
#020
contact TIM001 turns OFF the
TIM pedestrian Red light at rung 6
004
#030
and the Yellow car traffic
TIM004
light at rung 7, turns ON the
Flicker
3 CNT car traffic Red light at rung 8
PB
0000 005 and the pedestrian green
#05
light at rung 9.

Figure 5.7 – Ladder Diagram Continue to page 73


(rung 0 – rung 3)

72
APPLICATION 3 : PLC PROGRAMMING

TIM001 also activated TIM002 at rung 1. TIM002 provides a time delay


for 5 seconds before it activates the flicker circuit implemented by
TIM003 and TIM004 at rung 2. The number of flickering is counted by
CNT005 at rung 3.
At each flicker, the associated
+ - contact TIM003 will turn OFF
CNT005
TIM for 2 seconds and turn ON for
4 006 1 second. Thus making the
#020
Green_Car
pedestrian Green light to flicker
Green_Car
TIM000 1002 at rung 9.
5
Yellow_Car Red_Ped After 5 flickers, the associated
TIM001 1003
6 contact of CNT005 is activated,
CNT005
cutting off the flickering circuit at
rung 2, resetting TIM003 and
Green_Car Yellow_Car Yellow_Car TIM004 and causing the
TIM000 TIM001 1001
pedestrian Green light to turn
7
Red_Car
OFF at rung 9. At the same
Yellow_Car
TIM001 1000 instant, CNT005 contact also
8 turns ON the pedestrian Red light
Yellow_Car Red_Car Green_Ped at rung 6 as well as activates
TIM001 TIM002 1004
9 TIM006.
TIM003
Since the associated contact of
TIM006 is used to reset the
END
process as shown in rung 0. After
2 seconds, the system is returned
Figure 5.8 – Ladder Diagram to its initial condition whereby
(rung 4 – rung 9) the car Green traffic light and the
pedestrian Red light are turned
ON, waiting for the pedestrian to
press the button again.

73
APPLICATION 4 : PLC PROGRAMMING

A CONVEYOR DISPATCHING SYSTEM


Figure 5.9 show a simple conveyor dispatching system of boxes.
The system works as follow:
1. Press and release the ‘start’ Button (01) , motor (01) will rotate,
and conveyor will move to carry the box towards the sensor.
When the box on conveyor is detected by sensor (00) and
motor stops immediately.
2. Once the Box has been taken away from the conveyor, motor
will start to move after a delay of 5 seconds. Then process 1
and 2 are repeated.
3. When the tenth (10) Box is taken away from the conveyor,
motor stops, and lamp (02) turns ON for 1 minutes and then
turns OFF again.
4. If ‘stop’ button (02) is pressed , both motor and lamp will turn
OFF immediately .

Figure 5.9 - Simple Conveyor Dispatching System Of Boxes

74
APPLICATION 4 : PLC PROGRAMMING

Assuming that OMRON CPM2A is used, table 5.5 shows the


assignment of PLC terminal address to devices.

Table 5.5 – Input Output assignment


PLC input Output PLC output
Input device
terminal devices terminal
1 Start Button N/O 0001 Motor 1001
2 Stop Button N/C 0002 Lamp 1002
3 Sensor 0000

The solution for the control process is shown as ladder diagram


in Figure 5.10.

• Since a momentarily switch is used to start the process, we


need a latching circuit to hold on the start process when the
push button of the start switch is released.
• In this case a temporary bit (200.00) is used to fulfill this
purpose as shown in rung 0.
• The closure of the associated contact of bit 200.00 causes the
conveyor motor which is driving by PLC output 10.01 to start
running as shown in rung 1.
• A holding circuit for the sensor is also needed to prevent the
conveyor from moving once the sensor is not detecting the
box when it is taken away from the conveyor. IR 200.01 is
used for this purpose as in rung 2.
• The associated contact of IR 200.01 bit is used to stop the
conveyor during this time as shown in rung 1.

75
APPLICATION 4 : PLC PROGRAMMING

• Since the sensor input is latched, we need a way to find out


when does the box is removed from the conveyor. A DIFD is
used to generate a 1 cycle pulse when the sensor contact
transit from high to low while the box is removed. This is
shown in rung 3.
• The generated pulse causes bit 200.02 associated contact to
close and open in a cycle time. This momentarily close is
latched by bit 200.03 to energized TIM000 as in rung 4.
• A time delay of 5 seconds is implemented by TIM000, and its’
associated contact (TIM000) is used to reset itself in rung 4 and
to cut off the latching of sensor in rung 2.

+ start stop IR - + -
0001 0002 CNT001 200.00 200.02
0 5
CNT
200.00 001
TIM002
motor #010
200.00 200.01 1001
stop
1 0002
sensor latch sensor
0000 TIM000 200.01 lamp
2 CNT001 1002
200.01
6

TIM
sensor 002
0000
DIFD #600
3
200.02
END
latch DIFD
200.02 TIM000 200.03
4
200.03 Figure 5.10 – Ladder Diagram
TIM
000
#050

76
APPLICATION 4 : PLC PROGRAMMING

• The unlatching of sensor contact bit 200.01 in turn causes its


associated contact in rung 1 to close back and moving the
conveyor once again.
• The pulses generated by bit 200.02 when a box is removed
from the conveyor is used as input to CNT001 as in rung 5. The
counter value is set at a value of 10 for its associated contact
CNT001 to operate once the tenth box is removed from the
conveyor.
• This contact will set output bit 1002 to turn ON the lamp and at
the same time energized TIM002 as shown in rung 6. The same
associated contact is also used to reset bit 200.00 in rung 0 and
in turn reset output bit 1001 in rung 1 to stop the conveyor.
• After a time, delay of 1 minute, TIM002 associated contact
TIM002 is used to reset the counter so that contact CNT001
becomes open to turn off the lamp and TIM002 as well.
• The stop contact 0002 is used to stop the process at any time
when the stop button is pressed. At the same time, it is also
used to reset the counter.

You also can watch this


video to understand
how to write the
programming for this
application.

https://youtu.be/G4l
-frzBzCU

Just click this link or scan the QR code.

77
APPLICATION 5 : PLC PROGRAMMING

PART SORTING FOR ASSEMBLED MATERIAL


Figure 5.11 and figure 5.12 shows a system that can be used to sort
out assembled part from unassembled metal or plastic part.

Figure 5.11 - System Top View

Figure 5.12 - Parts

• When start switch is pressed and released, the conveyor belt


(motor) will move.
• A part is placed on the belt so that it will go through the sensors
along the way from left to right.
• At the end of the journey, it will either ejected by the plunger
into the Bad tray if the part is not assembled or otherwise it will
go into the good tray.

78
APPLICATION 5 : PLC PROGRAMMING

The input devices (sensors)


Capacitive sensor : Capacitive sensor can be used to detect nonmetallic
or metallic part. As long as there is part about a few mm in front of the
sensor head, the sensor will turn ON. Since it is mounted a few cm above
the belt, it can be used to sense the assembled plastic part.
Inductive sensor : Can only sense the metal piece. It will turn on when
there is a metal piece a few mm in front of it.
Through beam sensor : It will turn on when there is object blocking the
light beam.
Proximity sensor : It will turn on when there is object in front of it.

The output devices

Motor : This motor is used to drive the conveyor belt in order to carry
component from the left side to the right side of the conveyor system.
Plunger : The plunger is activated by the solenoid. Once the solenoid is
energized, it will extend to eject what ever object in front of it.

Table 5.6 shows the assignment of PLC terminal addresses to input


and output devices of the system.
Table 5.6 – Input Output assignment

PLC Output PLC Input


Input Devices Output Device
Terminal Terminal
Start Switch 0000 Motor (DC 24V) 1004
Stop (N.O) 0001 Plunger (Solenoid) 1003
Inductive Sensor (NPN) 0002
Capacitive Sensor
(NPN)
0003
Through Beam sensor
(NPN)
0004
Proximity Sensor (NPN) 0005
79
APPLICATION 5 : PLC PROGRAMMING

Explanation based on the ladder diagram control program


for the system.

• 3 sensors are used to detect the part move along the belt. If
the part is not assembled, one or two of the sensor will not be
activated.

• The capacitive sensor will detect the plastic assembled on top


of the metal piece.

• The inductive sensor will detect the lower part of a metal


piece. The through beam sensor will detect any part that
interrupt its’ light beam. If the part is not assembled, only the
capacitive sensor would not be activated.

• If it is a plastic part, only through beam sensor will be activated


and if it is metal part, both inductive and through beam
sensors will be activated.

The summarized of the detection outcomes as shown in Table 5.7.

Table 5.7 - Summarized the detection outcomes.


Inductive Capacitive Through beam
Condition Conclusion
(200.01) (200.02) (200.03)
Assembled
1 ON ON ON
part
2 plastic
2 OFF ON ON
stack up
3 OFF OFF ON Plastic part

4 ON OFF ON Metal part

80
APPLICATION 5 : PLC PROGRAMMING

The function KEEP used in ladder diagram is to start and stop the
system process. When the start button is pressed the system is
latched until the stop button is pressed.

+ -
Start
0000 The condition of the sensor is
0 used to latch a temporary bit
Stop KEEP
0001 200.00 as shown in rung 1. Inductive
sensor will latch bit 200.01 if it
Motor_Cvr
200.00 1004 sensed a metal piece.
1 Capacitive sensor will latch bit
Latch Inductive
Inductive Proximity
Sensor Sensor Sensor 200.02 if it sensed a assembled
0002 0005 200.01
plastic and through beam
sensor will latch 200.03 if there
200.01
is an interruption on its’ light
Capacitive Proximity
Sensor Sensor
Latch Capacitive
Sensor
beam path.
0003 0005 200.02

200.02
Rung 3 shows how the plunger
work. If a part is detected by
Through Proximity
Beam Sensor Sensor
Latch Through
Beam proximity sensor at the end of
0004 0005 200.03
the conveyor (contact 0005
will close), the activation of
200.03
Plunger
the plunger will depend on the
200.01 200.02 200.03 200.04 condition at rung 2. All
2 conditions will activate the
plunger to eject the part into
0005 200.04 1003 the bad tray except condition 1
3
(refer table 5.7), the
END
assembled part will go into
good tray.

Figure 5.13 – Ladder Diagram

81
APPLICATION: PLC PROGRAMMING

REFLECTION QUESTION
Figure 5.14 shows a filling and draining system. Based on the sequence
operation below, design PLC ladder diagram by using KEEP and DIFD
instruction.

Figure 5.14
i. If the start button (PB1) is pressed, motor valve 1 (MV1) is opens
and the water begins to fill the tank. At the same time, the
stirring motor (M) starts operation.
ii. When the water level passed to sensor LS2 and reaches sensor
LS1, MV1 closes and the stirring motor stop. Next, motor valve 2
(MV2) is opens and starts draining the water.
iii. When the water level drops below LS2, MV2 closes. After the
cycle of operation has repeated four times, the indicator lamp is
illuminated, and the buzzer operates for 5 seconds. The operation
can be restarted after the stop button (PB2) is pressed.

82
REFERENCE

[1] Petruzella, F. D. (2017). Programmable Logic


Controllers. New York. McGraw-Hill Companie

[2] W. Bolton (2015). Programmable Logic Controllers.


Elsevier Ltd.

[3] CPM2A Programmable Controllers Operation


Manual (1999). Omron

[4] A Beginners Guide to PLC. (2015). Singapore:


Omron

83
The Programming Logic Controllers (PLC)
Programming and Applications eBook is
aimed to equip students with the knowledge
and skills related to basic PLC programming
and it’s application in industry.

You might also like