57
1 Week © Vocational Training Council, Hong Kong. Lecture 3 Basic Programmable Logic Controller (PLC) Programming EEC3420 Industrial Control Department of Electrical Engineering

Eee3420 lecture03 rev2011

Embed Size (px)

Citation preview

Page 1: Eee3420 lecture03 rev2011

1Week © Vocational Training Council, Hong Kong.

│ Lecture 3 │

Basic Programmable Logic Controller (PLC) Programming

EEC3420 Industrial ControlDepartment of Electrical Engineering

Page 2: Eee3420 lecture03 rev2011

2© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Learning Objectives

Know different types of programming languages used in PLC

Understand the basic programming techniques of PLC

Page 3: Eee3420 lecture03 rev2011

3© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

IEC 61131 standards for PLC

the use of PLC has been standardized by the IEC

developed with the input of vendors, end-users and academics, IEC 61131 consists of five parts:

General information

Equipment and test requirements

PLC programming languages

User guidelines

Communications

Page 4: Eee3420 lecture03 rev2011

4© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

The IEC 61131-3 programming language

the international standard for programmable controller programming languages

specifies the syntax, semantics and display for the following suite:

Ladder diagram (LD)

Sequential Function Charts (SFC)

Function Block Diagram (FBD)

Structured Text (ST)

Instruction List (IL)

Page 5: Eee3420 lecture03 rev2011

5© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Ladder diagram (LD)

widely spread graphical programming language for PLCs

a programmatically replacement for relays and coils which can be combined using AND and OR operations

best suited to compute Boolean expressions

IEC 61131-3 defines a complete LD set of instructions, consisting of different types of contacts and coils

Page 6: Eee3420 lecture03 rev2011

6© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Ladder diagram (LD)

contacts lead (according to their type) the power from the left to the right

coils store the incoming value

both, contacts and coils, are assigned to Boolean variables

an LD network can be supplemented by jumps, returns, labels and comments

Page 7: Eee3420 lecture03 rev2011

7© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Sequential Function Charts (SFC)

SFC is the IEC 61131 -3 method to program sequential controls

actions may contain Boolean variables or entire networks, networks are programmed in Ladder Diagram, true action associations from several steps, several concurrent SFC networks in one diagram

Page 8: Eee3420 lecture03 rev2011

8© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Function Block Diagram (FBD)

FBD defined in IEC 61131-3 consists of different functions and function blocks that are either linked or connected to variables

in FBD networks, jumps, labels and returns can be used

similar to the creation of functional diagrams or block diagrams, with the control logic being created by simply connecting blocks and elements

frequently used in the process industry due to the flow-oriented properties of function blocks

Page 9: Eee3420 lecture03 rev2011

9© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Structured Text language (ST)

similar to the high-level language PASCAL or BASIC

uses statements like IF...THEN or FOR…NEXT

concerned compiler is responsible for syntactically correct insertion of the language constructions

text editor simplifies the programming work through syntax highlighting

syntax and the set of instructions of ST are optimally suited for mathematical calculations and data manipulations

Page 10: Eee3420 lecture03 rev2011

10© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Instruction List (IL)

an assembler type textual programming language

large (and mostly incompatible) sets of instructions have been created by many vendors

the IEC 61131 Instruction list reduced this set to a minimum and favours the usage of functions and function blocks for more complex tasks

code in IL consists of a sequence of instructions separated by lines, which consist of one operator ("command"), one operand (variable, constant or instance name) and one optional modifier respectively

Page 11: Eee3420 lecture03 rev2011

11© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Instruction List (IL)

jumps and labels can be used

concerned assembler is responsible for syntactically correct insertion of the language constructions

text editor simplifies the programming work through syntax highlighting (colour marking of language elements)

mainly used if the processing speed of the PLC program has high priority

Page 12: Eee3420 lecture03 rev2011

12© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Instruction List (IL)

Basic instructions used in Allen Bradley PLC

Mnemonic Function Mnemonic Function

LD Load ANDN And Not

LDN Load Not ORN Or Not

ST Store MPS Memory Push

STN Store Not MPP Memory Pop

AND And MRD Memory Read

OR Or MCR Master Control Relay

ANB And Block

ORB Or Block

Note: The instruction mnemonic may vary across different series of the Allen Bradley PLCs.

Page 13: Eee3420 lecture03 rev2011

13© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Instruction List (IL) Basic instructions used in Omron PLC

Mnemonic Function Mnemonic Function

