64
PLC Basics Fundamentals of PLC How PLC Works Programming Fundamentals and Examples Various Programming Languages

2. PLC Basics

Embed Size (px)

Citation preview

Page 1: 2. PLC Basics

PLC Basics

Fundamentals of PLC

How PLC Works

Programming Fundamentals and Examples

Various Programming Languages

Page 2: 2. PLC Basics

Block Diagram of Control System

PB1

LS1

INPUTSM1

M2R

LOGIC OUTPUTS

M1

SOL

Page 3: 2. PLC Basics

The first step involved in automating any industrial process or machine is to determine the sequence of operation or events which are specific to its operation. This sequence is then arranged into a set of logic functions.

Then this Logic scheme is turned into a physical system using the basic building blocks of the particular technology selected ,i.e. Mechanical, Fluidic, Pneumatic, Electromechanical, Electronics.

Most Popular method to turn Logic into physical system are, Relay Logic Wired Logic Programmable Controllers

What is Logic ?

Page 4: 2. PLC Basics

There are three basic system options that are open to a design engineer. Relay Logic

It has for many years been the work horse of most electrical installations.

Advantages: It was simple for small systems, hence cost advantages due to wide range of available coil voltages.

Disadvantages: As the number of relays increases, it requires larger physical area, coupled with costly enclosures, the labour charges, the schematic and connection diagrams, escalates the final cost.

Wired Logic Programmable Logic

Improved installation time eliminate the need for extensive wiring of timers, relays and other

components Improved flexibility enable control system changes simply by reprogramming Much more compact than relay control panels, yet enables

complex, high-level control Improved reliability

Which Logic System and Why ?

Page 5: 2. PLC Basics

Programmable Logic ControllersProgramming

Device

Input/OutputSystem

OutputDevices

InputDevices

UserProgram

Data Storage

OutputTable

InputTable

ProcessorProcessor I/O InterfaceI/O Interface Power SupplyPower Supply Programming DeviceProgramming Device

Page 6: 2. PLC Basics

Basic PLC PartsProcessor

Central Processing Unit

Memory

Input/Output Rack

Ad

ap

ter

Mod

ule

Mod

ule

Mod

ule

Mod

ule

Mod

ule

Mod

ule

Mod

ule

Mod

ule

Output Devices

SolenoidsMotor Starters

AlarmsIndicators

D/ALogicBCD

Input Devices

Limit SwitchesPres. SwitchesProx. SwitchesTemp. SwitchesPush Buttons

A/D Logic

Program Panel

Power Supply

Page 7: 2. PLC Basics

PLC Definition The National Electrical Manufacturers Association

(NEMA) defines a PLC as a digitally operating electronic apparatus which uses a programmable memory for internal storage of instructions by implementing specific functions, such as logic, sequencing, timing, counting, and arithmetic to control through digital or analog I/O [Input/Output] modules various types of machines or processes

A Programmable Logic Controller (PLC) is is a solid state device that uses soft wired logic contained in the controller’s memory to duplicate the functions of relays and hardwired solid state control devices. In operation, the memory unit sequentially scans inputs( sensors, limit switches, push buttons, photocells) in cyclic fashion to determine which outputs( contacts, motor starters, solenoids, pilot lights, converters, etc.) should be turned on or off.

Page 8: 2. PLC Basics

PLC Advantages Reliability Flexibility Advanced Functions Communications Speed Diagnostics

Ease of programming Ease of maintenance Designed for industrial environment Quick installation Adaptable to change

Page 9: 2. PLC Basics

Traditional PLC Application Packaging Bottling and canning Material Handling Power Generation HVAC/building control systems Security Systems Automated Assembly Water Treatment Food and Beverage Chemicals Pulp and Paper Pharmaceuticals Metals

Virtually any application that requires electrical control can use a PLC

Page 10: 2. PLC Basics

How PLC Works

CR???????

Optical IsolationBarrier

Optical IsolationBarrier

CentralProcessor

