Programming languagesfor PLC: International Standard IEC61131-3 (part two)



Similar documents
Automazione Industriale 3 - I linguaggi di programmazione.

Programming languagesfor PLC: International Standard IEC (part one)

S and STEP 7 Basic V10.5

Industrial Process Automation (Exercise)

2 Building Blocks of IEC

Automating with STEP7 in LAD and FBD

Micro800 Programmable Controllers: Getting Started with CIP Client Messaging

Automating witfi STEP7 in LAD and FBD

Applications & Tools. Configuration of Messages and Alarms in WinCC (TIA Portal) WinCC (TIA Portal) Application description December 2012

First Steps with CoDeSys. Last update:

Microsoft SQL connection to Sysmac NJ Quick Start Guide

Programmable Logic Controller PLC

Prototype environment for controller programming in the IEC ST language 1

SoMachine. Getting & Setting Real Time Clock SysTime Library Guide 04/ EIO SoMachine

SIMATIC. Structured Control Language (SCL) for S7-300/S7-400 Programming. Preface, Contents. Part 1: Designing Programs

IEC The Fast Guide to Open Control Software

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 OUTCOME 3 PART 1

Tool for Control Technology

Cover. SEB SIMOTION Easy Basics. Collection of standardized SIMOTION basic functions. FAQ April Service & Support. Answers for industry.

SIMATIC. S Getting started with S Preface. Quick review 1. Installation 2. Create a simple latch circuit 3. Complete the user program 4

Sources: On the Web: Slides will be available on:

Visual Programming of Logic, Motion, and Robotics

fakultät für informatik informatik 12 technische universität dortmund Data flow models Peter Marwedel Informatik 12 TU Dortmund Germany

THE STEP7 PROGRAMMING LANGUAGE

Ladder and Functional Block Programming

Magelis SCU EIO /2013. Magelis SCU. SoMachine Programming Guide 05/2013 EIO

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Candle Plant process automation based on ABB 800xA Distributed Control Systems

AKD EtherNet/IP Communication

Linear Motion and Assembly Technologies Pneumatics Service. Understanding the IEC Programming Languages

Compliance and Requirement Traceability for SysML v.1.0a

SECTION C [short essay] [Not to exceed 120 words, Answer any SIX questions. Each question carries FOUR marks] 6 x 4=24 marks

Digital Electronics Detailed Outline

Understanding the IEC Programming Languages

2011, The McGraw-Hill Companies, Inc. Chapter 5

PLC SW and Programming. Nagy István, BMF BGK MEI

EXPERIMENT 2 TRAFFIC LIGHT CONTROL SYSTEM FOR AN INTERSECTION USING S7-300 PLC

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

The goal is to program the PLC and HMI to count with the following behaviors:

SHORT TRAINING COURSES

Technical Training Module ( 30 Days)

SIMATIC. C7-621, C7-621 AS-i Control Systems. Volume 2 Working with C7 A B C D E. Contents. User Information. Introduction. Startup.

WESTMORELAND COUNTY PUBLIC SCHOOLS Integrated Instructional Pacing Guide and Checklist Computer Math

Programming A PLC. Standard Instructions

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

The programming language C. sws1 1

LADDER LOGIC/ FLOWCHART PROGRAMMING DIFFERENCES AND EXAMPLES

Library ModbusRTUlib Modbus RTU master communication. TXV rd Issue February 2010 All rights reserved

Embedded Software Development with MPS

Lecture 8: Synchronous Digital Systems

ON SUITABILITY OF FPGA BASED EVOLVABLE HARDWARE SYSTEMS TO INTEGRATE RECONFIGURABLE CIRCUITS WITH HOST PROCESSING UNIT

Programming Manual Catalog Numbers 1756 ControlLogix, 1769 CompactLogix, 1789 SoftLogix, 1794 FlexLogix, PowerFlex 700S with DriveLogix

1. True or False? A voltage level in the range 0 to 2 volts is interpreted as a binary 1.

Programmable Logic Controllers Definition. Programmable Logic Controllers History

ABB i-bus EIB Logic Module LM/S 1.1

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

CHAPTER 3 Boolean Algebra and Digital Logic

AQA GCSE in Computer Science Computer Science Microsoft IT Academy Mapping

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

