PLC programming Part 2: Programming. Topics  The structure of a PLC program  PLC operation  Execution of a PLC program  Programming languages.

Slides:



Advertisements
Similar presentations
Programming with Ladder Logic
Advertisements

Unit 7 Discrete Controllers
ARITHMETIC LOGIC SHIFT UNIT
PROGRAMMING. Each PLC manufacturer offers a different set of instructions within its PLC family. Many of these instruction sets are not applicable to.
Programmable Logic Controllers
Switchgears Control Using SCADA System Based on PLC
5/20/2015IENG 475: Computer-Controlled Manufacturing Systems 1 IENG Lecture 14 Ladder Logic Programming of PLCs.
PLC OPERATION & PROGRAMMING Dr. ONUR TOKER. What is a PLC ? PLC is a computer system controlling a process. inputs - the keyboard is analogous to a proximity.
Chapter 2: Input, Processing, and Output
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Lecture 4: Programmable logic Controllers
Chapter 19 Fundamental PLC Programming
Programming with Function Blocks
Lecture 6: PLC: Timers and Counters
Introduction to VHDL (part 2)
Advanced Instructions Most PLCs now support more advanced functions such as Floating point math, Boolean operations, Shifting, Sequencing, Program control.
Programmable Logic Controllers
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
Industrial Process Control System Simon Hui Engineer Control and Informatics, Industrial Centre.
CoE3DJ4 Digital Systems Design
Programming PLCs using LADDER Logic
Programmable Logic Controller (PLC)
Memory Layout and SLC500™ System Addresses. Processor Memory Division An SLC 500 processor's memory is divided into two storage areas. Like two drawers.
Input, Output, and Processing
Memory Layout and SLC500 System Addresses. Processor Memory Division An SLC 500 processor's memory is divided into two storage areas. Like two drawers.
Implementing software in IEC Languages in IEC IEC uses the following languages Instruction List – Assembly level programming using.
Chapter 10 Advanced Programming, PLC Interfacing, and Troubleshooting
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
© ABB University - 1 Revision C E x t e n d e d A u t o m a t i o n S y s t e m x A Chapter 11 Structured Text Course T314.
Timers and Counters by Dr. Amin Danial Asham. References  Programmable Controllers-Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.
PLC PROGRAMMING.
LADDER PROGRAMMING LANGUAGE by Dr. Amin Danial Asham.
Programming Languages IEC :The International Electromechanical Commission assigned the research committee 65A to define a PLC standard. Objective.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Prepared by: Engr. Qurban Ali Memon 11ES (SEC- 1 & 2)
1 RLL: Relay Ladder Logic CONTENTS 1. PLC operation 2. PLC programming 3. Ladder logic 4. Memory and gates.
PROGRAMMABLE LOGIC CONTROLLER (PLC) AND AUTOMATION
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
PLC ARCHITECTURE – Memory 2 by Dr. Amin Danial Asham.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Controlling Program Flow with Decision Structures.
Sequencers SQO,SQC,SQL.
Traditionally ladder logic programs have been written by thinking about the process and then beginning to write the program. This always leads to programs.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Concept V2.5 Lesson 17 Objectives: After completing this lesson, the learner will be able to: –Program logic using the ST Editor. –Demonstrate an Understanding.
MECH 1500 Chapter 4. MECH 1500 The Binary Concept 4.1.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Programmable Logic Controller
Actuators and Control, Part 4 Grant Agreement No LLP UK-LEONARDO-LMP Project acronym: CLEM Project title: Cloud services for E-Learning.
S7-200 PLC training courses
Chapter 5.
Programmable Logic Controllers
Chapter 5.
PLC Terminology and Application
Chapter 2: Input, Processing, and Output
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Introduction to Ladder Diagram
Lesson 19: PLC Programming Techniques
Chapter 7 Additional Control Structures
Distributed Energy Engineering
` Structured Programming & Flowchart
S RAJARAJAN_ASST PROF, BSARCIS&T
Programmable Logic Controllers (PLCs)
Chapter 2: Input, Processing, and Output
Control System Applications (2)
The .ASCII and .END Assembler Input ;Stan Warford ;January 13, 2005
Overview Version 2.1, September 2006 PLCopen 2006
Control System Applications (2)
Presentation transcript:

PLC programming Part 2: Programming

Topics  The structure of a PLC program  PLC operation  Execution of a PLC program  Programming languages

The structure of a PLC program  A PLC program consists of rules that make logic relation between inputs and outputs of the controller.  Basically it uses logic operands: AND, OR, negation  The structure of the rules is IF…THEN…ELSE…

Inputs, outputs, PLC program InputsOutputs & & ≥1 Input sideOutput sidePLC program switch relay Internal states

PLC operation  Read all field input devices via the input interfaces. Execute the user program stored in application memory, then, based on whatever control scheme has been programmed by the user. Turn the field output devices on or off, or perform whatever control is necessary for the process application.

PLC operation scheme Power-on the PLC Clear the output table Input links Input table update PLC program Instruction 1 Instruction 2 … Instruction n Output table update Output links …… Input signals Output signals

Execution of a PLC program  The PLC resolves the program rule by rule (sequential execution).  The PLC operates in a synchronous way i.e. inputs does not change under a scan cycle.

Order of execution Put the result into an internal variable Set the output

Program languages  Standardized by the IEC in 1993:  Structure Text Programming (ST)  Functional Block Programming (FB)  Instruction List (IL)  Sequential Function Chart (SFC)  Ladder Diagram (LD) - most common

Structured Text Programming  A high level language  Used to express the behavior of functions, function blocks and programs  It has a syntax very similar to PASCAL  Strongly typed language  Functions:  assignments  expressions  statements  operators  function calls  flow control

Data Types SINTshort integer1 byte INTinteger2 bytes DINTdouble integer4 bytes LINTlong integer8 bytes USINTunsigned short integer1 byte UINT unsigned integer2 bytes UDINTunsigned double integer4 bytes ULINTunsigned long integer8 bytes REALreal4 bytes LREALlong real8 bytes TIMEtime duration DATEcalendar date TODtime of day DTdate and time of day STRINGcharacter strings BOOLboolean1 bit BYTEbyte1 byte WORD16 bit bit string16 bits DWORD32 bit bit string32 bits LWORD64 bit bit string64 bits

Derived Data Types TYPE (* user defined data types, this is a comment*) pressure : REAL; temp : REAL; part_count: INT; END_TYPE; Structure: TYPE data_packet: STRUCT input : BOOL; t : TIME; out : BOOL; count: INT; END_STRUCT; END_TYPE;

Variable Declarations Local variable: Use VAR, VAR_INPUT, VAR_OUTPUT, VAR_IN_OUT, VAR_GLOBAL, VAR_EXTERNAL for different variable types. VAR I,j,k: INT; v: REAL; END_VAR

Operators and Expressions ( )parenthesized expression function( )function **exponentiation -negation NOTBoolean complement + - * /math operators MODmodulus operation =comparison operators =equal <>not equal AND, &Boolean AND XORBoolean XOR ORBoolean OR Y := X+1.0; y := a AND b; v := (v1 + v2 + v3)/3 output := (light = open) OR (door = shut);

Condition Statements IF a > 100 THEN redlight := on; ELSEIF a > 50 THEN yellowlight := on; ELSE greenlight := on; END_IF; CASE dial_setting OF 1 :x := 10; 2 :x := 15; 3 :x := 18; 4,5:x := 20; (* 4 or 5 *) ELSE x := 30; END_CASE

Iteration Statements FOR I:= 0 to 100 BY 1 DO light[I] := ON; END_FOR I := 0; REPEAT I := I + 1; light[I] := on; UNTIL I > 100; END_REPEAT I := 0; WHILE I < 100 DO I := I + 1; light[I] := on; END_WHILE

Functions FUNCTION add_num : REAL VAR_INPUT I,J : REAL END_VAR add_num := I + J; END_FUNCTION Call a function: x:= add_num(1.2, 5.6); Built-in Functions: ABS, SQRT, LN, LOG, EXP, SIN, COS, TAN, ASIn, ACOS, ATAN, ADD, MUL, SUB, DIV, MOD, EXPT, MOVE), logic functions (AND, OR, XOR, NOT), bit string functions (SHL, SHR shift bit string left and right, ROR, ROL rotate bit string), etc.

Programs PROGRAM example7.1 VAR_INPUT MSI: BOOL; C1:BOOL; C2: BOOL; C3:BOOL; C4:BOOL; END_VAR VAR_OUTPUT R1:BOOL : FALSE; R2:BOOL : FALSE; R3:BOOL : FALSE; R4: BOOL : FALSE; END_VAR R1 := MS1 AND (NOT R4); R2 := R4 AND (NOT C3) AND (NOT C2); R3 := C4 AND (NOT C3); R4 := C1; END_PROGRAM

Functional Block Programming  Functional block (FB) is a well packaged element of software that can be re-used in different parts of an application or even in different projects. Functional blocks are the basic building blocks of a control system and can have algorithms written in any of the IEC languages.

An Up Counter Function Block FUNCTION BLOCK CTU VAR_INPUT CU : BOOL; R : BOOL; PV : INT; END_VAR VAR_OUTPUT Q : BOOL; CV : INT; END_VAR IF R THEN CV := 0; ELSEIF CU AND (CV < PV) THEN CV := CV + 1; END_IF; Q := (CV >= PV); END_FUNCTION_BLOCK CU : input to be counted R : reset PV : preset value Q : contact output CV : counter value. The algorithm in Structured Text:

A PID Control Function Block PID block diagram PID control algorithm SPset point PVsensor feedback KPproportional error gain TRintegral gain TDderivative gain AUTOcalculate XOUToutput to process XOmanual output adjustment cycletime between execution

Instruction List Programming  A low level language which has a structure similar to an assembly language. Since it is simple, it is easy to learn and ideally for small hand-held programming devices. Each line of code can be divided into four fields: label, operator, operand, and comment.  For example: LD MS1 STR1 loopANDNC3

Operators Operator Modifiers Description LDNload operand into register STNstore register value into operand Sset operand true Rreset operand false ANDN, (Boolean AND &N, (Boolean AND ORN, (Boolean OR XORN, (Boolean XOR ADD(addition SUB(subtraction MUL(multiplication DIV(division GT(greater than GE(greater than and equal to EQ(equal NE(not equal LE(less than and equal to LT(less than JMPC, Njump to label CALC, Ncall function block RETC, Nreturn from function or function block )execute last deferred operator Modifier “N” means negate. “(“ defers the operator. “C” is a condition modifier, the operation is executed if the register value is true.

Sequential Function Chart  A graphics language used for depicting sequential behavior. The IEC standard grew out of the French standard Grafcet which in turn is based on Petri-net. A SFC is depicted as a series of steps shown as rectangular boxes connected by vertical lines. Each step represent a state of the system being controlled. The horizontal bar indicates a condition. It can be a switch state, a timer, etc. A condition statement is associated with each condition bar. Each step can also have a set of actions. Action qualifier causes the action to behave in certain ways. The indicator variable is optional. It is for annotation purposes.

SFC Action Qualifiers: Nnon-stored, executes while the step is active Rresets a store action Ssets an action active Ltime limited action, terminates after a given period Dtime delayed action. Pa pulse action, executes once in a step SDstored and time delayed DStime delayed and stored SLstored and time limited

Ladder diagram  Based on relay logic: ON/OFF  ON/OFF events mean logic values: TRUE/FALSE  Instructions have the logic form: IF…THEN…ELSE  Conditions and consequences consist of TRUE/FALSE values combined with AND/OR and NOT operations.  Ladder diagram is a graphical interpretation of the control laws.

Example: motor control (I.) For a process control, it is desired to have the process start (by turning on a motor) five seconds after a part touched a limit switch. The process is terminated automatically when the finished part touches a second limit switch. An emergency switch will stop the process any time when it is pushed.

Example: motor control (II.) Limit switch 1-2 (LS1-2) is on: true LS1-2 is off: false Push button (PB1) is on: true PB1 is off: false Relay 1-2 (R1-2) is on: true R1-2 is off: false Timer <5 sec: false =5 sec: true

Example: motor control (III.) IF (LS1 = true OR R1=true) AND PB1=false AND LS2=false THEN R1 := true; ELSE R1 := false; END_IF; IF R1 = true AND Timer=true THEN R2 := true; ELSE R2 := false; END_IF;

Elements of a ladder diagram ( ) Open contact Closed contact Inverter/Negation Coil Application instruction Rising pulse Falling pulse Horizontal link Vertical link Open branch Closed branch Rising pulse open branch Falling pulse open branch In the followings the Mitsubishi nomenclature will be used.

Normally open contact Ladder diagramInstruction list This symbol conducts when the associated device is energized. Program operation: Device name

Normally closed contact This symbol conducts when the associated device is de-energized. Ladder diagramInstruction list Program operation: Device name

Coil  This symbol always appears just before the right vertical ladder rail. It becomes energized when the logic before it conducts. When energized, the output with the same address becomes active. In instruction mode the mnemonic is OUT, for OUTPUT ACTIVATE. This symbol occupies 1 step of program space, unless being used for a timer or counter instruction, when it can occupy up to 5 steps.

Application instruction  This symbol usually appears just before the right vertical ladder rail when used for bit control. This symbol is typically used for word device commands; however there are a few bit instructions that use the brackets as well. It becomes energized when the logic before it conducts. This symbol occupies multiple steps of program space depending on the command used.

Invert  This symbol inverts the state of all logic before it. If the logic is true (positive) at the point of the invert, the output of the invert is false (negative). If the logic is false, the invert output is true.

Rising/Falling pulse  It works similar to open contact/closed contact, however it conducts for one cycle starting at the moment when the signal changes, i.e. rises up from 0 to 1/falls down from 1 to 0.

AND instruction Ladder diagramInstruction list Program operation:

OR instruction Ladder diagramInstruction list Program operation:

The problem of multiple outputs A typical programming error to set the value of the same device in several instructions. Condition merging solves this problem.

SET/RST instructions Ladder diagramInstruction list Program operation:

PLS/PLF instructions Ladder diagram Instruction list Program operation:

Data movement (I.) Ladder diagramInstruction list Program operation:

Data movement (II.) Ladder diagramInstruction list Program operation:

Devices Device nameTypeFunction XInputGets the input signal of the PLC YOutputGives the output signal of the PLC MAuxiliary relayA logic valued internal register TTimerTiming function CCounterCounts signal changes DData register16/32 bit data container

Inputs Name: X Role: Denotes the physical PLC inputs. Explanation: IF X0=true AND X1=false then Y10:=true; ELSE Y10:=false; END_IF; (1)(2)

Outputs Name: Y Role: Denotes the physical PLC outputs. Explanation: IF (X0=true OR Y10=true) AND X1=false then Y10:=true; ELSE Y10:=false; END_IF; (1) (2)

Auxiliary relays Name: M Role: internal programmable state marker Explanation: IF (X0=true OR M507=true) AND X1=false then M507:=true; ELSE M507:=false; END_IF; Other applications: general state marker, special internal register, PLC diagnostics (1) (2)

16 bit data registers 16 bit data range: 0000h – FFFFh (Hex) (Decimal) 0:= positive number 1:= negative number 16 bit data

32 bit data registers 32 bit data range: h – FFFFFFFFh (Hex) 0-4 billion (Decimal) 0:= positive number 1:= negative number 32 bit data

Special data registers: constants Notation: K Role: decimal constant values Types: 16 ( ) and 32 ( ) bit Usage: in counters, timers, instruction parameters Notation: H Role: Hexadecimal constant values Types: 16 (0 - FFFF) and 32 (0 – FFFF FFFF) bit Usage: in counters, timers, instruction parameters

Timers Ladder diagramInstruction list Program operation:

Retentive timers Ladder diagram Instruction list Program operation:

Counters Ladder diagram Instruction list Program operation:

References  Programming.ppt 