MEMORYprogram data

Low Voltage

POWER SUPPLY

Output

Circuits

Input

Circuits

Programming / Communication Devices

Page 11: 2. PLC Basics

PLC Operation

During the input scan PLC examines the external input devices -On or Off. The status of the inputs is temporarily stored in an input image memory file.

The PLC scans the instructions in the ladder logic program, uses the input status from the input image file & determines if an output will be energized. The resulting status of the outputs is written to the output image memory file.

Based on the data in the output image file the PLC energizes or de-energizes it’s output circuits, controlling external devices.

Page 12: 2. PLC Basics

Speed of PLC “through-put time”The throughput time includes the time for actuation of the physical input ; time for PLC’s input circuit to sense the signal, time for input scan, program scan and output scan; time for actuation of the output circuit & corresponding field device, and time for the CPU’s housekeeping or overhead functions.

Therefore the formula is -- PLC input circuit filter time + Input scan time + housekeeping time + program scan time (addition of instruction execution times when all instructions are True) + Output scan time + PLC output circuit turn on time

Page 13: 2. PLC Basics

Program ExecutionThe total loop is the throughput time of the PLC.

Start of Next Sweep

Start of SweepHousekeeping

Input Scan

RunMode

?

Logic Solution

I/OEnabled

?

Output Scan

ProgrammerCommunications

User ProgramChecksumCalculation

No

Yes

No

Yes

No

Yes

I/OEnabled

?

Diagnostics

Housekeeping

Data Input

Program Execution

Data Output

ProgrammerServiceS

can

tim

e o

f P

LC

Page 14: 2. PLC Basics

Central Processing Unit CPU,the primary component is made of a microprocessor & a memory

system. CPU has an executive program or system memory that directs & performs

“operation” activities of the internal functions of the CPU’s. This System Memory is Programmed by the manufacturer cannot be accessed by the user.

CPU reads the inputs,executes logic as dictated by the APPLICATION PROGRAM,performs calculations & controls the outputs accordingly.

PLC users work with 2 areas of the CPU : Program Files & Data Files. Program File stores an user application program,subroutines & the error files. Data files store data associated with the program,such as I/O status,

counter/timer preset /accumulated values & other stored constants or variables.

Page 15: 2. PLC Basics

PLC Memory Memory is a physical space inside the

CPU where the Program files & Data information are stored & manipulated.

Memory are 2 types -- volatile & non-volatile. Volatile memory can be easily

altered or erased, it can be written to & read from.Without backup,the programmed contents will be lost in absence of Power. Best known form is RAM & is typically backed up by battery or capacitor.

Non-volatile memory retains its programmed contents without a backup. The EEPROM offers the same flexibility as RAM.

MEMORY

PROGRAM

FILES

DATA FILES

Page 16: 2. PLC Basics

Memory Distribution

Program Data Backup

The application memory can be divided into 5 memory zones :

the application data is always in internal RAM,

the application program (application comments and executable task code)

the constants, initial values and configuration in internal RAM or on the PCMCIA card,

backup for the application program, constants and configuration values backup

backup of internal words

Page 17: 2. PLC Basics

Power Supply PLC Power supplies are typically designed to meet normal operation of +10

to -15%. Fluctuation in voltage.

Converts the incoming voltage to a useable form for the internal electronics

Protects the PLC ‘s components from voltage

Operates either on 120VAC/ 240 VAC/ 24VDC.

PLC’s Power Supply is designed to meet short power losses without affecting the operation of the system. PLC can operate for several “ms” without line power before the PS signals the processor that it can no longer provide adequate DC Power to the system. The CPU executes a controlled shut down which saves the users program & data in memory

The other factor affecting the function of the PLC is EMI or electrical noise.Use an isolation transformer, take care of shielding from Drives, ensure proper earthing & cabling practices.

Page 18: 2. PLC Basics

Programming Devices Personal Computer

Run PLC Programming Software It creates, edits, document, store and troubleshoot ladder

