Sei sulla pagina 1di 65

1: Review of PLC

Programming and Logic


Fundamentals
MTR 335 Advanced PLCs and Integration
Fall 2015
Dr. Jennifer Wilburn

Outline

Review of PLCs

Ladder Logic Fundamental Circuits

Memory and Project Organization

Bit-Level Programming

Review of PLCs

What is a PLC?

Programmable Logic Controllers (PLCs) is an industrial-grade


computer used to perform control functions.

PLCs were originally developed to replace complex relay logic control


circuits.

The capabilities of PLCs are ever-expanding, meaning that PLCs are


being used to control increasingly-complex systems. They are no
longer limited to simple digital input/output systems.

PLC Programming is designed to be readily accessible to field


engineers and technicians who may not necessarily be familiar with
computer programming.

Advantages of PLCs

Increased reliability
Physical contacts on electromagnetic relays wear out much faster than PLCs
Same program can be downloaded to many PLCs no chance of miswiring

More flexibility
Easier to make logic changes in the PLC program than the relay circuit
Expanded functionality not just digital I/O
Security features

Lower cost
Relays/Contactors are not cheap.
PLCs do not have to go out of service to process logic changes.

Communications capability
Supervisory control, data gathering, monitoring devices and process parameters, remote I/O

Faster response time


Designed for high-speed and real-time applications
Relay circuits do not respond quickly enough for systems that process thousands of parts per second

Easier to troubleshoot
Diagnostic capabilities, simulate inputs, check logic, watch program execute in real-time

Parts of a PLC
Modular

Fixed

Principle of Operations

Principle of Operations - Example

Principle of Operations - Example


1.

The pressure switch, temperature


switch, and pushbutton inputs are
examined and their statuses
recorded in the controllers memory.
a. Closed = 1, open = 0

2.

The ladder diagram is evaluated


based on these input states.
Activated rungs assign a logic value
of 1 to their output coils memory
location. Non-activated rungs
output coils are assigned a value of
0. This is why each output can be
set only once in a program.

3.

Contacts are opened and closed


according to the output coil states.

Typical PLC Instructions


Siemens SIMATIC STEP 7

Allen-Bradley RSLogix 5000

Normally-Open Contact

XIC Examine If Closed

Normally-Closed Contact

XIO Examine If Open

Positive Signal Edge

OSR One-Shot Rising

Assignment Coil

OTE Output Energize

Set Coil

OTL Output Latch

Reset Coil

OTU Output Unlatch

Typical PLC Instructions


Siemens SIMATIC STEP 7

Allen-Bradley RSLogix 5000

TOF Timer Off Delay

TOF Timer Off Delay

TON Timer On Delay

TON Timer On Delay

CTD Count Down

CTD Count Down

CTU Count Up

CTU Count Up

Addressing
Siemens

Allen-Bradley

I Input

I Input

Q Output

O Output

M Memory

Process Image: Only way to to access I/O


bits

M Memory

Format:

O0:01/00

Bool I 0.0, Q 0.0


Byte IB 10, QB 10
Word IW 16, QW 16
Double Word ID 24, QD 24

Timers: T34

Counters: C23

Local: L0.0, LB1, LW2, LD4

Pointer: P# followed by an address, like


P#2.0 or P#I4.1

File type O = output, I = input


: - file delimiter
0 rack number
1 group (0-7); 8 groups in a rack
/ - bit delimiter
00 terminal number (bit address)

Types of PLCs
Compact

Sometimes called Compact or


Micro PLCs

Limited number of I/O ports

I/O ports are integrated into the body


of the PLC with the CPU, memory, and
communications

No separate removable modules


Typical units are low-cost but limited
functionality
Some, like S7-1200, are considered
compact and have integrate I/O, but can
still be expanded with additional modules

Modular

Rack-mount/chassis-mount

Can select and combine different


I/O modules, CPUs, and
communications to suit a wide
variety of applications

Can support different voltage


ranges and types (e.g. 5VDC,
24VDC, 110VAC, 230VAC), signal
types (digital/analog,
sourcing/sinking), and
communications buses within the
same system

I/O Modules

Discrete I/O

Analog I/O

Special I/O Modules:

High-Speed Counter Module


Thumbwheel Module
TTL Module
Encoder-Counter Module
BASIC or ASCII Module
Stepper-Motor Module
BCD-Output Module
Proportional-Integral-Derivative (PID) Control Module
Motion and Position Control Module
Communication Modules