LOAD Load NOP No Operation

LOAD NOT Load Not TR Temp. Register

OUT Out IL InterLock (eq. to MC)

AND And ILC InterLockClear(eq. to MCR)

AND NOT And Inverted

AND LD And Block

OR Or

OR NOT Or Not

OR LD Or Block

Page 14: Eee3420 lecture03 rev2011

14© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Instruction List (IL) Basic instructions used in Mitsubishi PLC FX series

Mnemonic Function Mnemonic Function

LD Load NOP No Operation

LDI Load Inverted MPS Memory Push

OUT Out MPP Memory Pop

AND And MRD Memory Read

ANI And Inverted MC Master Control

ANB And Block MCR Master Control Reset

OR Or

ORI Or Inverted

ORB Or Block

Page 15: Eee3420 lecture03 rev2011

15© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

IL, LD and its associated logic equation

operation labeled with circle 1 is performed first as it is the deepest nested term, and operations proceed with circle 2,circle 3 and circle 4 consecutively

(Mitsubishi PLC codes)

Page 16: Eee3420 lecture03 rev2011

16© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Instruction List (IL) A list of commonly used IL operators defined in IEC 61131-3

Page 17: Eee3420 lecture03 rev2011

17© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Instruction List (IL) example of IL using the syntax defined in IEC 61131-3

Page 18: Eee3420 lecture03 rev2011

18© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Instruction List (IL)

example of IL using the syntax defined in IEC 61131-3

Page 19: Eee3420 lecture03 rev2011

19© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Instruction List (IL)

example of IL program using the instructions MPS, MPP & MRD to implement multiple outputs using the syntax defined in IEC 61131-3

Page 20: Eee3420 lecture03 rev2011

20© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Instruction List (IL)

example demonstrating the use of TR instruction (similar to MPS, MPP & MRD instructions defined in IEC 6113-3) in Omron PLC

Page 21: Eee3420 lecture03 rev2011

21© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Instruction List (IL)

example demonstrating the use of MCR instruction in Allen Bradley PLC

Page 22: Eee3420 lecture03 rev2011

22© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Instruction List (IL)

example demonstrating the use of MC & MCR instructions in Mitsubishi PLC

(N0 is the nested number, maximum 7,i.e. a total of 8 nested levels; SP means “space”)

Page 23: Eee3420 lecture03 rev2011

23© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Instruction List (IL)

example demonstrating the use of IL & ILC instructions in Omron PLC

Page 24: Eee3420 lecture03 rev2011

24© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Conversion of more complex logic gates

Page 25: Eee3420 lecture03 rev2011

25© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Multiplexer

Page 26: Eee3420 lecture03 rev2011

26© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Time Related Instruction – the Latch

• a latch in ladder logic uses one instruction to latch, and a second instruction to unlatch

• the output with an L inside will turn the output D on when the input A becomes true

• D will stay on even if A turns off

• D will turn off if input B becomes true

Page 27: Eee3420 lecture03 rev2011

27© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Time Related Instruction – the Latch

Page 28: Eee3420 lecture03 rev2011

28© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Time Related Instruction – the Latch

a typical timing diagram, ignoring the brief pulse

Page 29: Eee3420 lecture03 rev2011

29© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

The SR (Set-Reset) Flip Flop

Latches are not used universally by all PLC vendors, others such as Siemens use flip-flops

Page 30: Eee3420 lecture03 rev2011

30© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

The SR (Set-Reset) Flip Flop

the SR Flip Flop may be implemented by using AND-OR functions

Page 31: Eee3420 lecture03 rev2011

31© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

The SR (Set-Reset) Flip Flop

the SR Flip Flop may also be implemented by using SET-RESET functions

Page 32: Eee3420 lecture03 rev2011

32© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

The SR (Set-Reset) Flip Flop

implement the SR Flip Flop in Omron PLC

Page 33: Eee3420 lecture03 rev2011

33© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

The Timers• four fundamental types

• on-delay timer will wait for a set time after a line of ladder logic has been true before turning on, but it will turn off immediately

• off-delay timer will turn on immediately when a line of ladder logic is true, but it will delay before turning off

• retentive timer will sum all of the on or off time for a timer, even if the timer never finished

• non-retentive timer will start timing the delay from zero each time

Page 34: Eee3420 lecture03 rev2011

34© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Operation of a TON (non-retentive) Timer

Page 35: Eee3420 lecture03 rev2011

35© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Operation of a RTO (retentive time on) timer

