Introduction • Today programmable controllers are found in almost all areas of life. • In the past control tasks were solved with switch and relay controls. The function of controller was defined through the wiring and combination of switching elements. • For PLC, the wiring effort is considerably less. The function of controller is defined by program.
Outline • Section 1: Brief Introduction of Relay Control Panels • Section 2: Basic Components of PLC System • Section 3: Program Execution In PLC • Section 4: Basic PLC Programming • Section 5: Extending Ladder Logic Beyond Relay Logic
Section 1: Brief Introduction of Relay Control Panels
Before the invention of the Programmable Logic Controller (PLC), most industrial control was done using relay control panels. Logical decisions are made on relay control panels by wiring several to thousands of : Switches Relays
Pin 2 Pin1 Pin 3 Switch Switch is a type of binary state device. Take push button switch as example, it has two state: released and pressed Movable Contact • Depending on the wiring, switch has two different usages: • “normally closed switch” : • Pins 1 and 2 are wired to the circuit. • When the switch is released, current can pass through (closed circuit). • “normally open switch” : • Pins 1 and 3 are wired to the circuit. • When the switch is released, current cannot pass through (open circuit).
1 2 3 Relay • A relay is an electrically operated switch, which consists of coil and switch. • When no current is passed through the coil, pin 1 and 2 are connected. • When current is passed through the coil, the contact is pulled by electromagnetic force and pin 1 and 3 are connected. 1 • Combinations of switches and relays can realize simple to extremely complicated logical operations. • Control function is defined through wiring switching elements. 2 3 Coil off: Pin 1 and 2 connected Coil on: Pin 1 and 3 connected
V+ 2 3 “NOT” operation • Input connected to one relay, whose switch is wired as a normally closed switch Input Output
V+ 2 2 3 3 “AND” operation • Two relays in series • Input 1 connected to one relay, whose switch is wired as a normally open switch • Input 2 connected to the other relay, whose switch is wired as a normally open switch Input 1 Input 2 Output
V+ 2 2 3 3 “OR” operation • Two relays in parallel • Input 1 connected to one relay, whose switch is wired as a normally open switch • Input 2 connected to the other relay, whose switch is wired as a normally open switch V+ Input 1 Input 2 Output
V+ V+ 2 3 “XOR” operation • Four relays, two paths in parallel, on each path two in series • Input 1 connected to two relays, one on each path, whose switches are wired as a normally open switch and normally close switch, respectively • Input 2 connected to the other two relays, whose switches are wired opposite to Input 1 on each path Input 1 1 1 2 2 3 3 1 1 Input 2 Output 2 3
Problems with relay control panels: • Mechanical Relays and switches failed regularly (coil failure, contact wear and contamination, etc.) • Difficult to diagnose problems and replace relays and switches • Difficult to change hardwired logic (example: changing an “OR” circuit to “XOR”) • Consumed a lot of power To address these problems, Richard E. Morley of Bedford Associates invented the first PLC as a consulting project for General Electric in 1968. Bedford Associates is currently named Modicon and is a supplier of PLCs.
Section 2: Basic Components of PLC System
Basic PLC System Components include: • Power Supply • CPU • Signal Modules (expandable I/Os) • Communication Modules • HMI(Human Machine Interface) • Programming Device (e.g. PC) Siemens SIMATIC S7-1200 PLC system will be used as an example, which is installed in the Mechatronics Laboratory in 2012.
Power Supply • Every PLC has an external or internal Power Supply. • Typically 24 Volts for industrial PLCs. • Power Supplies convert 110V AC to 24V DC. • Power Supplies may have more than one isolated outputs. • One isolated output is reserved for the PLC CPU. The rest are reserved for other components such as communication module. The S7-1200 PLC uses the Siemens A&D PS307 5A power supply. The PS307 5A can source 5 amps of current at 24 volts. The PS307 5A has 3 isolated outputs. Siemens 07 5A
CPU • Every PLC system has at least one CPU The SIMATIC S7-1200 system comes in four different models, with CPU 1211C, CPU 1212C, CPU 1214C and CPU 1215C, that may each be expanded to exactly fit the application requirements. In our lab PLC system, CPU 1214C DC/DC/DC is used , which accepts up to eight signal modules at the right side of the CPU. The digital and analog I/Os can easily be expanded without affecting the physical size of the controller by installing a signal board inside the front of the CPUs. CPU 1214C DC/DC/DC
CPU ( Continued) • User Memory Areas on a CPU : • LOAD Memory • Non-volatile storage for the user program, data and configuration • For CPU 1214C: 2MB integrated Load Memory + SIMATIC Memory Card (optional) • WORK Memory • Volatile storage for some elements of the user project while executing. • When PLC starts, The CPU copies some elements of the project from load memory into work memory. • For CPU 1214C: 50 Kbytes of WORK memory • Retentive Memory • non-volatile storage for a limited quantity of work memory values • For CPU 1214C: 2 Kbytes of Retentive memory
CPU ( Continued) • Bit Memory (M) • Bit memory is a free area of RAM that can be used by the programmer • For CPU 1214C: 8192 bytes of WORK memory • Process Image • Process Image input (I) is memory location for each physical input pin • Process Image output (Q) is memory location for each physical output pin • To immediately access the physical inputs and physical outputs, append a ":P" to the address (e.g. I0.1:P).
Signal Modules (expandable I/Os) • CPU 1214C has 14 integrated digital inputs and 10 digital outputs • The number of input/output pins can be increased by adding additional signal modules to the right side of CPU. • Up to 8 digital or analog signal modules can be added to CPU 1214C. In our lab, we don’t have expanded signal modules.
Communication Module • CPU 1214C has an integrated Ethernet interface, which support the PROFINET communication with PCs, HMIs, other CPUs , etc. • Communication Module works like a hub or router, which provide multiple Ethernet ports to support multi-point communication. • Up to 3 communication modules can be added to any of the SIMATIC S7-1200 CPUs. • The RS485 and RS232 communication modules can also be added, which we don’t’ use in our lab and will not talk about in this lecture. PROFINET is the open standard based on Ethernet widely used in industrial communications. You can find a lot of information on line.
HMI(Human Machine Interface) • SIMATIC HMI KTP600 Basic Color Panel is connected with PLC CPU. • It has a 6 inch touch screen. • It has an Ethernet interface. • The user interface is programmable using TIA Portal.
Wiring of basic PLC components in lab CPU Communication Module PC Power Supply Power Cable Ethernet Cable HMI
Initially PLC was invented to directly replace relay control panels based on mechanical relays. • However, the power of PLC CPU make it possible to realize much more complicated controls than relay control panels. • The function of controller is defined by user program instead of wiring in the case of relay control panels.
PLC Operating System • The operating system is a program that is needed for the basic operation of PLC. • It is located on the CPU of a PLC. • It serves as a bridge linking between the user program and the hardware. • It also controls the communication between PLC and programming device (e.g. uploading user program, online debugging).
User Program • User program is a program which is created by PLC programmer to solve certain control tasks. • It is created with the help of programming device and uploaded to the PLC after compiling. • The Siemens TIA Portal (Totally Integrated Automation Portal ) is the programming environment where we can configure hardware and do the programming. • Three programming languages: • Function Block Diagram (FBD) • Statement List (STL) • Ladder Logic (LAD) • It’s easy to switch between different programming languages based on preference. • Ladder logic is a visual programming language, we will discuss it in detail later in this lecture.
Cyclical Program Execution • After the user program is uploaded to PLC, the operating system cyclically processes the user program • User programs and data are arranged in program blocks. • TIA portal will create a program block Main [OB1] automatically. • We start to program in OB1 and can create other blocks for better organization of programs. • OB1 is like the main function in C and is the entrance point of user programs. • The operating system cyclically execute the OB1 in a continuously running repeat loop. • This process is called cyclical program execution and each loop is a program cycle.
Cyclical Program Execution cont’ • Within each program cycle: • Reads Input pins and updates Process Input Image • Executes User Program Once (OB1) • Writes Process Output Image to Output pins • Take care of system processes ( such as communications with other PLCs, updating user program, checking for STOP condition, etc..) • Loop Back Update Process Input Image Execute User Program Update Output Pins program cycle Operating System
Cyclical Program Execution cont’ • PLC loads the states of all inputs in its memory (Process Input Image) first in each program cycle • ----Guarantee a constant signal state of inputs during the entire program cycle • After completion of execution of user program, all output pins are updated simultaneously based on Process Output Image • ----Guarantee all output states are resulting from the same set of input states • If the user program is revised, the new program is written first to LOAD memory. In each program cycle, after updating output pins, the operating system will copy the new program to WORK memory from LOAD Memory. During the next scan cycle, the new user program will be executed • ----Make it possible to upload new program to PLC during its running and without interrupting current program • The minimum response time for changing inputs is one program cycle, the maximum response time is two cycles.
PLC’s logic control is defined by user program instead of hard wiring of relay control panels. Ladder Logic is a graphical programming language. The programming process involves dragging and dropping elements, arranging them and specifying their corresponding memories and parameters. In this section, we will first talk about how to address memories in PLC CPU. Then we will learn how to realize simple logical operations in PLC using Ladder Logic.
___ ___ . ___ Memory Area Notation Byte Address Bit Number Memory Addressing • To address a bit of memory • To address a byte, word, or double word ___ ___ ___ Size of Addressed Memory Notation Memory Area Notation Byte Address
Memory Addressing (continued) Memory Area Notations: (Note: Advanced features such as Timers, Counters, Data Blocks will not be discussed in this lecture)
Memory Addressing (continued) Size of Addressed Memory Notations: • Byte Address: • Each Memory Area is addressed in one byte increments starting at byte 0. • Bit Number: • MSBit is 7 and LSBit is 0
Memory Addressing (continued) Examples: MB0 M1.3 (Note: only bit 3 of Marker Area byte 1) MW1 MD3 MD4
Ladder Logic • A ladder logic program has a “ladder” look. • The program is mapped in one or more networks. • On the left edge, the network contains one power rail. • Current flows from power rail to ground through each rung. • A rung is ended with a coil which is the result of logic operation of upstream elements on the same rung. Network 1 %Q0.1 “LED1” %I0.1 “Button1” %I0.2 “Button2” Power Rail Ground
Ladder Logic • In a network, there is at least one rung from the power rail. • The power rail can be extended with several rungs and branches can be started from or close to any rung. • Inputs and outputs are stored in CPU memories. • Tags make the memory location meaningful to programmer. • Elements are dragged and dropped to rungs from tool box. Network 1 %Q0.1 “LED1” %I0.1 “Button1” %I0.2 “Button2” %Q0.2 “Motor” Power Rail Ground %Q0.3 “LED1” %I0.3 “Button3” %I0.4 “Button4”
Ladder Logic : Basic Elements on Rungs <address> Normally Open Contact Current can be passed when the corresponding memory bit has value “1”. Corresponding memory bit is specified above it. <address> Current can pass through it when the corresponding memory bit has value “0”. Corresponding memory bit is specified above it. Normally Closed Contact <address> Corresponding memory bit will be set to “1” when current passes through it. Corresponding memory bit will be set to “0” when no current passes through it. Corresponding memory bit is specified above it. Coil Start a parallel branch from a rung. Open Branch Close Branch Close a branch to a rung.
Ladder Logic: “NOT” operation Network 1 • Drag and drop a Normally Closed Contact. Designate the corresponding memory bit as I0.0 (put “%” in front of global memory). “Button” is an example tag entered for this memory bit when a button is wired to PLC input pin associated with I0.0 • Drag and drop a Coil to end the rung. Designate the corresponding memory bit as Q0.0. “LED” is an example tag entered for this memory bit when a LED is wired to PLC output pin associated with Q0.0 • When I0.0 is set to 1, no current can flow to the coil, Q0.0 is set to 0. • When I0.0 is set to 0, current can flow to the coil, Q0.0 is set to 1. %Q0.0 “LED” %I0.0 “Button”
Ladder Logic: “AND” operation Network 1 %I0.0 “Button1” %I0.1 “Button2” %Q0.0 “LED” • Drag and drop two Normally Open Contacts and put them in series on a rung. Designate the corresponding memory bit as I0.0 and I0.1, respectively. Create any meaningful tag based on your application. • Drag and drop a Coil to end the rung. Designate the corresponding memory bit as Q0.0. Create any meaningful tag based on your application. • Only when both I0.0 and I0.1 are set to 1, current can flow to the coil and Q0.0 will be set to 1. • Otherwise no current can flow to the coil, Q0.0 is set to 0.
Ladder Logic: “OR” operation Network 1 %I0.0 “Button1” %Q0.0 “LED” %I0.1 “Button2” • Drag and drop two Normally Open Contacts andput them in parallel and merging to one rung . Designate the corresponding memory bit as I0.0 and I0.1, respectively. Create any meaningful tag based on your application. • Drag and drop a Coil to end the rung. Designate the corresponding memory bit as Q0.0. Create any meaningful tag based on your application. • Only when both I0.0 and I0.1 are set to 0, no current can flow to the coil and Q0.0 will be set to 0. • Otherwise current can flow to the coil, Q0.0 is set to 1.
Ladder Logic: “XOR” operation Network 1 %I0.0 “Button1” %Q0.0 “LED” %I0.1 “Button2” %I0.0 “Button1” %I0.1 “Button2” • Both I0.0 and I0.1 are controlling one Normally Open Contact and one Normally Closed Contact. The four elements are arranged as shown above, and finally merges to one Coil. • Only when I0.0 and I0.1 are set differently, current can flow to the coil and Q0.0 will be set to 1. • Otherwise no current can flow to the coil, Q0.0 is set to 0.
Section 5: Extending Ladder Logic Beyond Relay Logic
PLC’s CPU can be used for more than relay logic as relay control panels. Ladder logic has advanced components that take advantage of the CPU. These components can be categorized as follows: Bit logic, Counters, Comparator, Convert, Math, Program control, Shift/Rotate, Timers, and so on. It is impossible to cover all of these components in this lecture. This section will first explain data types supported by PLC S7-1200. Then, only a few categories and examples of advanced components will be presented. All advanced components can be found in the instruction window of TIA portal and pressing <F1> will open the help window showing the details of the component and how to use them.
PLC support a wide variety of data types. The complete description is located at Programming a PLC->Creating a user program->Programming basics->Data types under the Contents tab in Help window. A screen capture is shown here. We will extract some frequently used data types and present them here.