This action might not be possible to undo. Are you sure you want to continue?
IEC 61131 Control Languages
IEC 61131 Control Languages
Copyright © 1999 ABB Automation Products AB. PostScript™ and Acrobat Reader™ from Adobe Systems Inc. Windows™. The contents of this document can be changed by ABB Automation Products AB without prior notice and do not constitute any binding undertakings from ABB Automation Products AB. All rights reserved. FIX™ from Intellution and 3964R™ from Siemens. Trademarks Registered trademarks from other companies are: Microsoft™. Release: October 2001 Document number: 3BSE 021 358 R201 Rev B Printed in Sweden. Windows NT™ from Microsoft Corporation. ABB Automation Products AB is not responsible under any circumstances for direct. 3BSE 021 358 R201 Rev B . unexpected damage or consequent damage that is caused by this document. indirect.
. . .2 1. . . . . . . . . . Benefits Offered by the Standard . . . . . . . . . . . . . . Main Objectives . . . . . . . . . . . . . . . . . . . . . . . Distributed Systems . . . .5 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 2. . . . . . . Cyclic Execution . . . . . . . . . . . . . . . . . . . . . . . . . . Five Languages for Different Needs . Software Quality . . . . . . . . . . . . . . . . . . . . . . .1 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Software Exchange between Different Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Soft PLC . . . . Well-structured Software . . . . . . . . . .3 Introduction . . . . . . Communication with Other Systems . . . . . . . . . . . . Programmable Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 25 25 25 26 27 28 28 3 IEC 61131-3 Standard 3. . . . . . Computers for Process Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Software Cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Monitoring Subsystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 31 31 32 32 32 33 33 3. . . . . . . Programming Methods . . . . Closed-loop Control Subsystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Reusable Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Programming Dialects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Computer-based Programming Tools . . .1 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . I/O Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . PLCopen Trade Association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Programming Methods . . . . . . . . . . . . . . . Portable Software Applications . . . . . . . . . . . . . . . . . .1 3. . . . . . . . . . . . . . . . . . . . . . . . . Relay Logic . Sequencing Subsystems . . . . . . . . . . . . . . . History . . .3 2. . . . . . . . . . . . Control Applications . . . . . . . . . . . . . . . . . . . . . . . . . .6 2 Why Open Systems are Needed 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 2. . . . . . . 9 9 10 12 12 12 13 13 15 16 19 20 20 21 22 23 23 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Contents 1 Evolution of Control Systems 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 3BSE 021 358 R201 Rev B 5 . .
. Not Suitable for Conditional Statements . . . . . Suitable for Complex Calculations and Looping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Weak Software Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sequence Selection and Simultaneous Sequences . . . . . . . . . . . . . . . . High Threshold for Programmers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Easy to Understand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Limited Support for Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Steps and Transitions . . . . . . . . Other Programming Languages are Needed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . IL Language Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Statements . . . . . . . . . . . . . . . . . . . . . . . .6 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Advice on Good Programming Style . . . . . . . . . . . . . Action Descriptions . . . . . . . . . . . . . . .3 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Function Block Diagram . Syntax for Function Block Diagrams . . . . . . . . . . . . . . . . . . . . . . Weak Software Structure . . . . . . . . . . . . . . . . Best System Performance . . Similar to Electrical Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 4. . . . . . Data Types . . . Difficult to Reuse Code . . . . . . . . Chart Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Identifiers . . . . . . . . . . . . . . . .5 4. . . . . . . . . . . . . . . . . . . . . . . . . IL Instruction Set . . . . . . . .Contents 4 Programming Languages 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 35 37 37 38 39 40 41 42 43 44 45 46 46 47 49 49 49 50 50 51 51 53 53 53 54 54 55 60 60 61 62 62 64 64 65 67 67 68 68 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ladder Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Operators in Expressions . . . . . . . . . . . . . . . . . . . Constant Literals . . . . . . . Structured Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Calling Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Machine-dependent Behavior . . . . Boolean Functions and Feedback are Easy to Implement . . . . . . . . . . . . . . . . . . . . . . . Subsequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Instruction List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sequential Function Chart . . . . . . . . . . . . .7 6 3BSE 021 358 R201 Rev B . . . . . . . . . . Powerful Tool for Design and Structuring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Standard Function Block Types . . . . . . . . . . . . . . . . . . Common Elements . . . . . . . . . . . . . . . . . . . . . . . . . .4 4. . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . 69 70 71 72 73 74 5 Object-oriented Programs 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . User-defined Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Reuse of Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Coding . .4 7. . . . . . . . . . . . . 103 SFC Sequence Program . . . . 104 Control Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 7. . . . .1 8. . . . . . . . . . . . . . . . . . . . . . . . . . .5 Control Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Data Flow in Real-time Systems . . . . . . . . . . . . . . . . . . . . . . . 100 Variables and Parameters . . . . . . . . . . . 105 Control Module Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 9 Glossary Index 109 117 7 3BSE 021 358 R201 Rev B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8 89 89 90 90 92 92 94 94 94 8 Industrial Application Example 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Analysis . . . . . . . Differences between Functions and Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8 Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Objects in the Plant . . . . . . . . Documentation . . . . . . . . . . . . . . . . . Coding . . . . . . . . . .2 5. . . . . . . . . . . . . . . . . . . . . . . . . . .4 83 83 84 85 86 7 Project Management 7.3 5. New Life for an Old Method . . . . . . . . . . . . . . . . . . . Program Sorting . . Type and Instances . Maintenance . . . . .Contents 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 95 8. . . . . . . . . . . . . . . . . . . . . .6 75 75 77 78 79 81 81 6 Control Modules 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Graphical Programming . . . . . . . . . . . . . . . . .3 8. . . . . . . . . . . . 101 Ramp Function Block Type . . . . . . . .6 7. . . . . . . . . . . . . . . . . . . . . . . 96 Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 5. . . . . . . . . . . . . . . . . Control Module Concept . . . . .3 6. . . . . . . . . . . . . . . . . . . . . . . Libraries . . . . . . . . . . . . . . . . . . . . . . . .1 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How to Use Function Blocks in Control Programs . . . . . Analysis . . . . . . . . .5 7. . . . . . . . . . Interaction between Languages . . . . . . . . . . . . . . . . . . . . . . . . . . Stages of a Project . . . . . . . . . . . . . . . . . . . . . .1 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 6. . .4 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Applications for Control Modules . . . . . . . . . . . . . . . . . . .2 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Automatic Code Sorting . . . . . . . . . . . . . . . . . . . . . .2 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Project Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Testing . . . . . . . . . . Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Commissioning . . . . . . . . . . . . . . Testing . . . . . . . . . . . . . . . . . . . . .
Contents 8 3BSE 021 358 R201 Rev B .
Digital transducers measure conditions with distinct states. such as on/off or high/low. pressure. the plant could be an entire nuclear reactor for producing electrical energy for thousands of people.1 Introduction Chapter 1 Evolution of Control Systems 1.Chapter 1: Evolution of Control Systems 1.1 Introduction Almost all industrial plants need some kind of controller to ensure safe and economical operation. while analog transducers measure conditions which have a continuous range. At the other extreme. the controller and the actuators. At the simplest level. Apart from their size and complexity. Transducers Actuators Plant Inputs Controller Outputs Parameters Status Fig. flow or liquid level. such as temperature. The transducers convert physical properties into electrical signals that are connected to the controller inputs. The controller monitors the actual status of the plant processes through a number of transducers. 1 Overview of the components in an industrial control system. all control systems may be divided into three well-separated functional parts: the transducers. the plant may consist of an electric motor driving a cooling fan to control the temperature in a room. 3BSE 021 358 R201 Rev B 9 .
In most control systems based on relays and ICs. 1. Relays have proven to be a very cost-effective alternative. motors. faster and also have a longer lifetime. pumps and other devices by using electrical or pneumatic energy. Most actuators create movements of valves. especially for automating small machines with a limited number transducers and actuators. Since then. electrical relays have been used in a large number of control systems around the world. Since computers can be programmed they offer a great advantage compared with the wired logic function in systems based on relays or ICs. Systems with wired logic are easy to implement but unfortunately it is difficult and time-consuming to change their behavior. 10 3BSE 021 358 R201 Rev B . ICs based on TTL or CMOS integrated circuits are much smaller. These devices had to be individually adapted to each task and due to their mechanical nature they also suffered from a short life-time. paved the way for a new generation of control systems in the 1970s. Relay logic made it possible to develop larger and much more sophisticated control functions.1. The silicon-based integrated circuit. the control algorithm is permanently defined by the electrical wiring. The control function was implemented by using ingenious mechanical devices automating some of the most repetitive and critical tasks on the assembly lines. The operator interacts with the controller by providing control parameters. In today’s industry. IC. Compared with relays. Some controllers can display process status via a screen. In the early 1970s. the first commercial computers debuted as controllers in large control systems.2 History The first control systems were developed during the industrial revolution at the end of the 19th century. In the 1920s. The electrical signals from outputs are converted into process behavior via the actuators. relay logic is seldom chosen for new control systems but a large number of older systems are still in use. mechanical control devices were replaced by electrical relays and contactors.2 History Chapter 1: Evolution of Control Systems Based on the status of the inputs the controller uses a built-in or programmed algorithm to calculate the status of the outputs.
the PLC has a limited instruction repertoire. recipes and operations reports. Compared with an office computer. difficult to program and unfortunately also very sensitive to the harsh environment in many industrial plants. The transducers and actuators in the outside world are connected via robust interface cards. the overall control function in a plant is often distributed to a number of local programmable controllers which are positioned in the immediate neighborhood of the objects which are to be controlled. In today’s industrial plants there is often a need to handle both digital control and closed-loop analog control in the same control system. 1880 Mechanics Relays ICs Computers PLCs Process computers 1920 1970 1980 1990 2000 Fig. often only logical conditions. 2 The evolution of control systems since the end of the 19th century. The operator plays a very important role in today’s industry and many plant installations therefore have a computer-based Supervisory Control and Data Acquisition System (SCADA).2 History Early computer systems were large. SCADA systems have high-resolution color monitors on which the operator can select different application programs and study the status of the manufacturing process.Chapter 1: Evolution of Control Systems 1. As a result of demands from the American car industry the Programmable Logic Controller (PLC) was developed in the early 1970s. 3BSE 021 358 R201 Rev B 11 . expensive. Early PLCs had no analog inputs and therefore they could only handle digital control applications. These systems are often called Programmable Controllers since their operation is not limited to only logical conditions. Today. The different controllers are usually connected together into a local area network (LAN) with a central supervising process computer which administers alarms. The PLC is a computer designed to work in an industrial environment.
The system indicates alarms via warning lamps or audible signals. In such systems the real process components like motors. In order to improve the quality and make it easier to reuse programs. most processes can be simplified by dividing them into a number of smaller subprocesses. valves and PID controllers are programmed via standardized program objects stored in program libraries. flow etc. Signals can also be checked for alarm conditions.3 Control Applications It is easy to be overwhelmed by the complexity of an industrial plant process. while at the same time there is a more frequent need to carry out changes in the control function. In order to monitor the sequence of actions there is a need for memory functions. Monitoring subsystems. 12 3BSE 021 358 R201 Rev B .3 Control Applications Chapter 1: Evolution of Control Systems It is characteristic of today’s industry that the demand for profitability is increasing. Sequencing Subsystems The vast majority of all subprocesses can be described via a predefined sequence of actions that must be executed in a certain order. the output status is dependent on an entire sequence of input signals having occurred. Monitoring Subsystems A monitoring subsystem displays the process state to the operator and draws attention to abnormal conditions which require some kind of action from the operator. often accompanied by a paper printout. However. sequencing subsystems and closed-loop control subsystems will be further described in the following three sections. are displayed to the operator via indicators. pressure. Such objects are well proven and have a standardized user interface.1. Many monitoring systems also keep records of the consumption of energy and raw materials for accountancy purposes. In such a system it is not possible to specify a momentary combination of input signals resulting in a certain output signal. bar-graphs or via a computer screen. Instead. the cost of development and maintenance of software has become the predominant factor. meters. there are today many more people working with object-oriented systems. 1. The system may also create automatic warnings when critical components need to be exchanged. Such subprocesses can normally be divided into three different categories. Because the cost of computer equipment has fallen dramatically in recent years. The measured process values for temperature.
Normally. Integral and Derivative (PID) controller. Desired value SP PV Actual value Transducer Error SP-PV Control algorithm Actuator Process Controlled variable Fig. The control algorithm will try to adjust the actuator until there is zero error. flow or pressure that must be automatically maintained at some preset value or made to follow other signals. Relay logic systems contain a number of relays that are activated by digital transducer contacts. Closed-loop Control Subsystems Many subprocesses have analog variables such as temperature. by how the contacts are connected to each other and to the corresponding relay coils. This error signal is supplied to a control algorithm that calculates an output signal. a variable in the plant denoted PV (Process Value) is to be maintained at a desired value denoted SP (Set Point).4 Relay Logic The electromagnetic relay has been one of the most important components in the evolution of control systems. the PV can be made to track a changing SP. which affects the corresponding variable in the process.4 Relay Logic Sequencing subsystems have many advantages over control systems based on momentarily input status. which is passed on to an actuator. Since the control function is running continuously. 3BSE 021 358 R201 Rev B 13 . Many control algorithms are available but the most commonly used is the Proportional.Chapter 1: Evolution of Control Systems 1. they are easier to implement and present a better overview of the control function. 3 A closed-loop control system. Here. 1. Such a system can be represented by the block diagram in Fig. It is also easier to localize malfunctions in a transducer since this will cause the sequence to freeze. 3. PV is measured by a transducer and compared with SP to give an error signal. once and for all. The control function is defined.
1.4 Relay Logic
Chapter 1: Evolution of Control Systems
All relay coils are normally used to activate one or more built-in switches. These switches are connected to the actuators in the process. If one of the relay switches is used as an alternate input contact the result will be a circuit with memory function.
Fig. 4 Three often-used logical conditions implemented with relay logic.
A relay-based control system may contain any number, from a dozen up to thousands, of relays. The relays with corresponding wiring are contained in one or more cabinets. The transducers and actuators are normally connected via plinths. The logical function of a control system based on relays is described in ladder diagrams, presenting how transducer contacts and actuators are electrically connected. The ladder diagrams not only describe the logical function but are also used as drawings when the relay cabinets are manufactured. Since relays are relatively costly and electrical wiring is time consuming, the total cost of a relay-based control system depends mainly on the number of relays used. In large plants the limited number of contacts on both transducers and relays sometimes leads to engineering problems.
3BSE 021 358 R201 Rev B
Chapter 1: Evolution of Control Systems
1.5 Computers for Process Control
Experience shows that it is easy to develop small relay systems with a limited number of relays, but with increasing complexity the work will demand a very experienced engineer. A characteristic quality of relay-based control systems is the decentralization of the logic function into a large number of discrete relays. Since relays are electromagnetic components they have a limited life-time. Relay-based control systems therefore need continuous maintenance and service. Another disadvantage of relay systems is that it may be very difficult and time-consuming to change the logical function in an existing plant. Today, relay logic can only be justified in very small plants with less than a dozen inputs and outputs and in plants with severe electrical interference, where computers and programmable controllers cannot be used.
Computers for Process Control
The first computers that were developed during the 1950s were very large, expensive machines. Such systems were mainly used for administrative tasks like payroll administration, accounting and banking. The operations performed were most often batch processes. Microprocessors, developed in the 1970s, started a dramatic revolution resulting in much smaller and cheaper computer systems. During the 1970s, many control systems were developed using microprocessors as controllers. The most important advantage of computers, compared with wired logic, is that the programmed control function can easily be altered. Computers are also very suitable for performing arithmetic calculations and for storing huge amounts of data. A standard computer, however, is not equipped for communication with industrial equipment. Another disadvantage is the high learning threshold for developing computer programs. Early computer-based control systems needed extra interface equipment in order to handle real-world transducer and actuator signals. These interfaces normally had to be individually developed for each plant. Since then, several vendors have developed standard interface modules for both digital and analog process signals.
3BSE 021 358 R201 Rev B
1.5 Computers for Process Control
Chapter 1: Evolution of Control Systems
All computer programs consist of a number of instructions which tell the computer what to do when the program is run, or executed as programmers prefer to say. Because computers process binary information, the computer’s instructions are very different from our own verbal ways of describing the actions we want it to take. In programming, therefore, various aids are used to process and translate our verbal function description into the computer’s own language. These aids are ready-made computer programs which can be purchased relatively cheaply.
Machine Code and Assembler
Most computers have a limited set of instructions which carry out simple operations such as fetching data, storing data, adding numbers, etc. By combining a large number of such machine codes into long programs, the programmer can get the computer to carry out very complex functions. In order for the program to work, however, it is very important to follow the rules on how instructions should be used and combined, often called the syntax of the program. Because machine codes are binary or hexadecimal numbers, the job of programming is made easier by using what are known as assembler instructions. Each of these instructions has a three-letter name (memo-code), such as LDA for fetching data and ADD for adding two numbers. A ready-made program known as an editor is normally used when writing assembler instructions into the computer. An editor program has basic word processing functions for entering and correcting text. Before the assembler program can be executed, the memo-codes must first be translated into hexadecimal machine code. The translation to machine code is done by another program called an assembler. Assembler programs of this kind can be bought for most types of computers. Apart from the actual translation, the assembler program can also help in checking syntax and in calculating logical jumps within a program. Assembly is normally carried out on the same type of computer as will be used for program execution, but there are also assembler programs, known as cross-assemblers, which can be run on other types of computers. Test running of assembler programs is made easier by special programs that allow part of the program to be executed step by step. Using these so-called debugging programs, it is also possible to simulate real-life signals so that the function can be tested without having to connect the computer to the process.
3BSE 021 358 R201 Rev B
a properly written assembler program gives good performance and the optimal usage of the computer’s memory. This is important in. for example. industrial robots and where very large series are to be produced. On the other hand. The work demands a thorough knowledge of the technical workings of the computer.Chapter 1: Evolution of Control Systems 1. the problem description also has to be restructured so that the required function can be obtained using the instructions available in the computer’s repertoire. The completed program is entirely matched to one particular type of computer and cannot be transported to another type of computer. Compiling and Interpreting The work of programming is made considerably easier if the program is written in what is known as a high-level language.5 Computers for Process Control Start Editing using editor LDA IN1 L1 Test-running using debugger SUB C CMP B BNE L1 ADD D Functioning properly? Yes Stop No STO OUT1 Assembler Assembling F6 0A A9 23 12 E3 F8 76 06 A3 45 D3 A2 Fig. Working with assembler is often called low-level language because the instructions are similar to the computer’s own way of working. which is translated into machine code by a program-based compiler or interpreter. 5 In low-level programming several supporting programs are used. Programming using assembler instructions has both advantages and disadvantages. an assembler and a debugger. such as an editor. 3BSE 021 358 R201 Rev B 17 . in order to translate the program into machine code. In most cases.
The disadvantage of programs written in high-level languages is that they take up more room in the memory than corresponding programs written directly in assembler (machine code). Instructions in a high-level language are reminiscent of mathematical functions. and are therefore relatively easy to use.5 Computers for Process Control Chapter 1: Evolution of Control Systems The difference between compilers and interpreters is that the compiler first translates the whole program before it is executed. This also means that the performance of the computer is used less efficiently. Source code in Pascal 02 0C A7 43 37 E3 F8 86 16 A2 45 A2 05 A3 12 7B Profit := Income . This means that compiled programs are executed considerably faster than interpreted ones. 6 Programs written in a high-level language are totally machineindependent and are translated to computer-specific machine code by a compiler program. 18 3BSE 021 358 R201 Rev B . An example of an interpreted language is Basic. while the interpreter translates and executes the program instructions one by one. The most common high-level languages are Pascal and the closely related language C. The actual matching to the computer is done by the compiler or interpreter in the process of converting it to machine code. while the compiled result is called object code. assuming that a suitable compiler is available.1. Another advantage is that completed programs can be moved to another type of computer.Cost IF Profit>20 THEN PRINT "Profitable" ELSE PRINT "Loss" END Compiler Fig. The programmer writing in a high-level language does not need to know the technical details of the design of the computer or its memory. Both of these are normally compiling high-level languages. Programs that are written in highlevel languages are often known as source code. and the main parts of the programs can be written so that they are independent of the type of computer on which they will be run. All high-level languages are highly standardized.
from small machine control systems. all communicating via a bus unit. The PLC is an industry-adapted computer with a simplified programming language. PLC Engineering station Memory Central unit Bus unit I/O unit Input modules Output modules Transducers Actuators Fig. Independent of brand and type. Apart from logical instructions an increasing number of today’s PLCs also have arithmetic functionality. several vendors. The process status is monitored and sampled via the I/O unit.6 Programmable Controllers In answer to demands from the car industry. 3BSE 021 358 R201 Rev B 19 . Since then. PLCs have developed into the most commonly used type of control systems in all kinds of industrial plants. Programming of PLCs is normally carried out on an external computer-based engineering station. the memory and the I/O unit. presented the Programmable Logic Controller (PLC). up to entire manufacturing lines in large process industries. Some PLCs have an option for using the engineering station for online process status presentation. The compiled program is downloaded to the central unit and then into the program memory via a serial channel or via a LAN. The central unit coordinates all activities in the PLC and executes the control program in the memory. Many vendors are therefore using the term Programmable Controller instead of PLC.6 Programmable Controllers 1.Chapter 1: Evolution of Control Systems 1. while the control program is executing. most PLCs contain three functional parts: the central unit. in the early 1970s. 7 The components of a programmable controller system. Early PLCs were originally only intended to replace relay-based control systems.
Most analog transducers represent a physical value as a current within the range 4-20 mA. Most controllers have a modularized Input/Output unit (I/O) for direct connection of the transducer and actuator signals. Such an I/O unit can easily be customized to the specific signal levels of the plant. 20 3BSE 021 358 R201 Rev B . This is often achieved by optical isolators containing a lightemitting diode and a photoelectric transistor linked together in a package. The most commonly used I/O modules are digital DC inputs and outputs with the signal levels 24 V or 48 V. if necessary. A growing number of programmable controllers have arithmetic functionality. especially for people with previous knowledge of relay-based control systems. Programming Methods The first PLCs used a programming language based on relay ladder diagrams. The programming terminal compiled the ladder diagram into machine code which was sent to the controller for execution. The program was entered via a programming terminal with keys showing contact symbols (normally open/normally closed).6 Programmable Controllers Chapter 1: Evolution of Control Systems I/O Units A characteristic quality of the programmable controller is that it is designed to live in and interact with an industrial environment. Such systems have a need for analog input and output I/O modules. Programming with ladder diagrams is a very intuitive method.1. Since there are several different signal levels in a typical plant. with 4 mA indicating the minimum value. this method was initially preferred by American PLC vendors. making it possible to study the application and also. The purpose of the I/O unit is to convert the process signals to the lower signal level used in the controller and also to suppress electrical transients from the plant equipment. Therefore. with energized contacts and coils highlighted. Many vendors also offer modules with AC inputs and outputs with signal levels of 110 V or 220V. to debug the program. relay coils and parallel branches with which a maintenance electrician would be familiar. many I/O units allow the use of exchangeable I/O modules. With the controller executing the control program was presented on a screen.
3BSE 021 358 R201 Rev B 21 . A 001 A 012 ON 020 RP A 003 = 201 Fig.Chapter 1: Evolution of Control Systems 1. only usable for that purpose. Computer-based Programming Tools Early PLCs were programmed with dedicated terminals. The editor is used to define variables and for writing the control program instructions.6 Programmable Controllers In large plants and when people without previous knowledge of relay logic are to develop the control program. but often integrated. A complete system with computer and development software is often referred to as an engineering station. Simulation makes it possible for the programmer to test the application by manually altering the input signals. Most development tools contain several different. Boolean instruction lists are often preferred. The compiler translates the control application into machine code and downloads this code for execution in the programmable controller. Program editing is normally done offline. Most European PLC vendors have chosen this as the standard programming method in their systems. together with specific systems from one vendor. The simulated status of inputs and outputs is displayed on the computer screen. software applications which simplify the work of program development for the associated control system. 8 Examples of PLC programs using a ladder diagram and instruction list. not in communication with the controller. Most editors have syntax checking that helps the programmer avoid such errors. Today. which means that the engineering station is running locally. almost all programmable controllers are programmed with standard personal computers (PCs) running a dedicated development software tool. Many development tools provide a useful function that compiles and simulates the control function in the computer without downloading it to the controller. Control Builder Professional from ABB is an example of such a software tool intended for use with some of the programmable controllers supplied by ABB.
Sequential Function Charts and Function Block Diagrams. Changes in the incoming signals can therefore only affect the output signals at the end of each completed program cycle. The consequences of a delayed reaction therefore become unacceptable. With ever-increasing performance in computer-based engineering stations. An example is a machine in which some movement must be stopped when a particular limit is reached.6 Programmable Controllers Chapter 1: Evolution of Control Systems Some development tools can be used online. when the control application is executing in the programmable controller. Cyclic Execution Industrial control systems are real-time systems. several vendors now offer developing packages.1. The required interval time of the program is determined by the maximum allowed delay time in the process. the application program must have constant access to current input data from the process. Read inputs Execute program Interval time 1 . for displaying the actual process signal status on the computer screen. If the controller does not react in time. 9 A typical program scan in a programmable controller. in which it is also possible to use programming methods like Structured text. apart from ladder diagrams and instruction lists. the result may be damage to the machine or injury to the operator. To achieve this the compiled program is executed cyclically at a specific frequency. These methods are further described in Chapter 4. which means that changes in the input signal require immediate action on the corresponding output signals.50 ms Update outputs Fig. 22 3BSE 021 358 R201 Rev B . In order to fulfil the demands on a real-time system.
Several PLC vendors have developed their own proprietary protocols during the 1990s and some of these. considerable cost savings may be achieved by using remote I/O subsystems situated close to the actual subprocess.6 Programmable Controllers Because different subprocesses may have different time demands. 3964R from Siemens and the vendor-independent Profibus. Several software vendors have presented a new type of controller called the Soft PLC.Chapter 1: Evolution of Control Systems 1. 3BSE 021 358 R201 Rev B 23 . Distributed control systems require a standardized communication protocol in order to exchange information. Unfortunately. The cabling between transducers. each with its own interval time. the instructions have different names and the rules governing the syntax of the programs may vary. This strategy will improve total performance and also reduce the risk of total breakdown in the manufacturing process. like COMLI from ABB. have slowly emerged into de facto standards supported by more than one PLC vendor. The major advantage of a Soft PLC is that all the required hardware is vendor independent. The Soft PLC is real-time software executing a control application in a standard PC and communicating with the plant via a standardized modular I/O unit. In spite of the basic functions being practically identical. none of the software vendors has managed to establish their Soft PLC software as an industry standard. If the plant is spread out over a large area. some programmable controllers provide a function for dividing the total program into different tasks. This makes it difficult to communicate and exchange application programs between systems of different manufacture. actuators and the programmable controllers accounts for one of the major costs in a control system. Distributed Systems In many large industrial plants there is a need for distribution of the entire control function to several different programmable controllers and process computers. Soft PLC One problem with PLCs is that all vendors use their own proprietary controller hardware with an associated programming language. This means that control applications developed with one Soft PLC application cannot be transferred to Soft PLCs from other vendors.
1.6 Programmable Controllers Chapter 1: Evolution of Control Systems 24 3BSE 021 358 R201 Rev B .
Chapter 2: Why Open Systems are Needed 2. also brand-specific programming dialects. it is very important that programs can be understood by a wide range of industrial personnel. Since control systems are being used in so many plants and in applications concerned with safety.1 Programming Dialects The programmable controller is one of the most critical components in today’s industry. a control program should be easy to follow by technicians. the software programs become larger and therefore more difficult to manage. unfortunately. in order to minimize risks. 3BSE 021 358 R201 Rev B 25 . more than one programmer is needed to develop the application software for industrial automation. In most cases. Experience also shows that new industrial plants often encounter problems a long time after commissioning. In real-world applications this often leads to costly double work and problems in communication between systems from different manufacturers. in the worst case. plant managers and process engineers.2 Software Quality As more and more jobs in manufacturing and process industries become automated. Some failures can interrupt production or. consequently. For almost two decades. Besides the programmer. 2. result in serious damage to the production equipment or the processed material. Experience shows that the risk of program errors grows exponentially with the number of programmers involved and.1 Programming Dialects Chapter 2 Why Open Systems are Needed 2. the size of the program itself. Many customers using programmable controllers have decided to standardize their equipment to at least two different vendors. the market has been dominated by half a dozen vendors offering very similar solutions but.
Many of these packages have very poor facilities for working with modules. With the increasingly good relationship between hardware performance and price. In most projects. Before the IEC 61131-3 standard was established. most software for control applications is adapted to the specific needs of a single plant application. this leads to a final product that only partly fulfills the customer’s requirements. Most control software is developed either by a department in the customer organisation or by small software houses working in a close privileged relationship with the machine or plant manufacturer. good software engineering was an open goal in the control application environment. performance than yesterday’s mainframe computers.3 Software Cost Chapter 2: Why Open Systems are Needed It is well-known that good software quality comes at a high cost. Even small changes and additions tend to be very costly to implement. Today’s personal computers have equally good. In both cases. This makes it possible for software vendors to lower prices dramatically. software suppliers are not motivated to strive towards more efficient development methods and tools. have become very popular. and today many useful standard applications are available as shareware. while prices are constantly falling. In many cases. greater weight is attached to standardization and reuse of programs than with finding the optimal hardware. Software quality is therefore heavily dependent on the experience and intellectual capacity of the programmer. or even better. In contrast. Distribution via the Internet has pushed the limits even further. A customer without experience in software development can only present a rough functional description to the developer. for code reuse and for documentation. standardized software packages for personal computers. therefore. 2. 26 3BSE 021 358 R201 Rev B . This means that the total development cost has to be charged to a single customer.2.3 Software Cost During the last decade. like word processors and spreadsheets. almost free of cost. The vast majority of all control code is written with the proprietary software packages delivered by the control system vendors. especially in later phases of program development. The hardware on which computer programs are run is developing at an amazing speed. Most customers find it difficult to control the total software development cost. software production and thus cost is not governed by the free market. the total cost of an installation is becoming more dependent on the time required for program development. Consequently.
Therefore. Most control vendors use their own proprietary programming dialect. the software has to pass a particularly intense testing and validation procedure. there is often a need to port existing applications from older outdated hardware to newer systems. 3BSE 021 358 R201 Rev B 27 .4 Portable Software Applications The personal computer together with the Windows operating system is today a well-established de facto standard for information handling in almost all offices in the world. To many. If the application program has been written by inexperienced programmers. which can only be used with their hardware. An automation plant or machinery can pose a danger to the operators or the material if the control software has fatal errors. Application programs developed for Windows can be used on almost all PCs around the world. In real-world applications.Chapter 2: Why Open Systems are Needed 2. 2.4 Portable Software Applications Fig. it is incomprehensible that it has taken more than 25 years for the programmable controller market to start establishing a common programming standard like the IEC 61131-3. the cost of testing even may exceed the cost of program coding. More than 25 years after the introduction of the first programmable controllers. testing may be very time consuming. especially if the work has to be done with the process running. Since the cost of developing well-tested software is much higher than the hardware cost. this market still lacks an international standard similar to that for the PC. 10 Cost of hardware versus software. The main reason for the PC’s enormous penetration is software compatibility. This is surprising since almost all industries using programmable controllers have high demands on inter-system portability of control system software.
The huge control centers in e. is the key to a successful and cost-effective application program. often made by the customer. nuclear power stations are being replaced by PC-based Supervisory Control and Data Acquisition Systems (SCADA) using a large color screen to present process pictures showing plant status. structured and designed.5 Reusable Software Not so long ago. SattLine from ABB is an example of such a Distributed Control System (DCS). 2. great emphasis is put on operator interaction with the system. even real programmers realize that the first phase in a project when the overall function is analyzed. Unfortunately. this is difficult in industrial automation since most processes are very different in behavior. 28 3BSE 021 358 R201 Rev B . The traditional method of reducing software cost is to reuse common parts of the program code in several similar applications. the control function is normally divided into a number of different programmable controllers communicating with each other via some kind of standardized communication protocol. The only way to reduce the risk of seams is to encourage (read force) all the members of the team to follow certain rules and formalism for producing code. In today’s industrial plants. to coding in their favorite language. These controllers normally had no means of interaction with the machine operator or communication with other controllers.2. Two of the most commonly used SCADA systems are SattGraph from ABB and FIX from Intellution. Today.g. In large industrial plants.6 Communication with Other Systems The first programmable controllers presented in the seventies were often placed in an electrical equipment cabinet close to the machine or process being controlled. Instead. often ladder diagram or instruction list. When the final application is the result of teamwork there are often visible seams between the parts coded by different programmers.5 Reusable Software Chapter 2: Why Open Systems are Needed 2. Another obstacle to software reuse is that the program code is often strongly affected by the programmer’s own style. they move directly from a rough specification. many “real programmers” measured their effectiveness by the amount of program code they produced per day. Real programmers don’t like to “waste” their time on structuring and detailed specification.
6 Communication with Other Systems Most control system vendors have developed their own proprietary communication protocols for information exchange in SCADA and DCS. 3BSE 021 358 R201 Rev B 29 .Chapter 2: Why Open Systems are Needed 2. All industrial plants have computer-based Management Information Systems (MIS) for handling of statistical and economic information. Unfortunately. General Motors in the USA has developed a standard called Manufacturing Automation Protocol (MAP) for communication between different programmable controllers and MIS. the MAP standard has so far not been particularly successful. resulting in a total control and management system. There is often a need to connect MIS with SCADA and DCS. Some vendors also provide software-based protocol converters enabling communication between systems from different manufacturers.
2.6 Communication with Other Systems
Chapter 2: Why Open Systems are Needed
3BSE 021 358 R201 Rev B
Chapter 3: IEC 61131-3 Standard
3.1 Main Objectives
IEC 61131-3 Standard
3.1 Main Objectives
IEC 61131-3 is the first, and so far only, global standard for programmable controllers. Considering that programmable controllers have been used in automation systems for more than two decades, it is remarkable that a programming standard has taken so long to evolve. The IEC (International Electrotechnical Commission) working group, with members from all the leading vendors, has, after years of discussions, finally come to a consensus and produced a working standard. The main objectives of the IEC 61131-3 standard are as follows. • The standard encourages well-structured program development. All application programs should be broken down into functional elements, referred to as program organisation units or POUs. A POU may contain functions, function blocks or programs. • It should be possible to execute different parts of the application program at different rates. This means that the system must support individual interval times for different POUs. • Complex sequential behavior can easily be broken down into events using a concise graphical language. • The system must support data structures so that associated data can be transferred between different parts of a program as if they were a single entity. • The system should have parallel support for the five most used languages, Ladder Diagram (LD), Instruction List (IL), Function Block Diagram (FBD), Structured Text (ST) and Sequential Function Chart (SFC). • The programming syntax should be vendor independent, resulting in more or less portable code that can easily be transferred between programmable controllers from different vendors.
3BSE 021 358 R201 Rev B
3.2 Benefits Offered by the Standard
Chapter 3: IEC 61131-3 Standard
Benefits Offered by the Standard
The main purpose of the IEC 61131-3 standard is to improve overall software quality in industrial automation systems. The standard encourages the development of well-structured software that can be designed either as top down or bottom up software. One of the most important tools in achieving this is function blocks. A function block is part of a control program that has been packaged and named so that it can be reused in other parts of the same program, or even in another program or project. Function blocks can provide any kind of software solution from simple logical conditions, timers or counters, to advanced control functions for a machine or part of a plant. Since the definition of input and output data has to be very precise, a function block can easily be used, even by other programmers than those who developed it. By packaging software into function blocks the internal structure may be hidden so that well-tested parts of an application can be reused without risk of data conflict or malfunction.
Five Languages for Different Needs
The IEC 61131-3 standard supports five of the most commonly used programming languages on the market. Depending on previous experience, programmers often have their personal preferences for a certain language. Since most older programmable controllers use Ladder Diagram or Instruction List programming, there are often many such programs available. These programs can relatively easily be reused in new systems supporting the standard. Today’s programmable controllers can handle both logical conditions for digital signals and arithmetic operations on analogue signals. Arithmetic operations are much easier to program with Structured Text than with Ladder diagrams. The initial structuring of a control application is normally best done with the graphical language Sequential Function Chart. This method is ideal for describing processes that can be separated into a sequential flow of steps. An optimal software application often contains parts written in more than one of the five programming languages. The standard allows the defintion of function block types using all the languages.
3BSE 021 358 R201 Rev B
3 PLCopen Trade Association Software Exchange between Different Systems Before the IEC 61131-3 standard was established it was not possible to port control programs from one vendor’s programmable controller to a competing system. rather than by the type of programming languages supported by the controller. demonstrating their commitment to the standard. This has been a major obstacle to a free market. it is feasible to develop applications based on it. The organisation informs users/programmers about the standard via a website (www. With programmable controllers that are IEC compliant the potential for porting software is much better.independent worldwide association supporting the IEC 61131-3 standard.plcopen. participation at trade fairs and by arranging their own conferences. Base Level provides an entrance for control system vendors.3 PLCopen Trade Association Since the IEC standard has relatively weak compliance requirements. defining a core kernel of the standard.and product. 3. lower prices and also improved software quality. a number of the larger control system companies concerned with software portability have formed the PLCopen Trade Association. PLCopen is a vendor. The lowest class is Base Level. 3BSE 021 358 R201 Rev B 33 .org).Chapter 3: IEC 61131-3 Standard 3. at least theoretically. This means that a system can be compliant with the standard without supporting all features. PLCopen today also has supporting offices in Canada and Japan. Unfortunately such a high level of software portability may be difficult to achieve in practice. PLCopen has defined three different compliance classes concerning the portability of control system software. a free quarterly newsletter. Software developed for one manufacturer’s system should. The IEC 61131-3 standard defines many features and only requires that vendors of programmable controllers specify a list of which features their system supports. This would open up the market dramatically resulting in better standardization. where the customer selects a system based on the suitability of the hardware and price. Although rather restricted. In practice. portability will therefore be limited. since systems from two different vendors often have different feature lists. be possible to execute on any other IECcompliant system. Being founded in 1992 in The Netherlands.
34 3BSE 021 358 R201 Rev B . Full Compliance. This level also demands that the system has an export/import tool for easy exchange of program code between systems from different manufacturers. The highest level.3 PLCopen Trade Association Chapter 3: IEC 61131-3 Standard Portability Level contains a large set of features including user-defined functions and function blocks. provides exchange of complete applications.3. including configuration information. between different control systems.
Although most control systems may be implemented with any one of the five languages the resulting program will be more or less effective. FBD • Sequential Function Charts.1 Overview The IEC 61131-3 standard specifies five programming languages: • Ladder Diagrams. ST • Function Block Diagram. SFC is normally only used for sequences. 11 A simple Boolean condition programmed with four of the five IEC 61131-3 programming languages. IL • Structured Text. SFC IL and ST are textual languages while LD. A2 A3 IL 1 FBD & M1 ST Fig.Chapter 4: Programming Languages 4. it is important to have basic knowledge of the most suitable applications for each language. A1 A3 M1 A2 LDN AND( OR ) ST A3 A1 A2 M1 LD A1 M1 := ( A1 OR A2 ) AND NOT A3.1 Overview Chapter 4 Programming Languages 4. LD • Instruction List. FBD and SFC are based on graphical metaphors. 3BSE 021 358 R201 Rev B 35 . Since all of these languages have both advantages and disadvantages. depending on the requirements of the control application.
most of the applications were for purely Boolean logical conditions. most American vendors have preferred LD languages while European vendors have chosen FBD or IL languages. together with timers. High-level languages. Relay systems documented via LD were dominant in the 1950s. Many older control systems use LD as a direct analogy to systems based on relays and switches. By tradition. the five languages have evolved in parallel with the evolution of automation systems. LD or FBD is more popular among engineers with experience in automation systems using those programming languages. while ST is the natural choice for engineers with experience using computer systems with programming languages such as Pascal. Low-level languages normally have a limited number of instructions producing very effective software code but. counters and sequences. most vendors of programmable controllers supported only one or two of the programming languages. also totally tailored for a certain brand or model of system. Before the IEC 61131-3 standard was established. technical. the program may be compiled for many different programmable controllers. the demands for good structure and reuse of code are less important than in larger systems. and cultural factors. Logical circuits described by FBD were used mostly in the 1960s. The choice between different programming languages is governed by several economical.4. • In small applications with relatively few logical conditions. PLCs debuted in the 1970s with programming in IL. unfortunately. • When programmable controllers were first introduced in the 1970s. • Depending on background.1 Overview Chapter 4: Programming Languages Historically. 36 3BSE 021 358 R201 Rev B . Improved CPU power in the 1990s finally made it possible to work with graphical languages like SFC. on the other hand. like ST and SFC. Today. Programming with IL. • Program languages are often characterized by their level of abstraction. • In large plants involving many subprocesses the control function must be divided into an number of program modules with a high level of encapsulation in order to prevent the modules from interfering with each other. Computers for process automation were introduced in the 1980s with ST programming in languages like Pascal and C. a control system must handle both digital and analog control. A low-level language like IL is very closely coupled to the actual binary codes running the processor in the control systems. do not produce the most effective machine language but. programmers often have a preference for a certain language.
Since many control functions are used in the same way over and over again it is possible to simplify the application program by using generalized standard modules. ST and FBD are the most commonly used techniques for developing new control systems. Reuse of standard modules is by far the most effective method to reduce costs. data types. Two or more underscores may not be used together. 4. 12 The evolution of the five IEC 61131-3 programming languages. Today. have to support older and generally less effective languages. SFC.2 Common Elements • The cost of software development has a tendency to increase exponentially with the size of the application. for example. large parts of the old program code. data types. digits or underscore symbols which begin with a letter or an underscore. Structure level High SFC FBD ST IL Low 1950 LD Year 1960 1970 1980 1990 2000 Fig. are often reused. This section explains the rules for using identifiers. therefore. variables. An identifier is a string of letters. function blocks and programs. Space characters are not allowed in identifiers. constants and variables. 3BSE 021 358 R201 Rev B 37 . Identifiers Identifiers are used for naming different elements within the IEC language. • When industrial plants are redesigned with new control systems.Chapter 4: Programming Languages 4. Even the most up-to-date systems.2 Common Elements The IEC standard defines a number of common elements which are used in all of the programming languages. which have been tested and debugged over several years of intensive use.
True.4. False. but it can be likened to a cable containing a number of leads of different types. Programmer’s comments are delimited at the beginning and end by asterisks (*comment*). Comments can be placed anywhere except in IL language. the IEC standard provides a comprehensive range of elementary data types. Timer. Step. for example: Type. The most often used data types are described below. Program. 38 3BSE 021 358 R201 Rev B . Function. Such a data type has no physical correspondence in the plant. You are not allowed to use keywords as identifiers. Task. programmers can define their own Structured data types containing several components of data types. Return. Data type Boolean Integer Double integer Real numbers Duration of time Calender time Character string Keyword bool int dint real time date_and_time string Bits 1 16 32 32 In addition to elementary data types. Counter Some compilers may be able to distinguish between keywords based on their position but others may produce confusing results. For this reason. e. for the transfer of electrical power or telephone and TV signals. which has some restrictions.g. Data Types The first PLCs could only handle Boolean data but today’s systems are being used in an ever-widening range of industrial applications.2 Common Elements Chapter 4: Programming Languages Allowed identifiers Motor_1 Elapsed_Time _prog2 Illegal identifiers 1Motor switch 1 Conveyor__3 Keywords are special identifiers that are used within the IEC language as individual syntactic elements.
2 Common Elements All leads are given descriptive names so that the programmer can connect to them without having a detailed knowledge of their function. Numbers to bases other than 10 are represented in base 2. 13 Example of a structured data type containing several elementary data types. for example Pump3. Real literals may end with an exponent. 8 or 16 (prefix 2#. The initial value is normally specified in the variable declaration. TYPE PumpType On: boolean Off: boolean Level: real Name: string END_TYPE Each component in a structured data type is identified via the variable name and the component name separated by a point. Boolean data are represented by the values 0 and 1 or the keywords FALSE and TRUE. indicating the integer power of ten by which the preceding number is to be multiplied. Duration data are prefixed by the keywords TIME# or T# followed by the actual duration in terms of days. you prevent it from being changed after it is given its initial value. A new structured data type is declared by delimiting the definition with TYPE and END_TYPE.Chapter 4: Programming Languages 4. Constant Literals By giving a variable the attribute constant. Time literals are used either for Duration data or for Time of day.On. 8# or 16#). Decimal numbers are represented in conventional decimal notation. 3BSE 021 358 R201 Rev B 39 . seconds and milliseconds. PumpType On (boolean) Off (boolean) Level (real) Name (string) Fig. minutes. where the latter are distinguished from the former by the presence of a decimal point. hours. Time of day literals are prefixed by the keywords TIME_OF_DAY# or TOD#. There are two classes of numerical literals: integer and real.
If a variable has to start at a specific value. but can also be an internal memory storage. All variables are declared with a unique name and a corresponding data type. Global variables are accessible from any program or function block in the open project.2 Common Elements Chapter 4: Programming Languages Variables Variables is the name given to data elements whose content may change during execution of the application program. either retain. Local variables can only be accessed in the same function block or program in which they are declared. constant or a blank field. A variable must also have an attribute. global and access variables. A global variable must be declared as an external variable in the program organisation unit (POU) accessing it.000 10 The IEC standard defines three types of variables: local. otherwise it will start at a predefined value depending on its data type (normally 0). 40 3BSE 021 358 R201 Rev B . Variables with a blank attribute will always be calculated at system restart. A constant variable will not be changed by the system.4. A variable may be associated with a real-world input and output. The table below shows examples of names and attributes of variables of frequently used data types. Name Pump_1 PhotoCell_4 Duration_Open Event_Notation NumberOfRev Temperature_5 Data type bool bool time constant date_and_time constant dint real constant retain Attributes retain Initial value False False T#3m10s DT#1999-02-0112:30:00. This is normally done before the program code is written. Access variables can be used by other controllers. Retain means that the variable will retain its value when the system restarts. that value has to be specified as Initial value.
Parallel contacts represent logical OR operations. There are two types of contacts. switch1 alarm motor switch2 Normally closed contact Normally open contacts Power rails Fig. using contacts as a representation for inputs from the process and coils for outputs. power can flow along the rail and operate the coil on the right of the rung. in the car industry. In a real-world relay circuit this is equivalent to 3BSE 021 358 R201 Rev B 41 . Normally closed contacts present a false state (Boolean variable is 0) when they are open. 14 Example of a simple ladder diagram with three contacts and a coil. Each contact represents the state of a Boolean variable. normally a transducer. LD is a graphic representation of Boolean equations.Chapter 4: Programming Languages 4. normally open and normally closed. The power rails serve as a symbolic electrical power supply for all the contacts and coils that are spread out along horizontal rungs. either in the same or in other logical conditions. for example. but may also be an internal variable in the control system. in the true state. but sometimes also an internal variable in the control system. An LD diagram is limited on both sides by vertical lines.e. called power rails. Contacts which are normally open present a true state (Boolean variable is 1) when they are closed.3 Ladder Diagrams Ladder Diagrams (LD) have evolved from the electrical wiring diagrams that were used. i. When all contacts in a horizontal rung are made. The coil normally represents physical objects like a motor or a lamp. contacts connected horizontally in series represent logical AND operations. to describe relay-based control systems. Coil It is possible to create LD programs that contain feedback loops. where the variable from an output coil is used as an input contact. In analogy with electrical circuits.3 Ladder Diagrams 4.
42 3BSE 021 358 R201 Rev B . start stop fan fan Fig. 16 Status indication of an executing LD program. A person with experience in computing would probably call this a memory bit.3 Ladder Diagrams Chapter 4: Programming Languages using one of the relay’s physical switches as an input contact. Easy to Understand Programming with LD can be learnt relatively quickly and the graphical presentation is easy to follow. 15 Feedback loop in an LD program. The fan starts with an impulse on contact start and continues to run until the contact stop is opened. The method is particularly easy to understand by people who are familiar with simple electrical or electronic circuits. Fig.4.
This lack of data encapsulation is a serious problem when large programs are written by several different programmers. Apart from the physical value measured by the sensor. Weak Software Structure Ladder programming is a very effective method for designing small control applications. has to be very careful when accessing data from other program blocks. Unfortunately. the method can also be used to construct large control systems. With increasing processing power and memory size with today’s programmable controllers. which makes it almost impossible to have truly encapsulated data. therefore. it is difficult to break down a complex program hierarchically. record the time when the sensor is active and also raise an alarm if the sensor is activated longer than a certain prescribed period. The lack of features for passing parameters between program blocks makes it difficult to break down a large program into smaller parts that have a clear interface with each other. Since most programmable controllers have limited support for program blocks. Without a data structure the programmable controller has no provision for warning the programmer when incorrect data are accessed. There is always a danger that internal data in one block can be modified by faulty code in other program blocks.3 Ladder Diagrams LD programs are very popular among maintenance engineers since faults can easily be traced. Each programmer. Many control applications often have a need to group data together as a structure. place it in test mode. In most ladder programs such data is often spread out among different ladder rungs. 3BSE 021 358 R201 Rev B 43 . Some sensors provide more than one variable that has to be recorded by the control system. or subroutines. large ladder programs have several serious drawbacks.Chapter 4: Programming Languages 4. it is possible for one part of a Ladder Diagram to read and set contacts and outputs in any other part of the program. All of this information from the sensor should ideally be handled as a single structure that can be addressed using a common name. the application sometimes needs to disable the sensor. This provides a very powerful online diagnostics facility for locating incorrect logic paths or faulty equipment. Most programming stations generally provide an animated display showing the live state of transducers while the programmable controller is running. There are also problems in using structured data with ladder programs since data are normally stored and addressed in single memory bits. Usually.
Each state represents a unique condition in the plant being controlled. The feedback loop of a state is normally broken by the memory bit of a succeeding state. 17 Sequence program with three states controlling two outputs.3 Ladder Diagrams Chapter 4: Programming Languages Limited Support for Sequences Most control applications have a need to divide the function into a sequence of states. Normally. Each state consists of a feedback loop using the memory bit as an alternative condition for remaining in the state. 44 3BSE 021 358 R201 Rev B . state_3 transducer_a state_1 state_1 state_2 state_1 transducer_b state_2 state_2 state_3 state_2 transducer_c state_3 state_3 state_1 state_2 state_3 state_1 output_a output_b Fig.4. When sequences are constructed with ladder programming the normal method is to assign one internal memory bit to each state and to use contact conditions from the transducers to trigger transitions between the states. only one state is active at a time. To get real-world actions the memory bits are used as conditions in separate rungs to control the outputs.
The most obvious problem is that control of the memory-based sequence model is mixed with the application logic so the behavior of the complete program is difficult to understand and follow. This can result in very large.3 Ladder Diagrams From the above example it is obvious that ladder programs with sequences can become very large and difficult to maintain.Chapter 4: Programming Languages 4. Unfortunately. 3BSE 021 358 R201 Rev B 45 . Such systems consist of a large number of similar ladder rungs with only minor modifications to read different contacts and to set different outputs. Difficult to Reuse Code In many large control systems similar logic strategies and algorithms are used over and over again. A common application is to detect fire by using two or more transducers with a comparison algorithm to eliminate false alarms. unstructured programs. very few programmable controllers have an option for defining standardized ladder blocks that can easily be called upon many times with different inputs and outputs.
Comments are enclosed by asterisks (*comment*). while the operand identifies which variable is to be processed. 46 3BSE 021 358 R201 Rev B . IL instructions are normally structured so that labels. are placed in their own column to the left of the instruction. each on a new line. the operators should be separated by commas. The instructions only need to have labels if the program contain jumps.4 Instruction List Instruction List (IL) is a low-level language with a structure very similar to assembly language. used to identifying entry points for jump instructions. in which case. All labels should end with a colon. Large IL programs without comments are very difficult to follow. often used for programming microprocessors. operators. IL has been chosen as the preferred language by a number of PLC manufacturers for their small to medium-sized systems. Label Operator LD GT JMPCN LD ADD JMP Operand temp1 temp2 Greater speed1 200 End speed2 Comment (*Load temp1 and*) (*Test if temp1 > temp2*) (*Jump if not true to Greater*) (*Load speed1*) (*Add constant 200*) (*Jump unconditional to End*) (*Load speed2*) Greater: LD Fig. Some operators can process more than one operand. operands and comments are put in fixed tabulated positions. 18 Example of an IL program for controlling the speed of a motor. Comments are placed in a fourth column to the right of the operand. Labels.4. To improve readability. The lack of structured variables and weak debugging tools make the language less suitable for larger systems.4 Instruction List Chapter 4: Programming Languages 4. It is strongly advisable to add comments to all instructions during programming. An instruction consists of an operator followed by an operand. The operator tells the system what to do. IL programs are often written on a spreadsheet-like form with one column for operators and another for operands. IL Language Structure IL is a language with a series of instructions.
Boolean negation of the operand • C. is a selection of the most commonly used instructions in current programmable controllers. The program example in Fig. RR. Conditional operation • (. 3BSE 021 358 R201 Rev B 47 . Some IL operations can take operator modifiers after the mnemonic that change the behavior of the corresponding operation. In both cases. The result of an instruction is always stored in the result register. the next instruction loads RR with a new real value. IL register or accumulator. Each instruction is written as an abbreviation of the corresponding operation. The IL language. 19 Example of operator modifiers in an IL program. 18 on page 46 first loads the RR with a real variable. sometimes referred to as a mnemonic. This must naturally be taken into consideration by the programmer when writing code. which loads the accumulator with a variable. The final instruction stores the RR in a real variable called motor controlling the speed of the motor. The modifier character must complete the operator name with no blank characters in between. The result register changes its data type automatically during program execution in order to fit the value that needs to be stored. IL Instruction Set The IEC has developed a standardized instruction repertoire by examining the many low-level languages offered by different vendors. Programmable controllers normally only have one result register. delayed operation Operator Operand LDN AND( OR ) switch1 switch2 switch3 (*RR := NOT switch1 AND (switch2 OR switch3)*) Comment (*Load inverse of switch1*) (*Boolean AND with the following two operations*) Fig. The following three modifiers can be used: • N. Most operations consist of calculation between the result register and the operand. as defined in IEC 61131-3. The conditional jump instruction JMPCN uses the Boolean value in RR as a condition for either continuing with the next instruction (RR false) or jumping to the label Greater.Chapter 4: Programming Languages 4. called the result register. The second instruction compares RR with another variable which results in a Boolean TRUE or FALSE result in RR.4 Instruction List A characteristic of IL programs is that instructions always relate to an internal register. Most programs start with the instruction LD.
Operator LD ST S R AND OR XOR ADD SUB MUL DIV GT GE EQ LE LT NE ) CAL JMP RET C. 48 3BSE 021 358 R201 Rev B . N C. 20 The IL instruction set. The left-hand parenthesis indicates that the evaluation of the following instructions must be delayed until the righthand parenthesis is encountered. ( N. This is needed to change the execution order of the corresponding instructions. N C. N N.4 Instruction List Chapter 4: Programming Languages The C modifier indicates that the corresponding instruction may only be executed if the RR contains the Boolean value TRUE. ( ( ( ( ( ( ( ( ( ( ( Modifier N N Description Loads operand in RR Stores current result from RR Sets the operand Resets the operand Boolean AND Boolean OR Exclusive OR Arithmetic addition Arithmetic subtraction Arithmetic multiplication Arithmetic division Comparison greater than Comparison greater than or equal to Comparison equal Comparison less than Comparison less than or equal to Comparison not equal Executes delayed operation Calls a function block Jumps to label Returns from called function Fig. since there is only one result register. ( N. Parentheses are used to delay the operation of some parts in the program.4.
The behavior of the result register. It is very important that IL programs are well documented since conditional jumps will otherwise be very difficult to follow. with only one value available at a time.e. it is up to the programmer to ensure that each instruction is given correct variable data. IL has been found to be the most controversial. This means that different system types may respond differently if the programmer uses inappropriate data types. Weak Software Structure Since IL is a low-level language. During a period of several years a huge amount of software has been written and thoroughly tested. There is also another reason for using IL in order to optimize system performance. which means that it is very difficult to obtain consistent behavior when working with arrays or strings. i.Chapter 4: Programming Languages 4. Normally. 3BSE 021 358 R201 Rev B 49 . Machine-dependent Behavior Of all the five IEC languages.4 Instruction List Best System Performance IL is ideal for solving small straightforward problems. the way in which the instructions operate. Therefore. Errors can normally only be detected when the system is running the application. the RR is not intended for storing structured data. For example. great care should be taken in structuring the code so that it is easy to understand and maintain. Most compilers have no automatic function for checking whether the RR contains correct data for the actual instruction code. are not fully defined in the standard. Another problem is that the control system behavior for error conditions is not defined. the semantics. it is unclear how the result register stores values of different data types. Such software can be modularized into libraries and reused even by programmers with no detailed knowledge of the internal behavior. Unfortunately. makes it difficult to work with structured data variables. In the hands of an experienced programmer it produces very effective code resulting in applications that are optimized for fast execution.
21 Example of a simple ST program. END_IF. RETURN. variable := expression. speed3 := temp1*temp2 . similar to Pascal and C. When developing large control applications there is a need for structured programming tools.5 Structured Text Chapter 4: Programming Languages 4. REPEAT • function and function block control statements • control statements. CASE • iteration statements. especially in complex applications with many conditional statements and calculations. An expression can be short. ELSE. The computer will accept any number of spaces in a statement but it is good practice to place statements at a fixed position according to their role in the hierarchy. where a space is needed for separation. that has been specifically designed for use in programmable controllers.5 Structured Text Structured Text (ST) is a high-level language.8. IF speed3 < 0 THEN tank_level := 25. ELSE tank_level := 30.4. for example a literal constant. The assigned variable can be either simple or structured containing any number of elementary data types. motor := (start or motor) and not stop. ST has proven to be such an effective programming tool.5*value7.6. 50 3BSE 021 358 R201 Rev B . • selection statements. tabs. IF. Statements contain expressions which. Statement text should be written in a structured way. result in a value of a variable having any kind of data type. i. EXIT The language statements can be written in a fairly free style with spaces. WHILE. Fig. Expressions are composed of operators and operands. line feeds and comments inserted anywhere between operators and operands. when evaluated. THEN. Statements All ST programs contain a list of statements. or very complex involving many other nested operations.e. The ST language supports five different types of statements: • assignment statement. FOR. each ending with a semicolon separator.
>. END_FOR. >= = <> AND. The IEC standard provides a collection of conditional statements for this purpose. a specified number of times. FOR i:=1 TO 10 DO count := count + i.(before other operator) NOT ** * / Mod + <.5 Structured Text Operators in Expressions The table below summarizes the arithmetic and Boolean operators in the IEC standard. The operators are listed in execution order with the highest precedence first: Operator Parenthesis Function evaluation Negation Boolean complement Exponentiation Multiplication Division Modulus Addition Subtraction Comparison operators Equality Inequality Boolean AND Boolean XOR Boolean OR Symbol () Function (argument list) . count := 0. <=. The variable count starts with the value 0 and increases by 1 for each time the addition is repeated until the final value 10 is reached. or only when a certain condition is fulfilled.Chapter 4: Programming Languages 4. & XOR OR Precedence Highest priority Lowest priority Conditional Statements Often there is a need to execute certain statements repeatedly. 3BSE 021 358 R201 Rev B 51 . FOR Statement The statement FOR is used when the number of executions is known.
If A and B have different values the highest value will be given to both. REPEAT B := B + 1.4. When using conditional statements it is very important to avoid infinite loops. B := 0. END_WHILE. else both of the variables will be set to zero. alarm := TRUE. REPEAT Statement The REPEAT statement is very similar to WHILE but the difference is that the statement will always be executed once since the condition is written after the statement.5 Structured Text Chapter 4: Programming Languages WHILE Statement The statement WHILE is used when other statements are to be repeated an unknown number of times until the condition no longer is fulfilled. 52 3BSE 021 358 R201 Rev B . ELSEIF A<B THEN A := B. UNTIL B>10 END_REPEAT. ELSE A := 0. END_IF. All statements must therefore include a condition that can be fulfilled. IF A>B THEN B := A. IF Statement An IF statement is used when one or more other statements are to be executed conditionally. WHILE switch1 OR switch3 DO pump := FALSE.
calling function blocks and creating conditional expressions. Suitable for Complex Calculations and Looping The ST language has an extensive range of constructs for assigning values to variables. Most programmable controllers supporting the SFC language use ST as the default programming language to describe the step actions in sequences.5 Structured Text Calling Function Blocks ST programs often need to access function blocks such as timers and counters. When switch3 is activated the lamp is turned on after the specified delay1. 3BSE 021 358 R201 Rev B 53 . all of them written within parentheses. Structured Text is often the natural choice for people with former experience in computer programming. PT := delay1. i. Function blocks are invoked by a statement consisting of the instance name followed by a list of named input and output parameter value assignments. On the whole. Control engineers without computer knowledge sometimes consider ST to be more complex with a higher learning threshold than the LD or IL languages. Q => lamp). High Threshold for Programmers Of the five IEC languages. This is very useful for evaluating complex mathematical algorithms. commonly used in analog control applications. The language is a good general purpose tool for expressing different types of behavior with all kind of structured variables. when certain parts of the program code are to be repeated a fixed or a conditional number of times.Chapter 4: Programming Languages 4. Timer1( IN := switch3. ST is fairly easy to learn and a very effective tool for developing control applications. No other IEC language can match the power of ST when iterations are needed.e.
All function blocks have a built-in algorithm for calculating output values based on the status of the inputs.6 Function Block Diagram Function Block Diagram (FBD) is a graphic language in which the control function is divided into a number of function blocks or functions connected by flow signals. Input signals to function blocks may either come from transducer signals. 54 3BSE 021 358 R201 Rev B . 22 Example of an FBD program with two logical function blocks and a timer block. from local variables or from other function block outputs. The function block type name is normally shown within the block. close to the corresponding signal. Some systems use a NOT function block instead of the circle. but can also provide a complex control function to a subprocess in a machine or even an industrial plant. Syntax for Function Block Diagrams Each function block is drawn as a rectangle with inputs entering from the left and outputs exiting on the right. negated inputs or outputs can be shown using a small circle placed at the corresponding line. close to the block symbol.6 Function Block Diagram Chapter 4: Programming Languages 4. timers or counters. In an FBD program the normal signal flow is from the left to the right. When working with Boolean signals. The formal names of input and output parameters are also shown within the block.4. In1 In2 In3 Time1 PT ET Out2 1 & IN TON Q Out1 Fig. A function block may contain simple logical conditions. For some of the most common logical functions a standardized Boolean symbol may be used instead of type names. Signal names are normally shown at the corresponding connecting lines.
The output is set (SR) or reset (RS) as a memory when the triggering input (S1 or R1) momentarily becomes true. OR. When the other input becomes true the output returns to its initial state. 23 Some fundamental rules for drawing function block diagrams. 3BSE 021 358 R201 Rev B 55 .6 Function Block Diagram Function block type AND IN TON Q Negation symbol PT ET Input parameters Output parameters Fig. The most commonly used blocks are: • Boolean conditions like AND. If both inputs are true the SR will be set while the RS will be reset. These are predefined in most of today’s programmable controllers. XOR and NOT • Bistables • Edge detectors • Timers • Counters Bistables Two types of bistables are available.Chapter 4: Programming Languages 4. Both of them have two Boolean inputs and one output. SR and RS. Standard function blocks are often used to construct user-defined function blocks. Standard Function Block Types The IEC 61131-3 standard defines a small repertoire of rudimentary standard function block types.
56 3BSE 021 358 R201 Rev B . 24 SR and RS bistable symbols with their corresponding functions below. according to the type of edge detector.6 Function Block Diagram Chapter 4: Programming Languages SR bistable SR S1 R Q1 RS bistable RS S R1 Q1 S1 Q1 R R1 Q1 S Fig. After that the output remains false until a new edge is detected.4. which are used to detect the changing state of a Boolean input. Rising edge trigger (R_TRIG) and Falling edge trigger (F_TRIG). 25 Edge detectors create a single pulse with the same duration as the execution time of the function block. When the input changes state. Edge Detectors There are two edge-detecting function blocks. The output of the blocks produces a single pulse when a transition edge is detected. the output is true during one function block execution. Rising edge detector R_TRIG CLK Q1 Falling edge detector F_TRIG CLK Q1 CLK Q CLK Q Fig.
the output remains false. Both delay timers are used to delay an output action by the specified time PT when a certain condition becomes true. The off-delay timer delays the deactivation of an output. The required delay (or pulse width) is specified on input PT (Preset Time) while the actual elapsed time is shown on output ET (Elapsed Time). Note that the output Q will remain true until the pulse time has elapsed. The elapsed time ET is increased linearly as long as the pulse output is true. The on-delay timer delays the activation of an output.6 Function Block Diagram Timers Timers are among the most used function blocks in a control application. on-delay timers (TON) and off-delay timers (TOF). The output Q remains true until input IN becomes false. A pulse timer is normally used to generate output pulses of a specified duration. the output Q becomes true and the elapsed time is held. If input IN is not true longer than the specified delay in PT. the elapsed time starts to increase and continues until it reaches the specified delay given by PT. There are three different types of timer function blocks. the elapsed time is held until the input changes to false. In most programmable control systems the timing is based on the CPU system clock.Chapter 4: Programming Languages 4. a Boolean output called Q. pulse timers (TP). even if the input changes to false. an input of type time called PT and an output of type time called ET. If the elapsed time reaches the value specified in PT. When input IN becomes true the output Q follows and the elapsed time is reset to zero. When the input IN becomes true the elapsed time at output ET starts to increase. which means that the specified time intervals are very precise. Whenever there is a need for a time delay between a change of state and the corresponding action a timer can be used. 3BSE 021 358 R201 Rev B 57 . When input IN changes to the true state the output Q follows and remains true for a duration specified by input PT. The output Q is then set to false and the elapsed time is frozen. When the input IN becomes false. All of them have a Boolean input called IN. When the pulse terminates.
the Boolean output Q becomes true and counting stops.6 Function Block Diagram Chapter 4: Programming Languages Pulse timer IN PT TP Q ET On-delay timer IN PT TON Q ET Off-delay timer IN PT TOF Q ET IN PT PT IN PT PT IN PT PT Q ET Q ET Q ET Fig. Counters Counters are another commonly used type of function block. CTUDs can be used to both count up and count down and have two outputs indicating both maximum value and zero. down-counters (CTDs) and up-down counters (CTUDs). completed production batches. 26 Timing diagrams for the three different types of timer function blocks. on counting down from a specified value. These are designed to be used in a wide range of applications. A CTU block counts the number of pulses (rising edges) detected at the Boolean input CU. the Boolean input R (reset) can be used to set the output Q to false and to clear CV to zero. Each time a new rising edge occurs on CU the output CV (Counter Value) of type integer is incremented by one. CTDs indicate when the counter reaches zero. When the counter reaches the value specified in PV. for example counting pulses. There are three types of counter blocks. 58 3BSE 021 358 R201 Rev B . If necessary.4. up-counters (CTUs). revolutions. The input PV (Preset Value) of data type integer defines the maximum value of the counter. CTUs are used to indicate when the counter has reached a specified maximum value. A CTU has three inputs and two outputs. etc.
When the counter reaches zero. the input LD can be used to load the value from PV to the output CV while the input R can be used to clear the output CV to zero.6 Function Block Diagram Up counter CTU bool bool int CU R PV CV int CV CV=0 CU Q bool Q R CV=PV Fig. Down counter CTD bool bool int CD LD PV CV int CV Fig. the output QD is set to true and counting stops when the counter reaches zero. Similarly to the two other counters. When the counter reaches the value specified in PV the output QU is set to true and counting stops. It has two Boolean inputs. the integer input PV defines the counter’s maximum value. 28 Example of a CTD counter block with preset value PV=5. used for counting up and counting down the value in output CV. 27 Example of a CTU counter block with preset value PV=5. The CTD is very similar to CTU with three inputs and two outputs. CU and CD. the Boolean input LD (load) can be used to clear the output Q to false and to load the output CV with the value specified in PV. Q bool CD Q LD CV=PV CV=0 The CTUD is a combination of the other two counter blocks. If necessary. A CTD counts down the number of pulses detected at the Boolean input CD. Each time a new rising edge occurs on CD the output CV is incremented by one.Chapter 4: Programming Languages 4. If necessary. 3BSE 021 358 R201 Rev B 59 . the output Q becomes true and counting stops. In a similar way. The input PV is used to specify the starting (integer) value of the counter.
counters and bistables. Like ICs. Most programmable controllers have such function blocks predefined in standard libraries for direct use by the programmer. function blocks can provide standard solutions to common control functions. Electrical engineers who have experience in designing and analyzing circuit diagrams often have a preference for programming with FBD. Many analog control systems. The FBD program gives a good overview of signal flow in systems with feedback. use closed-loop control where some output signals are fed back and used as inputs in the control algorithm. a function block can be compared to an integrated circuit (IC). for example. 29 Example of a CTUD counter block with preset value PV=3. 60 3BSE 021 358 R201 Rev B . the building block of today’s computers and other electronic devices. There is no other programming language where timers and counters are so easy to implement as in FBD. Boolean Functions and Feedback are Easy to Implement FBD is very suitable for describing Boolean logic with associated timers. be used to count the number of products placed on and taken off a store shelf. It could.4. for example PID controllers. The connection lines between blocks symbolize signal flow in the system. The CTUD is often used in applications where there is a need to monitor the actual number of items in a process. Similar to Electrical Diagrams In many ways.6 Function Block Diagram Chapter 4: Programming Languages Up-down counter bool bool bool bool int CTUD CU QU CD QD R LD CV PV CU bool bool int LD R CV=PV CV=PV CV=0 CD QU QD CV Fig.
3BSE 021 358 R201 Rev B 61 . or only as long as a certain condition is fulfilled.6 Function Block Diagram Not Suitable for Conditional Statements FBD programs have very weak support for conditional statements when one or more actions are to be repeated for a specified number of times. WHILE. This kind of construct is much easier to accomplish in the ST language with one of the statements FOR.Chapter 4: Programming Languages 4. REPEAT or IF.
be described directly in the associated step rectangle. The SFC standard has evolved from Grafcet. The execution flow is normally down the page.7 Sequential Function Chart Sequential Function Chart (SFC) is a very powerful language for describing the structure of a control system. Sequences can also be hierarchical with a main sequence containing several subsequences. deactivates the step before the transition and activates the step after the transition. e. One of the most important aspects of SFC is that it gives an overview of all the main states of a control application. all the possible changes of states and also the reasons why these changes may occur. Since SFC is not a full programming language it requires instructions taken from the other languages to construct a complete application program. Each step is normally associated with one or more actions. However. Most European vendors have offered support for Grafcet in their most advanced programmable controllers since the beginning of the 1990s. Each step represents a physical state of the system being controlled. An important consideration in SFC programs is that only the code in active steps is executed. On each connecting line there is a horizontal bar representing a transition. These actions describe the actual physical behavior in the plant. The transition is associated with a transition condition which. The result is an application program with a good overview providing detailed information about the controlled process objects. in most editors the actions are described as separate program statements (normally in ST language) in other code blocks or in an separate editor window associated with the step. open valve. 62 3BSE 021 358 R201 Rev B . Chart Structure SFC is a method of dividing the control function into a series of steps represented by rectangular boxes and connected by vertical lines. in some editors. but SFC can also branch backwards in the chart.4. The SFC language can be used to divide the entire control application into parts that are executed only when needed. An action can. providing a method of optimizing the performance of the programmable controller. a graphical method of describing sequential behavior. and so on. when true. Many experienced programmers consider SFC combined with ST statements to be the ultimate method for developing structured control applications.7 Sequential Function Chart Chapter 4: Programming Languages 4. start motor.g.
Note the cyclic execution being enabled by the Tr6 transition condition. or FBD languages. close to the corresponding bar. Cyclic execution is enabled by a conditional branch backwards to the first step in the flow. In order to clarify the flow the transition name is written at both places. However with more complex conditions it is better to put the code in a separate window. the sequence can also repeat the same behavior cyclically. The program is often written in ST language but many editors also allow the use of LD.Chapter 4: Programming Languages 4. Some editors allow the programmer to describe short transition conditions directly on the SFC. Initial step Start Tr1 Pusch Tr2 Drill Tr3 Wait Tr4 Label Tr5 Stop Tr6 Fig. To avoid cluttering the SFC with crossing lines. branches are drawn with a starting arrow where the branch begins and a concluding arrow at the step where the branch ends up. When the sequence has finished. If necessary. the flow can be terminated by a step with no associated action. The initial step remains active until the following transition enables flow to the next step.7 Sequential Function Chart All SFC sequences must have an initial step identifying where program execution starts after system initialization. 30 Example of an SFC program for an automatic drilling machine. Steps with code in other windows Transition Transition conditions with code in other windows 3BSE 021 358 R201 Rev B 63 . IL. This step is drawn as a rectangular box with double border lines.
64 3BSE 021 358 R201 Rev B . Any of the four IEC languages can be used to describe the behavior of an action.X. Every step has an automatically defined Boolean Step active flag variable that is true while the corresponding step is active.g. variables and parameters. Fig. To avoid overloading the SFC with too much detailed information the boxes can be folded in or out.4. The transition conditions may contain any kind or complexity of statements. 31 Example of a step with the associated actions folded out and one of them described in a separate editor window. A transition that always occurs can be expressed by the Boolean literal TRUE. Drill. It can be used within the current SFC to control the logical flow. as long as the result can be expressed as a Boolean variable. In order to get real-world actions each state has one or more action descriptions containing program code controlling the physical objects. e. When the programmable controller executes an SFC program the state model only works as an internal memory representation of the control function. Most editors use a separate window or another code block for specifying the actions. Each action can have one or more action qualifiers that determine when and how the action is executed. • The N action qualifier (Non-stored) causes the action code to be executed continuously as long as the step is active.T. Drill P1 N P0 Drill_P1 Drill_N Drill_P0 Drill_Motor := Drill. Two adjacent steps must always be separated by a transition condition which produces a Boolean result. Action descriptions are normally placed in rectangular boxes that are attached to the step with a connection line. Most editors support the following three action qualifiers. The Step active flag is given the same name as the step plus the suffix X. Action Descriptions Steps in an SFC are used to describe the states of a controlled plant or machine.7 Sequential Function Chart Chapter 4: Programming Languages Steps and Transitions All steps within an SFC must have unique names and may only appear once in each flow.
often referred to as sequence selection. Fig. Note that only one branch can be executed at a time.Chapter 4: Programming Languages 4. S4 Tr5 Tr3 3BSE 021 358 R201 Rev B 65 . It is not necessary to use all three action qualifiers. 30 on page 63) has only one main flow path. 32 Example of a sequence selection with two branches. Sequence Selection and Simultaneous Sequences In its simplest form. In the example below with divergent paths. When either of the transition conditions Tr2 or Tr3 becomes true. Most sequences use the N action qualifier. each branch starts and ends with a transition. To use one or more of the action qualifiers the programmer writes the code statements in the associated editor window.7 Sequential Function Chart • The P1 (Pulse rising edge) action qualifier causes the action code to be executed once when the step becomes active.g. This type of system (e. but it is possible to leave all three qualifiers empty resulting in a step without any actions. S1 Tr1 S2 Tr2 S3 Tr4 S5 Tr6 Fig. an SFC program consists of a series of steps in a closedloop executed continuously. If more than one transition condition is true the leftmost branch has the highest execution priority. the corresponding branch is selected and execution continues along that path. When the last transition in the selected branch becomes true the flow converges back to the main flow. This is required in many batch process applications. In many systems there is a need for two or more branches in the sequence flow. • The P0 (Pulse falling edge) action qualifier causes the action code to be executed once when the step becomes inactive.
in many batch process applications there is a need for simultaneous sequence structure with several branches. Execution then continues in parallel and independently along all three paths until convergence is reached. The main sequence is used for primary process control.e. In the example below. otherwise the control system may shut down the process. Start Tr1 Acid Tr2 Water Tr3 Heat Tr5 Wait Tr6 Fig. An important characteristic of such parallel branches is however. Both the divergent and the convergent flow in simultaneous sequences are drawn with a pair of lines to distinguish the construct from a sequence selection. when the last step of each branch is active.g. all three divergent branches start with a common transition condition. while secondary parallel sequences are used to monitor that the process is running normally. i. that only one step in one of the branches may be active at any time. check that plant temperatures and pressures are within required limits.4. Such parallel sequences can e.7 Sequential Function Chart Chapter 4: Programming Languages We have earlier seen how divergent paths can be used to execute alternative paths in sequences. The transition condition that succeeds the simultaneous sequence structure will not be tested until all the branches have finished execution. 33 Example of a simultaneous sequence with three continuous branches. However. Temp Press Tr4 Monitor 66 3BSE 021 358 R201 Rev B .
Most processes can be described by a relatively small number of main states. Advice on Good Programming Style Names of steps. Steps and actions from different hierarchical levels are never visible at the same time. A subsequence usually contains sequence parts that perform a set of logically related actions. It is better to put detailed behavior in the action blocks or in other SFCs at a lower hierarchical level. each represented by a general symbol. This allows attention to be focused on either the overall behavior of the entire plant or on the detailed operation of the controlled process objects.g. function block). 3BSE 021 358 R201 Rev B 67 . each representing a subprocess with a number of minor states. transitions and actions should be unique within each program organisation unit (e.7 Sequential Function Chart Subsequences One of the main uses of SFC is as a tool for developing the top down design of the control function in a complex plant. It is good practice to reduce the interaction between simultaneous sequences to a minimum. Some editors provide a method for dividing large SFC programs into a number of subsequences. To study the inside of a subsequence the programmer has to step into the subsequence which changes the SFC view. so that only the contents of the selected subsequence are displayed. Avoid using constructs in which a divergent path branches out of a simultaneous sequence since this may lead to a sequence that never completes or behaves unpredictably. Never allow step actions from different simultaneous sequences to change the same variables. Try to keep all SFCs as small as possible and focused on the overall behavior. A subsequence may in turn contain other subsequences which provides a powerful tool for structuring the overall control function into any number of hierarchical levels.Chapter 4: Programming Languages 4. It as also wise to use meaningful names whenever possible.
Some controllers also allow programming with FBD or IL. Most experienced programmers prefer the ST language as a complement to SFC. The SFC’s graphical metaphor can be used from the beginning. system designer and programmer can be reduced to a minimum. this is not recommended since the resulting code will be much longer and therefore slower in executing than code in other programming languages. Therefore. By using an easy-to-follow tool for the preliminary specification the number of misunderstandings between customer. Actions associated with overall steps can then be described via other nested SFC schemes. but can also be used to describe the more detailed behavior of the plant objects being controlled. In the early phases of a project. 68 3BSE 021 358 R201 Rev B .7 Sequential Function Chart Chapter 4: Programming Languages Powerful Tool for Design and Structuring SFC is a very suitable top-level design tool in the early phase of a project.4. Other Programming Languages are Needed Even though SFC has many advantages as a design and structuring tool it is not a complete programming language. Therefore. The SFC schemes produced in the first phase of a project can be further specified and refined as new information becomes available. the vast majority of programmable controllers use ST as the default language for detailed descriptions in SFC schemes. to give an initial representation of the overall behavior of the system. the transition conditions and action descriptions have to be programmed with one or more of the other four IEC programming languages. Since the description is very easy to follow SFC is a very suitable means of communication between the customer and the programmer. Although it is possible to implement simple Boolean conditions with the help of transitions in SFC schemes. The good continuity of SFC from the initial phase to the refining design phases makes it very popular among system designers and programmers. there are normally many aspects of the system behavior that have not been defined.
The use of ICs has simplified the design of electronic hardware enormously. Function blocks may be regarded as basic building blocks for control systems.8 Function Blocks 4. A function block can be compared to an integrated circuit (IC) which is used in almost all electronic equipment. 34 The abbreviation POU is a common name for all these program parts. A POU may contain functions. The IEC standard ensures that function blocks can be realized using any of the five programming languages. Each function block is a well-packaged software module that can easily be reused in other parts of the control application. IC with counter Up counter CTU CU R PV CV Q Fig. function blocks or entire programs. 3BSE 021 358 R201 Rev B 69 .8 Function Blocks All IEC 61131-3 software applications can be broken down into functional elements called program organisation units (POUs). Function blocks can provide a similar offthe-shelf solution to common control problems.Chapter 4: Programming Languages 4. Application Program Function block Function Program Function block Function block Function Function block Function Function block Fig. 35 Comparison between an IC and a counter function block.
This is especially true in large plants containing a lot of similar control functions which means that function blocks can be reused many times. and • an algorithm that calculates output parameters using the input parameters and. The use of function blocks encourages well-structured design which in return will speed up program development considerably. A function block describes both the behavior of data and the data structure. A function block may be defined using any one of the five programming languages. local variables for intermediate storage. also only called function block.4. It may also be interesting to compare function blocks with objects used in object-oriented programming. The algorithm may be expressed in any one of the five IEC 61131-3 programming languages. These data are required since the function block has to remember its values between each call in the application program. Function blocks contain truly encapsulated data and also have methods (the algorithm of the control function) for processing the data. which uses a number of predefined function blocks. like inheritance. internal variables and output parameters. is a unique set of data values considered together as a structure based on the common rules in the type algorithm.8 Function Blocks Chapter 4: Programming Languages The ability of a function block to store both data and algorithms means that it is possible to develop truly encapsulated control functions. Function blocks may also be called from all the five programming languages. if necessary. Type and Instances One of the main reasons for programming with function blocks is the ability to reuse parts of the application software several times. Do not mix up function blocks with the programming language FBD. However. The function block type contains two parts: • a specification of the data structure for input parameters. This means that although a function block type may use a very complicated algorithm the memory required to store the data for 70 3BSE 021 358 R201 Rev B . are not fully supported by function blocks. The function block instance only contains data that are unique to the particular set of function block type. A function block instance. other features from object-oriented languages. This is accomplished by first establishing a function block type and then creating one or many function block instances of that type.
In many cases. 36 Function block type and function blocks. Many user-defined function blocks are also constructed by combining standard function blocks into more complex structures. There are many advantages of constructing well-proven function blocks that can be used to solve a wide range of control problems.Chapter 4: Programming Languages 4. 3BSE 021 358 R201 Rev B 71 .8 Function Blocks each function block instance may be very modest. A user-defined function block has a close resemblance to an entire application program. the ST programming language is the most suitable for writing the algorithm. Most of today’s programmable controller editors allow the user to define the function block algorithm using any of the five programming languages. Local variables are only available inside the function block and are used for intermediate storage by the algorithm. Parameters are used to transfer data in to or out of the function block. An application program based on several function blocks therefore requires less memory than programs containing duplicates of code. Function block type Converter Variable declarations Converter1 Converter2 Function blocks Converter3 Algorithm Fig. it is always worth considering as many current and future uses of the block as possible. programmers should develop their own function block types for all program parts that can be reused. Each function block instance is given a unique function block name for identification purposes. User-defined Function Blocks In order to fully utilize the potential of function blocks. When designing a new function block type. has its own variables and parameters and a characteristic algorithm describing the tasks it performs. The same algorithm is used several times to calculate the unique sets of data in each function block. The name is shown above the function block symbol. The function block is given a unique type name.
Differences between Functions and Function Blocks Most programmable controllers have a number of predefined functions that can be used in expressions like variables or constants. sin. exp or log. Any number of parameters of any type may be used in a function. tan. 72 3BSE 021 358 R201 Rev B .8 Function Blocks Chapter 4: Programming Languages On the other hand. Fig. 37 Example of a user-defined function block with two statistical calculations. The IEC 61131-3 standard states that when a function is used it should result in one and only one value. Functions may be used in all the five programming languages. This value is calculated from the function’s input parameters. care should be taken not to include so many features and variations into the function block that it becomes cumbersome to use. and conversions like real_to_int or time_to_string.4. A function always results in the same value for the same input values. Function blocks communicate via input and output parameters. Each function block results in a unique set of parameters. Among the most commonly used functions are mathematical ones such as cos. When using a predefined or custom function block the type must always be created and given a unique function block name.
How to Use Function Blocks in Control Programs Before a function block type can be used. you first write the name of the function block followed by a parenthesis.Chapter 4: Programming Languages 4. When called. To call a function block with the ST language. it has to be called.8 Function Blocks A function block cannot be used in expressions. 3BSE 021 358 R201 Rev B 73 . If a function has output parameters it must be used like a function block. To create a function block means almost the same as making a copy of the function block type data. For example. Here. In the programming editor this is normally done via the window used to declare variables. 37 on page 72 connected to local variables in an ST program. 38 A function block from Fig. The programmable controller then reserves individual memory space for the variables and parameters in the function block type. a function can have both input and output parameters. Control Builder Professional from ABB has an increased functionality concerning functions as regards the standard IEC 61131-3. this is the case for a counter which counts up every time it is called and remembers its values until the next count up. Fig. Within this parenthesis you have to fill in the local variables that connect to the parameters in the function block. the programmer has to create a fuction block of it and give this a unique name. Contrary to functions. the programmer has to connect both input and output parameters to local variables in the POU. a function block can create different output parameters although the input parameters have the same values.
The programmer only has to connect the input and output parameters to local variables. Since SFC is not a complete language. of course. Application programs from older control systems may be transformed relatively easily to IEC compliant programmable controllers by using these two languages. but this language unfortunately only has limited power for conditional execution. Experienced programmers often prefer the ST programming language since it gives a compact description and has several tools for conditional execution and powerful mathematical functions. Programmers with previous experience of LD or IL languages may. 74 3BSE 021 358 R201 Rev B . When a function block type is used with the FBD language the editor presents the function block instance as a graphical symbol. although they do not provide the same power as ST or FBD. all logical conditions and calculations have to be written in the other languages. Programmable controllers that are IEC compliant allow the programmer to choose the most suitable language for each task. FBD is another alternative giving a very good overview of logical conditions. use their favorite language. One of the main objectives of the IEC standard is to encourage well-structured program development by breaking down the total function into a number of program organisation units (POUs). It works both as a communication tool between the customer and the programmer and as a structuring tool for the overall design of the control application. Interaction between Languages All the five IEC programming languages have their advantages and disadvantages and no single one of them is suitable for all control tasks. as described above.8 Function Blocks Chapter 4: Programming Languages With the IL programming language you have to call a function block by using the instruction CAL followed by the function block unique name. Such POUs may be programmed in any of the five languages and it is strongly advisable to combine the benefits of more than one language in a total plant application. SFC is by far the most suitable language for the early design and structuring of a control application. The local variables are specified in a similar way as with ST.4.
The increased demands on the hardware. both of which have an extensive degree of standardization of man/machine communication. which is the basic building block for all life. we shall look briefly at a cell. which may be anything from converting energy to producing movement. The behavior of the cell may 3BSE 021 358 R201 Rev B 75 . the latter being a development of the language C. many program projects have been realized with a technique called object-oriented programming. The information on how the cell is to carry out its task is stored in the cell nucleus. however. can be balanced by great savings in time and improvements in the quality of the software.1 New Life for an Old Method Chapter 5 Object-oriented Programs The IEC 61131-3 standard for programmable controllers is not the only effort towards better program quality. but the method is really just a return to an old and more natural way of describing problems. 5. One thought-provoking consequence of this is that beginners often learn to program using object-orientation more quickly that experienced programmers.1 New Life for an Old Method Thinking in an object-oriented manner is perhaps new to many system analysts and programmers. who are hindered by their own traditional way of thinking. Compared with programs that have been produced using more conventional tools. In order to explain the principles of object orientation and some of the basic concepts. Examples of object-oriented programming languages include Simula. In this chapter. object-oriented programs require both more memory and better performance from the computer.Chapter 5: Object-oriented Programs 5. Smalltalk and C++. Every cell has a very specialized task. standardization and the reuse of existing programs in new projects. During the past decade. that technique will be compared with the IEC standard for programmable controllers. Other successful examples using object-oriented techniques are the operating systems for the Macintosh and Windows.
All cells are contained within a membrane which has two important tasks. A message consists of one or more parameters with data which affects specific variables in the cell.e. The receiving cells then react by carrying out the required action. i. All communication between cells occurs by means of chemical substances which pass through the cell membranes. Cells coordinate with other cells via chemical messages which pass through the membrane. the variables. 39 A living cell is object-oriented in the way it works and interacts with other cells. In other words. There are many different types of cell. The class of cell. the first is to protect the cell so that foreign material cannot enter it. however. 76 3BSE 021 358 R201 Rev B . and muscle cells which can alter their shape and carry out work. Examples of these are plant cells with hard membranes. Note that the internal activity of the cell is completely separate from that of surrounding cells. The living cell is an object with a function which is determined by methods in the cell nucleus and by the particular chemical substances which are available. it is sufficient to send orders as to what should be done but not how it should be done.5. blood cells which are mobile and specialized for the transport of gases. but all have the same class or definition of their internal structure and function. Every subclass occurs in a large number of individual instances which have almost identical characteristics. allows several subclasses with different variations.1 New Life for an Old Method Chapter 5: Object-oriented Programs vary according to the particular chemical substances which it may contain at any instant. In order to coordinate with other cells it is sufficient to send chemical messages. and the second is to screen and separate the internal activity of the cell from surrounding cells. thereby affecting the variables. Object Methods Variables Message Fig.
it is quicker to write completely new procedures than to adapt already existing programs to new tasks. 3BSE 021 358 R201 Rev B 77 . etc. it is by no means clear where the boundaries should be drawn between objects. The aim of drawing boundaries is partly to achieve a simple functional description. which reduces the risk of program errors. The programs for the different objects can then be tested individually before the total function is commissioned. The program designer then has to take all the details into account. is called a program organisation unit (POU). Examples of such objects might be valves.2 Objects in the Plant A necessity for being able to work in an object-oriented manner is of course that the total function in the industrial plant can be divided up into subfunctions comprising a number of objects. The simplest implementation is when actual physical objects each have their own corresponding program object. The vast majority of computer programs produced by traditional methods are designed to solve a specific problem. and partly to minimize the total requirement for communication between objects.2 Objects in the Plant 5. PID controllers. In most cases. Fig. robots.Chapter 5: Object-oriented Programs 5. which in the IEC 61131-3 standard. Every object is then programmed with its own program object. In industries where raw materials are processed. similar installations. 40 Object distribution on the right is more efficient as it needs less communication. and to write unique programs for every application. Such programs are difficult to use in other.
5. The situation can be compared with the industrial manufacturing of products where functional units are assembled (e. Programming a system then becomes a matter of selecting suitable objects which can be connected together and thereby simulate the real-life functioning of the installation. The system designer then does not need to know in detail how the final objects work internally.3 Data Flow in Real-time Systems Chapter 5: Object-oriented Programs If program objects (function blocks) which correspond to actual physical objects are used instead. In summary. In order for it to be possible to use program objects efficiently. then there is a greater likelihood that the programs can be reused. the machine may be damaged or the operator injured. a certain delay between cause and effect can be accepted. but as long as the delay is kept at a reasonable level the effect will be minimal. The consequences of a delayed reaction therefore become unacceptable. they must be well documented. for example. cars) with the help of a large number of well-proven standard components. Some of these components may have relatively complex functions. An example may be a machine where some movement has to be stopped when a particular limit is reached.5. on the other hand. particularly regarding their interface with the outside world. which means that changes in the input signal require immediate action on the corresponding output signal. such as the electronic fuel injection system. such as printing out and reporting. complex components of this type can be used without having to have a knowledge of their internal functioning. If the controller does not react in time.3 Data Flow in Real-time Systems Industrial control systems are real-time systems. we have to be able to guarantee correct answers to all conceivable occurrences within a predetermined time. For certain functions. but only how they interact with the environment. This.g. The main part of the programming time would then be taken up in combining and connecting together well-proven program objects to produce finished systems. is the situation in a PID controller. A delay in the operator’s work can naturally have an adverse effect on production. Given that their interface with the outside world is carefully specified. Another notable characteristic of process control is that the internal state of a POU can be altered without any external influence from the input signals from the process. we can say that a real-time system is predictable. where the 78 3BSE 021 358 R201 Rev B . Regardless of the status of the input signals and the internal condition of the system.
and where one often finds a delay between cause and effect. 5. In a data flow-controlled model of this type.4 Program Sorting In order to fulfil the demands made on a real-time system. the POU must have constant access to current input data from the process and from other objects. When the receiving object gets the message. the output signal from a timer has to be updated when the set time delay expires. As 3BSE 021 358 R201 Rev B 79 . several messages are required from other objects before the particular object sends new messages.4 Program Sorting output signal is calculated as the sum of the control error. In an object-oriented system the objects send messages to one another when changes occur. 41 Example of data flow between program POUs in a real-time system. In many real-time systems the object-oriented model is complemented with a mechanism which determines the ordering of messages on the basis of the data flow between the objects. This type of event-controlled activation of objects results in a complex system in which it is difficult to predict the behavior in all conceivable situations. Fig. its integral and its derivative. The object’s program code is executed when all the input data are available. the object is active all the time. the information is stored in the object’s local variables. Under normal circumstances.Chapter 5: Object-oriented Programs 5. Similarly. The integral part is changed automatically with time. which means that the output signal has to be updated at regular intervals.
Because different POUs may have very variable time demands. which are then sorted into a suitable order. This leads to a new execution. 42 During compilation the program code of the objects is sorted in order to give a suitable order for their data flows (compare previous diagram). Sorting of the object’s program blocks is a complex operation. Changes in the incoming signals and local variables therefore affect the output signals at the end of each completed program cycle.4 Program Sorting Chapter 5: Object-oriented Programs soon as the output data have been calculated they immediately become available to other POUs. The total program is executed cyclically with a predetermined interval time. 80 3BSE 021 358 R201 Rev B . During compilation. The interval time (cycle time) of the program is determined by the demands on the maximal delay time in the process. etc. the total program can be divided up into a number of program parts. The total function of the network of objects is then translated into a program list divided into blocks. the aim of which is to achieve the best ordering for their messages. an analysis is first carried out of the data flow between objects. in cyclical succession. The compiled program is executed cyclically at a specific frequency. each with its own interval time. Fig..5.
there are still many who are rediscovering the wheel over and over again. The software for commonly occurring objects is then produced by people with long experience which results in high quality. etc. nuts or similar components.6 Libraries Nowadays. pulse generators. for example. alarm functions. The programmer starts by defining the function block and then creates the required number of instances (copies of data sets). In real-time systems there is less need to create or change program objects while the system is in operation.Chapter 5: Object-oriented Programs 5.5 Reuse of Code 5. limiters. PID controllers. This means that we create abstract classes of objects which describe characteristics common to several different objects. Examples of these are valves with on/off. counters. Abstract classes in many cases lack a physical counterpart in reality. so that it is possible to use them without knowing anything about their internal function. more specialized classes can be created from this type of father class. Examples of objects of this type are PID controllers. New. One of the greatest advantages of object-oriented programming is that it is easy to reuse objects with standard functions. 3BSE 021 358 R201 Rev B 81 . hardly any companies manufacture their own screws. In general object-oriented systems. Concrete classes called POUs (functions. Most IEC compliant programmable controllers today are delivered with a large number of ready-made functions and function blocks stored in standard libraries. and these will automatically inherit all the father’s characteristics. It is important to document the interaction of the objects with their surroundings accurately. function blocks or programs) are therefore used instead of the method of inheritance. etc. on the other hand.5 Reuse of Code Many programmers strive to design program objects which exactly imitate real-life process objects and which contain the same control functions. When it comes to program development using traditional methods. program objects often are reused by a method known as inheritance. continuous or threeposition functions. The production of standard components is carried out by a few large companies who have long experience of the business and who can produce goods of high quality at a low price. It is therefore important to look for patterns and to design general function blocks which can be reused with minimal adaptation. Most installations contain a large number of more or less similar variations of process objects. 5. common functions such as timers. communication units.
43 The standard function block library supplied with Control Builder Professional. In the design of application programs it is important for the programmer to use the standard functions and function blocks as often as possible. one must have a general view of their capabilities and limitations. Fig. This guarantees high quality in terms of the modules’ function . Several standard function blocks can also be combined into user-defined function blocks. 82 3BSE 021 358 R201 Rev B . In order to be able to use the standard function blocks to the full.5. however.6 Libraries Chapter 5: Object-oriented Programs The standard modules are produced by people with many years’ experience of applications in the process industry. be noted that there is a considerable knowledge threshold for the programmer to surmount before it becomes possible to make full use of the advantages of program libraries. which can take a considerable time for complex systems. It should.
like tanks and mixers.1 Control Module Concept A control module is a container for both application programs and graphical objects. The use of control modules promotes object-oriented data flow programming and yields flexible and efficient automation solutions. The engineering tool Control Builder Professional from ABB provides an extension called control modules. 6. like valves and motors. Some vendors of programmable controllers have therefore extended their systems with extra functionality. 44 Mixer process controlled via object-oriented control modules.1 Control Module Concept Chapter 6 Control Modules The IEC 61131-3 standard does not fully support all requirements for objectoriented programs. Control modules are created with a graphical editor providing basic shapes. or more complex subprocesses. Control modules may represent simple process objects. interaction objects and composite objects. 3BSE 021 358 R201 Rev B 83 . Control modules facilitate structuring of large controller applications.Chapter 6: Control Modules 6. Application Material A Conveyor 1 Submodules Conveyor 2 Material B Code for internal behavior Mixed product Submodule handling the interface to neighbors Material A Fig.
Compare this program with Fig. Control modules also provide basic supervision capabilities. 6. 84 3BSE 021 358 R201 Rev B . ellipses. but they also expand the functionality with new features such as graphical programming and automatic code sorting.2 Graphical Programming Control modules are normally created in the Control Module Diagram Editor which is accessed from the Project Explorer window. squares. This window is made up of two toolbars. a status bar and the drawing area. Application programs can be written in any one of the five IEC programming languages described in Chapter 4. The graphics toolbar on the left contains basic autoshapes such as text. Current process status may be presented graphically and the user can feed in parameters through command buttons and input fields. Text objects may be either static or used for displaying actual parameter values in the application.6.2 Graphical Programming Chapter 6: Control Modules A control module may have an application program inside the module. lines. Control modules have a great deal in common with IEC function blocks. All graphical objects may be freely positioned and scaled and it is possible to change the object color. 45 The project explorer shows the hierarchy of all control modules which are edited in the Control Module Diagram Editor. 44. Fig. The drawing area normally has a visible grid which simplifies exact positioning of objects. segments and polygons.
input fields. which may be used for more advanced functions. the compiler then determines the optimal execution order.3 Automatic Code Sorting As was explained earlier. such as command buttons. The non-graphical interaction button is invisible in online mode and is therefore normally placed on top of another graphical object.Chapter 6: Control Modules 6.3 Automatic Code Sorting The graphical toolbar also has ready-to-use interaction objects. For control modules. the compiler analyzes each code block separately with respect to which variables are read and written by each block. Based on the result of that analysis. Control modules are only executed once per scan (cycle). A very important difference between function blocks and control modules is that the control module code blocks are executed in an order based on optimal data flow. bargraphs and trend-graphs. whereas function blocks may be executed several times per scan (or not at all). in Chapter 5. The bar-graph tool is used to produce a graphical presentation of one or more real variables in bar form. real-time systems are sensitive to the order of execution in different parts of the control program. In application programs based on function blocks the programmer has to deal with the sorting manually which may be very difficult and time-consuming in large plants. there are four composite objects: image selectors. several values of variables over a given time period. 6. The visibility of objects may be controlled by Boolean variables which offer a powerful way of showing only the main functionality and temporarily hiding unnecessary details. The string selector is used in a similar way to display one of several text strings. option buttons.3. 3BSE 021 358 R201 Rev B 85 . The automatic program sorting of control modules eliminates program errors due to incorrect execution order. A code block that assigns a value to a variable has to be executed before other blocks that need to read this value. that is. Finally. Such objects make it possible for the user to change process variables and open or close windows while the programmable controller is executing the control application. as determined by the compiler. The trend-graph is used for presenting trend curves. check boxes. windows buttons and non-graphical interaction objects. The image selector is used for displaying one of several pictures or control modules in a specified position. string selectors.
while control modules are recommended for large process applications.4 Applications for Control Modules Before you start to design a control application you should decide whether to use traditional sequence programs with function blocks.4 Applications for Control Modules Chapter 6: Control Modules The technique is called code sorting and means that the optimal execution order will be based on data flow instead of program flow (as is the case for function blocks). the compiler gives a warning message that a program loop exists.6. P1 P2 Fig. it is possible for one module to make a request to another module and to react to the answer within the same scan (cycle). followed by module 1 and finally module 3.10. The choice depends on both application size and the need for reusable program objects. V2 := 20 * P2. P2 := 3 * P1. Control module 2 P1 := 2. 6. Since the execution order of the code blocks in the control modules is determined automatically. R2 := P1 + P2. meaning that the execution order cannot be resolved automatically. Control modules often generate a more effective code than function blocks. V1 Control module 1 V1 := 10 + P1. As a general guideline. when more than one control module uses the same variable for both reading and writing. 46 Automatic code sorting detects that the control module 2 must be executed first. Object-oriented programs are very suitable for controlling batch processes which are often used in the medical 86 3BSE 021 358 R201 Rev B . P1 P2 Control module 3 R1 := V1 . traditional programming is often suitable for small control applications. However. Such a problem can be solved by introducing a new intermediate code block with an extra variable storing the result from the previous scan. or an object-oriented solution based on control modules. Control modules make it much easier to develop object-oriented programs than the standard IEC function blocks. In large applications the performance of the programmable controller often has to be optimized.
47 Time spent in the different phases of a control program project. The reason for this is that object orientation is not normally cost-effective at the lowest complexity level in a plant. Many engineers find this frustrating since they are eager to produce code.4 Applications for Control Modules industry and in the food industry. traditional programming with function blocks is a more cost-effective strategy. i. the control module strategy entails a systematic and time-consuming design process.e. it will also be much easier to manage the maintenance of the plant. 3BSE 021 358 R201 Rev B 87 . Compared with function blocks. However. the time spent on design is repaid during the later phases of implementation. Design Implement Reuse Test Control Module Function Block Fig.Chapter 6: Control Modules 6. Most application programs with control modules also contain function blocks. reuse and testing of the control application. Such program objects can easily be reused in similar subprocesses. If all the code for process objects is concentrated into modules. For simple Boolean logic.
6.4 Applications for Control Modules Chapter 6: Control Modules 88 3BSE 021 358 R201 Rev B .
will result in a control application that takes a very long time to develop. Sometimes. The control system often has to deal with hundreds or even thousands of different inputs and outputs. More experienced programmers use a strategy in which the control application is developed in seven stages.1 Stages of a Project Chapter 7 Project Management Developing large industrial control systems is a demanding task. and is very difficult to debug. An unstructured program for such a system will be very difficult to write.Chapter 7: Project Management 7. This chapter presents a number of methods resulting in a more structured control program with improved software quality. which is then considered to be the design stage. 48.1 Stages of a Project Inexperienced engineers are often very eager to produce control code as fast as possible without “wasting” time on problem analysis. or perhaps lack of strategy. the first two stages are combined into one. 3BSE 021 358 R201 Rev B 89 . Analysis Design Coding Testing Documentation Commissioning Maintenance Fig. 48 The recommended stages of a control system project. 7. as shown in Fig. However. experience shows that such a strategy. specification and design. and even more difficult to follow for maintenance and fault finding.
In large industrial plants this method results in considerable improvements in software quality. the final testing requirements should also be defined. Another important consideration is to provide some form of manual maintenance control that can be used for testing or rescuing an automated plant which has failed to function as expected. In the IEC 61131-3 standard these parts are called POUs. long application program. the most difficult stage in a project.2 Analysis The initial stage of analyzing the control problem is. 90 3BSE 021 358 R201 Rev B . By working from the top down. without doubt. the programmer should not write a single. The result of the analysis stage is a description of how the plant will work. Ideally. what maintenance aids are to be included and a complete list of the I/O signals. what operator stations and control are needed and how these will be implemented. A hierarchical structure is used with POUs at different levels. 7. the supplier/programmer of the control system meets with the other contractors and the operators in the plant to determine what controls are needed and how the control actions are to be carried out. At this stage. Although programmable controllers are easy to reprogram such work will be very time consuming if it has to be carried out during the commissioning stage. Experience shows that inadequate analysis will be very difficult and costly to correct in the later stages of a project. where every POU represents its own particular part of the plant. Often. if possible in an object-oriented structure. At this stage.3 Design In large control applications.2 Analysis Chapter 7: Project Management 7. but instead break it down into many small program parts. the whole problem can be divided up into manageable parts. together with electrical specifications and physical location in the plant. The highest level in the hierarchy gives an overview. each program part should contain no more than about ten logical conditions. since this is the maximum most human minds can hold at any time. while the subordinate levels contain more and more detailed information. the lower down one goes. This work has to be done by people with a good knowledge of both the plant that is to be controlled and of the actual control system being used. it is also important to establish what operator controls are needed. Over the years many methods have been developed which make the work simpler and also result in better software quality. and breaking down the function of the installation into a hierarchical structure of programs.7.
and can then be used in different plant application programs.Chapter 7: Project Management 7. it will be easy for several people to work together on building up the application program. 49 Comparison between block diagram and POU hierarchy for an installation. Each such POU can be tested and optimized individually. The disadvantage of this method is that the POUs have to be very generalized. and it can then take a very long time to correct finished program modules. the top down method is often used at the beginning of a project. Physical plant objects are programmed as self-contained modules communicating with other modules in a data flow-driven model. 3BSE 021 358 R201 Rev B 91 . and so on. while the bottom up method is best for handling the internal object behavior. in which every POU contains subordinate POUs. Assuming that the collaboration between POUs has been accurately specified. where complete POUs are produced at a lower level without having to take account of the structure above them. The need for restructuring grows with the total size of the program project. The hierarchy can therefore also be written as a block diagram. When working with object-oriented programming. which produces less effective program code than with the top down method. An alternate method is to work from the bottom up. Object-oriented programming is described in Chapter 5. The object-oriented approach is the newest method for structuring large control applications. we only need to know how it interacts with other POUs.3 Design POUs at the higher levels in the hierarchy are constructed of a number of other POUs which. It is normally not necessary to know exactly how a complete POU is constructed or how it works inside in order to be able to use it. in turn. Such problems are often not discovered until much later. One limitation of the top down method is that it can be difficult to draw boundaries between program POUs at the beginning of a project. can contain further POUs. Fig.
The resulting actions of actuators are calculated by software in the engineering station and presented graphically on the screen. without communicating with the process. thereby simulating the real transducers. There may also be a need to divide some subprocesses into further subprocesses. A very important advantage of softwarebased control systems is that testing can be carried out with the system running offline. The programmer manually provides input signals via the engineering station. During the work on coding it will sometimes be necessary to further specify the control function in some of the plant subprocesses. 92 3BSE 021 358 R201 Rev B . 7. However. If the initial two stages of analysis and design have been carried out carefully the coding need not involve more than 10% of the total time spent on a project.5 Testing All control systems must be tested carefully before they are allowed to interact with the real-world plant process. the coding can now be done with any of the five IEC programming languages.4 Coding Chapter 7: Project Management 7. Most computer-based engineering stations have a useful simulation feature providing graphical display of selected control functions. Fig. An effective design with well-defined behavior and carefully defined interactions between different subprocesses makes it possible to divide the work of coding between several programmers. it should be noted that such project groups must be managed by an experienced project leader with a good overview of the entire control function. 50 Simulation of SFCs is a very powerful method for testing the control function in a subprocess.7.4 Coding Based on the structure laid down at the design stage.
51 Example of an I/O configuration for a programmable controller. such tests are omitted and faults are not discovered until years after the plant has commissioned. online when the plant is in operation. At this stage. Before the simulated control program can be tested online it is necessary to configure the I/O unit with all the variables that are used in the application. safety-related testing must never be omitted. it is also advisable to test the electrical connections between transducers. Most programmable controllers have LED indicators displaying the status of the I/O unit signals. it can be very time consuming to check all the controls and actions that have been specified in the analysis.5 Testing Since most programmable controllers use standardized I/O modules a control program can be developed using variable names for all the real-world inputs and outputs but without knowledge of the address configuration where the physical signals are connected to the controller. In many projects there is spoken or unspoken pressure to hand over the plant control as soon as all the basic operations have been tested. but with more rarely used options untried. With all but the simplest systems. 3BSE 021 358 R201 Rev B 93 . It is therefore very important to establish what testing must be carried out before the plant can be started and what can be tested later.Chapter 7: Project Management 7. actuators and the programmable controller. Finding out that an emergency stop sequence does not work when it is used for the first time in a real emergency will definitely create a disaster. Fig. Too often. However.
6 Documentation At every stage in a project new documents are added describing the plant from several different aspects. After successful testing. which includes fault finding and minor changes in the specified control function. When a new control system is introduced in a plant all personnel involved must be informed about the system.6 Documentation Chapter 7: Project Management 7. The cost of online testing together with the process may sometimes be more than ten times higher than testing offline. 94 3BSE 021 358 R201 Rev B . the online test together with the process should not result in any unpleasant surprises. Therefore. Since it is very easy to alter the control function in programmable controllers there always is a risk of losing grip on the plant after program changes. if there are some process conditions that could not be simulated effectively offline. Well structured documentation is one of the best tools for this purpose. The purpose of the documentation is both to help the operators during normal use and to serve the maintenance personnel when something goes wrong. time consuming and therefore also very expensive. it is of vital importance that control programs be developed and documented so they can be easily changed. commissioning is an undramatic experience. the online testing may be very difficult. It is therefore very important that the documents are well structured and adapted to the needs of both these categories. 7. Experience shows that the maintenance stage accounts for almost 50% of the total time spent on a project during its life-time. In many plants. 7. all these documents have to be gathered together to provide total documentation of the plant control system. Such changes are often a response to market needs or to new technologies being developed.8 Maintenance The final maintenance stage seems to be very far away during the earlier stages of a project. once a plant control system is handed over it must be maintained. also by people who were not involved in the previous stages.7 Commissioning If the application has been tested thoroughly offline. However. It is therefore very important that all documents are updated with changes made to the control function during the project.7. However.
Conveyor ES LSL Forward/Back Open/Close Left/Right LSB LSF Machine LSR Fig.1 Control Problem The subprocess in question is an industrial robot moving car parts from a conveyor to a manufacturing machine.1 Control Problem Chapter 8 Industrial Application Example In this final chapter we are going to apply the earlier described structuring methods and programming techniques to a real-world plant. To keep complexity at a reasonable level we will concentrate our efforts on one of many subprocesses in the manufacturing line of an automobile factory. The car plant contains a number of such robots with similar behavior.Chapter 8: Industrial Application Example 8. 8. 52 The industrial robot moves car parts between a conveyor and a machine. 3BSE 021 358 R201 Rev B 95 . The system is to be controlled by a programmable controller of the type AC800M/C.
The robot system uses four limit switches to collect information about the current position of the arm. If the machine has completed the previous operation a command from the conveyor control program starts the robot arm moving forward. the foremost part of the arm can also move forwards or backwards and the gripper.8. The total time needed for the gripper to close completely is 2 s. All the movements are to be controlled by six digital output signals from the programmable controller. All the inputs and outputs are summarized in the table below.2 Analysis Chapter 8: Industrial Application Example 8. The reason for moving the arm forwards and backwards is that there is limited space when the arm rotates between the conveyor and the machine. This makes it possible to hold the output signal from the control system for a short while after the gripper has reached its final position. With the gripper closed around the car part the arm is now moved backwards and when LSB is active the arm begins to rotate right towards the machine. The entire arm can rotate left or right. When the arm reaches its forward position (indicated by LSF) the gripper begins to close around the car part.2 Analysis The robot has three different electrical engines which move the manipulator. thereby eliminating the need for two limit switches. can open or close. The gripper has a mechanical device that stops it from pressing too hard on closing and opening. When LSR at the machine 96 3BSE 021 358 R201 Rev B . I/O signal Arm_Forward Arm_Backward Arm_Right Arm_Left Gripper_Closes Gripper_Opens Limit_Switch_Left Limit_Switch_Right Limit_Switch_Back Limit_Switch_Forward Emergency_Switch I/O AF AB AR AL GC GO LSL LSR LSB LSF ES In/Out Description Out Out Out Out Out Out In In In In In Robot arm moves forwards Robot arm moves backwards Robot arm turns right Robot arm turns left Gripper closes Gripper opens Robot arm at the conveyor Robot arm at the machine Robot arm in its backward position Robot arm in its forward position Emergency signal from operator In its initial state the robot is placed at the conveyor with the arm in its backward position and with the gripper fully open. finally.
The conveyor and the machine are both controlled by other control programs.Chapter 8: Industrial Application Example 8. All the transducer signals from the limit switches and the emergency switch are of digital type. Since the robot motors should be started and stopped smoothly. This is accomplished through a ramp signal with a duration adapted to the needs of the different movements and for start and stop. all robot movements should start and stop smoothly. the arm is moved backwards until LSB is active followed by a turn to the left until LSL indicates that the arm is back in its initial state. The robot control program has to communicate with these via the following four Boolean parameters: Parameter name Conveyor_Request Machine_Ready Robot_Home Robot_Ready Short In/Out CR MR RH RR In In Out Out Information Conveyor needs transportation Machine has finished operation Robot is back in initial position Robot has finished transportation If something goes wrong in the plant the operator stops the control system via an emergency switch. After an emergency situation the operator puts the system into its initial state by controlling the motors manually in a normal sequence.2 Analysis indicates that the arm is in the correct position it begins to move forwards again. After this. all the actuator signals have to be of analog type. All motors must then stop immediately. The total time needed for the gripper to open completely is 1 s. This means that our programmable controller must have an I/O unit with five free digital inputs and six free analog outputs. The gripper now opens and releases the car part to the machine. In order to minimize energy consumption and reduce the risk of damaging the equipment and the car parts. 3BSE 021 358 R201 Rev B 97 . which continues until LSF is active.
Conveyor_Request Conveyor Robot_Home Robot Robot_Ready Machine_Ready Machine Fig.8. which together with a control program (interlocking with emergency switch). thereby standardizing the operator interface and reducing the programming work. The control program uses the internal states of the SFC sequence interlocked with the emergency signal to control the motors. control program and ramp function block. 53 Communication between the robot and its neighboring subprocesses. handles the movement of the robot arm.3 Design Chapter 8: Industrial Application Example 8. According to the top down strategy the robot control module should contain an SFC sequence program. Such a module may be reused several times in the plant. All motor controls will pass through a ramp function block generating a smoothly increasing or decreasing output signal. 98 3BSE 021 358 R201 Rev B . Since the plant contains several similar robots the control problem should preferably be solved via an object-oriented robot control module. The robot control module should have a graphical symbol with color shifts indicating its state.3 Design The analysis has shown that our robot is a self-contained system with relatively limited communication with the surrounding subprocesses in the plant. Gray may be used to signify inactive. 54 The structure of our robot control module with SFC program. green for active (moving car parts) and red for emergency state. Robot control module SFC sequence program Control program Ramp Fig.
Chapter 8: Industrial Application Example 8. 3BSE 021 358 R201 Rev B 99 . The sequential control function for our robot arm is shown in such a flow chart below. even for those with no engineering background. 55 Flow chart describing the control function for our robot sequence. The sequence uses eight different working states plus the initial waiting state . Init 1 N CR and MR Y AF AF LSF Y N LSF Y GC N GO Delay 1s Y N Delay 2s Y AB N AB LSB Y N LSB Y AR N AL LSL Y N LSR Y N 1 Fig.3 Design Technicians who are not familiar with SFC often use flow charts to describe sequential behavior. Such flow charts are easy to follow. But unfortunately they often become very large and therefore will be difficult to manage in large plants.
56 Timing diagram for a ramp function block. the function block must have a shorter interval time than the rest of the application. It must be possible to change the ramp up and ramp down times depending on which movements are to be controlled. Input Output 100% 0% 1s 0. it is advisable to appoint one programmer to be responsible for the project-specific libraries and to allow the others to use them as read-only files.4 Coding Our robot control project will now be implemented with the engineering tool Control Builder Professional from ABB. equipped with a digital input I/O module and an analog output I/O module. An example of such a ramp timing diagram is shown below.g. function blocks types. e. Since the robot control module and the ramp function block will both be used several times in our application. we will create a library called MyLib for that purpose. 8.8. functions and data types that are to be used several times are normally placed in one or several project-specific libraries. they should both be placed in MyLib.4 Coding Chapter 8: Industrial Application Example The ramp function block type should generate a smooth increase or decrease in the analog output as soon as the digital input is turned on or off. In large projects with several programmers involved. Such control functions can easily be reused in a similar manner as the objects in SystemLib. In order to produce a smooth output. The control project will be developed for downloading to an AC 800M programmable controller. The ramp function block should be programmed via cyclical addition and subtraction. All the 100 3BSE 021 358 R201 Rev B .5 s Fig. 100 ms compared with the normal 250 ms. In our example. Project Libraries All project-specific control modules types.
Fig. These can either be defined as global variables in the application or as local variables in the module where they are needed. should also be placed in MyLib. Following the rules of object-orientation we will use a structured variable for communication between the robot module and its surrounding modules. Variables and Parameters Before the actual coding starts it is recommended that all the variables and parameters needed in the project are defined. In most cases the work therefore starts with the real-world I/O signals. 57 The Project Explorer window showing our robot project’s configuration of MyLib and the AC 800M controller. it is often difficult to predict what local variables are needed inside control modules and function blocks. The system accepts both kinds of variables when connection to the I/O modules is established. However. The data type of this variable. called Robot_Communication.Chapter 8: Industrial Application Example 8.4 Coding underlying control modules used in the robot control module will automatically be available as control module types in MyLib. 3BSE 021 358 R201 Rev B 101 .
The only parameter needed in the robot control module is the project declared Robot_Communication used for signal exchange with other modules. RealIO and BoolIO are both composite data types containing the current value plus a number of components used for manual signal forcing. In our project we will choose this last method. Fig. since all modules may write to such variables. 102 3BSE 021 358 R201 Rev B . this also increases the risk of data corruption. Unfortunately. 58 Local variables used in our robot control module.8. Using local variables gives better encapsulation of data but also has a small disadvantage in that modules cannot be moved in the hierarchy once the connection to the I/O unit is established.4 Coding Chapter 8: Industrial Application Example Global variables are available at all module levels in an application which simplifies the programming.
Fig. the function block must have two parameters establishing these two values.Chapter 8: Industrial Application Example 8. 59 The ramp function block type uses conditional cyclic addition or subtraction of a step value that is calculated from the time demands on the ramp signal. Since the different robot movements may have their own demands on the delay time. The ramp will be used six times for the different robot motor outputs and the ramp function block type must therefore be created six times. The purpose of this buffering is to achieve smooth acceleration and retardation when the motors start and stop. A shorter interval time is accomplished by connecting the six function blocks to the Task Fast and setting its interval time to 100 ms in the Tasks window. for both increasing and decreasing.4 Coding Ramp Function Block Type The ramp function block type will be used as a buffer between the digital states in the SFC sequence program and the analog output signals to the motors creating robot arm movements. 3BSE 021 358 R201 Rev B 103 . In order to create almost linear output signal these function blocks should be executed with a shorter interval time than the SFC sequence and the control program.
Our sequence uses two timer function blocks to create delays in the states Close and Open.8.4 Coding Chapter 8: Industrial Application Example SFC Sequence Program The flow chart functional description of the sequence is easy to program as an SFC program block. 104 3BSE 021 358 R201 Rev B . 60 The robot sequence as an SFC code block with the selected transition condition Tr4 in a separate window. Each state is represented by a named SFC step with code in separate windows and transition conditions in other windows. Fig. The required timer statements are placed in the code windows for continuous action at the two corresponding steps.
From the above mentioned it is evident that there is a need for an extra control program block containing the interlocking logic and the “summing up” of the different conditions for activation. Finally we must not forget to create the two Boolean signals that are used to tell other control modules that the robot has moved a car part to the machine and that it is back in it’s initial position at the conveyor.X) is not used directly for controlling the outputs in a process. 3BSE 021 358 R201 Rev B 105 . This is also the case for the steps Backward1 and Backward2. Additionally.Chapter 8: Industrial Application Example 8. In our robot sequence either the step Forward1 or the step Forward2 should result in the same action. 61 The robot control program is used to connect the Boolean step states with the analog motor outputs via six function blocks of the ramp function block type. This program block is also a suitable place in which to call the ramp function block that are to create smooth robot arm movements. Fig. the binary status from an SFC step (Stepname. The reason for this is that there is often a need to interlock the step status with other variables such as emergency signals. many systems do not have a one to one relation between the steps and corresponding process actions.4 Coding Control Program Normally.
but in the screen above they have been moved to illustrate the method 106 3BSE 021 358 R201 Rev B . In our robot process we want to indicate the status of the robot arm with colors. the module may also contain interactive graphical objects. apart from its control programs. This can be accomplished in several ways. Fig. Such objects can be used for presenting actual process status to the operator. Normally.4 Coding Chapter 8: Industrial Application Example Control Module Graphics An important advantage of using control modules is that. 62 The variables Any_Action and Emergency_Switch.8. The visibility of modules can easily be controlled by Boolean variables. but one of the simplest is to use three similar robot modules with different colors and to only show one at a time. the modules are placed exactly on top of each other.Value can be used to control the visibility of three differently colored robot modules.
5 Testing 8. All testing normally follows such a bottom-up procedure. separately. 3BSE 021 358 R201 Rev B 107 . The sequence function is very easy to test via simulation since the status is displayed directly on the screen.Chapter 8: Industrial Application Example 8. 63 By providing simulated variable values. If a function block is connected to surrounding local variables it is possible to simulate and observe the function. Real-world input signals are then fed in manually either by typing on the keyboard or by the pointing device.5 Testing When large applications are to be tested it is of vital importance to reduce the complexity by first testing smaller program parts. the programmer can test run the function without being in contact via the programmable controller. like function blocks. Fig. and control modules. In our robot project the testing starts with the ramp function block. Once the smaller parts have been debugged the entire application can be tested more effectively. Most engineering stations have a simulation feature where an entire program project can be tested without compiling and downloading it to the programmable controller.
5 Testing Chapter 8: Industrial Application Example When function block types and control module types are to be tested it is normally best to work with a funbction block and control module and connect it to other modules providing the necessary parameter communication. Most simulations are carried out with much less processing power than during real execution in the controller. Parameter communication is accomplished through a temporary structured variable.8. 64 When the robot control module type is to be tested it is best to create another temporary control module using a control module of the robot module. 108 3BSE 021 358 R201 Rev B . compared with online execution. After successful simulation the control project should always be downloaded to the programmable controller and tested online. The exact timing behavior of critical control functions may therefore be very different when simulated. It may sometimes be necessary to create variables or control modules that are used for testing only and deleted afterwards. Fig.
e. step by step. temperature.Chapter 9: Glossary 8. ASCII is the most commonly used code for character representation in data processing systems. how a problem is to be solved.5 Testing Chapter 9 Glossary A adaptive control Control system where the controller parameters are automatically adjusted to the properties of the process. analog signal A continuously variable signal which represents a physical quantity. algorithm A collection of rules which describe. assembler instructions A low-level programming language using letter codes to represent the machine code instructions. 3BSE 021 358 R201 Rev B 109 . application The application contains a number of instructions that are compiled and downloaded for execution in the controller. flow or pressure.g. ASCII An abbreviation for American Standard Code for Information Interchange.
CPU The Central Processing Unit in a computer or programmable controller is the “brain” that coordinates all activities and carries out all operations specified in the application program.8. bus A system of parallel circuit wires for connecting the different units in a computer system or a programmable controller. Boolean A variable that can only hold logical values such as True and False or 1 and 0.5 Testing Chapter 9: Glossary B baud A unit used to specify the data transmission rate between two devices. In PLCs the name Central Unit is often used instead of CPU. One baud is equal to one bit per second. 110 3BSE 021 358 R201 Rev B . C compiler An application program that translates the control application to low-level machine language that can be executed in a computer or programmable controller. bottom up A method for structuring application programs where the individual program objects are developed without consideration of the program structure above them. cycle time All application programs in programmable controllers are executed repeatedly at a specified time interval.
5 Testing D digital signal A signal with only two possible states. 3BSE 021 358 R201 Rev B 111 . F falling edge The change from 1 to 0 of a Boolean variable. distributed systems A control system with several computers or programmable controllers communicating with each other via a local network. download A common name for the transfer of a compiled application program from the engineering tool to the programmable controller. full duplex A transmission method where data can be both transmitted and received simultaneously. on and off or 1 and 0. fieldbus A communication bus used for digital information interchange between sensors. execution When a computer is running the instructions are executed one at a time. feedback A signal from the controlled process may be fed back to the controller where it is used in the control algorithm. E editor Application program that is used for writing and editing text or instructions. actuators and programmable controllers. called high and low.Chapter 9: Glossary 8.
It translates between different communication protocols. 112 3BSE 021 358 R201 Rev B . high-level language A programming language similar to ordinary written text where each instruction or statement results in several machine code instructions.5 Testing Chapter 9: Glossary G gateway A communication unit for connecting different types of networks. hexadecimal A system of numbers to the base 16. H half duplex A transmission method where data can only be transmitted in one direction at a time. The numbers 0 – 9 are not changed while 10 – 15 are represented by the letters A – F. Pascal. C and Java are common high-level languages. hardware A common name for all the equipment in a computer system.8. global variable A variable that can be accessed by all programs.
5 Testing I I/O module Many programmable controllers use expandable I/O units making it possible to add more input or output signals via extra modules. LSB An abbreviation for Least Significant Bit. 3BSE 021 358 R201 Rev B 113 . integrated circuit Electronic functional unit containing a large number of semiconductors which have been compressed to a small silicon chip. local variable A variable that can only be accessed in the program where it is defined. i. instruction A programming language element that specifies an operation and the values or location of its operands.Chapter 9: Glossary 8. A LAN is used to enable high-speed communication between several computers and programmable controllers in a plant. modules and other language objects.e. the bit in a binary number with the lowest value. initialization Establishing basic conditions when a system starts up. Assembler is a typical low-level language. parameters. I/O signal The physical inputs or outputs of the I/O module. low-level language A programming language with letter codes where each instruction results in one machine code instruction. L LAN Abbreviation for Local Area Network. identifier A combination of letters. numbers and other characters used to give names to variables.
This is the normal situation for editing the source code. which specifies the messages used for industrial communication (manufacturing. The decimal digits 8 and 9 are not used in this system. O object code Common name for the resulting code produced when the compiler has translated an application program to executable machine language. process robotics etc. a specification for open communication based on the OSI model. online A computer (with editor and compiler) is considered to be online when it is connected to the controller where the program is being executed. the bit in a binary number with the highest value. MMS An abbreviation for Manufacturing Message Specification. 114 3BSE 021 358 R201 Rev B . MSB An abbreviation for Most Significant Bit. i.). offline A computer (with editor and compiler) that is not connected to the controller is considered to be offline. This is the application layer used within MAP (Manufacturing Automation Protocol).5 Testing Chapter 9: Glossary M machine code When a computer executes a program it must be available in machine code language which is a low-level language with binary or hexadecimal codes. This is the normal situation with the plant application executing and the process status being displayed in the editor. octal A system of numbers to the base 8.e.8.
Chapter 9: Glossary
PLC An abbreviation for Programmable Logic Controller which is the most common type of control system in today’s industry. POU An abbreviation for Program Organisation Unit. The IEC standard describes programs, function blocks and functions as POUs. protocol A set of rules which determines the procedure for communication between different I/O units, computers or controllers.
RAS Abbreviation for Remote Access Service. With RAS a remote client can dial up a gateway machine resident on a LAN and establish a connection over the telephone network. real-time system A system where changes in the input signals will result in immediate actions on the corresponding output signals. Almost all control systems are of this type. rising edge The change from 0 to 1 of a Boolean variable. RS-232C International standard for serial data transmission with the signal levels -12V and +12V. Mainly used over relatively short distances.
3BSE 021 358 R201 Rev B
Chapter 9: Glossary
sampling Computer-based control systems cannot communicate continuously with the surrounding transducers and actuators. Instead, the control system samples the environment (collects and transmits values) periodically with a specified sample time. SattBus A fairly fast (62.5 kbit/s) fieldbus with token bus protocol. It is intended to be used for short messages to field devices such as transducers, actuators, etc. simulation Many computer-based engineering tools provide a function for simulating the control function in the computer without downloading it to the programmable controller. source code Programs written in high-level languages are often called source code before they are compiled to object code.
TCP/IP An abbreviation for Transmission Control Protocol/Internet Protocol. TCP/IP is used both on the Internet and on many Local Area Networks.
top down A method of breaking down the entire control function into a hierarchical structure of subprocesses.
workstation A common name for a computer with associated software used for editing and compiling control programs.
3BSE 021 358 R201 Rev B
Chapter 9: Glossary
3BSE 021 358 R201 Rev B
Chapter 9: Glossary 8.5 Testing 3BSE 021 358 R201 Rev B 118 .
Index Numerics 3964R 23 control modules 83 controller 9 cross-assembler 16 I I/O unit 19. 50 C++ 75 central unit 19 class 76 closed loop control 13 code sorting 86 COMLI 23 comment 38. 70. 72 function block name 72 M machine code 16. 91 E edge 56 editor 16. 72 function block 32. 46 common elements 37 communication protocol 23 compatibility 27 compiler 17. 21 elementary data type 38 encapsulated data 43. 76 minor state 67 MIS 29 mnemonic 47 monitoring subsystem 12 G global variable 40. 21 event 31 execute 16. 80. 31. 69 identifier 37 IL register 47 inheritance 70. 81 instruction 16. 19 memory bit 42 message 76 methods 70. 76. 83 F feedback loop 41 flow chart 99 function 54. 20 IC 10. 21 Macintosh 75 main state 67 MAP 29 memory 12. 101 Grafcet 62 H high-level language 17 3BSE 021 358 R201 Rev B 117 . 81 initial step 63 initial value 40 instance 53. 101 loop 86 low-level language 17 C C 18. 69. 46 instruction list 21 integrated circuit 60 interaction object 85 internal state 78 interpreter 17 interval time 22. 21 compliance class 33 composite object 85 conditional statement 51 constant 39 contact 41 Control Builder Professional 21. 86 Boolean data 39 bottom up 32. 103 A abstract classes 81 access variable 40 accumulator 47 action 62 action description 64 action qualifier 64 actuator 10 analyze 90 assembler 16 assembly language 46 D data flow 79 data structure 31 DCS 28 debugging program 16 definition/type 76 distributed system 23 divergent path 65 download 21 Duration 39 B Basic 18 batch process 65. 70 engineering station 19. 54. 22 expression 50 L label 46 ladder diagram 20 LED indicator 93 libraries 12 local area network 11 local variable 40.
76 Pascal 18. 77. 67. 70. 72. 76 W Windows 75 R real-time system 22. 69. 41 relay logic 13 remote I/O 23 result register 47 retain 40 S SCADA 11. 90 transducer 9 transition 62 transition condition 62 type 70 V variable 40. 50 operator 46. 78 relay coil 13.Index O object 76 object code 18 object-oriented programming 75 object-oriented systems 12 offline 21. 103 Time of day 39 timer 79 top down 32. 78 PLCopen 33 plinth 14 POU 31. 92 online 22. 28 semantics 49 sensor 43 sequence 12. 40. 90 power rails 41 process computer 11 Process Value 13 Profibus 23 Programmable Controller 11. 81 118 3BSE 021 358 R201 Rev B . 93 operand 46. 44 sequence selection 65 Set Point 13 shareware 26 Simula 75 simulation 21. 50 PID controller 13. 50 operator modifier 47 optical isolator 20 state 44 statement 50 step 62 Step active flag 64 structured data type 38 subclass 76 subprocess 12 subroutine 43 subsequence 67 syntax 16 syntax checking 21 SystemLib 100 P parameter 54. 19 Programmable Logic Controller 11. 92 simultaneous sequence 66 Smalltalk 75 Soft PLC 23 source code 18 standard libraries 60. 19 protocol 28 T task 23.
3BSE 021 358 R201 Rev B October 2001 .
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.