3 PLC Programming The long march to IEC 61131 PLC industry needs - - PowerPoint PPT Presentation

3 plc programming the long march to iec 61131
SMART_READER_LITE
LIVE PREVIEW

3 PLC Programming The long march to IEC 61131 PLC industry needs - - PowerPoint PPT Presentation

EPFL, Spring 2017 3 PLC Programming The long march to IEC 61131 PLC industry needs aggreement on Data types (operations may only be executed on appropriate types) Programming languages Software structure (program organization units


slide-1
SLIDE 1

3 PLC Programming

EPFL, Spring 2017

slide-2
SLIDE 2

Industrial Automation | 2017 2

The long march to IEC 61131

Source: Dr. J. Christensen

77 78 79 81 80 93 94 95 70 82 83 84 85 87 86 88 89 90 91 92

NEMA Programmable Controllers Committee formed (USA) GRAFCET (France) IEC 848, Function Charts DIN 40719, Function Charts (Germany) NEMA ICS-3-304, Programmable Controllers (USA) IEC SC65A/WG6 formed DIN 19 239, Programmable Controller (Germany) MIL-STD-1815 Ada (USA) IEC SC65A(Sec)67

Type 3 report recommendation

96

IEC 65A(Sec)38, Programmable Controllers IEC 1131-3 IEC SC65A(Sec)49, PC Languages IEC 64A(Sec)90

IEC 61131-3 name change

it took 20 years to make that standard…

PLC industry needs aggreement on

  • Data types (operations may only be executed on appropriate types)
  • Programming languages
  • Software structure (program organization units for modularity, encapsulation)
  • Execution
slide-3
SLIDE 3

Industrial Automation | 2017 3

Extend procedural languages to express time

"Real-Time" languages

(“introduce programming constructs to influence scheduling and control flow”) Languages developed for cyclic execution and real-time ("application-oriented languages") Ladder Diagrams Function block diagrams Instruction lists GRAFCET Sequential flow charts etc...

  • wide-spread in the control industry.

Now standardized as IEC 61131 ADA Real-Time Java MARS (TU Wien) Forth “C” with real-time features etc… could not establish themselves

slide-4
SLIDE 4

Industrial Automation | 2017 4

Matching the analog and binary world

Analog World Binary World

A B C

continuous processes

P2

P1

I1

regulation, controllers discrete processes combinatorial sequential Relay control, pneumatic sequencer Pneumatic and electromechanical controllers

PLC time constant of the control system must be at least one order of magnitude smaller than smallest time constant of plant. variables with non-overlapping values, transition from one state to another is abrupt, caused by external events.

slide-5
SLIDE 5

Industrial Automation | 2017 5

IEC 61131-3 programming languages

Structured Text (ST)

VAR CONSTANT X : REAL := 53.8 ; Z : REAL; END_VAR VAR aFB, bFB : FB_type; END_VAR bFB(A:=1, B:=‘OK’); Z := X - INT_TO_REAL (bFB.OUT1); IF Z>57.0 THEN aFB(A:=0, B:=“ERR”); END_IF

Ladder Diagram (LD)

OUT PUMP http://www.isagraf.com

Function Block Diagram (FBD)

PUMP AUTO MAN_ON ACT DO V

Instruction List (IL)

A: LD %IX1 (* PUSH BUTTON *) ANDN %MX5 (* NOT INHIBITED *) ST %QX2 (* FAN ON *)

Sequential Flow Chart (SFC)

START STEP T1 T2 D1_READY D2_READY STEP A ACTION D1 N D ACTION D2 STEP B D3_READY D4_READY ACTION D3 N D ACTION D4 T3 CALC IN1 IN2 OUT >=1

Graphical languages Textual languages

AUTO MAN_ON ACT CALC IN1 IN2 OUT

slide-6
SLIDE 6

Industrial Automation | 2017 6

Importance of IEC 61131

IEC 61131-3 are the most important automation languages in industry. 80% of all PLCs support it, all new developments are based on it. Depending on the country, some languages are more popular than others. IEC 61499 extends IEC 61131 with an event-driven model, has not established itself yet.

More information: http://www.plcopen.org/pages/tc1_standards/downloads/plcopen_iec61131- 3_feb2014.pptx http://www.plcopen.org/pages/pc2_training/downloads/index.htm

slide-7
SLIDE 7

Industrial Automation | 2017 7

Connecting to Input/Output

The inputs and outputs of the PLC must be connected to (typed) variables

OUT_1

The I/O blocks are configured to be attached to the corresponding I/O groups.

IN_1

slide-8
SLIDE 8

Industrial Automation | 2017 8

Connecting to Input / Output

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,…

slide-9
SLIDE 9

Industrial Automation | 2017 9

Function Block Diagrams

& A B C

Trigger

Tempo &

Running Reset

S R

Spin

Example 1: Example 2:

external inputs external outputs

Q

  • Graphical language to express programs in a way similar to electronic circuits
  • Using predefined and custom functions, like Matlab / Simulink
  • For continuous functions and combinatorial logic, may have memory (e.g. RS-flip-flops)
slide-10
SLIDE 10

Industrial Automation | 2017 10

Function block elements

"continuously" executing block, independent, no side effects set point measurement command parameters The block is defined by its:

  • Data flow interface (number and type of input/output signals)
  • Black-box behavior (functional semantic, e.g. in textual form).

Signals are typed connections that carry a pseudo-continuous data flow (set point) (set point) set point PID input signals

  • utput signals
  • verflow
slide-11
SLIDE 11

Industrial Automation | 2017 11

Function block rules

Each signal is connected to exactly one source. This source can be the output of a function block or a plant signal. The type of the output pin, the type of the input pin and the signal type must be identical.

  • Signals should flow from left to right and from top to bottom

Retroactions are an exception to this rule, where the signal direction is identified by an arrow (forbidden in some editors, use global variables instead).

a b y x z c

slide-12
SLIDE 12

Industrial Automation | 2017 12

Types of Programming Organisation Units (POUs)

1) “Functions”

  • are part of the base library.
  • have no memory.

