1 Trademarks All terms mentioned in this book that are known to be trademarks have been appropriately marked. Use of a term in this book should not be regarded as affecting the validity of any trademark. The following terms are registered trademarks of Rockwell Automation Inc. Allen Bradley SLC500 PLC-5 ControlLogix CompactLogix DriveLogix SoftLogix FlexLogix RSLogix 5 RSLogix 500 RSLogix 5000 The following terms are registered trademarks of Schneider Electric Industries Twido TwidoSuite TwidoSoft TSX Micro TSX Premium Unity Pro The following terms are registered trademarks of Siemens Corporation. Simatic Simatic Step 7-Micro/Win32
2 Copyright Information Copyright 2009-2010 ThePlcCorner.com All rights reserved. No part of these pages may be used for any purpose other than personal use. Therefore, reproduction, modification, storage in a retrieval system or retransmission, in any form or by any means, electronic, mechanical or otherwise, for reasons other than personal use, is strictly prohibited without prior written permission from the author. About the Author Francisco Chumbiauca is an Electronics Engineer. He has worked at Schneider Electric, Peruvian branch (2 years internship at the automation laboratory giving technical support to system integrators) and Rockwell Automation (Field Support Engineer for 3 years, teaching certification trainings and supporting installed base in the Andean Region: Peru, Ecuador, Colombia and Venezuela). He has also developed automation projects for industrial and mining companies in Peru.
3 Content Content... 3 INTRODUCTION... 6 A REVIEW OF PLC ARCHITECTURE... 8 THE PROGRAM... 8 COMPACT AND MODULAR CONFIGURATIONS... 10 DIGITAL AND ANALOG SIGNALS... 12 INPUTS... 13 OUTPUTS...14 PROGRAMMING SYSTEM... 15 DATA TYPES... 15 UNDERSTANDING THE PLC MEMORY... 16 INPUTS AND OUTPUTS IMAGES... 18 BIT AND INTEGER MEMORY FILES... 22 REAL MEMORY FILES... 26 MEMORY FILES FOR TIMERS AND COUNTERS... 28 LABELS AND SYMBOLS... 30 SCAN PROCESS... 30 LADDER DIAGRAM... 32 AND LOGIC... 34 OR LOGIC... 35 BIT INSTRUCTIONS... 37 Bit Input Instructions... 37 Bit Output Instructions... 38 Set-Reset / Latch-Unlatch Bit Output Instructions... 41 TIMER INSTRUCTIONS... 42 TIMER ON-DELAY... 42 TIMER OFF DELAY... 43 TIME BASE... 44 ADDRESSING TIMERS IN RAM MEMORY... 44 Referencing timer associated data while programming... 45 COUNTER INSTRUCTIONS... 48
4 ADDRESSING COUNTERS IN RAM MEMORY... 50 COMPARISON INSTRUCTIONS... 52 MOVE INSTRUCTION AND EDGE DETECTION INSTRUCTIONS... 54 MATH INSTRUCTIONS... 57 OPERATION BLOCK... 58 APPLICATION - COUNTING... 59 APPLICATION MOTOR STARTER... 61 EXAMPLE OF LADDER PROGRAMMING ENVIROMENTS... 66 FUNCTION BLOCK DIAGRAM... 69 BIT LOGIC FUNCTIONS BLOCK INSTRUCTIONS... 72 SET AND RESET... 74 NEGATE BOOLEAN INPUT... 75 COMPARISON INSTRUCTIONS... 76 TIMERS AND COUNTERS... 78 MATH INSTRUCTIONS... 80 ANALOG FUNCTION BLOCK INSTRUCTIONS... 81 SCALE (SCL) INSTRUCTION... 81 ALARM (ALM) INSTRUCTION... 83 STRUCTURED TEXT... 86 ASSIGNMENTS... 86 ASSIGNMENT WITH ARITHMETIC OPERATORS... 87 ASSIGNMENT WITH BOOLEAN EXPRESIONS... 88 ADDING COMMENTS... 89 CONTROL FLOW STATEMENTS... 89 IF THEN... 89 CASE OF... 90 FOR DO... 91 WHILE DO... 93 REPEAT UNTIL... 93 SEQUENTIAL FUNCTION CHART / GRAFCET... 96 STEPS... 98 TRANSITIONS... 99 TIME BASED TRANSITION... 100
5 PROJECT Traffic lights... 102 BRANCHES... 107 SELECTION BRANCH... 108 SIMULTANEOS BRANCH... 109 ACTION QUALIFIERS... 111 PROJECT MIXER TANK... 117 INSTRUCTION LIST... 121 Example AND logical operation... 122 Example OR logical operation... 123 Example AND / OR... 123 Example AND / OR... 124 Example Negated bits... 125 Example SET / RESET bits... 126
6 INTRODUCTION This book is designed to help people who want to start programming PLC (Programmable Logic Controllers). PLCs, which are worldwide used in industries and machines, has input lines which allow it to know what is happening in the process (temperature above or below certain level, pushbuttons pressed, object detected on conveyor, etc) and has output lines which allow PLC to modify the process (open or close a valve, start a motor, etc). But, how the PLC knows the moment in which the valve must be closed or the motor must start? The program is the one that tells the PLC what to do and when to do it. For programming PLC there are a lot of languages and environments. The most common language is called Ladder diagram. Early PLCs, in the 1960s, 1970s and even 1980s, were programmed using proprietary programming terminals. Nowadays, PLCs are programmed using special programming software installed in a PC or laptop. The international standard IEC 61131-3 specifies the syntax and semantics for five programming languages for PLCs: Ladder diagram, Function Block Diagram, Structured Text, Sequential Function Chart and Instruction List. Almost all PLCs support at least one of these languages and this book explains the basics for these five PLC programming languages standardized by IEC 61131-3. This book is focus on the fundamental concepts of PLC programming, which are common to almost all manufacturers. Here you will learn the syntax and programming environment of the five standardized programming languages. All the PLC programming editors have the same common standard instructions but also each PLC vendor has its own custom functions. This book is focused on the common instructions for most PLCs manufacturers. Upon finishing this book, you must be able to draft a PLC program in any of the five languages and easily adapt it to the PLC of your choice. This book is not focused on a particular programming environment; you should learn about the vendor specific programming environment you have chosen in order to apply there all the programming knowledge you have acquired from this book. Even though the five languages explained in this book are standardized, it is impossible to take an application that runs in a PLC and copy it to another type of PLC (for example, taking a program from a Siemens PLC and try to
7 run it on a Allen Bradley PLC). Among the things that prevent us from moving an application to another type of PLC are: different vendors use different scheme to address inputs and outputs, each vendor may have implemented different set of instructions, the organization of the PLC memory vary from vendor to vendor (different naming conventions for data files, different size of arrays, etc). In this guide it is explained the most used naming conventions and input/output addressing modes used by most PLC manufacturers. The fundamental concepts of PLC programming are common to most PLCs, for example, all ladder editors from all manufacturers have open contacts, close contacts, timers, counters, output coils, move instructions, math instructions, etc. You just need to get familiar with the programming software of the PLC you want to use in order to know how to place instructions into the ladder editor, how to configure instructions, available instructions (advanced instructions may vary from one PLC to another), naming convention, addressing, etc. Once you have learned the five languages, you need to consider some factors before deciding which to use for your application. First of all, not all the PLCs are capable of running all the five programming languages, especially if you are using a micro PLC; you must select a language allowed by your PLC. Each one of the five languages has different capabilities. Ladder diagram has universal acceptance and it is easier to modify the code later; when working with conditional operations, ladder diagram is the best choice. For implementing complex mathematical operations the easier language is Structured Text (it is also the easiest to understand for PC programmers). For applications with concurrent operations and repeating process, Sequential Function Chart is a good choice. For close loop control, the best choice is Function Block Diagram. The instructions and programming syntax explained in this book are common to many PLC manufacturers; some instruction names may vary from one manufacturer to another, but the behavior of the instructions is almost the same in most PLC. Some examples in this book are shown using more than one programming environment from different vendors, so you can compare the instructions, syntax and addressing from two different environments. Read carefully all the examples, exercises and projects in this book. Understand very well the basics of Ladder diagram language and then you may go on with the other languages. I really hope you enjoy this book. THE AUTHOR