SIMATIC. System Software for S7-300 and S7-400 Program Design A B C D. Programming Manual C79000-G7076-C Preface, Contents

Course Title: Software Development

STEP 7 MICRO/WIN TUTORIAL. Step-1: How to open Step 7 Micro/WIN

EasyC. Programming Tips

Moving from CS 61A Scheme to CS 61B Java

SIMATIC. WinCC V7.0. Getting started. Getting started. Welcome 2. Icons 3. Creating a project 4. Configure communication 5

Simple Cooperative Scheduler for Arduino ARM & AVR. Aka «SCoop»

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

#820 Computer Programming 1A

PLCs and SCADA Systems

Robotics and Automation Blueprint

13 File Output and Input

Training Document for Integrated Automation Solutions Totally Integrated Automation (TIA) MODULE M1

Programming Logic controllers

S7 for Windows S7-300/400

Creating the program. TIA Portal. SIMATIC Creating the program. Loading the block library. Deleting program block Main [OB1] Copying program blocks

TwinCAT Manual Quick Start V.1

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

TwinCAT NC Configuration

WA Manager Alarming System Management Software Windows 98, NT, XP, 2000 User Guide

PROFINET IO Diagnostics 1

Lecture 7: Programming for the Arduino

Memory Systems. Static Random Access Memory (SRAM) Cell

VHDL GUIDELINES FOR SYNTHESIS

Attention: The installation of the ABB Automation Builder software requires administrator rights.

Automation software Concept V2.6 The flexible IEC development environment to optimize PLC performance

RAPID PROTOTYPING OF DIGITAL SYSTEMS Second Edition

Application of RT-Preempt Linux and Sercos III for Real-time Simulation

EMC Publishing. Ontario Curriculum Computer and Information Science Grade 11

Beckhoff TwinCAT The Windows Control and Automation Technology. TwinCAT NC PTP Examples

Industrial IT. Basic Control Software Introduction and Configuration. Compact Control Builder AC 800M. Version 5.0

Digital Logic Design. Basics Combinational Circuits Sequential Circuits. Pu-Jen Cheng

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

PROGRAMMABLE LOGIC CONTROL

UNIT 1 INTRODUCTION TO NC MACHINE TOOLS

From Control Loops to Software

Programming Languages

Keil C51 Cross Compiler

Transcription:

Automation Robotics and System CONTROL Università degli Studi dimodena e Reggio Emilia Programming languagesfor PLC: International Standard IEC61131-3 (part two) Cesare Fantuzzi (cesare.fantuzzi@unimore.it) Ingegneria Meccatronica AA 2012/2013

Instruction Lists (1) Instruction lists is the machine language of PLC programming It has 21 instructions (see table) Three modifiers are defined: "N" negates the result "C" makes it conditional and "(" delays it. All operations relate to one result register (RR) or accumulator. C. Fantuzzi 3. I Linguaggi di Programmazione 2

Instruction Lists Example (2) End: ST temp3 (* result *) Instructions Lists is the most efficient way to write code, but only for specialists. Otherwise, IL should not be used, because this language: provides no code structuring has weak semantics is machine dependent C. Fantuzzi 3. I Linguaggi di Programmazione 3

Data Types All the programming languages share a common method for the variable definition. Each variable used in IEC routine should be defined in the declaration area: VAR AVERAGE_SPEED : REAL; Enable : BOOL; END_VAR The general declaration syntax: VAR <VAR_NAME> : <TYPE> ; <VAR_NAME> : <TYPE> := <INITIAL _VALUE> ; END_VAR C. Fantuzzi 3. I Linguaggi di Programmazione 4

61131 Elementary Data Types No. Keyword Data Type Bits 1 BOOL Boolean 1 2 SINT Short integer 8 3 INT Integer 16 4 DINT Double integer 32 5 LINT Long integer 64 6 USINT Unsigned short integer 8 7 UINT Unsigned integer 16 8 UDINT Unsigned double integer 32 9 ULINT Unsigned long integer 64 10 REAL Real numbers 32 11 LREAL Long reals 64 12 TIME Duration depends 13 DATE Date (only) depends 14 TIME_OF_DAY or TOD Time of day (only) depends 15 DATE_AND_TIME or DT Date and time of day depends 16 STRING Character string 17 BYTE Bit string of length 8 8 18 WORD Bit string of length 16 16 19 DWORD Bit string of length 32 32 20 LWORD Bit string of length 64 64 C. Fantuzzi 3. I Linguaggi di Programmazione 5