Examples: and gate, adder, multiplier, selector,.... 2) “Elementary Function Blocks” (EFB)

  • are part of the base library
  • may 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 (control flow not visible in the FBD

Examples: PID controller, overcurrent protection, motor sequence (a library of compound blocks may be found in IEC 61804-1)

slide-13
SLIDE 13

Industrial Automation | 2017 13

Function block library

The programmer chooses the blocks in a block library, similarly to the hardware engineer who chooses integrated circuits in a catalogue. The library describes the pinning of each block, its semantics and the execution time. The programmer may extend the library by defining function block macros composed of library elements. If some blocks are used often, they will be programmed in an external language (e.g. “C”, micro-code) following strict rules.

slide-14
SLIDE 14

Industrial Automation | 2017 14

Library functions for discrete and continuous plants

Logical operations(AND, OR, …) Flip-flop Selector m-out-of-n Multiplexer m-to-n Timer Counter Memory Sequencing Basic blocks Display Manual input, touch-screen Safety blocks (interlocking) Logging Compound blocks Alarm signaling Basic blocks Summator / Subtractor Multiplier / Divider Integrator / Differentiator Filter Min, Max Regulation Functions P, PI, PID, PDT2 controller Fixed set-point Ratio, multi-component regulation 2-point regulation 3-point regulation Output value limitation Ramp generator Adaptive regulation Drive Control

slide-15
SLIDE 15

Industrial Automation | 2017 15

Function block library for specialized applications

MoveAbsolute AXIS_REF Axis Axis AXIS_REF BOOL Execute Done BOOL REAL Position BOOL REAL Velocity CommandAborted WORD REAL Acceleration BOOL REAL Deceleration REAL Jerk MC_Direction Direction Error ErrorID

standardized blocks are defined in libraries, e.g. motion control or robotics

slide-16
SLIDE 16

Industrial Automation | 2017 16

Specifying the behaviour of function blocks

Time Diagram:

0 T T x y y x S R x1 1 1 x2 1 1 y previous state 1 1

Truth Table: Mathematical Formula:

x1 x2

Textual Description:

y x

 

t i d p

xd K dt dx K x K 

Calculates the root mean square of the input with a filtering constant defined in parameter „FilterDelay“

slide-17
SLIDE 17

Industrial Automation | 2017 17

Function block specification in structured text

slide-18
SLIDE 18

Industrial Automation | 2017 18

Execution of function blocks

F1 A B X01 F2 X01 X F3 B C X02 F4 X X02 Y Machine Code: function input1 input2

  • utput

A

F1 F2

B

F4

Y X01 X02

F3

C X

Segment or POU (program organization unit) The function blocks are translated to machine language (intermediate code, IL), that is either interpreted or compiled to assembly language Blocks are executed in sequence, normally from upper left to lower right The sequence is repeated every t ms.

slide-19
SLIDE 19

Industrial Automation | 2017 19

Input-output of function blocks

execute

individual period

I O X I O X I O X read inputs write

  • utputs

Run-time:

time

Executed cyclically: 1. all inputs are read from memory or plant (possibly cached) 2. segment is executed 3. results are written into memory or to plant (possibly to cache)

  • Order of execution of the blocks does not matter
  • For speed it can help to impose execution order on blocks
  • Different segments may be assigned different periods
slide-20
SLIDE 20

Industrial Automation | 2017 20

IEC 61131-3 library (extract)

CU – input (rising edges count up) R – reset counter (CV:=0) PV – preset value Q – 1 if CV >= PV CV – current value dominant reset Q:=!R1&(Q|S) rising edge detector dominant set Q:=S1|(Q&!R) ADD SUB MUL DIV adder subtractor multiplier divider INT PV Integrator In Reset (if reset) Out := PV, else Out:= Δt *In + Out

More details http://calc1.kss.ia.polsl.pl/content/dydaktyka/PC/PLC_IEC61131-3.pdf

Boolean Functions

Select one of N inputs depending

  • n input K

Binary selection

Arithmetic Functions Flip-flop Trigger Up counter Selector

slide-21
SLIDE 21

Industrial Automation | 2017 21 CTU CU RESET PV Q CV

1.

DIV INT PV In Reset = 0

Out

In1

(2) (initially 0)

2.

(1024)

In2

3. t1 t2 t3 t4 t5 t6 t7 t8 CU Reset = 0, PV = 3, CV = #up Q = (CV >= PV) ? Remember: INT If (Reset) : Out := PV, Else: Out := Δt *In + Out

Exercise: What do the following blocks do ? (Δt = 1)

4. S R Q Flipflop: dominant set or reset?

S RS Q R1

dominant reset Q:=!R1&(Q|S)

S1 SR Q R

dominant set Q:=S1|(Q&!R)

http://tinyurl.com/IAFunctionBlock

ADD

Out In

(10) (initially 2)

What are the values of Out? What happens if Reset = 1 or if Out is initially 1024? What are the values

  • f Out?
slide-22
SLIDE 22

Industrial Automation | 2017 22

3. CV = 1, 1, 2, 2, 3, 3, 4, 4 Q = 0, 0, 0, 0, 1, 1, 1, 1 4. S R Q

ftp://advantechdownloads.com/Training/KW%20training/ S1 SR Q R

dominant set Q:=S1|(Q&!R)

Exercise: What do the following blocks do ?

1. 2, 12, 22, 32, 42 2. If Out=0 initially: 0, 0, 0, 0, 0 If Reset=1 initially: 1024, 1024, 1024, 1024 If Out =1024 initially: 1024, 1536, 2304, 3456 http://tinyurl.com/IAFunctionBlock

slide-23
SLIDE 23

Industrial Automation | 2017 23

Exercise: Asymmetric Sawtooth Wave

Build an asymmetric sawtooth wave generator with IEC 61131 function blocks

75

  • 25

5s 12s

Hints:

  • Compute the slopes
  • Use integrators, comparators, flip-flops and selectors
slide-24
SLIDE 24

Industrial Automation | 2017 24

Exercise: Saw-tooth FBD

+ 8.3

  • 20.0

75.0

  • 25.0

Other solutions exists.

Out

slide-25
SLIDE 25

Industrial Automation | 2017 25

Function block decomposition

A function block describes a data flow interface. Its body can be implemented differently: The body is implemented in an external language (micro-code, assembler, IEC 61131 ST): Elementary block 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. . Compound block

procedure xy (a,b:BOOLEAN; VAR b,c: BOOLEAN); begin ...... .... end xy;

= =

slide-26
SLIDE 26

Industrial Automation | 2017 26

Function block segmentation

An application program (task) is decomposed into segments ("Programs") for easier reading, each segment being represented on one (A4) printed page.

  • Within a segment, the connections are represented graphically

.

  • Between the segments, the connections are expressed by signal names

.

Segment A Segment B X1 M2 M1 Y1 Y2 M2 X2 M1 X3

slide-27
SLIDE 27

Industrial Automation | 2017 27

Structured Text

(Strukturierte Textsprache, langage littéral structuré)

Structured Text is an imperative language similar to Pascal (If, While, etc..) The variables defined in ST can be used in other languages ST is used for complex data manipulation and to write blocks Caution: writing programs in structured text can breach real-time rules !

slide-28
SLIDE 28

Industrial Automation | 2017 28

Structured Text Examples

IF tank.temp > 200 THEN pump.fast :=1; pump.slow :=0; pump.off :=0; ELSIF tank.temp > 100 THEN pump.fast :=0; pump.slow :=1; pump.off :=0; ELSE pump.fast :=0; pump.slow :=0; pump.off :=1; END_IF;

pos := 0; WHILE((pos < 100) & s_arr[pos].value <> target)) DO pos := pos + 2; String_tag.DATA[pos] := SINT_array[pos]; END_WHILE;