Discrete I/O Module

Digital Input Module used to read


inputs such as: pushbuttons,
selector switches, limit switches,
proximity switches

Digital Output Module used to


activate: indicator lights, signaling
columns, relays, motor coils

Available in various AC and DC


voltage ratings

Modules receive power from


backplane

Devices receive power from fieldsupplied voltage source

Analog I/O Module

Typical analog inputs and outputs


vary from 0 to 20 mA, 4 to 20 mA,
or 0 to 10 V.

Two basic types of analog inputs:


Current sensing
Voltage sensing

Typical quantities measured:

temperature
speed
level
flow
weight
pressure
position

Special Modules

High-speed counter: counts independently from the processor, rates up to 100kHz

Thumbwheel module: reads thumbwheel switches

TTL module: communicate with TTL-level signals

Encoder-counter module: Reads encoder, stores data to be read later by processor

BASIC or ASCII module: runs user-written BASIC and C programs independently


from PLC; interface between remote devices and PLC processor

Stepper-Motor module: Provides pulse trains to drive a stepper motor

BCD output module: Used to control BCD outputs like 7-segment displays

PID module: allows complex PID control algorithm to be computed outside the PLC
CPU, freeing the PLC from these cumbersome calculations

Motion and Position Control module: control stepper and servo motors with high
precision for high-speed machining and packaging operations

Communications module: Used to establish point-to-point communications for


exchange of data among modules, computers, PLCs, operator stations, process
control systems, etc.

Ladder Logic
Fundamental Circuits

AND gate
A

OR gate
A

NOT gate
A

NAND gate
A

NOR gate
A

XOR gate
A

Inverting Inputs and Outputs

A relay must be used to invert the


output of a logic operation.

A simple NC contact is sufficient to


invert the input to a gate.

Memory and Project


Organization

Programmable Automation Controllers

More advanced math and logic manipulation functions

PACs look and act like PLCs, but with expanded capabilities:

For Allen-Bradley PLCs, these PACs include:

advanced control of communications


data logging
signal processing
motion control
process control
machine vision
ControlLogix
CompactLogix
FlexLogix
SoftLogix 5800
DriveLogix

Software makes the difference. Standard Ladder Logic doesnt change, but
addressing of instructions does.

Memory Layout

ControlLogix (CLX) processors have a flexible memory structure no


fixed areas of memory allocated for specific types of data or for I/O

Memory organization is configured by the user in RSLogix 5000

A CLX system can be composed of only a controller and standard I/O


modules in a single chassis or it can be as complex as a highlydistributed system containing several chassis and networks working
together.

Configuration

Configuration of a modular CLX system


involves establishing a communications link
between the controller and the process.

The software needs to know what hardware


is being used in ordered to be able to send
or receive data.

Configuration includes what processor(s),


I/O modules, special modules, and
networking are being used.

RSLogix 5000 is used to configure the


memory of the controller

RSLinx is used to create a connection


between RSLogix 5000 and the hardware.

Configuration (contd)

To establish communications with a controller, a driver must be created in


RSLinx.

RSWho allows you to view all configured network drivers.

After drivers are configured, the modules are configured in RSLogix 5000. They
must be configured correctly or they will not work properly (or at all).

RSLinx can also be used to find data about modules like firmware and revision
version.

Project

RSLogix 5000 (and 500) stores a


controllers programming and
configuration information in a file
called a project.

The project file contains all


information relating to the project:
tasks
programs
routines

A controller can only hold and


execute one project at a time.

Project (contd)

RSLogix 5000 project organization tree shows:

Tasks
Programs
Routines
Data types
Trends
I/O configuration
Tags

Folders group common functions together

Right-clicking on different objects brings up


relevant, context-sensitive popup menus

Tasks

Tasks are the first level of scheduling within a


project

A task is a collection of scheduled programs

When a task is executed, the associated