diagrams, and generates printed reports. Hand Held Programmer

Mainly a troubleshooting tool. On factory floor you can modify the program, store the

program and transfer the program to multiple machines.

These products communicate with the PLC through a Serial communication port.

Page 19: 2. PLC Basics

Input Devices

Pushbuttons Selector Switches Limit Switches Photoelectric Sensors Proximity Sensors Motor Starter Contacts Relay Contacts Thumbwheel Switches Transducers/Transmitters Encoders/Tachos/Resolvers Level/Pressure/Temperature Switches

Page 20: 2. PLC Basics

Input Devices Can be Discrete or Analogue. Can be varying voltages/ currents.

24 V DC/AC. 110 V DC/AC. 230 V AC 4-20 mA, 0-10 V DC, T/C, RTD, mV etc.

Field signals are unfiltered. Conditioning of the signals are required because the internal components of a PLC operate on 5V DC. This minimizes the possibility of damage by shielding them.

To electrically isolate the internal components from the input terminals, PLC employ an optical isolator -- a device which uses light to couple signals from one electrical device to another.

The field signal needs to be qualified as valid which means it needs to be distinguished from the electrical noise. This activity is done by Input Filters which determine the validity of the signal of a signal by it’s duration -- they wait to confirm that a signal is a reference from an input device rather than an electrical noise.

Page 21: 2. PLC Basics

Output Devices Valves Motor Starters Solenoids Control Relays Alarms Lights Fans Horns

Page 22: 2. PLC Basics

Output Devices Can be Discrete or Analogue. Can be varying voltages/ currents.

24/110 V DC. 24/110/230 V AC. 4-20/0-20 mA, +/-10 V, 0-10 V DC.

Output circuits operate in a manner similar to the input circuits – signals from the CPU passes through an isolation barrier before energizing outputs.

Output Circuits can be -- ..Relays ---can be either for AC/DC, handle higher amp,slow, wear & tear. --- Transistors --Switches DC Power,Fast,lower Amp handling typically 0.5A. Triacs -- Switches AC Power,other features same as Transistors.

Note -- Solid State Outputs ( Triacs & Transistors) can be damaged by over

voltage or over current.

Page 23: 2. PLC Basics

Various Programming Languages

Page 24: 2. PLC Basics

What is a Program A Program is a user developed series of instructions or commands that directs the

PLC to execute actions.

A Programming Language provides rules for combining the instructions so that they produce the desired actions.

The latest standard (IEC 1131-3) has tried to merge plc programming languages under one international standard. We now have PLCs that are programmable in function block diagrams, instruction lists, C and structured text

Various Programming Languages are, Ladder Logic Function Block Structured Text Instruction List. Sequential Function Chart

Page 25: 2. PLC Basics

Ladder Logic Programming

Page 26: 2. PLC Basics

Ladder Logic Programming

The most commonly used Programming Language is ‘LADDER LOGIC’

Ladder Logic is evolved from electrical ladder diagrams, which represents how electrical current flows thru the devices to complete an electrical circuit.

The Ladder logic programming language is an adaptation of an electrical relay wiring diagram, also known as ladder diagram.

Ladder Logic is a graphical system of symbols and terms even those not familiar with relay wiring diagram can easily learn it.

Page 27: 2. PLC Basics

Ladder Logic Each electrical circuit in the diagram is considered a rung. Each Rung must be connected to Power Line on Left side. Each Rung must contain at least one control instruction on Extreme Right Side. Every rung has two components

It contains at least one device that is controlled It contains the condition(s) that control the device.

Page 28: 2. PLC Basics

Connecting Objects All contacts can be connected in sequence

(AND-BOOL) All contacts can be connected in parallel (OR-

BOOL) All contacts can be connected in both,

parallel and sequence The network must be connected to the power

rail The power rail refers to the data type BOOL FFB's can be inserted at any position of the

network Coils have to be connected to contacts or

FFB-outputs The right and left side of a coil always has the

