Iec61131 3 training
This presentation is the property of its rightful owner.
Sponsored Links
1 / 158

IEC61131-3 Training PowerPoint PPT Presentation


  • 98 Views
  • Uploaded on
  • Presentation posted in: General

IEC61131-3 Training. Agenda. Introduction to the standard Using the workbench Programming languages - Ladder Diagram (LD) - Function Block Diagram FBD) - Structured Text (ST) - Instructions List (IL) - Sequential Function Charts (SFC) 4. Exploring the OCS using IEC61131

Download Presentation

IEC61131-3 Training

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Iec61131 3 training

IEC61131-3 Training

IEC61131-3 Training Course


Agenda

Agenda

  • Introduction to the standard

  • Using the workbench

  • Programming languages

  • - Ladder Diagram (LD)

  • - Function Block Diagram FBD)

  • - Structured Text (ST)

  • - Instructions List (IL)

  • - Sequential Function Charts (SFC)

  • 4. Exploring the OCS using IEC61131

  • - high speed counter

  • - serial communications

  • - CompactFlash for data-logging

  • - PID

  • - Ethernet

  • 5.Appendices

IEC61131-3 Training Course


Introduction to the standard

Introduction to the standard

  • The wide range of different programming techniques and languages for industrial applications and PLCs meant that one had to spend a lot of time and money training staff.

  • The industrial community and the IEC recognised this problem and looked at the complete design of PLCs, including hardware design, installation, testing, documentation, programming and communications.

  • During the 1990s the IEC published various parts of the IEC61131 standard (see appendix)

  • The IEC recognises the need for an ‘open systems’ approach to build large systems using equipment from different manufacturers.

IEC61131-3 Training Course


Deficiencies of ladder programming

Deficiencies of ladder programming

Conventional ladder programming has a number of deficiencies:

  • Ladder symbols vary between different PLC products

  • Poor facilities for structured or hierarchical program decomposition

  • Limited facilities for software reuse

  • Poor facilities for addressing and manipulating data structures

  • Limited facilities for building complex sequences

  • Limited control over program execution

  • Facilities for arithmetic operations are cumbersome

IEC61131-3 Training Course


Features of iec61131 3

Features of IEC61131-3

Encourages well structured “top-down” or “bottom-up” development

  • Allows a program to be broken down into functional elements including functions, function blocks and programs.

    Requires strong data typing

  • Reduces programming errors

    Support for full execution control

  • different parts can scan at different rates under “task” control

    Full support for describing sequences

  • Complex sequential behaviour can be easily broken down using SFC to describe steps and transitions

IEC61131-3 Training Course


Features of iec61131 31

Features of IEC61131-3

Support for defining data structures

  • Associated elements can be passed between different part of a program as a single entity. Improves program readability and ensures associated data is always accessed correctly.

    Flexible language selection

  • 3 graphical and 2 textual languages for expressing different parts of a control application.

    Standardised languages and methods of program execution

  • A wide range of technological problems can be programmed as vendor-independent software elements.

IEC61131-3 Training Course


Sequential function charts

Sequential Function Charts

  • A graphical language for depicting sequential behaviour of a control system.

  • It is used for defining control sequences that are time and event driven.

  • This is an extremely effective graphical language for expressing both the high level sequential parts of a control program as well as programming low-level sequences, e.g. to program an interface to a device.

IEC61131-3 Training Course


Structured text

A high level textual language that encourages structured programming.

It has a syntax that strongly resembles PASCAL and supports a wide range of standard functions and operators.

The standard includes a formal syntax definition of ST

Structured Text

IEC61131-3 Training Course


Instructions list

Instructions List

A low level “assembler like” language that is based on similar instruction list languages found in a wide range of today’s PLCs.

IEC61131-3 Training Course


Function block diagram

A graphical language for depicting signal and data flows through function blocks (re-usable software elements).

FBD is very useful for expressing the interconnection of control system algorithms and logic.

Function Block Diagram

IEC61131-3 Training Course


Ladder diagram