To define an array: or a matrix Array VAR <ARRAY_NAME> : ARRAY [<INDEX_MIN>..<INDEX_MAX>] OF <TYPE> ; END_VAR VAR <MATRIX_NAME> : ARRAY [<ROW_MIN>..<ROW_MAX>] OF ARRAY[<COL_MIN>..<COL_MAX>] OF <TYPE>; END_VAR Example POSITIONS : ARRAY [0..10] OF REAL ; C. Fantuzzi 3. I Linguaggi di Programmazione 6

Structure A structure is a collection of heterogeneous variables: VAR STRUCT <VAR_1> : <VAR_1_TYPE>;... <VAR_N> : <VAR_N_TYPE>; END_STRUCT; END_VAR; C. Fantuzzi 3. I Linguaggi di Programmazione 7

Derived Data Type The IEC allows the definition of custom data type. This improves the readability of the software. Improve the checking possibility of the compiler on the user code. Syntax: Example TYPE <TYPE_NAME> : <TYPE> ; END_TYPE TYPE PUMP_PRESSURE : REAL ; END_TYPE VAR Pump_cooler : PUMP_PRESSURE; END_VAR; C. Fantuzzi 3. I Linguaggi di Programmazione 8

A UserDefined data types can be A subrange of a elementary data type: A list of constant (the enum data type) An Array or Matrix. A structure. TYPE ROBOT_POSITION : REAL(0..100) ; END_TYPE TYPE MACHINE_STATUS : (STOP, RUN, FAULT, IDLE) ; END_TYPE C. Fantuzzi 3. I Linguaggi di Programmazione 9

Example of Derived Types TYPE ANALOG_CHANNEL_CONFIGURATION STRUCT RANGE: ANALOG_SIGNAL_RANGE; MIN_SCALE : ANALOG_DATA ; MAX_SCALE : ANALOG_DATA ; END_STRUCT; ANALOG_16_INPUT_CONFIGURATION : STRUCT SIGNAL_TYPE : ANALOG_SIGNAL_TYPE; FILTER_CHARACTERISTIC : SINT (0.99) CHANNEL: ARRAY [1..16] OF ANALOG_CHANNEL_CONFIGURATION; END_STRUCT ; END_TYPE C. Fantuzzi 3. I Linguaggi di Programmazione 10

Connecting to Input / Output, Symbol table: Variables configuration All program variables must be declared with name and type, initial value and volatility. A variable may be connected to an input or an output, giving it an I/O address. Several properties can be set: default value, fall-back value, store at power fail, These variables may not be connected as input, resp. output to a function block. predefined addresses C. Fantuzzi 3. I Linguaggi di Programmazione 11

SFC (Sequential Flow Chart) START STEP T1 STEP A STEP B N ACTION D1 D ACTION D2 D1_READY D2_READY T2 SFC describes sequences of operations and interactions between parallel processes. It is derived from the languages Grafcet and SDL (used for communication protocols), its mathematical foundation lies in Petri Nets. C. Fantuzzi 3. I Linguaggi di Programmazione 12

SFC: Elements S0 event condition ("1" = always true) "1" transitions Sa example transition condition states Ea Sb Ec = ((varx & vary) varz) token Eb Sc example: Sc is true, S0, Sa, Sb are false rule: there is always a transition between two states, there is always a state between two transitions C. Fantuzzi 3. I Linguaggi di Programmazione 13

SFC Rules of execution The sequential program consists of states connected by transitions. A state is activated by the presence of a token (the corresponding variable becomes TRUE). The token leaves the state when the transition condition (event) on the state output is true. Only one transition takes place at a time the execution period is a configuration parameter (task to which this program is attached) C. Fantuzzi 3. I Linguaggi di Programmazione 14

SFC: Initial state State which come into existence with a token are called initial states. All initial states receive exactly one token, the other states receive none. Initialization takes place explicitly at start-up. C. Fantuzzi 3. I Linguaggi di Programmazione 15