same value! At coils with negation or transition the value

will be stored in the associated variable

Ladder Logic

Page 29: 2. PLC Basics

Function Block Programming

Page 30: 2. PLC Basics

Function Block ProgrammingThe primary concept behind a FBD is data flow. In these types of programs the values flow from the inputs to the outputs, through function blocks.

A FBD program is constructed using function blocks that are connected together to define the data exchange. The connecting lines will have a data type that must be compatible on both ends.

FBDs use data flow from left to right through function blocks Inputs and outputs can be inverted Function blocks can have variable argument list sizes When arguments are left off default values are used

Page 31: 2. PLC Basics

Understanding FBDs

Execution order Programmer SelectedInstance Name

Inverted (Normally Closed) Input.Outputs can also be inverted.

Value Passedwithout declaring

Variable Passedby linking

and declared

Output can be linkedto multiple inputs

Page 32: 2. PLC Basics

Various Function Blocks Basic Logic Functions

Basic Timing Functions

Basic Math Functions

Page 33: 2. PLC Basics

Various Function Blocks Basic Latches and Comparisons

Basic Counters

Page 34: 2. PLC Basics

FBD Program Example

Page 35: 2. PLC Basics

Structured Text Programming

Page 36: 2. PLC Basics

Structured Text Programming ST is a high level language, similar to PASCAL or BASIC.

ST is a distinct language that has been specifically developed for industrial control applications.

Fairly straight forward and easy to learn and to use.

Compact formulation of a complex programming task.

Powerful constructs for controlling the instruction flow.

Useful for complex mathematic solutions.

Simple solutions for difficult problems in FBD, LD or IL.

Page 37: 2. PLC Basics

Understanding ST Statements, Expressions and Operators

A structured text program contains: statements.

A statement contains: Expressions Keywords

An expression contains one or more: Operators with Operands

Statements must close with semicolons (;) One line may contain several statements, separated by (;)

Page 38: 2. PLC Basics

Understanding ST – Statements The following statements are available:

VAR ... END_VAR Declaration of FFB'sFunction Block Calls Invoking of FFBsIF ... THEN ... END_IF Conditioned execution of statementsELSIF ... THEN Conditioned execution of statements,

if the preceded expression is notfulfilled (false).

ELSE ... Execution of statements, if expressionsof preceded statements are not fulfilled(false).

CASE ... OF ... END_CASE A list of statements with given labels. Execution, if the label is true.FOR ... TO ... BY ... DO ... END_FOR Repeated execution of statements up to a given number. WHILE...DO...END_WHILE Repeated execution of statements up to preceded condition = 0.REPEAT ... UNTIL ... END_REPEAT Repeated execution of statements up to succeeded condition = 0.EXIT To terminate repeat statements (FOR, WHILE, REPEAT) before the end condition is true.

Page 39: 2. PLC Basics

Understanding ST - Operators

Operators are generic, i.e. they automatically adjust to the data type of the operand.

The evaluation of an expression consists of applying the operators to the operands in the order defined by the rule of precedence of the operators.

The operator with the highest rule of precedence in an expression will be executed first.

Operators with the same precedence are executed from left to right, as described in the expression.

This order can be changed through the use of parenthesis.

Page 40: 2. PLC Basics

Understanding ST – Operators

( ) Expression Bracketing 1 (highest)

FUNCNAME ANY Function editing (call) 2

* * REAL, ANY_NUM Raising to a power 3

ANY_NUM Negation 4

NOT ANY_BIT Complement 4

* ANY_NUM or TIME Multiplication 5

/ ANY_NUM Division 5

MOD ANY_NUM Modulo 5

Operator Operand Significance Precedence

+ ANY_NUM or TIME Addition 6

ANY_NUM or TIME Subtraction 6

< ANY_ELEM Less than 7

> ANY_ELEM Greater than 7

< = ANY_ELEM Less or equal 7

> = ANY_ELEM Greater or equal 7

