0% found this document useful (0 votes)
39 views74 pages

PLC 5

programable logic control

Uploaded by

Abdo Hesham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views74 pages

PLC 5

programable logic control

Uploaded by

Abdo Hesham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

Programmable

Logic Controllers
Third Edition

Frank D. Petruzella
McGraw-Hill
Chapter 5

Basics of PLC
Programming
Processor Memory Organization
The memory of a PLC is organized
by data types.

The memory space can be divided


into two broad categories:
program and data memory.

Advanced ladder logic functions allow controllers to


perform calculations, make decisions and do other
complex tasks. Timers and counters are examples of
ladder logic functions. They are more complex than
basic input contacts and output coils and rely
heavily upon data stored in the memory of the PLC.
Processor Memory Organization

While the fundamental concepts of PLC


programming are common to all manufacturers,
differences in memory organization, I/O addressing,
and instruction set mean that PLC programs are
never perfectly interchangeable among different
makers. Even within the same product line of a single
manufacturer, different models may not be directly
compatible
Memory Map
A memory map can be used to show how memory is
organized in a PLC.

▪ Input/output locations
Data table ▪ Internal relay and
timer/counter locations

The user program causes


User program the controller to operate
in a particular manner
Used to carry out
Housekeeping memory functions needed to make
the processor operate
(no access by user)
Memory Addresses
Memory is organized
into blocks of elements
in an array called a file.

The individual sections,


their order, and sections'
lengths will vary and may
be fixed or variable,
depending on the
manufacturer and model.
Program Files

The user program will


account for most of the
memory of a PLC system.

Program files contain


the logic that controls
the machine operation.
This logic consists of
instructions that are
Program file organization programmed in a
for SLC-500 controller. ladder logic format.
Data file organization Data Files
for SLC-500 controller.

The data file portion of memory


stores input and output status,
processor status, the status of
various bits and numerical data.
Data Files
Data files are organized by the type of data they contain
PLC-5 Memory
Organization

There are about 1,000


program files.
With the processor
set up for standard
ladder logic, the main
program will always
be in program file 2,
and the program files
3 through 999 will be
subroutines.
The data files are where
the variable data are
stored that the PLC
programs operate on.
PLC-5 Data Files
Timer, counter, and control
elements are three words in
length.
Each data file is made up off
numerous elements of different
lengths.
All other elements are a
single word in length, with
each word consisting of 16-
Floating point
bits. elements are two
words in length.
All data types except the
floating-point files, are
treated as whole numbers.
All element and bit addresses in
the output and input data files are
numbered octally. Element and
bit addresses in all other data files
are numbered decimally.
Input Table File Operation

Input module

Switch Open Processor continually


reads current input
Switch Closed
status and updates
input image table file
Binary 0 stored Binary 1 stored
01
Output Table File Operation

Output module
Output
Processor continually OFF
activates or deactivates
output status according
to output image table
file status Output
ON
01
Status 01
ControlLogix Processor
ControlLogix processors provide more flexible
memory structure.
With other controllers you develop your
application in such a way as to fit within the
confines of the controller's data table.

The ControlLogix processor eliminates this restriction


by providing arrays and user defined structures. This
allows data to be constructed to meet the needs of your
application rather than requiring your application to
fit a particular memory structure.
ControlLogix Processor
Task 32

Task 1

Tasks schedule and provide priority for executing


programs. There are two types of tasks: continuous
and periodic. A continuous task has the lowest
priority and is always interrupted by a periodic task.
ControlLogix Processor

Program 32

Program 1

Programs group logic and data.


ControlLogix Processor

Main Program
Routine (Local Tags)

Fault
Routine Other
Routines
Routines contain the logic of the executable code.
A routine is similar to a program file found in the
PLC-5 or SLC processor and is basically a set of
logic instructions in a single programming logic,
such as ladder logic.
ControlLogix Tags
The ControlLogix controller uses tags instead of
addresses to access data. The following types of tags are
used to identify memory locations:

Base Tag – defines the memory location where a data


element is stored

Alias Tag – references a memory location that has been


defined by another tag

Consumed Tag – references data that comes from


another controller
ControlLogix Data Types

Basic Data Type Type Of Data Stored

BOOL 1-bit Boolean


Basic
Types SINT 1-byte Integer
Of
Data INT 2-byte Integer

DINT 4-byte Integer

REAL 4-byte Floating


Point
STRUCTURED Type Of Data Stored
ControlLogix DATA TYPE
Data Types CONTROL Control structure for array
instructions
COUNTER Control structure for
counter instructions
MOTION_INSTRU Control structure for
CTION motion instructions
Structured
PID Control structure for PID
Types instructions
Of TIMER Control structure for timer
Data instructions
AXIS Control structure for an
axis
MESSAGE Control structure for the
message instructions