Page 36: Eee3420 lecture03 rev2011

36© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Operation of a TOF (non-retentive t-off) timer

Page 37: Eee3420 lecture03 rev2011

37© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Timers in Mitsubishi PLCs • in FX1N and FX2N series, there are four types of

timers

• T0 ~ T199 are non-retentive time on timer with timing interval of 100 ms

• T200 ~ T245 are non-retentive time on timer with timing interval of 10 ms

• T246 ~ T249 are retentive time on timer with timing interval of 1 ms

• T250 ~ T255 are retentive time on timer with timing interval of 100 m

Page 38: Eee3420 lecture03 rev2011

38© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Using non-retentive time on timer in Mitsubishi FX series PLC

Page 39: Eee3420 lecture03 rev2011

39© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Timers in Omron PLC

• in CP series, there are 48 timers/counters with timing range running

• from 0.1s to 999.9s if it is set as common timer

• or 0.01s to 99.99s if it is set as high speed timer

Page 40: Eee3420 lecture03 rev2011

40© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Timers in Omron PLC

Page 41: Eee3420 lecture03 rev2011

41© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

The Counters• two basic counter types:

count-up and count-down.

• when the input to a count-up counter goes true the accumulator value will increase by 1, if the accumulator value reaches the preset value the counter DN bit will be set

• a count-down counter will decrease the accumulator value until the preset value is reached

Page 42: Eee3420 lecture03 rev2011

42© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

An up-down counter in Allen Bradley PLC

Page 43: Eee3420 lecture03 rev2011

43© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Counter operation in Mitsubishi PLC

Page 44: Eee3420 lecture03 rev2011

44© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Counter operation in Omron PLC

Page 45: Eee3420 lecture03 rev2011

45© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

The Edge Triggering Instructionsin Mitsubishi FX series PLC, there are two edge triggering instructions, namely, PLS (PuLSe) and PLF (PuLse Falling)

Page 46: Eee3420 lecture03 rev2011

46© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

The Edge Triggering Instructionsin Mitsubishi FX series PLC, there are two edge triggering instructions, namely, PLS (PuLSe) and PLF (PuLse Falling)

Page 47: Eee3420 lecture03 rev2011

47© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

The Edge Triggering Instructionsin Omron PLC, there are similar edge triggering instructions, namely, the DIFU (DIFferentiate Up) and the DIFD (DIFferentiate Down)

Page 48: Eee3420 lecture03 rev2011

48© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

The Edge Triggering Instructionsin Omron PLC, there are similar edge triggering instructions, namely, the DIFU (DIFferentiate Up) and the DIFD (DIFferentiate Down)

Page 49: Eee3420 lecture03 rev2011

49© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Applications of Time Related Instructions

The timers and the counters find their applications in many industrial process controls

Page 50: Eee3420 lecture03 rev2011

50© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Applications of Time Related Instructions

Pulse generator circuit

Page 51: Eee3420 lecture03 rev2011

51© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Applications of Time Related Instructions

Fixed width pulse generator circuit

Page 52: Eee3420 lecture03 rev2011

52© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Applications of Time Related InstructionsDelay off timer - Many PLCs such as Mitsubishi do not provide delay off timer, but this function can easily be built by the delay on timer

Page 53: Eee3420 lecture03 rev2011

53© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Applications of Time Related Instructions

Light flasher

Page 54: Eee3420 lecture03 rev2011

54© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Applications of Time Related Instructions

Variable delay on/variable delay off circuit with Mitsubishi PLC

Page 55: Eee3420 lecture03 rev2011

55© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Applications of Time Related Instructions

Variable delay on/variable delay off circuit with Omron PLC

Page 56: Eee3420 lecture03 rev2011

56© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Summary of Basic PLC Programming

․ The Instruction List programming language uses stack operation to perform the operations specified.

․ Logic can be represented with basic Boolean operations AND, OR, NOT.

․ Boolean equations can be converted to and from ladder logic or instruction list.

․ The MPS, MPP and MRD enable intermediate results to be pushed, pop and read to facilitate multiple outputs.

․ Use of the MC/MCR instructions simplifies the organization of the ladder logic.

․ The time related instructions realize the sequential functions.

Page 57: Eee3420 lecture03 rev2011

57© Vocational Training Council, Hong Kong.

EEE3420 Industrial Control

Week

Basic PLC Programming

End of Lecture 3

RevisionMitsubishi PLC FX series hardware handbook.Allen Bradley PLC handbookOmron PLC manual