Ladder diagram

  • A graphical language that is based on the relay ladder logic (a technique commonly used on current generation PLCs.

  • However, the IEC Ladder Diagram language also allows the connection of user defined blocks and functions and so can be used in a hierarchical design.

IEC61131-3 Training Course


Benefits of iec61131 3

Benefits of IEC61131-3

  • Provides a variety of languages for solving different types of industrial control problem.

  • Encourages the development of quality software through well structured design, the use of encapsulation and information hiding.

  • Its use will allow the same control software to be developed for different PLC products.

  • Formalisation of re-usable software, especially function blocks should result in improving the productivity of system designers through the provision of off-the-shelf solutions.

  • Programming tools are emerging that offer support for the complete PLC software life-cycle.

IEC61131-3 Training Course


The iec workbench

The IEC workbench

A new look to OCS programming

IEC61131-3 Training Course


Using the workbench

Using the workbench

  • Launch the IEC workbench from Cscape using the IEC61131 button

IEC61131-3 Training Course


The main window

The main window

The main workbench window contains the following buttons:

1. Always on top pin:ensures that the main window is always visible

2. Program list button:opens the program list window containing all the programs and sub-programs present in the project.

3. Variables editor button:opens the variables editor window containing all the variables used in the project grouped by global, retain, and program locals

4. Window list box:gives a quick access to a specific open window

5. Compile button:compiles the project ready or download to the target; any errors will be shown in the build window

6. Connect to target button:puts the workbench into debug mode and monitors variables and program state on the target

7. Watch window button:opens the watch window containing the list of specific variables to monitor

8. Screens editor button:opens the standard Cscape screen editor after a successful compilation, i.e. there are no errors in the program

9. I/O configuration:opens the standard I/O configuration that allows the user to select the target configuration

10.Network configuration:opens the Cscape Network configuration allowing the user to set networked data exchanges up

11.Download button:opens the Cscape smart download window allowing the user to specify which parts of the project need to be downloaded to the target

12.The traffic light buttons: have the same functionality as in the standard Cscape workbench. Switching the target between different operational modes (RUN, Do I/O, Stop)

IEC61131-3 Training Course


Iec61131 3 training

3. Variables editor button

2. Program list button

4. Window list Box

5. Compile button

1. Always on top pin

7. Watch window button

8. Screen editor button

12. “Traffic lights” buttons

6. Connect to target button

9. I/O configuration button

10. Network configuration button

11. Download button

IEC61131-3 Training Course


The program list

The program list

  • The program list window contains the list of programs and subprograms in the project.

  • To add a new program/sub-program click on the New Program button.

  • A right click in the program list allows to create new programs but not sub-programs and offers a short cut to other program manipulations.

  • The execution order is the order in which the programs appear in the list.

IEC61131-3 Training Course


The variables editor

The variables editor

  • The variable editor lists all the variables declared in each program and sub-program as well as global variables.

  • To help in the program documentation descriptions can be added to the variable definition.

IEC61131-3 Training Course


Workbench panes

Workbench panes

The variable editor enables you to create/ change variable declaration in place.

The information pane guides you to the most important links in the help. It also enables you to quickly navigateamong the programs and sub-programs of the application.

The library of blocks shows the list of available functions and blocks from the library and the project.

The build pane shows the result of the compilation.

IEC61131-3 Training Course


Constant expressions

Constant expressions

  • Boolean (BOOL)

    • Reserved keywords TRUE and FALSE

    • Small integer (SINT)

    • Signed 8 bit value (-128 to 127)

    • Must be prefixed with “SINT#”

  • Integer (INT)

    • Signed 16 bit values (-32768 to 32767)

    • Must be prefixed with “INT#”

  • Double integer (DINT)

    • Signed 32 bit values (-2147483648 to 2147483647)

    • Default type does not need a prefix

IEC61131-3 Training Course


Constant expressions1

Constant expressions

  • Real (REAL)

    • Single precision floating point values

    • Always require a “.0” at the end of the number

    • USE “F” or “E” separators for specifying the exponent

  • Time of day (TIME)

    • Time constant expressions represent duration less than 24hours

    • Must be prefixed with “T#” or “TIME#”

    • “h” for hours, “m” for minutes, “s” for seconds and “ms” for milliseconds

    • Example: T#3h42m15s30ms

IEC61131-3 Training Course


Programming languages

Programming languages

Languages adapted to expressing solutions to different problems

IEC61131-3 Training Course


Ladder diagram ld

Ladder diagram (LD)

“Programming with contacts and relays”

IEC61131-3 Training Course


Ld power rails

LD - Power rails

  • The power rail on the left represents the TRUE value and initiates the rung state.

  • The power rail on the right receives connections from the coils and has no influence on the execution of the program.

IEC61131-3 Training Course


Ld contacts

LD - Contacts

  • Contact types:

    Normal: The rung state on the right is the boolean AND between the rung state on the left and the associated variable.

    Negated: The rung state on the right is the boolean AND between the rung state on the left and the negation of the associated variable.

    Positive pulse: The rung state on the right is TRUE only when the rung state on the left is TRUE and the associated variable changes from FALSE to TRUE (rising edge).

    Negative pulse: The rung state on the right is TRUE only when the rung state on the left is TRUE and the associated variable changes from TRUE to FALSE (falling edge).

IEC61131-3 Training Course


Ld coils

LD - Coils

Coil types:

Normal: The associated variable is forced to the value of the rung state on the left of the coil.

Negated: The associated variable is forced to the negation of the rung state on the left of the coil.

Set: The associated variable is forced to TRUE if the

rung state on the left is TRUE (No action is the rung state is FALSE).

Reset: The associated variable is forced to FALSE if the rung state on the left is TRUE (No action if the rung state is FALSE).

Positive edge pulse: The associated variable is TRUE for one cycle when the rung state changes from FALSE to TRUE.

Negative edge pulse: The associated variable is TRUE for one cycle when the rung state changes from TRUE to FALSE.

IEC61131-3 Training Course


Ld editor

Insert contact before selection

Insert contact after selection

Insert contact in parallel with selection

Insert FB before selection

Insert FB after selection

Insert FB in parallel with selection

Insert jump

Insert a coil

Insert a new rung

Insert a comment line

LD - Editor

Shift rung right

IEC61131-3 Training Course


Ld exercise 1

LD - Exercise 1

  • Create a simple LD program that:

    • Sets bOut1 to TRUE when bIn1 is FALSE and bIn2 is TRUE

    • Sets bOut2 to TRUE when bIn3 is TRUE and (bIn4 is FALSE or bIn5 is TRUE)

IEC61131-3 Training Course


Ld exercise 1 a solution

LD - Exercise 1 (a solution)

IEC61131-3 Training Course


Ld block call

LD - Block call

  • Blocks are connected to the rung with their first input and output.

  • This implies that special “EN” and “ENO” input and output are added to the block if its first input and output are not boolean.

IEC61131-3 Training Course


Ld exercise 2

LD - Exercise 2

  • Create a simple LD program that has the following actions on the rising edge of bOn:

    • Val4 = Val1 + Val2 + Val3

    • Val6 = Val4 - Val5

IEC61131-3 Training Course


Ld exercise 2 a solution

LD - Exercise 2 (a solution)

IEC61131-3 Training Course


Ld jump label

LD - Jump/Label

  • Each rung may begin with a label.

  • Labels are used as destination for jump instructions.

IEC61131-3 Training Course


Ld exercise 3

LD - Exercise 3

  • Create a simple LD program that does the following:

    • If Val1 > Val2 then dResult = Val1 - Val2

    • Else dResult = Val2 - Val1

IEC61131-3 Training Course


Ld exercise 3 a solution

LD - Exercise 3 (a solution)

IEC61131-3 Training Course


Function block diagram fbd

Function Block Diagram (FBD)

“It looks like electronic schematic capture”

IEC61131-3 Training Course


Fbd data flow

FBD - Data flow

  • A function block diagram is a data flow between constant expressions or variables and operations represented by rectangular blocks.

  • The data flow is going from left to right and top to bottom.

IEC61131-3 Training Course


Fbd editor

Selection button

Insert a function block

Insert a variable

Insert a comment

Draw an arc

Insert a corner

Insert a break

Insert a label

Insert a jump

Insert a left power rail

Insert a contact

Insert an OR bar

Insert a coil

Insert a right power rail

FBD - Editor

IEC61131-3 Training Course


Fbd exercise 1

FBD - Exercise 1

  • Create an FBD program that does the following:

    • Result1 = In1 + In2 + In3

    • Result2 = In1 * In2 * In3

IEC61131-3 Training Course


Fbd exercise 1 a solution

FBD -Exercise 1 (a solution)

IEC61131-3 Training Course


Fbd instance

FBD - Instance

  • The name of the operation or function, or the type of function block is written within the block rectangle.

  • For a function block call, the name of the called instance must be written above the block rectangle.

  • A function or operation has no memory, a function block may have internal memory. This is reflected by the need for an instance name.

IEC61131-3 Training Course


Fbd boolean negation

FBD - Boolean negation

  • On boolean connections, one can use a connection link terminated by a small circle indicating the negation of the data flow.

IEC61131-3 Training Course


Fbd jump label

FBD - Jump / Label

  • Labels are used as a destination for jump instructions.

  • A jump to a label branches the execution of the program to the functions following the label.

IEC61131-3 Training Course


Fbd return

FBD - Return

  • Jump to the RETURN label effectively terminates the execution of the current program.

IEC61131-3 Training Course


Fbd exercise 2

FBD - Exercise 2

  • Create an FBD program that sets bRun to TRUE 5 seconds after the following conditions are TRUE:

    • bEmergencyStop is FALSE

    • bStart is TRUE

  • Use the TON100MS function block

IEC61131-3 Training Course


Fbd exercise 2 a solution

FBD - Exercise 2 (a solution)

IEC61131-3 Training Course


Fbd ladder diagram

FBD - Ladder diagram

  • LD symbols may also be entered in FBD language and linked to FBD objects.

IEC61131-3 Training Course


Structured text st

Structured Text (ST)

“It’s a bit like PASCAL”

IEC61131-3 Training Course


St comments

ST - Comments

(* My comment *)

a := d + e;

(* A comment can also be on

several lines *)

b:= d * e;

c := d - e;(* Inline comment*)

  • Begin with “(*”

  • End with “*)”

  • Anywhere in the program

  • Several lines

  • Cannot be nested

IEC61131-3 Training Course


St expressions

ST - Expressions

  • Each statement describes an action and may include evaluation of complex expressions.

  • An expression is evaluated:

    • from left to right;

    • according to the default priority order of operators

    • the default priority can be changed using parenthesis

  • Arguments of an expression can be:

    • declared variables

    • constant expressions

    • function calls

IEC61131-3 Training Course


St conditional execution

ST - Conditional execution

  • The conditional execution of statements is done using:

    • IF…THEN…ELSE…ELSIF…END_IF;

  • One or more ELSIF are allowed.

IF (a=b) THEN

c := 0;

ELSIF (a < b) THEN

c := 1;

ELSE

c := -1;

END_IF;

IEC61131-3 Training Course


St exercise 1

ST - Exercise 1

  • Create an ST program that does the following action:

    • If Temperature is less or equal to 18C the set the display to “Cold”

    • If Temperature is greater than 18C and less or equal to 22C then set Display to “Comfortable”

    • If Temperature is greater than 22C then set Display to “Hot”

IEC61131-3 Training Course


St exercise 1 a solution

ST - Exercise 1 (a solution)

IEC61131-3 Training Course


St multiple choices

ST - Multiple choices

  • Switch between enumerated statements according to an expression

  • The expression is a double integer (DINT)

CASE dChoice OF

0:

SetString(‘Nothing’, MyString);

1..5,9:

SetString(‘First Case’, MyString);

6,8:

SetString(‘Second Case’, MyString);

ELSE

SetString(‘Other Case’, MyString);

END_CASE;

IEC61131-3 Training Course


St test first loops

ST - Test first loops

  • Repeat a list of statements.

  • Condition is evaluated before the statement.

  • Warning:

    • Loop instructions may lead to infinite loops that block the target cycle and cause a timeout reset

    • NEVER test the state of an input in the condition as the input will not be refreshed until the next cycle

dCount := 0;

WHILE dCount < 100 DO

dCount := dCount + 1;

MyVar := MyVar + 1;

END_WHILE;

IEC61131-3 Training Course


St test last loops

ST - Test last loops

  • Repeat a list of statements.

  • Condition is evaluated after the statement.

  • Warning:

    • Loop instructions may lead to infinite loops that block the target cycle and cause a timeout reset

    • NEVER test the state of an input in the condition as the input will not be refreshed until the next cycle

dCount := 0;

REPEAT

MyVar := MyVar + 1;

dCount := dCount + 1;

UNTIL dCount >= 100 END_REPEAT;

IEC61131-3 Training Course


St test last loops1

ST - Test last loops

  • Iteration of statement execution

  • The “BY” statement can be omitted, the default value is 1

  • Warning:

    • Loop instructions may lead to infinite loops that block the target cycle and cause a timeout reset

    • NEVER test the state of an input in the condition as the input will not be refreshed until the next cycle

FOR dCount := 0 TO 100 BY 2 DO

MyVar := MyVar + 1;

END_FOR;

IEC61131-3 Training Course


St exercise 2

ST - Exercise 2

  • Create an ST program that counts the number of spaces

    of a string

    • Use StringLen function to get the size of the string

IEC61131-3 Training Course


St exercise 2 a solution

ST - Exercise 2 (a solution)

IEC61131-3 Training Course


St function

ST - Function

  • To call a function in ST:

    • Enter its name, followed by the input parameters written between parenthesis and separated by commas

    • The function call may be inserted into any complex expression

    • A function call can be used as an input parameter of another function

a := StringLen( sString );

d := any_to_dint( StringLen( sString ) );

IEC61131-3 Training Course


St function block

ST - Function block

  • To call a function block in ST:

    • Declare an instance of the function block

    • Use the instance name as instruction, followed by the input parameters written between parenthesis and separated by commas

    • The outputs of the function block are stored in the instance

MyCTU(CU,RESET,PV); (* FBlock call *)

Q := MyCTU.Q; (* Get output *)

CV := MyCTU.CV; (* Get current value *)

IEC61131-3 Training Course


St exercise 3

ST - Exercise 3

  • Create a simple ST program that counts the number of rising edges of a boolean variable

    • Use the “R_TRIG” function block to detect the rising edge

IEC61131-3 Training Course


St exercise 3 a solution

ST - Exercise 3 (a solution)

IEC61131-3 Training Course


Instruction list il

Instruction list (IL)

“Assembly language for the PLC”

IEC61131-3 Training Course


Il comments

IL - Comments

(* My comment *)

LD a

ST b

(* A comment can also be on

several lines *)

LD c

ST d(* Inline comment*)

  • Begin with “(*”

  • End with “*)”

  • Anywhere in the program

  • Several lines

  • Cannot be nested

IEC61131-3 Training Course


Il mechanism

IL - Mechanism

  • A complete IL statement is made of instructions for:

    • First: evaluating an expression (called current result)

    • Then: use the current result for performing actions

(* a:=b+c *)

LD b (* Load b in CR *)

ADD c (* Add c to CR *)

ST a(* Store CR in a *)

IEC61131-3 Training Course


Il instructions

IL - Instructions

Evaluation of expressions:

InstructionOperandMeaning

LD/LDNany typeLoads the operand in the current result

AND/ANDN (&)booleanAND between the operand and the CR

OR/ORNbooleanOR between the operand and the CR

XOR/XORNbooleanXOR between the operand and the CR

ADDnumericalAdds the operand to the CR

SUBnumericalSubtracts the operand from the CR

MULnumericalMultiplies the CR with the operand

DIVnumericalDivides the CR by the operand

GTnumericalChecks if operand is greater than the CR

GEnumericalChecks if operand is greater or equal to CR

LTnumericalChecks if operand is less than the CR

LEnumericalChecks if operand is less or equal to CR

EQnumericalChecks if operand and CR are equal

NEnumericalChecks if operand and CR are different

Function callargumentsCalls a function

ParenthesisChanges the execution order

IEC61131-3 Training Course


Il instructions1

IL - Instructions

Actions:

InstructionOperandMeaning

ST/STNany typeStores the CR in the operand

JMPlabelUnconditional jump to a label

JMPC/JMPNClabelJump if CR is TRUE

SbooleanSets the operand to TRUE if the CR is TRUE

RbooleanSets the operand to FALSE if the CR is TRUE

CALfunction blockUnconditional call to a function block

CALC/CALNCfunction blockCall a function block if the CR is TRUE

IEC61131-3 Training Course


Il jump and label

IL - Jump and Label

BEGIN:

LD bPart1

JMPC Part1

LD bPart2

JMPC Part2

Other:

LD ‘Other’

ST sMsg

JMP End

Part1:

LD ‘Part 1’

ST sMsg

JMP End

Part2:

LD ‘Part 2’

ST sMsg

End:

  • Each instruction may begin with a label followed by a colon (“:”)

  • Labels are used as destinations for jump instructions

IEC61131-3 Training Course


Il function

IL - Function

  • To call a function in IL:

    • Load its first input parameter before the call

    • Use the function name as an instruction, followed by the other input parameters, separated by commas

    • The result of the function is then the current result

LD sMsg (* Load the string *)

StringLen (* Get the length *)

ST iLength(* Save the result *)

IEC61131-3 Training Course


Il function blocks

IL - Function blocks

  • To call a function block in IL:

    • Declare an instance of the function block

    • Use the CAL instruction with the instance name as operand, followed by the input parameters written between parenthesis and separated by commas

    • The result of the function block is stored in the instance.

    • Load the output parameter using the instance name

CAL MyCTU(CU,RESET,PV)

LD MyCTU.Q

ST Q

LD MyCTU.CV

ST CV

IEC61131-3 Training Course


Il exercise

IL - Exercise

  • Create an IL program that:

    • Increments dCount when bOn is TRUE

    • Resets dCount when bOn is FALSE

IEC61131-3 Training Course


Il exercise a solution

IL - Exercise (a solution)

IEC61131-3 Training Course


Sequential function chart sfc

Sequential Function Chart (SFC)

“Sequences ‘R’ us”

IEC61131-3 Training Course


Sfc language description

SFC - Language description

  • Sequential Function Charts (SFC) are a graphical language used to represent processes where a succession of steps can be identified

  • A SFC chart is a set of steps. Each step represents a well defined state of the process. Each step may be active or inactive

  • Transitions represent the conditions/events that move the activity from a step to another

IEC61131-3 Training Course


Sfc steps

SFC - Steps

  • A step is represented as a square box; each step is identified by a number; all steps of a program must have a unique number

  • Naming a step in program instructions:

    • GSn (where n is the step identifier)

  • A step is a local object; a program cannot have access to a step defined in another program

IEC61131-3 Training Course


Sfc step state

SFC - Step state

  • A step is either active or inactive; the step activity can be used in program expressions:

    • GSn.X (which is a BOOL expression)

  • A step represents a stable state of the process; the duration of step activity can be used in expressions:

    • GSn.T (which is a TIME expression)

IEC61131-3 Training Course


Sfc boolean actions

SFC - Boolean actions

  • BoolVar (N);

    • Forces the variable “BoolVar” to TRUE when the step is activated, and to FALSE when the step is de-activated.

  • BoolVar (S);

    • Forces the variable “BoolVar” to TRUE when the step is activated.

  • BoolVar (R);

    • Forces the variable “BoolVar” to FALSE when the step is activated.

  • / BoolVar;

    • Forces the variable “BoolVar” to FALSE when the step is activated and to TRUE when the step is de-activated.

IEC61131-3 Training Course


Sfc actions within a step

SFC - Actions within a step

  • Actions can be attached to a step; the execution of the action depends on the action qualifier:

    • “P1”: once when the step becomes activate

    • “N”: on each cycle while the step is active

    • “P0”: once when the step is deactivated

IEC61131-3 Training Course


Sfc actions within a step1

SFC - Actions within a step

  • Other possible qualifiers:

    • “S”: set to TRUE (when the step becomes active)

    • “R”: reset to FALSE (when the step becomes active)

  • An action can be:

    • A BOOL variable to be forced depending on the step activity signal

    • A program (ST/IL/LD/FBD) to be executed

IEC61131-3 Training Course


Sfc programmed actions

SFC - Programmed actions

For ST, IL, LD and FBD languages

  • Possible qualifiers for a programmed action block:

    • P1: Executed only once when the step becomes active

    • N: executed on each cycle while the step is active

    • P0: Executed only once when the step become inactive

IEC61131-3 Training Course


Sfc transitions

SFC - Transitions

  • A transition is represented as a horizontal line that crosses a vertical line drawn from one step to another.

  • The default direction for vertical links is from the top to the bottom.

  • Each transition of an SFC program is identified by a unique number.

  • A condition is associated with each transition. The condition is a BOOL expression.

  • If no condition is entered, it is assumed as always TRUE.

IEC61131-3 Training Course


Sfc conditions

SFC - Conditions

  • Each SFC transition must have a condition that indicates if the transition can be crossed. The condition is a BOOL expression that can be programmed either in ST or LD language.

  • In ST language, enter a BOOL expression. It can be a complex expression including function calls and parenthesis. For example: bForce AND (bAlarm OR AND_MASK ( wSettings, int#16#0080))

  • In LD language, the condition is represented by a single rung. The coil at the end of the rung represents the transition and should have no symbol attached. For example:

IEC61131-3 Training Course


Sfc how it all works

SFC - How it all works

  • The chart must have an initial situation. It shows the state of the process when the application starts.

  • The initial situation is represented by initial step(s) drawn with a double line border.

  • The transitions and their condition describe how the SFC situation changes.

  • Each active step is marked with a small circle (token).

IEC61131-3 Training Course


Sfc divergences

SFC - Divergences

  • A divergence represents an exclusive OR situation change in the SFC flow.

  • The conditions are evaluated with a left to right priority, which means that the first condition (from the left) that returns TRUE at the divergence will be taken.

IEC61131-3 Training Course


Sfc parallel branches

SFC - Parallel branches

  • A parallel branch links several steps to a single entry and exit transition.

  • Each branch in the parallel branch is executed in parallel.

  • Parallel divergence and convergence is represented by a double horizontal line.

  • To avoid blocking situations there should be no links between branches inside the parallel execution block and the outside of the block.

IEC61131-3 Training Course


Sfc jumps

SFC - Jumps

  • Jump symbols may be used to represent a link from a transition to a step. This replaces the actual drawing of the link and simplifies the chart. The destination step is expressed using its identifier (number).

  • A jump to a transition is forbidden, as it corresponds to a convergence of parallel branches. All parallel convergences must be explicitly drawn.

IEC61131-3 Training Course


Sfc crossing a transition

SFC - Crossing a transition

  • A transition is crossed when:

    • All steps linked before the transition are active

    • AND the condition of the transition is TRUE

  • When a transition is crossed:

    • All steps linked before the transition are de-activated

    • All steps linked after the transition are activated

  • Important note:

    • When the same step is linked before and after the transition, it remains active (no pulse in its activity signal).

IEC61131-3 Training Course


Sfc execution

SFC - Execution

  • The SFC is sampled at every scan cycle.

  • When a transition is crossed within a cycle, the following steps are activated and the evaluation of the chart will continue on the next cycle.

  • If several consecutive transitions are TRUE within a branch, only one of them is crossed within one scan cycle.

IEC61131-3 Training Course


Sfc editor

Insert initial step

Insert a step

Insert a transition

Insert a jump

Insert a divergence convergence

Join to a divergence

Join to a convergence

Insert a macro-step

Toggle view mode between code and notes

SFC - Editor

Insert a macro-step body

IEC61131-3 Training Course


Sfc action editor

Indicates the program currently edited

Indicates the step number

Use this tab for commentsregarding this step’s action

Use this tab for simple boolean actions

or ST expressions enclosed in a ACTION (x):

some code;

END_ACTION;

Where x is either P1, N or P0 and some code is any valid ST code.

Use this tab for actions occurring

once at step activation.

The action can be written in ST,

LD or FBD. To select the language

go to the Edit menu and select the

required language.

Use this tab for actions occurring

once at step activation.

The action can be written in ST,

LD or FBD. To select the language

go to the Edit menu and select the

required language.

Use this tab for actions occurring at every scan while the step is active.

The action can be written in ST,

LD or FBD. To select the language

go to the Edit menu and select the

required language.

SFC - Action editor

IEC61131-3 Training Course


Sfc transitions editor

Indicates the transition number

Use this pane to add comments

regarding this transition.

Use this tab to enter the condition to

cross the transition.

The transition can be written in either

ST or LD. To select the language go to the Edit menu and choose the required

language.

Note: For LD the coil should not be

associated to a variable.

SFC - Transitions editor

IEC61131-3 Training Course


Sfc exercise 1

SFC - Exercise 1

  • Create an SFC program that:

    • Waits for bStart to be TRUE

    • Lights a lamp for 3 seconds

    • Waits for bStart to be FALSE

    • Repeat the sequence

IEC61131-3 Training Course


Sfc exercise 1 a solution

SFC - Exercise 1 (a solution)

IEC61131-3 Training Course


Sfc when should we use it

SFC - When should we use it?

  • SFC should be used when you need to manage sequences of stable process states.

  • Using SFC avoids complex switches and the declaration of multiple flags in programs.

  • When you think: “when the process is in this situation…” then you should prefer the use of SFC.

IEC61131-3 Training Course


Sfc when not to use it

SFC - When not to use it

  • SFC should never be used as a decision diagram or flow chart for describing an algorithm. This leads to complex SFC charts and poor runtime performance.

  • Do never use a step to represent an intermediate point within a calculation. Prefer ST in that case.

  • When you think “If/Then/Else…”, then do not use SFC.

IEC61131-3 Training Course


Sfc macro steps

SFC - Macro-steps

  • A macro step is a unique symbol that represents a group of steps and transitions in a chart.

  • The body of the macro step is drawn separately in the same program.

  • The body of a macro step must begin with a step and finish with a step and should have no links to the outside.

  • Warning: a macro step is not a function intended to be instantiated several times.

IEC61131-3 Training Course


Sfc macro steps1

SFC - Macro-steps

A: Main chart

B: Body of the macro-step

1: Macro-step symbol

2: “Begin” step

3: “End” step

IEC61131-3 Training Course


Sfc exercise 2

SFC - Exercise 2

  • Create a program that manages the mix of two products in a tank with three pumps.

  • Wait for bStart value to be TRUE before starting.

  • Note: - Pump1: Fills the tank with Ingredient 1

    - Pump2: Fills the tank with Ingredient 2

    - Pump3: Drains the tank

Product 1:

20% Ingredient 1

Wait 3s

40% Ingredient 2

Wait 3s

Drain

Product 2:

40% Ingredient 2

Wait 3s

Drain

IEC61131-3 Training Course


Sfc exercise 2 a solution

SFC - Exercise 2 (a solution)

IEC61131-3 Training Course


Exploring the ocs with iec61131

Exploring the OCS with IEC61131

An in-depth look at some of the functionalities of the OCS

IEC61131-3 Training Course


High speed counter

High speed counter

Counting real-time events

IEC61131-3 Training Course


High speed counters

High speed counters

First configure the HSC module using the I/O configuration wizard

IEC61131-3 Training Course


High speed counters1

High speed counters

First configure the HSC module using the I/O configuration wizard

IEC61131-3 Training Course


High speed counters2

High speed counters

Then note the I/O mapping for the HSC module

IEC61131-3 Training Course


High speed counters3

High speed counters

  • Once all the I/O modules are configured start the IEC editor

  • Open the variable editor and map variables to the various I/O registers that the application will use

  • The functionality of each register can be found in the HSC supplement

  • Now that the HSC module is configured and variables mapped to the registers you can start using the HSC module in any of the IEC languages

    • Don’t forget to enable the HSC either by turning the external input to high or setting the corresponding %Q register to TRUE.

IEC61131-3 Training Course


Serial communications

Serial communications

Modbus and ASCII data transmissions

IEC61131-3 Training Course


Modbus communications

Modbus communications

  • Modbus RTU is a Master/Slave communication protocol and the OCS is capable of both functions

  • To turn the OCS into a Modbus slave all one has to do is to open the relevant serial port and call the Modbus Slave function bloc

    • Note that the ModbusSlave FB needs to be declared in the variable editor first

IEC61131-3 Training Course


Modbus communications1

Modbus communications

An example code to realise the Modbus Slave function would be as follows:

IEC61131-3 Training Course


Modbus communications2

Modbus communications

  • For the Master operation there are two options:

    • The first one is to use function blocks in code; this works on all OCS platforms so is useful for backward compatibility

    • The second one is to use the downloadable protocolThis works on all new OCS models (LX, NX, QX…)

  • The downloadable protocol method allows greater flexibility as one can use the same program with a different protocol in a very easy fashion

IEC61131-3 Training Course


Serial protocols setting up

Serial protocols: setting up

  • In the menu bar select Program/Protocol config...

Click on drop down button to select from a list of supported protocols

IEC61131-3 Training Course


Serial protocols setting up1

Serial protocols: setting up

  • Easy configuration...

Click on Network button to configure

the network connected to that port.

IEC61131-3 Training Course


Serial protocols setting up2

Serial protocols: setting up

  • Easy configuration...

Check the protocol settings match your set-upRead more about the protocol specific details in the protocol help.

IEC61131-3 Training Course


Serial protocols setting up3

Serial protocols: setting up

  • Easy configuration...

Click on Devices button to configure the devices connected to the network

IEC61131-3 Training Course


Serial protocols setting up4

Serial protocols: setting up

  • Easy configuration...

Add devices to the network

IEC61131-3 Training Course


Serial protocols setting up5

Serial protocols: setting up

  • Easy configuration...

Name the device and assign a network address to it

IEC61131-3 Training Course


Serial protocols setting up6

Serial protocols: setting up

  • Easy configuration...

Click on Scan list button to configure the data mapping

IEC61131-3 Training Course


Serial protocols setting up7

Serial protocols: setting up

  • Easy configuration...

Add data mappings to/from configured devices to/from OCS internal registers

IEC61131-3 Training Course


Serial protocols setting up8

Serial protocols: setting up

  • Easy configuration...

Select a configured device, enter the starting parameter,

enter the length of the data block to be transferred.

Enter an internal register for the source/destination of the transferred data.

Select the type of data transfer.

IEC61131-3 Training Course


Serial protocols setting up9

Serial protocols: setting up

  • Easy configuration...

The data will be scanned in the order it appears in the list.

IEC61131-3 Training Course


Ascii custom protocol

ASCII custom protocol

  • Although we have an extensive library of protocols at our disposal from our TIU range, we are only slowly porting these to the OCS platform on an opportunity basis.

  • The user may want to develop his/her own communication protocol with a third party device.

  • Using serial read and write function blocks allows the user to create his/her own protocol in a relatively easy manner.

IEC61131-3 Training Course


Ascii custom protocol1

ASCII custom protocol

  • The serial read FB is illustrated below:

EN: Boolean input that triggers the FB execution on a rising edge.

It has to be maintained for as long as one wants to receive characters.

#Port: constant indicating which serial port to use. This can be PORT1, PORT2 or PORT3(if present).

N: the number of characters to receive.

Data[]: a USINT array that will contain the received characters.

Count: indicates the number of characters received so far.

IEC61131-3 Training Course


Ascii custom protocol2

ASCII custom protocol

  • The serial send FB is illustrated below:

EN: Boolean input that triggers the FB execution on a rising edge.

It has to be maintained for as long as one wants to send characters.

#Port: constant indicating which serial port to use. This can be PORT1, PORT2 or PORT3(if present).

N: the number of characters to send.

Data[]: a USINT array that contains the characters to be sent.

Count: indicates the number of characters sent so far.

IEC61131-3 Training Course


Compactflash operations

CompactFlash operations

Data logging

IEC61131-3 Training Course


Data logging and retrieving

Data logging and retrieving

  • Data logging with the NX range is facilitated using the CompactFlash function block library.

    • WriteCF: writes to a new file or appends or overwrites an existing one.

    • ReadCF: Reads from a file on CompactFlash.

    • RenameCF: renames a file on CompactFlash.

    • DeleteCF: deletes a file from CompactFlash.

  • Using these function blocks one can archive any data available in the NX.

  • Operations to CompactFlash are slow so in order to increase data-logging speeds one may need to use some register space as a buffer zone.

IEC61131-3 Training Course


Compactflash write

WRITE_CF has the following Inputs and outputs:

EN: Enable the function bloc

#MODE: Constant indicating the file opening mode

#TYPE: data type to be written

Filename: file name to write to

Src[]: array of values to write to CompactFlash

Num: number of values to write

Col/Row: number of columns per row.

File type: Binary or CSV file type

End of row: terminates a short row with CR/LF

Status: indicates the operation’s success/failure code

CompactFlash - Write

IEC61131-3 Training Course


Compactflash read

READ_CF has the following Inputs and outputs:

EN: Enable the function bloc

#TYPE: data type to be read

Filename: file name to read from

Offset: optional offset within the file to read from

Num: number of values to read

Dest[]: array of values to write to from CompactFlash

File Type: Binary or CSV file type

Status: indicates the operation’s success/failure code

CompactFlash - Read

IEC61131-3 Training Course


Compactflash rename

RENAME_CF has the following Inputs and outputs:

EN: Enable the function bloc

Old name: the current name of the file to rename

New name: the new name of the file

Status: indicates the operation’s success/failure code

DELETE_CF has the following Inputs and outputs:

EN: Enable the function bloc

File Name: the name of the file to delete

Status: indicates the operation’s success/failure code

CompactFlash - Rename

IEC61131-3 Training Course


Compactflash notes

The EN input activates the function bloc on a rising edge and has to be maintained until the operation has been completed.

The status register is a 32-bit register used to show the status of the function block. The first 16-bit register is a status code. The second 16-bit register shows the number of elements successfully read.

77 Attempt to open / rename file that is open

81 Specified file already exist

86 Function block contains illegal parameter

88 Too many open files*

92 Attempt to write failed

94 Sharing violation*

95 No disk present*

96 Directory structure corrupt

98 Incorrect data format

* - These Status Codes never should occur, being duplicates

of higher priority status codes. However, they are included in the code because some people can break anything.

CompactFlash - Notes

0 Operation completed successfully

-1 End of file was reached before completing

-2 Function is active, waiting for operation to complete

-3 Function is waiting on another CF function to complete

-4 Function block is inactive (usually no power flow)

1 Card present but unknown format

2 No card in slot

3 Card present, but not supported

4 Card swapped before operation was complete

5 Unknown error

66 File / Path specified does not exist

73 Bad file descriptor (corrupt file)

IEC61131-3 Training Course


Iec61131 3 training

PID

Regulating processes

IEC61131-3 Training Course


Iec61131 3 training

PID

  • Before being able to use a PID function block in the program it has to be initialised using the SetPID function.

IEC61131-3 Training Course


Iec61131 3 training

PID

  • The parameters have the following meaning:

    • CB[] is the Control Block used by the PID Function block this array has to be declared as an array of 15 int

    • Period is the sampling period of the PID FB in 10ms multiples. i.e. a value of 100 gives a sampling period of 1s

    • Deadband+ and Deadband- give the upper and lower band values within which the error value is considered equal to 0

    • Kp is the proportional gain in multiples of 100th of percentage i.e. 100 give 1%/%

    • Ki is the integral gain in 100th of rep/s

    • Kd is the derivative gain in 100th of a second

IEC61131-3 Training Course


Iec61131 3 training

PID

  • The parameters have the following meaning:

    • CvBias is the bias value added to CV after the PID calculations

    • UpClamp and LowClamp give the upper and lower values of CV

    • MinSlew is the minimum slew rate for CV. That is the fastest rise time of the PID output in 10ms multiples

    • Manual forces the PID output when in manual override mode. This function is not yet implemented so set to int#0.

IEC61131-3 Training Course


Iec61131 3 training

PID

  • Now that the PID has been initialised simply call the PID function bloc

IEC61131-3 Training Course


Iec61131 3 training

PID

  • CB[] is the control bloc that you just initialised

  • SP is the set point

  • PV is the process value i.e. the measured system value

  • CV is the control value i.e. the system’s input value

  • MAN is the manual override for the PID

  • UP and DOWN increment or decrement the CV value independently of the PID calculation. These only have an effect when MAN is TRUE

IEC61131-3 Training Course


Iec61131 3 training

PID

  • For the PID function bloc that support auto-tuning the following parameters are also defined:

    • TUNE: Boolean that starts the auto-tuning process

    • Done: Boolean output that indicates that the PID has completed its auto-tuning process.

    • #FILTER: is a DINT constant indicating how much noise filtering should be done.

    • #RESP: is a DINT constant indicating the response type required from the PID.

    • #TYPE: is a DINT constant indicating the type of PID control that should be tuned.

    • #TUNE2/3: is a BOOL constant that indicates whether the PID should be tuned to 2/3rd response or not.

IEC61131-3 Training Course


Iec61131 3 training

PID

  • For the constant values required for the auto-tuning parameters use the constants defined in the library

IEC61131-3 Training Course


Iec61131 3 training

PID

  • The code presented here will initialise and then RUN a single PID loop

IEC61131-3 Training Course


Iec61131 3 training

PID

  • The PID function blocs have been designed to work with the actual I/O points of the OCS system

  • If you need to display the system values in a different format then use the scaling function ScaleINT

  • E.g. a user can set the system temperature between 50.0°C and 250.0°C corresponding to an output scale of 0 to 32000 (value in %AQ register)

    • Set-up a display variable %R that will contain the user value

    • Insert a data field the displays this %R with 1 decimal digit

    • Insert the following code in your program:

      • SetPoint := ScaleINT( DisplayValue, int#0, int#32000, int#500, int#2500)

IEC61131-3 Training Course


Ethernet

Ethernet

Connecting to the world

IEC61131-3 Training Course


Ethernet1

Ethernet

  • Ethernet connectivity is available on all OCS products either as a built-in module or a SmartStack add-on module

  • Ethernet allows the OCS to be connected to the enterprise network and data fed into management systems and/or process supervision

  • The latest ETN modules support multiple IP based protocols such as Modbus TCP slave and HTTP server

  • The modules require minimal configuration to deliver these functionalities

IEC61131-3 Training Course


Ethernet configuration

Ethernet - Configuration

  • Configure the Ethernet module to suit your network requirements for IP addresses

IEC61131-3 Training Course


Ethernet diagnostics

Ethernet - Diagnostics

  • It is advised to either configure the unit’s IP address to be taken from a register or using the unit’s CAN ID for the last octet

  • The status register is composed of the following bits:

    • Bits 1 to 8 are the number of active TCP connections

    • Bit 9 is the link state

    • Bit 10 indicates the OCS is transmitting data

    • Bit 11 indicates the OCS is receiving data

    • Bit 13 indicates the speed of the connection (10 or 100Mbps)

    • Bit 14 indicates the link mode (half or full duplex)

IEC61131-3 Training Course


Ethernet modbus tcp

Ethernet – Modbus TCP

  • The OCS can be enabled to respond to Modbus requests over Ethernet

Tick box to enableModbus TCP slave

IEC61131-3 Training Course


Ethernet modbus tcp slave

Ethernet – Modbus TCP slave

  • The OCS will now respond to the following Modbus commands:

IEC61131-3 Training Course


Ethernet web server

Ethernet – Web server

  • Simply select the HTTP tick box to enable the web server functionality

  • The Web server can be password protected to avoid unauthorised access (user name and password can be up to 40 characters long)

IEC61131-3 Training Course


Ethernet web server1

Ethernet – Web server

  • The web server retrieves files stored on CompactFlash and sends them to the client

  • The user has the possibility of displaying register values from html pages as well as sending values to the OCS

  • Files are stored on CompactFlash in 8.3 file format

  • There is no default page access. The client has to specify a full url (e.g. 192.168.254.128/index.htm)

  • Custom HTML files are created to suit the application. These files can be created with a simple text editor or with a 3rd party HTML Editor

  • Within the static HTML file, <iframe> and <form> tags respectively read and write OCS Register data, by referencing two specially named dynamic HTML files (readreg.htm and writereg.htm)

IEC61131-3 Training Course


Ethernet web server read

Ethernet – Web server - read

  • The read register operation is performed within an IFRAME tag

    • <iframe src="readreg.htm;reg-R11;fmt-UINT;rfs-2"></iframe>

    • Reads R11 and in UINT format and refreshes the value every 2 seconds

  • The formats available are:

    • BOOL, BOOL-<on text>-<off text>, BIN, HEX, INT, UINT, DINT, UDINT, REAL, REAL-E, ASCII-<num characters> and IPADR

  • The refresh rate may be from 0 to the limits set by the browser

    If this parameter is omitted the page has to be refreshed manually

IEC61131-3 Training Course


Ethernet web server write

Ethernet – Web server - write

  • The write register operation is performed within an FORM tag

    • <form action="writereg.htm;reg-R11;fmt-UINT" method="post"><input type="text" name="value" value="0" /><input type="submit" value="Send" /></form>

    • This will write a value into %R11 when the Send button is pressed

  • Important: The OCS HTTP Server requires the name=”value” attributes to appear exactly as shown

IEC61131-3 Training Course


Ethernet ftp

Ethernet - FTP

  • File Transfer Protocol (FTP) is a standard Client/Server Internet protocol, based on RFC959, which supports efficient and reliable file transfers over a TCP/IP network. In this context, the Ethernet Module acts as an FTP Server, which responds to file transfer requests from one or more FTP Clients.

    • Note: FTP protocol is supported only by OCS Models, which have built-in Ethernet and an OCS file system with removable media (such as Compact Flash). For OCS Models that do not have an OCS file system, the FTP (File Transfer) checkbox will be grayed out in the Ethernet Module Configuration dialog.

IEC61131-3 Training Course


Iec61131 3 training

Ethernet - FTP

- The Ethernet Module’s FTP Server supports both anonymous and authenticated file transfers between an FTP Client and the OCS file system. Authenticated file transfers require that the FTP Client provide one of two possible User Name and Password pairs, before the OCS file system can be accessed.

- Properly authenticated, an FTP Client can access OCS file system functions, which include file read, file create, file delete, file rename, file write, directory read, directory create and directory delete.

IEC61131-3 Training Course


Ethernet ftp1

Ethernet - FTP

  • During the Ethernet configuration the user can optionally set up the FTP Configuration parameters for User 1 and/or User 2 as follows:

    • User Name: Enter an alphanumeric string (up to 40 characters) for the FTP Client’s User Name

    • Password: Enter an alphanumeric string (up to 40 characters) for the FTP Client’s Password

    • Read Only: Select this option to give the FTP Client read-only access to the OCS file system

    • Read / Write: Select this option to give the FTP Client read-write access to the OCS file system

IEC61131-3 Training Course


Iec61131 3 training

Ethernet - FTP

  • Note: User Names and Passwords are case-sensitive and, by default, User Name and Passwords for both User 1 and User 2 are empty. In this case, anonymous FTP Clients can access OCS files, but file access will be read-only. In a typical application, both User 1 and User 2 should be configured - one with read- only access and the other with read-write access.

  • The Ethernet Module FTP Server will automatically disconnect an FTP Client after about 3 minutes of inactivity, the user might want to configure the FTP Client to periodically send NOOP (No Operation) commands to the FTP Server, to keep the connection alive.

IEC61131-3 Training Course


Ethernet ftp file access

Ethernet – FTP file access

  • When using FTP to exchange files with an OCS, the user should know that the OCS file system implements an “8.3” filename format, which means file and directory names consist of up to 8 characters, followed by an optional dot, and an optional extension with up to 3 characters.

  • Also, the OCS file system allows multiple concurrent file accessing. For example, an FTP Client can read a file at the same time the OCS ladder program is logging data to another file. It is also possible for both the FTP Client and OCS ladder functions to read the same file at the same time.

  • If there is a file access conflict, such as an FTP Client attempting to delete a file that is currently being read or written by ladder, the file delete request is denied and an error response is sent to the FTP Client.

IEC61131-3 Training Course


The end

The end

Thank you for your attention, I hope you enjoyed this training course.

IEC61131-3 Training Course


Appendices

Appendices

Looking for more information

IEC61131-3 Training Course


List of iec61131 sub parts

List of IEC61131 sub parts

  • Part1: General information; Definition of basic terminology and concepts

  • Part2: Equipment requirements and tests; Electronic and Mechanical construction and verification tests

  • Part3: Programmable languages. PLC software structure, languages and program execution

  • Part4: User guidelines; Guidance on selection, installation and maintenance of PLCs

  • Part5: Messaging service specification; Software facilities to communicate with other devices using communications based on MAP Manufacturing Messaging Services

  • Part6: Communications via fieldbus Software facilities of PLC communications

IEC61131-3 Training Course


Recommended reading

Recommended reading

  • For an in-depth analysis of the IEC61131-3 standard:

    • Programming industrial control systems using IEC1131-3 Revised edition by R.W. Lewis (ISBN 0 85296 950 3)

IEC61131-3 Training Course


  • Login