Problems with Ladder Programming From a software engineering perspective, programming PLC using conventional ladder diagrams suffers from the following deficiencies: The ladder symbols and facilities vary between different PLC products. Poor facilities for structured or hierarchical program decomposition. Limited facilities for software re-use. Poor facilities for addressing and manipulating data structures (i.e. no support for grouping data into a structure). Limited facilities for building complex sequences Limited control over program execution Facilities for arithmetic operations are cumbersome. AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Unclear Sequence: An Example Step1 Equip_OK Trans1_2 Step2 Speed_Stable Trans2_3 Step1 Step2 Step3 / / / Ready Transition rungs Step1 Step rungs Trans1_2 Step2 Step2 Step1 Speed1 Step actions Step2 AUB161 - Industriella Tillverkningssystem I VT04 Speed2 Amos Ng Programming Languages in IEC 1131-3 • 5 languages (3 graphical + 2 textual) • Structured Text (ST) • Instruction List (IL) • Ladder Diagram (LD) • Function Block Diagram (FBD) • Sequential Function Chart (SFC) • Today almost all PLC programming systems, to a certain extent, support all these 5 languages. • 1 or 2 more language: Flowchart ? Statechart ? AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Software Model of IEC 1131-3 A layered model - each layer hides many of the features of the layers beneath it. Configuration Resource Resource Task Task Task Task Program Program Program Program var FB FB FB var FB var Global and directly represented variables Access paths Communication functions defined in IEC1131-5 AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Configurations and Resources Configurations • • The entire software that defines the behaviour of a PLC for a specific application. For most PLC systems, it means the hardware platform that contains one or more resources. • A configuration is able to communicate with other IEC configurations within different PLC systems via defined interfaces (e.g. Ethernet, Fieldbus, proprietary backplane bus, etc). Resources • • A resource provides support for all of the features needed for the execution of programs (e.g. interface between programs and physical I/O channels). An IEC program cannot function unless it is loaded into a resource. • A resource may be simulated within a personal computer instead of a “PLC” to support program testing. AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Programs and Tasks • Programs • A logical assembly of all programming elements and constructs necessary for the intended processing required for the control of a machine or a process. • A program may consist of 1) a number of interconnected FBs; 2) a ladder diagram or 3) a SFC with its underlying action and transition subprogram or ... • Tasks • A task can be configured to control a set of programs and/or FBs either to execute periodically or upon the occurrence of a specified trigger. FBs can be assigned to a specific task. Some PLC programming systems e.g. ISaGRAF, do NOT directly support configurable tasks. AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Functions, FB and POUs • Functions • A software element which when execute, with a particular set of input values, produce one result (e.g. SIN( ), COS( ) ). • Function Blocks • Support hierarchical design - Use FB to contain program defined with other languages. A FB may itself be built up with smaller FBs. • When compared with functions, FB may have numerous outputs. A FB is able to store values declared as internal variables. • Program Organisation Units (POUs) • The standard describes programs, function blocks and functions as POUs. POUs can be used repeatedly in different parts of an application. • FB instances from a particular type have to be created before use. • IEC 1131-3 specifically forbids the use of recursion within POUs. AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Variables and Access Paths • Local and global variables • Variables can be declared in a configuration, resource, program, FB or function. • Variable may be declared as global which may be accessed to all software elements within the resource. • Access Paths • Provide facilities for transferring data and information between different configurations. Each configuration may have a number of designated named variables which can be accessed by other remote configurations. • Lower level communication facilities are beyond the scope of IEC1131-3. AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Some Common Elements in the Languages • Language keywords • Comments: (* …… *) • Data types • Initial values • Constants • Derived data types: e.g. structured data types or array data types • Variables: • Input variables • Output variables • Internal variables • Retain values - values will be retained from, when the PLC loses power, to when the power is returned • Functions and FBs AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Basic IEC Data Types • Strings have a size. It represents the maximum number of characters that the string can contain. • Timers contain values less than one day and cannot be used to store dates. • Users can define their own types based on the above basic types: user type. AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Structured Text (ST) (1) • Although there are some minor similarities to PASCAL, ST is a distinct language that has been specifically developed for industrial control applications. • Assignment: • X:=Y; • Operators: • -, NOT, +, -, *, /, MOD, <, >, <=, >=, =, <>, AND, &, XOR, OR • Conditional statements: • IF...THEN...ELSIF...ENDIF; • CASE … OF … ELSE … END_CASE; • FOR … TO … BY … DO… END_FOR; • WHILE … DO … END_WHILE; • REPEAT … UNTIL … END_REPEAT AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Structured Text (ST) (2) • EXIT - can be used within iteration statements and allows iteration loops to be ended prematurely. • RETURN - can be used only within function and FB bodies to return from the code body prematurely. • Function call: • result := myfunc(param1, param2); • Accessing FB in ST: • MyFBinstance(inparam1, inparam2); • result1:=MyFBinstance.outparam1; • result2:=MyFBinstance.outparam2; AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Structure of a ST Program AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Instruction List (IL) AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Introduction to Petri nets Carl Adam Petri (1960), Kommunikation mit Automaten, University of Darmstadt 2 P1 T1 P2 Legend P3 Net structure 2 2 P1 P1 Place T1 Transition P3 P2 T1 P2 a. Initial marking Directed Arc Token P3 b. T1 enabled 2 2 P1 P1 T1 P3 P2 T1 P3 P2 c. T1 firing (t 0) d. Fired AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Modelling Features Sequence Sychronization Concurrency Conflict Shared resource AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Sequential Function Chart (SFC) • Date back to the early 1960s, Petri nets by C.A. Petri. Special case of binary interpreted Petri nets. • A graphical PLC language based on the French national standard Grafcet. • Standard IEC848 published in 1988. • Most of the definitions in IEC848 have been directly imported into the IEC1131-3 standard to form the SFC. Mainly enhanced to integrate with other IEC1131-3 languages. • Important and useful to show the main states of a system. Can be used in high level to organise other language elements and low level to control devices directly. AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng SFC Basic Chart Structure S0 Initial Step Direction of control flow Step N Action0 StartSwitch S1 N Action1 Temperature > 30 S2 N AUB161 - Industriella Tillverkningssystem I VT04 N Transition with transition condition Action2 S2.T > T#10s S3 Action ST, IL, LD, FBD or SFC Action qualifier Action3 Amos Ng SFC Step Executing and Time Variables • Every step is associated with two variables: • The step active flag (.X). Boolean variable that is only true while the corresponding step is active. Used to test step state from other part of the SFC using syntax <Stepname>.X • Elapse time (.T) variable of data type TIME. It records how long a step was active the last time it was activated. Can be accessed in the form of <Stepname>.T, e.g. in a transition condition: • .X and .T are not supported in GX IEC Developer S1 N Action1 S1.T > T#10s AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng SFC Divergent Paths S0 Branch or Link Divergent Path (OR) Left-to-right or user-defined Precedence S1 S2 S3 S4 Convergent Path Jump S0 AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng SFC Simultaneous Sequences S0 Simultaneous Sequence Divergence S1 Simultaneous Sequence Convergence S2 S3 S5 S6 S4 Enabled only when S4, S5 & S6 are active S7 AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng SFC Action Qualifiers (1) Non stored action qualifier S1.X N S1 Action1 Action1 T1 T1 S S1 Set and Reset action qualifiers Action1 S1.X T1 T1 Action1 SN.X R SN AUB161 - Industriella Tillverkningssystem I VT04 Action1 TN TN Amos Ng SFC Action Qualifiers (2) Pulse on activation S1.X P1 S1 Action1 Action1 T1 T1 Pulse on deactivation S1.X P0 S1 Action1 Action1 T1 T1 AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Child SFC - Macro Steps N S1 SFC2 S0 T1 S1 Action qualifier N, S or R AUB161 - Industriella Tillverkningssystem I VT04 S2 N Action0 N Action1 N Action2 Amos Ng Function Block Diagram (FBD) • Can be used to express the behaviour of functions, FBs and programs as a set of interconnected graphical blocks. It can be used within the SFC to express the behaviour of steps, actions and transitions (NOT directly in GX IEC Developer). • Used when the problem involves the flow of signal between control blocks or processing elements. E.g. describing control loop. • Input and output parameters can only use data types defined within the standard. • Instance must be created before use. • A list of fairly rudimentary FBs are defined in the standard. • Can be implemented with other general-purpose languages provided that the block has input and output parameters that are defined using IEC1131-3 data types. • Fundamental building blocks for other standard IEC1131 Part 5, Part 7 and IEC 61499. AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng FB Re-use (1) AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng FB Re-use FB (2) AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng Benefits of using IEC 1131-3 • Above all, it is an international standard • Theoretically, inter-system portability (still a dream!) • Inter-language portability and Reuse • e.g. FB can be programmed in any of the standard languages. • e.g. FBs can be re-used as the basic building blocks of a control system if a library of ‘off-the-shelf’ FBs provided by different vendors is available. • OMAC (Open, Modular Architectural Controllers) Specification • Laid down the requirements for an open, modular architecture controller known to the supplier and technology development communities, from the perspective of the automotive industry. • Under the section Discrete Event Control: “The IEC1131-3 standard languages must be used to program discrete I/O logic” AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng PLCopen (www.plcopen.org) • NOT a standards-governing or -setting up body. • A supplier and vendor organisation that helps and guides users of PLCs, mainly concerning the IEC 1131 standard. Based in the Netherlands and now has more than 100 members from Europe, USA and Japan. • Actively defining different compliance levels with the objective that products that have the same compliance level will support a known level of software portability. • Actively developing concepts for common implementation. AUB161 - Industriella Tillverkningssystem I VT04 Amos Ng