= ANY_ELEM Equality 8

< > ANY_ELEM Inequality 8

&, AND ANY_BIT Logic AND 9

XORANY_BIT Logic exclusive OR 10

OR ANY_BIT Logic OR 11

All operands also: Expression, literal, variable, direct address

Page 41: 2. PLC Basics

Structured Text Example

ST Example

Comment

FFB-Declaration

AND-Function with Allocation

FFB call with Allocation

AND-Function with Allocation

FFB call with Allocation

Page 42: 2. PLC Basics

Instruction List Programming

Page 43: 2. PLC Basics

Instruction List (IL) Instruction List (IL) is a low level textual language which has a

structure similar to a simple machine assembler. The IEC has developed IL by reviewing the many low level languages

offered by PLC manufacturers. IL provides a wide range of operators that represent those most

commonly found in proprietary instruction list languages of current day PLCs

Page 44: 2. PLC Basics

Understanding IL With IL the following operations can be executed:

logical (AND...), arithmetic (ADD...), compare (GT...) operations and assignments (ST, S, R).

Jumps within a section unconditioned / conditioned (JMP / JMP C, JMP CN)

Functions and function blocks unconditioned / conditioned (CAL / CAL C, CAL CN)

Before invoking an FFB, it has to be declared using VAR and END_VAR.

Each FFB instance must be invoked once. FFB-call:

with CAL and a list of input parameters or with CAL and Load/Save of the input parameters or by using the input operators.

Page 45: 2. PLC Basics

Understanding IL – Operators Operator Modifier Operand / Significance

LD N Loads the value of the operand into the Accumulator Literal, variable, direct address from data type ANY

ST N Saves the value of the Accumulator in the operandLiteral, variable, direct address from data type ANY

S Sets the operand to 1 if the Accumulator content is 1Literal, variable, direct address from data type BOOL

R Sets the operand to 0 if the Accumulator content is 1 Literal, variable, direct address from data type BOOL