SFC: Switch and parallel execution token switch : the token crosses the first active transition (at random if both Ea and Eb are true) Note: transitions are after the alternance "1" Ea Sa E0 Sc Eb token forking : when the transition Ee is true, the token is replicated to all connected states Note: transition is before the fork Sb Se Ed Sd Ec token join : when all connected states have tokens and transition Eg is true, one single token is forwarded. Note: transition is after the join C. Fantuzzi 3. I Linguaggi di Programmazione 16 Sf Ef Ee Eg Sg

SFC: P1, N and P0 actions State1 P1 State1_P1: do at enter N State1_N: do while P0 State1_P0: do at leaving P1 (pulse raise) action is executed once when the state is entered P0 (pulse fall) action is executed once when the state is left N (non-stored) action is executed continuously while the token is in the state P1 and P0 actions could be replaced by additional states. The actions are described by a code block written e.g. in Structured Text. C. Fantuzzi 3. I Linguaggi di Programmazione 17

Special action: the timer Rather than define a P0 action reset timer., there is an implicit variable defined as State.t that express the time spent in that state. S Sf S.t > t#5s C. Fantuzzi 3. I Linguaggi di Programmazione 18

SFC: graphic rules The input and output flow of a state are always in the same vertical line (simplifies structure) Alternative paths are drawn such that no path is placed in the vertical flow (otherwise would mean this is a preferential path) intentional displacement to avoid optical preference of a path. Priority: The alternative path most to the left has the highest priority, priority decreases towards the right. Loop: exit has a higher priority than loopback. C. Fantuzzi 3. I Linguaggi di Programmazione 19

Function blocks And SFC Function Blocks: Continuous (time) control Sequential Flow Charts: Discrete (time) Control Many PLC applications mix continuous and discrete control. A PLC may execute alternatively function blocks and flow charts. A communication between these program parts must be possible. Principle: The SFC taken as a whole can be considered a function block with binary inputs (transitions) and binary outputs (states). C. Fantuzzi 3. I Linguaggi di Programmazione 20

Executing SFC As blocks A function block may be implemented in three different ways: procedure xy(...); begin... end xy; extern (ST) function blocksflow chart Function blocks and flow chart communicate over binary signals. C. Fantuzzi 3. I Linguaggi di Programmazione 21

SFC or Function Blocs? A task can sometimes be written indifferently as function blocs or as SFC The application may decide which representation is more appropriate: SFC Function Block a S "1" b R c c NOT d b d a C. Fantuzzi 3. I Linguaggi di Programmazione 22

SFC or Fun. Blocks? (2) SFC Function Blocks "1" a b A B C c init a b c S R & S R & S R & A B C In this example, SFC seems to be more appropriate: C. Fantuzzi 3. I Linguaggi di Programmazione 23

Programming Organisation Units - POU A POU is a portion of code which is encapsulated in a routine, which has an internal memory: Function Block. Program or hasn t Function C. Fantuzzi 3. I Linguaggi di Programmazione 24

Types of POUs 1) Functions - are part of the base library. - have no memory. Example are: adder, multiplier, selector,... 2) Function Blocks (FB) - are part of the base library - have a memory ("static" data). - may access global variables (side-effects!) Examples: counter, filter, integrator,... 3) Programs (Compound blocks) - user-defined or application-specific blocks - may have a memory - may be configurable Examples: PID controller, Overcurrent protection, Motor sequence C. Fantuzzi 3. I Linguaggi di Programmazione 25

Function Block library The programmer chooses the blocks in a block library, similarly to the hardware engineer who chooses integrated circuits out of the catalogue. This library indicates the pinning of each block, its semantics and the execution time. The programmer may extend the library by defining function block macros out of library elements. If some blocks are often used, they will be programmed in an external language (e.g. C, micro-code) following strict rules. C. Fantuzzi 3. I Linguaggi di Programmazione 26

IEC 61131-3 library (extract) binary elements AND OR XOR and or exclusive-or GT TON IN Q PT ET GE greater equal GT greater than LT less than LE less equal timer on delay analog elements ADD SUB MUL adder subtractor multiplier S1 SR R Q0 flip-flop CTU CU RESET PV Q ET up counter (CTD counter down) DIV divider R_TRIG S1 Q0 positive edge bool int SEL MUX selector (1:2) multiplexer (1:N) INT Reset PresetVal In integrator (if reset) {out = PresetVal;} C. Fantuzzi 3. I Linguaggi di Programmazione 27