MOTION_GROUP Control structure for a


motion group
ControlLogix Tag Example

Use of tags instead of addresses to access data


Program Scan
During each operating cycle, the processor reads all
inputs, takes these values, and energizes or de-energizes
the outputs according to the user program. This
process is known as a scan.
I/O scan – records status data of input
devices. Energizes output devices that
have their associated status bits set to
ON (1)

Program scan – instructions are


executed sequentially
Because the inputs can change at any time, the PLC
must carry on this process continuously.
Scan Process
The scan time indicates how fast the controller can react
to changes in inputs. Scan times vary with computer
model and program content, and length. If a controller
has to react to an input signal that changes states twice
during the scan time, it is is possible that the PLC will
never be able to detect this change.

Scan time may be a concern


in high speed operations
Scan Process

Read inputs

The scan is a
a continuous
and sequential
process
Adjusts Run
outputs program
Data Flow Overview

Input Output
Input data Input Output data Output
image
modules table file image
modules
table file

Examine data Return results


Program

Check/compare/examine Take some


specific conditions action
Scan Process
Input Output
Module Module
Input Output
Input Output
file device
device file
I:3/6 O:4/7
I:3/6 O:4/7

Program
When the input is The processor turns
closed, the input
O:4/7 light output O:4/7
module senses a I:3/6
ON during the next
voltage and an ON During the program I/O scan
condition (1) is scan the processor
entered into the sets instructions I:3/6
input table bit I:3/6 and O:4/7 to ON (1)
Scan Patterns
Horizontal Scanning
Order

The processor examines


input and output
instructions from the
first command, top left
in the program,
horizontally, rung by
rung.
End of ladder

In addition to the program itself, the scan time is also


dependent on the clock frequency of the processor!
Scan Patterns

Vertical Scanning
Order

The processor examines


input and output
instructions from the
first command, vertically,
column by column and
page by page. Pages are
executed in sequence.
End of ladder

Misunderstanding the way the PLC scans can cause


programming bugs!
1. The memory space of a PLC can be divided
according to _______and _________memory.
(a) current, non-current
(b) program, data
(c) input, output
(d) module and field

2. Each memory location in a processor has


a/an:
a. address c. contact
b. rung d. coil
3. The individual memory sections, their order,
and length is standard for all PLC models.
(True/False)

4. The user program will account for most of the


memory of a PLC system. (True/False)

5. The data file portion of memory stores:


(a) input and output status
(b) processor status
(c) the status of various bits and numerical data
(d) all of these
6. The ControlLogix controller uses tags instead
addresses to access data. (True/False)

7. Scan time may be a concern in low speed


operations. (True/False)

8. The shorter the scan time, the faster the PLC


can react to changes in inputs. (True/False)
9. The input image table file is changed to reflect
the current status of input devices during the
program scan phase of operation.
(True/False)

10. Misunderstanding the way the PLC scans a


program can cause programming bugs.
(True/False)
PLC Programming Languages
The term PLC programming language refers to the
method by which the user communicates information
to the PLC.

The three most common


language structures are:
Ladder diagram language
ladder diagram language,
Boolean language, and
functional chart.
Functional
chart
Boolean language
Comparing Programming Language
PB1 CR1 CR2 SOL
Relay Schematic
LS1

PB1 CR1 CR2 SOL


Equivalent ladder
diagram language
LS1

Equivalent Boolean language


Sequential Function Chart (SFC) Programming

A functional chart program is a pictorial representation


or a special type of flowchart of a sequential control
process.

It allows the description of the process to become the


actual program.

Functional chart programming uses function blocks


made up of steps and transition units.
Sequential Function Chart (SFC) Programming

Check for stop


Wait for Check for Lock the Press the Unlock Move
start part clamp part clamp conveyor

One Continuous
cycle

Check mode
International Standard for Programmable
Controllers (IEC 61131-3) Defined Standard
Programming Languages
Ladder Diagram (LD) – graphically depicts a process
with rungs of logic, similar to the relay ladder logic
schemes that were replaced by PLCs.
Sequential Function Charts (SFC) – flowchart of steps (one or more
actions) and transitions (defined conditions) before passing to the next step.
Instruction List (IL) – assembler-type, text-based language for building
small applications or optimizing complex systems.

Functional Block Diagram (FBD) – graphical depiction of process flow


using simple and complex building blocks, ranging from analog I/O to
closed loop control, algorithms, and diagnostics.

Structured Text (ST) – a language developed for IEC


to provide high-level syntax using "If" and "Then" statements.
Relay-Type Instructions
The ladder diagram language is basically a symbolic
set of instructions used to create the controller
program.

These ladder instructions symbols are arranged to


obtain the desired control logic.
Examine If Closed (XIC) Instruction

Symbol Analogous to the normally open