AND N, N(, ( Logic AND OR N, N(, ( Logic OR XOR N, N(, ( Logic exclusive OR ADD ( Addition SUB ( Subtraction MUL ( Multiplication DIV ( Division GT ( Compare : > EQ ( Compare : = NE ( Compare : <> LT ( Compare : < JMP C, CN Jump to label CAL C, CN FBNAME (name of instance) Invoking a FFB FUNCNAME Executing a function Literal, variable, direct address

(data type is subject to function) ) Editing reset operations

Page 46: 2. PLC Basics

Understanding IL – Rules When entering keywords, separators and

comments, there is an immediate spell check

If a keyword, a separator or a comment is detected, it is identified with a color shading.

If unauthorized keywords (instructions or operators) are entered, this will be identified through color shading as well.

Spaces and tabs have no effect on syntax, they can be used anywhere.

Page 47: 2. PLC Basics

Instruction List Example

IL example

Comments

FFB-Declaration

AND-Function Assignment FFB call

Assignment AND-Function

FFB call

Assignment

Page 48: 2. PLC Basics

Sequential Function Chart

Page 49: 2. PLC Basics

Sequential Function Chart (SFC) A Sequential Function Chart is a graphic method of representing a

sequential control system by using a sequence of steps and transitions.

Each step is a command or action that is either active or inactive. The flow of control passes from one step to the next through a

conditional transition that is either true or false.

TransitionJump

S_2_1

Step

S_2_1

Parallel Branch

Parallel Joint

Alternative Branch

Alternative Joint

SFC - Elements

Page 50: 2. PLC Basics

Understanding SFC

1. A Sequential Flow Chart section

must have an Initial Step and

only one Initial Step.

2. A Transition must follow a Step.

3. A Step must follow a Transition.

SFC Rules

Page 51: 2. PLC Basics

Understanding SFC SFC - Elements: The Step

Step types are the initial step or steps.

A step becomes active when the prior transition has been satisfied

A step becomes inactive when the succeeding transition has been satisfied AND the step delay time has elapsed.

None, one or multiple actions, with qualifiers, can be declared for each step.

A supervision time can be defined for each step.

Page 52: 2. PLC Basics

Understanding SFC SFC - Elements: The Transition

A transition is the condition that transfers control from one step to another.

Only transitions following active steps are solved / evaluated. When a transition is True on the next scan:

The preceding step(s) is deactivated The following step(s) is activated The True transition between the steps is no longer solved The transition following the new active step is solved

Page 53: 2. PLC Basics

Understanding SFC SFC - Elements: The Jump

The jump allows the program to continue from a different location.

A jump can be used in two ways: sequence jump sequence loop

Jumps into or out of a parallel sequence area are not possible.

Page 54: 2. PLC Basics

SFC Example

Up Limit SW

Slow Speed Limit SWBottom Limit SW

Up Limit SW

Slow Speed Limit SWBottom Limit SW

Up Limit SW

Slow Speed Limit SWBottom Limit SW

Up Limit SW

Slow Speed Limit SWBottom Limit SW

Wait

Up Limit SW reached

Lower Fast, drill motor on

Start Pushbutton Pressed

Lower Slow, drill motor on

Slow Speed Limit SW reached

Raise Drill, drill motor on

Bottom Limit SW reached

Start

Start

Start

Start

Page 55: 2. PLC Basics

Programming Example

Page 56: 2. PLC Basics

ObjectiveHere, we want the fill motor to pump lubricating oil into the tank until the high level sensor turns on. At that point we want to turn off the motor until the level falls below the low level sensor. Then we should turn on the fill motor and repeat the process.

Here we have a need for 3 I/O (i.e. Inputs/Outputs). 2 are inputs (the sensors) and 1 is an output (the fill motor). Both of our inputs will be NC (normally closed) fiber-optic level sensors. When they are NOT immersed in liquid they will be ON. When they are immersed in liquid they will beOFF.

PLC

Motor

Drain

Oil Tank

Page 57: 2. PLC Basics

DesignHere we have a need for 3 I/O (i.e. Inputs/Outputs). 2 are inputs (the sensors) and 1 is an output (the fill motor). Both of our inputs will be NC (normally closed) fiber-optic level sensors. When they are NOT immersed in liquid they will be ON. When they are immersed in liquid they will be OFF.

PLC

Motor

Drain

Oil Tank

Input Address :

Low : 0000High : 0001

Output Address :

Motor : 0500

Internal Utility Relay : 1000

Page 58: 2. PLC Basics

The Logic – Electrical Diagram

Low

High

Aux. Contactor – K1

K1-1 K1-2

Motor Contactor

Page 59: 2. PLC Basics

The Logic – Ladder Logic

Low High Temp. Bit

Motor

0000 0001 1000

1000

1000 0500

Page 60: 2. PLC Basics

Program Scan

Low – 0000

High – 0001

Temp. Bit – 1000

0000 0001 1000

1000

1000 0500Motor – 0500

0000 0001 1000

1000

1000 0500

1st Scan Start 1st Scan Complete

Page 61: 2. PLC Basics

Program Scan

Low – 0000

High – 0001

Temp. Bit – 1000

0000 0001 1000

1000

1000 0500Motor – 0500

0000 0001 1000

1000

1000 0500

2st Scan Start 2st Scan Complete

Page 62: 2. PLC Basics

Program Scan

Low – 0000

High – 0001

Temp. Bit – 1000

0000 0001 1000

1000

1000 0500Motor – 0500

0000 0001 1000

1000

1000 0500

X Scan Start X Scan Complete

Page 63: 2. PLC Basics

Program Scan

Low – 0000

High – 0001

Temp. Bit – 1000

0000 0001 1000

1000

1000 0500Motor – 0500

0000 0001 1000

1000

1000 0500

X+1 Scan Start X+1 Scan Complete

Page 64: 2. PLC Basics

Questions . . .? ? ? ?