Exercise: Tooth saw generator exercise: build a tooth-saw (asymmetric) generator with the IEC 61131 elements of the preceding page 75% 5s 12s 0% -25% C. Fantuzzi 3. I Linguaggi di Programmazione 28

Function Block library for AXIS_REF specialized applications Axis MoveAbsolute Axis AXIS_REF BOOL Execute Done BOOL REAL Position CommandAborted BOOL REAL Velocity Error BOOL REAL Acceleration ErrorID WORD REAL Deceleration REAL Jerk MC_Direction Direction Example: FB for motion control C. Fantuzzi 3. I Linguaggi di 29 Programmazione

Time Diagram: Specifying the behaviour of Function Block 0 T x y x y T Truth Table: x1 S x1 0 x2 0 y previous state x2 R 0 1 1 0 0 1 1 1 1 Mathematical Formula: x Kpx + K d dx + Ki dt t 0 xdτ y C. Fantuzzi 3. I Linguaggi di 30 Programmazione

Function Block specification in Structured Text C. Fantuzzi 3. I Linguaggi di 31 Programmazione

Function Block decomposition A function block describes a data flow interface. Its body can be implemented differently: Elementary block Compound block The body is implemented in an external language (micro-code, assembler, java, IEC 61131 ST): procedure xy(a,b:boolean; VAR b,c: BOOLEAN); begin =...... end xy; The body is realized as a function block program Each input (output) pin of the interface is implemented. as exactly one input (output) of the function block. All signals must appear at the interface to guarantee freedom from side effects. = C. Fantuzzi 3. I Linguaggi di Programmazione 32

Function Block segmentation An application program is decomposed into segments ("Programs ) for modularity Within a segment, the connections are represented graphically Between the segments, the connections are expressed by signal names X1 Segment A M2 M1 Y1 Segment B X2 Y2 M1 X3 M2 C. Fantuzzi 3. I Linguaggi di Programmazione 33

Execution of Function Blocks Segment or POU (program organization unit) Machine Code: A B C F1 F3 X01 X02 F2 F4 X Y The function blocks are translated to machine language (often an assembly language), Blocks are executed in sequence, normally from upper left to lower right The sequence is scheduled repeated every x ms. function input1 input2 output F1 A B X01 F2 X01 X F3 B C X02 F4 X X02 Y C. Fantuzzi 3. I Linguaggi di 34 Programmazione

Input-Output of Function Blocks Run-time: Write outputs Read inputs I X O I X O I X O individual period execute The function blocks are executed cyclically. all inputs are read from memory (corresponding to a sensor on the plant). the segment is executed the results are written into memory (corresponding to a actuator on the plant The different segments may be assigned a different individual period. C. Fantuzzi 3. I Linguaggi di Programmazione 35 time

Parallel execution Function blocks are particularly well suited for true multiprocessing (parallel processors). The performance limit is given by the needed exchange of signals by means of a shared memories. Semaphores are not used since they could block an execution and make the concerned processes non-deterministic. processor 1 processor 2 processor 3 input/ output shared memory shared memory shared memory shared memory C. Fantuzzi 3. I Linguaggi di Programmazione 36

Software application Configuration The software application (the complete control program) is divided into tasks: A task is a run-time execution of a software routine. An execution period might be assigned to each task to respect real time deadline, if not, the task run continuously (free-run). A priority is assigned to respect task priorities. A task might be triggered by an external event. C. Fantuzzi 3. I Linguaggi di Programmazione 37

Programming environment capabilities A PLC programming environment (ABB, Siemens, CoDeSys,...) allows: programming of the PLC in one of the IEC 61131 languages defining the variables (name and type) binding of the variables to the input/output (binary, analog) simulating downloading to the PLC of programs and firmware uploading of the PLC (seldom provided) monitoring of the PLC documenting and printing.

61131 Programming environment symbols configuration, editor, compiler, library firmware download code variable monitoring and forcing for debugging network PLC C. Fantuzzi 3. I Linguaggi di Programmazione 39