relay contact. For this instruction
we ask the processor to EXAMINE
IF (the contact is) CLOSED (XIC)

Typically represents any input. Can be a switch


or pushbutton, a contact from a connected output,
or a contact from an internal output.
Has a bit-level address which is examined for an
ON condition.

The status bit will be either 1 (ON) or 0 (OFF).


Examine If Closed (XIC) Instruction

I:012
I:012

04

IfIfthe
thestatus
statusbit
bitisis0 1(OFF),
(ON), then the instruction
is TRUE.
is FALSE.
Examine If Open (XIO) Instruction

Symbol Analogous to the normally closed


relay contact. For this instruction
we ask the processor to EXAMINE
IF (the contact is) OPEN (XIO).

Typically represents any input. Can be a switch


or pushbutton, a contact from a connected output,
or a contact from an internal output.
Has a bit-level address which is examined for an
OFF condition.

The status bit will be either 1 (ON) or 0 (OFF).


Examine If Open (XIO) Instruction

I:012
I:012

04

IfIfthe
thestatus
statusbit
bitisis1 0(ON), then
(OFF), thethe
then instruction
instruction
isisFALSE.
TRUE.
Output Energize (OTE) Instruction
Analogous to the relay coil. The
Symbol processor makes this instruction
true (analogous to energizing a coil)
when there is path of true XIC and
XIO instructions in the rung.

Typically represents any output that is controlled by


some combination of input logic. Can be a connected
device or an internal output (internal relay).

If any left-to-right path of input conditions is TRUE,


the output is energized (turned ON).
Output Energize (OTE) Instruction

O:013

I:012

I:012 I:012 O:013

11 15 01

OUTPUT ENERGIZE instruction - TRUE


FALSE
Status Bit Examples
A Input module
Bit status

Button
Buttonnot actuated
actuated

A Output
ON
OFF

False
True
A Output
ON
OFF
True
False
Ladder Rung Output
A B C instruction

Input conditions
D

For an output to be activated or energized, at least one left-to-right path of


contacts must be closed. A complete path is referred to as having logic
continuity. When logic exists the rung condition is said to be TRUE.
A ladder rung consists of a set of input conditions, represented by contact
instructions, and an output instruction at the end of the rung, represented by the
coil symbol.
Each contact or coil symbol is referenced with an address number that identifies what
is being evaluated and what is being controlled. The same contact instruction can be
used throughout the program whenever that condition needs to be evaluated.
Rung Continuity

Bit in memory Bit in memory


01 01

LS_1 SOL_5

The
The Examine
Examine IfIf Closed
Closed instruction
instruction isis TRUE
FALSE
making
making the
the rung
rung TRUE
False
Allen-Bradley SLC-500 Controller Addressing
Address
output
terminal
Output image table O:4/6
File Type : Slot Nu. / Bit Nu. file 0
I:3/12

O:0:4/6
Address Bit address
input
terminal Input image table
I:3/12 Energized
file 1
output

I:3/12
Bit address
Closed input
I1:3 O:0:4
User-programmed rung
12 6
Parallel Input Branch Instructions
A C Branch instructions are used
to create parallel paths of
input condition instructions.
If at least one of these parallel
B branches forms a true logic
path, the logic is enabled.
Parallel Output Branching
A C

D
B
E

On most PLC models, branches can be established at


both the input and output portion of the rung.

With output branching, you can program parallel


outputs on a rung to allow a true logic path to
control multiple outputs.
Nested Input and Output Branches

Input and output branches can be nested to avoid


redundant instructions and to speed up the processor
scan time.
A nested branch starts or ends within another branch.
Nested Contact Program
A B C Y
On some PLC models,
the programming of a
D Nested nested branch circuit
contact cannot be done directly.
E

A B C Y
Reprogrammed to
obtain the required
Contact logic.
D C instruction
C repeated
E
PLC Matrix Limitation Diagram
Max series
contacts

Max parallel No. outputs


lines per rung and
location of the
output in the rung

There may be limitations to the number of series


contacts instructions, number of parallel lines, and
the number of outputs and their location on the rung.
Programming of Vertical Contacts
A D Y
Original program
C
Y = (AD) + (BCD) + (BE) + (ACE)
B E

A D Y

B C D
Reprogrammed to obtain the
B E required logic
A C E
Programming for Different Scan Patterns

A B C Y
Original program
D E

F
Y = (ABC) + (ADE) + (FE) + (FDBC)

A B C Y

A D E
Reprogrammed to obtain the
F E required logic

F D B C
Internal Control Relay
The internal output operates just as any other output
that is controlled by programmed logic; however, the
output is used strictly for internal purposes.

The internal output does not directly control an


output device.

The advantage of using internal outputs is that there