programs are executed in the order listed (the
program schedule.

Tasks provide scheduling contain no executable


code.

Only one task may execute at a time

Main types of tasks:


Continuous execute non-stop but are always
interrupted by periodic tasks; lowest priority. Named
Main Task, similar to File 2 in the SLC 500 platform.
Periodic function as timed interrupts; interrupt
continuous tasks; execute for a fixed length of time at
specific time intervals.
Event event-driven interrupts; triggered by events
that occurred or failed to occur.

Programs

Programs are the second level of


scheduling within a project

The folders under Task Main Task


determine which programs execute
and in what order.

No executable code within a


program.

Routines within programs execute


in the order listed.

Programs not assigned to a task


are downloaded to the controller,
but will not execute.

Routines

Routines are the third level or scheduling


within a project.

Routines contain the executable code for the


project.

Each routine contains a set of logic elements


for a specific programming language.
When a routine is created, it is specified as
Ladder Logic, Sequential Function Chart, Function
Block Diagram, or Structured Text.
Any one routine must be in only one language,
but different routines may contain different
languages within the same project.

Libraries of standard routines can be created


and reused on multiple machines or
applications.

A routine can be assigned as:


Main routine executes first in the program
Subroutine called by another routine, used for
complex tasks, or those that require more than
one programming language.
Fault routine executes if controller finds a
program fault. Each program can have one fault
routine (if desired).

Tags

Tag-based addressing structure

Tags are meaningful names, like


variables

No predefined data tables in


RSLogix 5000

Use tag names to refer to memory


locations, instead of addresses

Tags allow for self-documented


logic

When you want to group data, you


create an array, which is a
grouping of tags of similar types

Tags (contd)

Scope refers to which programs have


access to a tag

Scope must be declared when you


create the tag

Two scopes:
Program scope (local data, visible within
routines within the program)
Controller scope (global data, accessible
by all routines within a controller)

The same tag name may appear within


different programs as local variables,
because other programs cannot see the
tag.

The scope of a tag must be declared


when you create the tag.

Tags (contd)

I/O tags are automatically defined as


controller scoped tags.

There are four different types of


tags:

base
alias
produced
consumed

Base stores various types of data


for use by logic in the project
Ex. Local:2:O.Data.4

Tags (contd)

Alias used to create an alternate name for a


tag, or another name for an already-named
address in memory
Any action to the base also happens to the
alias and vice versa.

Produced/consumed tags are used to


share tag information over a network
between 2 or more devices.

A produced tag sends data


Produced tags are always control-scoped

A consumed tag receives data


Multiple controllers can connect to any
data being produced, which prevents the
need to send multiple messages
containing the same data.

Data Types

Logix controllers are based on 32-bit operations

Types of data that can be a base ta are:

BOOL
SINT
INT
DINT
REAL

The controller stores everything ina minimum of 4 bytes or 32 bits of


data

Data Types (contd)

BOOL
one bit of data stored in bit

0 of a 4 byte memory location

SINT single integer, 8 bits of


memory (low byte), range of -128
to 127

INT integer base tag is 16 bits,


lower bytes, range of -32768 to
+32767

DINT double integer base tag, 32


bits or all 4 bytes, range of to

REAL uses 32 bits, has a range of


values based on the IEEE Standard
for Floating-Point Arithmetic

Structures

Structures are another data-type

A structure-type tag is a grouping of


different data types that function as
a single unit and serve a specific
purpose.

Each element of a structure is called


a member and each member can be
a different data type

There are three different types of


structures in a ControlLogix
controller:
Predefined
Module-defined
User-defined

Predefined Structures

The controller creates predefined


structures for you that include:

timers
counters
messages
PID

In the figure, the Counter structure


contains the preset value, the
accumulation value, and the
counter instructions status bits.

Module-defined Structures

Module-defined structures are


automatically created when the I/O
modules are configured for the system.

When you add input or output modules,


a number of defined tags are
automatically added to the controller
tags,

The figure shows two structures (tags)


added when an input module is added.
One stores input data, and the other
stores configuration data.

Local indicates that these tags are in


the same rack as the processor.
The 1 indicates that the module is in slot
1 of the chassis.

User-defined Structures

User-defined structures provide the ability


to store and handle data as a group.

Example: The structure in the figure


contains data for a storage tank, so that
all data relative to the tank are stored
together.

When designing, the programmer creates


the structure that contains all the different
aspects of the storage tank,

Each member has a meaningful name and


an appropriate data type.

It is easy for installation and maintenance


personnel to locate all data associated
with the operation of the tank, as it is
stored together.

Creating Tags

Many ways to create tags:


create tags from the tag editor before
programming
enter tag names as you program
use ? as placeholders and enter tag
names later

When defining tags, the following


information must be specified:

Tag name
Tag description (optional)
Tag type
Data type
Display style
Whether the tag is consumable and the
number of controllers that can consume
it

Monitoring and Editing Tags

After tags have been created, they


can be monitored in the Monitor
Tags window

The Force Mask is used to force


inputs and outputs when
troubleshooting.

In the Edit Tags window, you can


edit existing tags or create new
tags.

Array

Many control programs require the


ability to store blocks of
information as tables that can be
accessed at runtime.

An array is a tag type that contains


a block of multiple pieces of data.

Each element of an array must be


the same data type (ex. all BOOL,
all SINT, or all INT)

An array occupies a contiguous


block of controller memory.

Arrays allow large amounts of data


to be retrieved efficiently.

Bit-Level Programming

Program Scan

When a ControlLogix controller


executes a program , it must know
in real time when external devices
controlling a process are changing.

During each operating cycle, the


processor:
1.
2.
3.
4.

Reads all the inputs


Stores these values
Evaluates the user program
Energizes and deenergizes the
outputs in accordance with the user
program.

This is the program scan.

Program Scan (contd)

During the program scan, the controller reads the rungs


and branches from right-to-left and top-to-bottom as
follows:
The status of inputs at the input module are checked for true
(1 or ON) or false (0 or OFF) conditions
The status signals from the inputs are stored in the input tags.
As the program is scanned by the process, the input tag data is
used to evaluate the ladder logic.
Only one rung is scanned at a time.
The result of logic operation (RLO) for each rung is then sent to
the output tags for storage.
During the output update portion of the scan, output value are
sent to their corresponding process or machine through the
output module.

I/O updates occur asynchronously to the scan of the logic.


There are 2 separate 32-bit processes running simultaneously,
which are not synchronized.
This is a newer type of scan cycle, which allows the input
module to update input tags and the output tags to be written
to the output module at any point (or at multiple points) in the
scan cycle.
This results in greater efficiency and better control over when
the input field device data is pulled from the input field devices,
and when output tag data is sent to the output module to
update output field devices.

Creating Ladder Logic

Of the five available programming


languages for PLCs, Ladder Logic is
the most prevalent.

In general, Ladder Logic is


composed of INPUT instructions
and OUTPUT instructions.
The most common INPUT instruction
is equivalent to the closing of a relay
contact.
The most common OUTPUT
instruction is equivalent to the
energizing of a relay coil.

Creating Ladder Logic (contd)

Of the five available programming languages for PLCs, Ladder Logic is the
most prevalent.

In general, Ladder Logic is composed of INPUT instructions and OUTPUT


instructions.
The most common INPUT instruction is equivalent to the closing of a relay contact.
The most common OUTPUT instruction is equivalent to the energizing of a relay coil.

When creating ladder I/O bit instructions, the following rules apply:
All input instructions must be to the left of an output instruction.
A rung cannot contain an output instruction if it also contains an input instruction.
This means that you can have only an output instruction in a rung.
This is because the rung is evaluated from left-to-right including all inputs before
determining the value of the output.

A rung does not require an input instruction but it must have at least one output
instruction.
A rung with only one output instruction is always TRUE.

Creating Ladder Logic (contd)

All input instructions must be to the left of an output instruction.


The last instruction on a rung must be an output instruction.
The XIC (Examine If Closed) returns TRUE if the input value is 1.
The XIO (Example if Open) returns TRUE if the input value is 0.
The OTE (Output Energize coil) instruction sets the tag associated with it to
TRUE (1) when the rung has logic continuity. When true, it can be used to
energize an output device or to set the value of a memory bit to 1.

Creating Ladder Logic (contd)

ControlLogix PLCs (RSLogix 5000)


support multiple outputs on one
rung.

It also supports series output


configurations that would not work
if connected this way in an actual
electrical circuit.
This is not the case for RSLogix 500
this series output configuration would
not be valid.

RSLogix 5000 also permits output


instructions to be placed between
input instructions, as long as the
last item on the rung is an output.

Tag-Based Addressing

RSLogix 5000 supports tag-based addressing structure.

A tag is like a variable name for a section of memory when


a piece of data is stored.
Tags are meant to give meaningful names to otherwise difficult-toremember addresses.

In the example, the tag Limit_switch has address


Local:1:I.Data.2(C).
Local indicates that the module is in the same rack as the processor
1 indicates that the input module is in slot 1 of the rack
I indicates that the module is the input type
Data indicates that it is a digital input
2 indicates that the limit switch is attached to terminal 2 on the
module
C indicates that it is a controller tag, which has global access

In the example, the tag High_limit_light has address


Local:2:O.Data.4(C).
Local indicates that the module is in the same rack as the processor
2 indicates that the input module is in slot 2 of the rack
O indicates that the module is the output type
Data indicates that it is a digital output
4 indicates that the high limit light is attached to terminal 4 on the
module
C indicates that it is a controller tag, which has global access

Tag-Based Addressing (contd)

One advantage of the use if tag-based addressing is that all the


allocation of variable names for program values is not tied to specific
memory locations in the memory structure.

Initially, all program development can proceed with just the tag
names and the data types assigned.

Using tag aliases, programmers can write code independent of


electrical connection assignments.

At a later time, input and output field devices are easily matched to
the pin numbers on the respective module the are connected to.

Adding Ladder Logic to the Main Routine

In the figure of the hardwired


motor start/stop circuit, the
normally-open start button is
momentarily closed to energize
the contactor coil ad close its main
contacts to start the motor.

The seal-in auxiliary contact is


connected in parallel with the start
button to keep the motor coil
energized when the start button is
released.

The normally closed stop button is


momentarily opened to deenergize the contactor coil and
stop the motor.

Adding Ladder Logic to the Main Routine


(contd)

The figure shows the PLC/Ladder


Logic setup for the motor start/stop
circuit.

The ? are used in place of tag


names to show that we do not have
to tie an instruction to a memory
address/tag before we create the
next instruction.

The wiring is as shown:


The stop button is wired to input
terminal 3.
The start button is wired to input
terminal 4.
The contactor coil is wired to terminal
4 of the output module.

Adding Ladder Logic to the Main Routine


(contd)
Tags help document or comment

your ladder code.

For this simple circuit, 3 tags are


created:
Motor_Start
Motor_Stop
Motor_Run

Looking at Motor_Start, a link


through the module to the field
device must be specified to link
input terminal 3 to the proper tag
name.

Tag names are downloaded and


stored in the controller, but the
description is not. It is considered to
be part of the documentation.

Adding Ladder Logic to the Main Routine


(contd)

The same data can be referenced


multiple times under different
names using aliases.

When the motor is operating:


The XIC Motor_Start instruction is
false.
The XIC Motor_Stop is true.
The OTE instruction is true because
the rung has logic continuity.

Internal Relay Instructions

Internal relay instructions are used


when other than real-world field
devices are needed as input or
output reference instructions.

Commonly, an internal relay bit is


used as an output when the RLO of
the rung is used to control other
internal logic.

In RSLogix 5000, we do this by


creating a tag (either program or
controller type) and assigning a
Bool data type to it.

Latch and Unlatch Instructions

The output latch (OTL) instruction is a


retentive output instruction that is
used to maintain, or latch, an output.

If this output is turned on (energized),


it will stay energized on future scan
cycles, even if the rung that energized
it is no longer true.

The only way to turn the energized


output back off is to energize an
unlatch (OTU) instruction with the
same tag as the previously activated
(OTL).

The latched state will even be


maintained if the PLC is powered down
and back up again.

One-Shot Instruction

The one-shot (ONS) instruction is


an input instruction used to turn
an output on for exactly one scan
cycle.

For instance, in the example, we


use the ONS instruction to ensure
that we add 1 to the sum only
once each time the limit switch is
pressed, no matter how many scan
cycles the switch is held depressed
for.

This is also commonly used when


configuring momentary switches
as toggle switches.

References
1.

Frank D. Petruzella, Chapter 1 - Programmable Logic Controllers


(PLCs): An Overview, Programmable Logic Controllers, 4th edition,
McGraw-Hill, 2011.

2.

Frank D. Petruzella, Chapter 2 PLC Hardware Components,


Programmable Logic Controllers, 4th edition, McGraw-Hill, 2011.

3.

Frank D. Petruzella, Chapter 4 Fundamentals of Logic,


Programmable Logic Controllers, 4th edition, McGraw-Hill, 2011.

4.

Frank D. Petruzella, Chapter 15 ControlLogix Controllers, Part 1


Memory and Project Organization, Programmable Logic Controllers,
4th edition, McGraw-Hill, 2011.

5.

Frank D. Petruzella, Chapter 15 ControlLogix Controllers, Part 2


Bit-Level Programming, Programmable Logic Controllers, 4th edition,
McGraw-Hill, 2011.

Potrebbero piacerti anche