[http://literature.rockwellautomation.com/idc/groups/literature/documents/pm/1756-pm007_-en-p.pdf]

Predefined functions, e.g.: SIZE(SINT_array, 0, SINT_array_size); Count the number of elements in SINT_array (array that contains inputs) and store result in SINT_array_size (DINT tag). IF( Switch_0 AND Switch_1 ) THEN Start_Motor := 1; Start_Count := Start_Count + 1; END_IF;

slide-29
SLIDE 29

Industrial Automation | 2017 29

Structured Text Example

Move ASCII characters from a SINT array into a string tag. (In a SINT array, each element holds one character.) Stop when you reach the carriage return.

element_num := 0; SIZE(SINT_array, 0, SINT_array_size); WHILE SINT_array[element_num] <> 13 DO String_tag.DATA[element_num] := SINT_array[element_num]; element_num := element_num + 1; String_tag.LEN := element_num; IF element_num = SINT_array_size then exit; END_IF; END_WHILE;

[http://literature.rockwellautomation.com/idc/groups/literature/documents/pm/1756-pm007_-en-p.pdf]

Explanations: 1. Initialize element_num to 0. 2. Count number of elements in SINT_array (ASCII characters), store in SINT_array_size. 3. If the character at SINT_array[element_num] = 13 (carriage return), then stop. 4. Set String_tag[element_num] = the character at SINT_array[element_num]. 5. Add 1 to element_num. This lets the controller check the next character in SINT_array. 6. Set length member element_num (records number of characters in String_tag so far.) 7. If element_num = SINT_array_size, then stop. (if at end of array and no carriage return.) 8. Go to 3.

slide-30
SLIDE 30

Industrial Automation | 2017 30

Structured Text Exercise

A user-defined data type (structure) stores information about an item in an Inventory array:

  • Inventory[i].ID: Barcode ID of the item (string data type)
  • Inventory[i].Qty: Quantity in stock of the item (DINT data type)

An array of the above structure contains an element for each different item in your inventory. You want to search the array for a specific product (by its barcode) and determine the quantity in stock. Pseudocode:

  • 1. Get size of Inventory array and store result in Inventory_Items (DINT tag).
  • 2. Loop over positions in array.
  • 3. If Barcode matches the ID of an item in the array, then:
  • a. Set the Quantity tag = Inventory[position].Qty
  • b. Stop.

[http://literature.rockwellautomation.com/idc/groups/literature/documents/pm/1756-pm007_-en-p.pdf]

slide-31
SLIDE 31

Industrial Automation | 2017 31

Structured Text Exercise Solution

A user-defined data type (structure) stores information about an item in an Inventory array:

  • Inventory[i].ID: Barcode ID of the item (string data type)
  • Inventory[i].Qty: Quantity in stock of the item (DINT data type)

An array of the above structure contains an element for each different item in your inventory. You want to search the array for a specific product (by its barcode) and determine the quantity in stock. Pseudocode:

  • 1. Get size of Inventory array and store result in Inventory_Items (DINT tag).
  • 2. Loop over positions in array.
  • 3. If Barcode matches the ID of an item in the array, then:
  • a. Set the Quantity tag = Inventory[position].Qty
  • b. Stop.

[http://literature.rockwellautomation.com/idc/groups/literature/documents/pm/1756-pm007_-en-p.pdf]

Solution: SIZE(Inventory,0,Inventory_Items); FOR position:=0 to Inventory_Items - 1 DO IF Barcode = Inventory[position].ID THEN Quantity := Inventory[position].Qty; EXIT; END_IF; END_FOR;

slide-32
SLIDE 32

Industrial Automation | 2017 32

SFC (Sequential Flow Chart)

(Ablaufdiagramme, diagrammes de flux en séquence )

  • Describes sequences of operations and interactions between parallel processes.
  • Derived from Grafcet and SDL (Specification and Description Language, used for

communication protocols), mathematical foundation lies in Petri Nets.

START STEP ACTION D1 N D1_READY D ACTION D2 D2_READY T1 T2 STEP B STEP A

slide-33
SLIDE 33

Industrial Automation | 2017 33

SFC: Elements

  • Program consists of states connected by transitions.
  • A state is activated by a token (the corresponding variable becomes TRUE).
  • Token leaves state when transition condition (event) on state output is true.
  • Only one transition takes place at a time,
  • Execution period is configuration parameter (task to which program is attached)

Ec = ((varX & varY) | varZ)

token

Sa Sb "1" Ea Sc Eb

transitions states

event condition ("1" = always true) example transition condition S0

Rule: there is always a transition between two states, there is always a state between two transitions

slide-34
SLIDE 34

Industrial Automation | 2017 34

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. In some systems, initialization may be triggered in a user program (initialization pin in a function block).

slide-35
SLIDE 35

Industrial Automation | 2017 35

SFC: Switch and parallel execution

Sa Sb "1" Se

token switch : token crosses the first active transition (at random if both Ea and Eb are true) Note: transitions are after the switch token forking : when the transition Ee is true, the token is replicated to all connected states Note: transition is before the fork

Ed

token join when all connected states have tokens and transition Eg is true, one single token is forwarded. Note: transition is after the join

Ee Sc Sd Sf Sg Eg

E0 Ea Eb Ec

Ef

slide-36
SLIDE 36

Industrial Automation | 2017 36

SFC: P1, N and P0 actions

P1 State1_P1: do at enter N State1_N: do while P0 State1_P0: do at leaving State1 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.

slide-37
SLIDE 37

Industrial Automation | 2017 37

Special action: the timer

rather than define a P0 action “ reset timer….”, there is an implicit variable defined as <state name>.t that express the time spent in that state.

Sf S.t > t#5s

S

slide-38
SLIDE 38

Industrial Automation | 2017 38

SFC: Exercise

Speed = 5 cm/s from I1 to I0 and from I2 to I3, faster otherwise. Initially: move vehicle at reduced speed until it touches I0 and open the trap for 5s (empty the vehicle). 1 - Let the vehicle move from I0 to I3 2 - Stop the vehicle when it reaches I3. 3 - Open the tank during 5s. 4 - Go back to I0 5 - Open the trap and wait 5s. repeat above steps indefinitely

I2 I3 Inputs generate “1” as long as the tag of the vehicle (1cm) is

  • ver the sensor.

Register = {0: closed; 1: open} I0 I1 trap +speed Speed = {+20: +1 m/s; +1: +5 cm/s; 0: 0m/s} negative values: opposite direction Variables Input: I0, I1, I2, I3 (boolean); Output: Trap = {0: closed; 1: open} Register = {0: closed; 1: open}

slide-39
SLIDE 39

Industrial Automation | 2017 39

Exercise SFC Example Solution

slide-40
SLIDE 40

Industrial Automation | 2017 41

SFC: Structuring

Every flow chart without a token generator may be redrawn as a structured flow chart (by possibly duplicating program parts) A B C

a b d c

Not structured A B C

a b a b

B' A'

d c d

structured

slide-41
SLIDE 41

Industrial Automation | 2017 42

Function Blocks And Flow Chart

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.
  • Communication between these program parts is possible.

Principle: A flow chart taken as a whole can be considered a function block with binary inputs (transitions) and binary outputs (states).

slide-42
SLIDE 42

Industrial Automation | 2017 43

Executing Flow Charts As blocks

A function block may be implemented in different ways:

procedure xy(...); begin ... end xy;

extern (ST/IL) function blocks flow chart Function blocks and flow chart communicate over binary signals.

slide-43
SLIDE 43

Industrial Automation | 2017 44

Flow Charts or Function Blocks ?

A task can sometimes be written indifferently as function blocs or as flow chart. The application may decide which representation is more appropriate:

c d "1" b a a b c d

Flow Chart Function Block

NOT S R

slide-44
SLIDE 44

Industrial Automation | 2017 45

Flow Charts Or Blocks ? (2)

In this example, a flow chart seems to be more appropriate:

A B C "1" a b c

S R ≥ & S R & S R & init a b c A B C

Flow Chart Function Blocks

slide-45
SLIDE 45

Industrial Automation | 2017 46

Exercise: write the SFC for this task

L1 T V1 V2

  • pen V1 until tank’s L1 indicates upper level
  • pen V2 during 25 seconds
  • pen V3 until the tank’s L1 indicates it reached the lower level

while stirring. heat mixture during 50 minutes while stirring empty the reactor while the drying bed is moving repeat MS V3 MD temperature (sensor) H1 upper lower V4 heater (actor)

slide-46
SLIDE 46

Industrial Automation | 2017 47

Ladder Diagrams (1)

Ladder Diagrams is the oldest programming language for PLC

  • based on relay intuition of electricians.
  • widely in use
  • not recommended for large new projects.

(Kontaktplansprache, langage à contacts)

Rung 0 Rung 1 Rung 2 Input instructions (conditions) Output (actions)

slide-47
SLIDE 47

Industrial Automation | 2017 48

Ladder Diagrams (2)

The contact plan or "ladder diagram" language allows an easy transition from the traditional relay logic diagrams to the programming of binary functions. It is well suited to express combinational logic It is not suited for process control programming (there are no analog elements). The main Ladder Diagrams symbols represent the elements: make contact break contact relay coil contact travail contact repos bobine Arbeitskontakt Ruhekontakt Spule

slide-48
SLIDE 48

Industrial Automation | 2017 49

Ladder Diagrams Example (3)

01 02 50 01 02 03 50 03

relay coil (bobine) break contact (contact repos) make contact (contact travail)

corresponding ladder diagram

  • rigin:

electrical circuit 50 05 44 rung "coil" 50 is used to move

  • ther contact(s)
slide-49
SLIDE 49

Industrial Automation | 2017 50

Ladder Diagrams (4)

Binary combinations are expressed by series and parallel relay contact: + 01 02 50 Coil 50 is active (current flows) when 01 is active and 02 is not. 01 02 50 Series + 01 40 02 Coil 40 is active (current flows) when 01 is active or 02 is not. Parallel Ladder Diagrams representation “logic" equivalent 01 02 40

slide-50
SLIDE 50

Industrial Automation | 2017 51

Ladder Diagrams (5)

The Ladder Diagrams is more intuitive for complex binary expressions than literal languages 50 1 2 3 4 5 6 ! 1 & 2 & ( 3 & ! 4 | ! 5 & 6 ) = 50 Or N1 & 2 STR 3 & N4 STR N5 & 6 / STR & STR = 50 50 1 4 5 6 7 2 3 10 11 12 N0 & 1 STR 2 & 3 / STR STR 4 & 5 STR N 6 & 7 / STR & STR STR 10 & 11 / STR & 12 = 50 textual expression

slide-51
SLIDE 51

Industrial Automation | 2017 52

Ladder Diagrams (6)

  • Ladder Diagrams stems from time of relay technology.
  • As PLCs replaced relays, not everything could be expressed in relay terms.
  • Language was extended to express functions.

literal expression:

!00 & 01 FUN 02 = 200 200 FUN 02 01 00

  • Intuition of contacts and coil gets lost.
  • More or less hidden control of the flow destroys the

freedom of side effects and makes programs difficult to read.

slide-52
SLIDE 52

Industrial Automation | 2017 53

Ladder Diagrams Example

Source: http://teacher.buet.ac.bd/zahurul/ME6401/ME6401_PLC.pdf Ladder Diagrams diagram for a batch process: filling a container with a liquid, mixing the liquid, and draining the container. The sequence of events is as follows:

  • 1. fill valve opens and lets the liquid into the container until it is full.
  • 2. liquid in the container is mixed for 3 minutes.
  • 3. a drain valve opens and drains the tank.

O = output I = input Address of variable (module number, port number)

slide-53
SLIDE 53

Industrial Automation | 2017 54

Ladder Diagrams Exercise

Source: http://teacher.buet.ac.bd/zahurul/ME6401/ME6401_PLC.pdf Consider a PLC with one input module and one output module. Two external switches (SW-0 & SW-1) are connected via terminal IN-0 and In-1 of input module. Two terminals of the output module (OUT-0 & OUT-1) drive two indicator lamps (Lamp-0 & Lamp-1). Which lamps are lit with the current switch positions? What happens if you change the position of Switch SW-1?

slide-54
SLIDE 54

Industrial Automation | 2017 55

Ladder Diagrams Exercise Solution

Source: http://teacher.buet.ac.bd/zahurul/ME6401/ME6401_PLC.pdf The top rung will light Lamp-0 if both SW-0 and SW-1 are closed. The bottom rung will light Lamp-1 if either SW-0 or OUT-0 are closed. In the current position LAMP-1 is lit. If we change the position of Switch SW-1 then LAMP 0 will be lit too.

slide-55
SLIDE 55

Industrial Automation | 2017 56

Ladder Diagrams (7)

Ladder Diagrams provides neither:

  • sub-programs (blocks), nor
  • data encapsulation nor
  • structured data types.

Not suited to make reusable modules. IEC 61131 does not prescribe the minimum requirements for a compiler / interpreter such as number of rungs per page nor does it specifies the minimum subset to be implemented. Therefore, it should not be used for large programs made by groups of people It is very limited when considering analog values (it has only counters) → used mostly in manufacturing, not in process control

slide-56
SLIDE 56

Industrial Automation | 2017 57

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. (Instruktionsliste, liste d'instructions)

slide-57
SLIDE 57

Industrial Automation | 2017 58

Instruction Lists (2)

Accumulator-based pogramming:

  • First, values are loaded into the accumulator (LD instruction)
  • Then, operations are executed with first parameter taken out of accumulator

and second parameter of operand.

  • Result put in the accumulator, from where it can be stored (ST instruction)

Conditional executions or loops are supported by comparing operators like EQ, GT, LT, GE, LE, NE and jumps (JMP, JMPC, JMPCN, for the last two the accumulators value is checked on TRUE or FALSE) Syntax:

  • each instruction begins on a new line and contains an operator and,

depending on the type of operation, one or more operands separated by commas

  • before an instruction there can be a label, followed by a colon (:), as target for jumps
  • use brackets to define order of execution
  • comments must be placed last
  • empty lines are allowed.
slide-58
SLIDE 58

Industrial Automation | 2017 59

Instruction Lists Examples (4)

Labels LD TRUE (*load TRUE into the accumulator*) ANDN BOOL1 (*execute AND with the negated value of the BOOL1 variable*) JMPC mark (*if the result was TRUE, then jump to the label "mark"*) LDN BOOL2 (*load the negated value of BOOL2 into the accumulator*) ST RES (*store the content of the accumulator in RES*) JMP continue (*jump to label “continue"*) mark: LD BOOL2 (*save the value of *) ST RES (*BOOL2 in RES*) continue: … Brackets (without) (with) LD 2 LD 2 MUL 2 MUL(2 ADD 3 ADD 3 ) ST RES (*7 is stored in RES*) ST RES (* 10 is stored in RES*)

slide-59
SLIDE 59

Industrial Automation | 2017 60

Instruction Lists Example (3)

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

End: ST speed3 (* result *)

slide-60
SLIDE 60

Industrial Automation | 2017 61

Instruction Lists Exercise(3)

What is the resulting speed3 for the following input?

End: ST speed3 (* result *)

a) Temp1 = 10 Temp2 = 15 Speed1 = 50 Speed2 = 100 b) Temp1 = 10 Temp2 = 5 Speed1 = 50 Speed2 = 100

slide-61
SLIDE 61

Industrial Automation | 2017 62

Exercise IEC 61131 Languages

http://tinyurl.com/IA61131 https://docs.google.com/forms/d/1lGkFXQrlwlnoKc8gUg-_ESAdtVy-RgIOLnFbkIOGNa8/viewform

Instruction List ? ? ? ? ? ? Function Block Diagram A C B ? C:= ? Structured Text A B C

  • | |--|/|----------------( )

Ladder Diagram ? ?

slide-62
SLIDE 62

Industrial Automation | 2017 63

Exercise IEC 61131 Languages

http://tinyurl.com/IA61131 https://docs.google.com/forms/d/1lGkFXQrlwlnoKc8gUg-_ESAdtVy-RgIOLnFbkIOGNa8/viewform

Instruction List LD A ANDN B ST C Function Block Diagram A C B AND C:= A AND NOT B Structured Text A B C

  • | |--|/|----------------( )

Ladder Diagram

slide-63
SLIDE 63

Industrial Automation | 2017 64

Programming environment capabilities

A PLC programming environment (e.g. ABB ControlBuilder, Siemens Step 7, CoDeSys,...) allows the programmer to

  • program in one of the IEC 61131 languages
  • define the variables (name and type)
  • bind the variables to the input/output (binary, analog)
  • run simulations
  • download programs and firmware to the PLC
  • upload from the PLC (if provided, rare)
  • monitor the PLC
  • document and print
slide-64
SLIDE 64

Industrial Automation | 2017 65

IDE Example: PLCOpenEditor

http://www.openplcproject.com/plcopen-editor

slide-65
SLIDE 65

Industrial Automation | 2017 66

61131 Programming environment

workstation

download

symbols code

variable monitoring and forcing for debugging

firmware

network

configuration, editor, compiler, library

PLC

slide-66
SLIDE 66

Industrial Automation | 2017 67

Is IEC 61131 FB an object-oriented language ?

Not really: it does not support inheritance. Blocks are not recursive. But it supports interface definition (typed signals), instantiation, encapsulation, some form of polymorphism. Some programming environments offer “control modules” for better

  • bject-orientation
slide-67
SLIDE 67

Industrial Automation | 2017 68

Limitations of IEC 61131

  • No support to distribute execution of programs over several devices
  • No support for event-driven operation. Blocks may be triggered by a

Boolean variable (intentionally, for good reasons).

  • If structured text increases in importance, better constructs are

required (object-orientation)

slide-68
SLIDE 68

Industrial Automation | 2017 69

Assessment

Which are programming languages defined in IEC 61131 and for what are they used ? In a function block language, which are the two elements of programming ? How is a PLC program executed and why is it that way ? Draw a ladder diagram and the corresponding function block chart. Draw a sequential chart implementing a 2-bit counter. Program a saw tooth waveform generator with function blocks. How are inputs and outputs to the process treated in a function block language ? Write a program for a simple chewing-gum coin machine. Program a ramp generator for a ventilator speed control (soft start and stop in 5s)