are many situations where an output instruction is
required in a program, but no physical connection to
a field device is needed. Their use in this type of
instance can minimize output card requirements.
Extending the Number of Series Contacts Using
an Internal Control Relay

Internal
relay coil
Rung 1

Rung 2

Internal Discrete output (requires


relay one physical connection
contact on the output module)
Programming The XIC Instruction
PB1 PB2
Hardwired Circuit
PL

PB1 PB2 PL User program


providing the
same results
Note that both pushbuttons are represented by the
XIC symbol. This is because the normal state of an input
(NO or NC) does not matter! What does matter is that if
contacts need to close to energize the output, then the XIC
instruction is used. Since both PB1 and PB2 must close to
energize the PL, the XIC instruction is used for both.
Programming The XIO Instruction
PB1
PB1
CR P
L
CR1
P
User program providing
L the same results
Hardwired Circuit
When the pushbutton is open in the hardwired circuit,
relay coil CR is de-energized and contacts CR1 close to
switch the PL on. When the pushbutton is closed, relay
coil CR is energized and contacts CR1 open to switch the
PL off. The pushbutton is represented in the user program
by an XIO instruction. This is because the rung must be
true when the external pushbutton is open, and false
when the pushbutton is closed.
Operation of The XIC and XIO Instructions

Summary of status conditions

The status of the instruction is:


XIC XIO OTE
If the data Examine If Closed Examine If Open Output Energize
table bit is:

Logic 0 False True False


Logic 1 True False True
Operation of The XIC and XIO Instructions
State of the output as determined by the changing
state of the inputs in the rung

Inputs Output Bit status


Time
XIC XIO OTE XIC XIO OTE
t1 False True False 0 0 0
(initial)
t True True Goes true 1 0 1
t2 True False Goes false 1 1 0
3
t False False Remains false 0 1 0
4

Input instructions Output instruction


XIC XIO OTE
Entering the Ladder Diagram
A personal computer is most often used to enter the
ladder diagram.

The computer is adapted


to the particular PLC
model using the relevant
programmable controller
software.
RSLogix Main Screen
Different screens, toolbars and windows dialog boxes are
used to navigate through the Windows environment
Bit Instructions Tool Bar

To place an instruction on a rung, click its icon


on the toolbar and simply drag the instruction
straight off the toolbar onto the rung of the
ladder.
Select Processor Type Screen
The programming software needs to know what
processor is being used in conjunction with the program.

1747-L40E
You simply
scroll down
the list until
you find the
processor you
are using and
select it.
I/O Configuration Screen

The I/O screen


lets you click or
drag-and-drop a
module from an
all inclusive list to
assign it to a slot
in your
configuration.
Data File Screen
Data file screens
contain data that
is used in
conjunction with
ladder program
instructions. These
include:
Input
Output
Timer
Counter
Integer
Bit
Monitoring a Ladder Logic Program
Operation of the logic is apparent from the highlighting
of rungs of the various instructions on screen, which
identifies the logic state in real time and has logic
continuity.

Highlighted rungs indicate the instruction is true


Modes of Operation
A processor has basically two modes of operation:
the program mode or some variation of the run mode.
Program Mode – may be used to
⮚ enter a new program
⮚ edit or update an existing
program
⮚ upload files
⮚ download files
⮚ document programs
⮚ change software configurations
When the PLC is switched into the
program mode, all outputs from the PLC
are forced off regardless of their rung
logic status, and the ladder I/O scan
sequence is halted.
Variations of the Run Mode

Run Mode – is used to execute the


user program. Input devices are monitored
and output devices are energized
accordingly.

Test Mode – is used to operate, or monitor,


the user program without energizing any
outputs.

Remote Mode – allows the PLC to be


remotely changed between program and run
mode by a personnel computer connected
to the PLC processor.
11. Which of the following is not a common
PLC language structure?
(a) ladder diagram language
(b) Boolean language
(c) Fortran
(d) functional chart

12. The ladder diagram language is basically a


numbered set of instructions used to create the
controller program. (True/False)
13. A programmed normally closed contact
instruction is examined for an "ON" condition.
(True/False)

14. A ladder logic rung is always true or has logic


continuity whenever all input contact instructions
are at logic 1. (True/False)

15. The Output Energize instruction is true when


there is a path of true instructions in the rung.
(True/False)
16. Branch instructions are used to create series
paths. (True/False)

17. The maximum number of rungs allowed in


a program is limited only by the memory size.
(True/False)

18. The last element to be entered on a ladder


logic rung is a contact instruction. (True/False)
19. If there are no physical outputs wired to a
bit address, the address can be used as a (an)
______ storage point.
a. internal c. temporary
b. external d. permanent

20. Normally intensified rungs to an instruction


on the screen of a display indicate the instruction
is true and has logic continuity. (True/False)

You might also like