plc lecture 2

42
300044 Microcontrollers and PLCs 2011 Chapter 4, page 1 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones) 1 Chapter 4. More About Ladder Logic 4.1. Memory Areas How many inputs and outputs can a PLC have? The PLCs we use have 12 inputs (bits 00.00 to 00.11) and 8 outputs (100.00 to 100.08). However CX-programmer allocates The whole of words 00 to 99 (100 words or 1600 bits) to inputs and The whole of words 100 to 199 (100 words or 1600 bits) to outputs.

Upload: nam-doan

Post on 06-Mar-2015

232 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 1 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

1

Chapter 4. More About Ladder Logic

4.1. Memory Areas How many inputs and outputs can a PLC have?

The PLCs we use have 12 inputs (bits 00.00 to 00.11) and 8 outputs (100.00 to 100.08). However CX-programmer allocates

The whole of words 00 to 99 (100 words or 1600 bits) to inputs and

The whole of words 100 to 199 (100 words or 1600 bits) to outputs.

Page 2: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 2 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

2

What about when we want to store the output from one rung for use elsewhere in the program? CX-programmer has a memory area called the work area for this. This area is addressed by placing a W before the memory address, and has 512 words (8192 bits):

words W0 to W511 (bits W0.00 to W511.15).

When the power to the PLC is interrupted, the values in all these memory addresses are lost.

However there are situations where we want the PLC to maintain its memory values even after the power is interrupted or the PLC is shut down. CX-programmer has a separate memory area called the holding area that achieves this.

This area is addressed by placing a H before the memory address, and has 1535 words (24,560 bits):

words H0 to H1535 (bits H0.00 to H1535.15).

Page 3: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 3 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

3

4.2. Program Cycling and the Order of Execution of Rungs. The same logic could be obtained by using the rung of the ladder diagram as an electrical circuit diagram and:

holding its left hand rail at a non-zero potential and its right hand rail at a zero potential

replacing the inputs by normally open switches.

replacing the negated inputs by normally closed switches.

replacing the outputs by solenoids

taking the normally open switches to represent true when pressed and false when not pressed

taking an energised solenoid to represent true.

Page 4: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 4 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

4

An exception to the above analogy between ladder logic and electrical circuits becomes apparent in ladder diagrams containing more than one rung (as ladder diagrams almost always do). In an electrical circuit, all rungs are energised, and therefore perform their logic, simultaneously. But ladder logic is a computer language executed by a microprocessor in the PLC, so it can’t analyse every rung simultaneously. In order to make ladder logic more closely resemble this simultaneous operation, the execution proceeds in a continuous cycle as shown in this figure.

0001

00020001

0001

0002

1103

00030010

1101

1102

1103

1104

1105

Read the PLC Input Signals Execute the first rung

Execute the last rung Activate the PLC Output Signals

Page 5: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 5 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

5

Only one rung is executed at a time. The program cycles continuously from the

moment the PLC is put into run mode (even when nothing on the rig has been touched)

A PLC does not wait for a rung to go true before the following rung is executed. If the rung is false, the output is set low and the PLC moves onto the following rung

The PLC input signals are read only at the start of each cycle.

The PLC output signals are activated only after the last rung has been executed

Each rung takes a time in the order of milliseconds to execute.

Each rung happens immediately after the preceding rung.

0001

00020001

0001

0002

1103

00030010

1101

1102

1103

1104

1105

Read the PLC Input Signals Execute the first rung

Execute the last rung Activate the PLC Output Signals

Page 6: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 6 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

6

The whole cycle is executed in a very short time, giving the impression of the instantaneous and continuous execution of a hardwired electric circuit. Unlike an electric circuit, the order in which the rungs are arranged is important (as will be shown in coming weeks) . You should never use the addresses of the PLC inputs as the output of a rung. Since the PLC outputs are activated only after the last rung is executed, if a PLC output is used as the output to more than one rung, only its last value will ever be sent to the plant.

0001

00020001

0001

0002

1103

00030010

1101

1102

1103

1104

1105

Read the PLC Input Signals Execute the first rung

Execute the last rung Activate the PLC Output Signals

Page 7: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 7 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

7

4.3. Some more Examples Suppose that we want to extend cylinder 1 (memory address 100.02) when either the red button or the black button is pressed. One possibility program is:

Looking at the logic of this program:

We see that the red button has no influence on the program – Every time the red button controls 100.02, it is immediately changed by the following rung. Clearly this program does not achieve the required output.

RED BLACK 100.02 State of Cylinder 1

1 0

0 1

1 1

0 0

RED 100.0

BLACK 100.0

Page 8: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 8 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

8

A better solution is: (extend cylinder 1 when either the red button or the black button is pressed)

Looking at the logic of this program:

RED BLACK 100.02 State of Cylinder 1

1 0

0 1

1 1

0 0

RED 100.0

BLACK

Page 9: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 9 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

9

This is also true for cylinder 2 and cylinder 4, despite being driven by two memory addresses. Suppose that we want to extend cylinder 2 when the red button is pressed, but retract it whenever the black button is pressed. Since we know that cylinder 2 extends when 100.04 is high and 100.03 is low, it is tempting to try the following program: Looking at the logic of this program: Clearly this program does not achieve the required output.

RED

BLACK 100.03 100.04 State of Cylinder 2

1 0

0 1

1 1

0 0

RED 100.04

BLACK 100.03

Page 10: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 10 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

10

A better solution is: (extend cylinder 2 when the red button is pressed, but retract it whenever the black button is pressed)

RED

BLACK 100.03 100.04 State of Cylinder 2

1 0

0 1

1 1

0 0

RED 100.04 BLACK

100.03

Page 11: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 11 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

11

4.4. Using a Time Chart to Simulate a PLC’s behaviour In writing and debugging a PLC program, it is useful to be able to simulate how the PLC executes the rungs of a Ladder Diagram. We can do this by constructing a Time Chart. We start with a rectangular grid as shown. For each bit listed in the Each column represents a program scan. A single bit line from left to right is used for each

bit. The bit line jumps between the high line to the low line whenever the bit changes its logical value.

GB RB Ext-C1 Ext-C2 Ret-C2

Page 12: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 12 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

12

For the first program scan we work our way through the program. We determine the value of the output/coil of each rung, based on the current values of the rung’s input/contacts.

If the value of a bit changes from low to high or visa versa, its bit line is drawn vertically.

After the first program scan, each bit line is extended horizontally to the vertical grid line corresponding to the second program scan.

We repeat the process for the second program scan.

GB RB Ext-C1 Ext-C2 Ret-C2

Page 13: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 13 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

13

If there are no changes during a program scan, and not changes to the PLC inputs, subsequent scans will be exactly the same. Such a situation is called a steady state and is represented by a -//- in each bit line.

No further scans are recorded until a PLC input is changed from outside.

Once a PLC input is changed, the above steps are repeated.

GB RB Ext-C1 Ext-C2 Ret-C2

Page 14: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 4, page 14 of 14 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

14

Example

Black Green Cyl 1 Cyl 2

Page 15: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 1 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

1

Chapter 5. CX-Programmer II

5.1. More Help with CX-Programmer CX-Programmer has a good online help – make use of it. However, it sometimes crashes the computer, so open it from the start menu: Start | Programs | OMRON | CX-One

| CX-Programmer | CX-Programmer | Help.

Page 16: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 2 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

2

5.2. Opening an existing Project Existing programs can be opened and run on any of our PLCs. However, if ever you want to run a program on a different model of Omron PLC, you must change the PLC type. To do this, double click on the PLC line in the Project Workspace. A dialogue opens which allows you to change

o The PLCs name, o the PLC type o the Network Type

You can choose the PLC’s name. For the Device Type, select CP1L. The Network Type should be set to USB.

Page 17: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 3 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

3

5.3. Special Instructions: In addition to the logic achievable by arranging a rung’s contacts in different AND and OR arrangements, most PLC’s have a variety of special built in instructions or functions.

To access one of these, click on the New PLC Instruction icon . The New Instruction dialogue opens. Enter the name or number of the instruction in the top space.

Page 18: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 4 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

4

The corresponding bit address or name is entered in the space labelled Operands Some instructions require more than one operand. This is indicated below the Operands box. The operands are placed one below the other. If the small instruction dialogue opens, either expand it by clicking on Details, or enter the instruction’s name and operands separated by spaces.

Page 19: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 5 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

5

If you want help with an instruction, click on “Instruction Help” in the expanded New Instruction dialogue. This opens a help file specific to the instructions supported by the PLCs we use.

Page 20: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 6 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

6

One important special instruction is the END(01) instruction. Every ladder program in CX-Programmer has to end with an END(01) instruction. When you open a new program, this is inserted for you in a special section called END.

Make sure that you don’t delete this.

Page 21: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 7 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

7

5.4. Some more CX-Programmer functions The KEEP Instruction In the programs you wrote last week, the cylinders all returned to their retracted positions as soon as the input button(s) were released. In practice we don’t want to have to hold down the start button all the time to keep our factory running. This can be achieved by using the output/coil as a rung input/contact, so that once the output/coil is set high (by pressing the green button), it keeps itself high. It then stays high until the red button is pressed.

Page 22: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 8 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

8

CX-Programmer has a special instruction that achieves the same result. This is the KEEP(11) instruction we saw before. This instruction is used as the output/coil to a rung. It requires two input branches. The top Branch sets the output/coil high, and it stays high until it is reset (cancelled) by the bottom branch going high.

Set

Reset

Page 23: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 9 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

9

Differentiate up DIFU(13) Using the buttons as inputs as we do, the input goes high when the button is pressed and stays high until it is released. However, sometimes we want a bit to go high for only one program scan. CX-Programmer has a built-in instruction (DIFU) that achieves this. The argument of this instruction goes high for one program scan after a truth path has been established to the instruction and then goes low again.

GB RB DU

00.09

GB

DIFU(13)

W0.03

W0.03

DU

W0.01

00.11

RB

Page 24: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 10 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

10

Differentiate down DIFD(14) The argument of this instruction goes high for one program scan after a truth path that did exist is broken. Its time chart looks as follows:

GB RB BB DD

00.09

GB

DIFD(14)W0.03

W0.03

DD

W0.01

00.11

RB

00.08

BB

Page 25: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 11 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

11

5.5. Timers Timers are PLC bits which go high after predetermined time. They are used as a rung output and go high after a truth path has been maintained for a set period.

A timer is inserted as for other special functions – clicking on the icon and selecting the instruction name “TIM”. It requires two arguments: An identification number in the range 0-4095 A set value (the time to count down from) – in tenths of a second and

preceded by a #.

Page 26: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 12 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

12

A timer can then drive other PLC bits, by being used as an input/contact to another rung. This is achieved by using the bit address “Tn” In this program, T25 goes high 7.5 seconds after the green button is pressed. So its time chart looks as follows: GB T25 Ext-C3 The timer goes low again as soon as the truth path activating it goes low.

00.09

GB

TIM

025

#0075

T25

7.5 sec

100.0

Ext-C3

7.5d

Page 27: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 13 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

13

If the truth path goes low before the timer has gone high, the timer won’t go high at all, and any time that been accumulated is lost. GB T25 Ext-C3

00.09

GB

TIM

025

#0075

T25

7.5 sec

100.0

Ext-C3

7.5d 7.5d

Page 28: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 14 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

14

5.6. Counters (CNT) A counter (CNT) is a special instruction which, when used as a rung output, goes high after a truth path pulses (is established) a predetermined number of times. A counter is selected by entering the special function “CNT”, it requires two arguments: An identification number A Set Point - The number to count down from, (preceded by a #).

A counter has two input sub-rungs, the upper sub-rung is the pulse that gets counted, the lower rung resets the counter, back to its set point.

00.09

GB

CNT

027

#003 00.08

BB

Page 29: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 15 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

15

When used as a rung input/contact, the counter is identified by “Cn” where n is its identification number. For example, In the above program, when the black button is pressed, the value of the counter becomes equal to the set point. Each time the green button is pressed, the value of the counter decreases by one. When the counter value equals zero (after 3 presses of the green button), the counter bit C27 goes high. When the black button is pressed again, the counter is reset – the counter value returns to the set point and the counter bit goes low.

00.09

GB

CNT

027

#003

C27

3 times

100.05

Ext-C3

00.08

BB

Page 30: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 16 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

16

So its time chart looks as follows:

GB BB C27 Counter value

00.09

GB

CNT

027

#003

C27

3 times

100.05

ExtRB

00.08

BB

Page 31: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 5, page 17 of 17 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

17

If the black button is pressed before the counter value reaches zero, the counter value returns to the set point again. GB BB C27 Counter value

To ensure that the counter counts down from the correct value, it is best to reset the counter before each time it is used, particularly the first time. Note: Timers and counters use the same addresses, so if timer T3 has been used in a program, counter C3 can’t be used.

Page 32: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 6, page 1 of 9 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

1

Chapter 6. CX-Programmer III

6.1. Naming Bits It is often difficult to remember memory addresses. We therefore attach a name to each bit.

This makes programs easier to write and, easier to follow (particularly for someone else).

Page 33: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 6, page 2 of 9 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

2

To create names; Go offline ( PLC | WORK ONLINE, Ctrl+W,

or ) Double click on “symbols” in the Project Workspace. This will open the symbol table. Right click in the table and then click on “Insert Symbol”

Page 34: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 6, page 3 of 9 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

3

This will open the New Symbol dialogue. Enter the bit’s memory address, and the name that you want to use. Leave data type as BOOL. Click OK. When you want to continue writing your program, double click on “Section 1” in the project workspace.

Page 35: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 6, page 4 of 9 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

4

The rules for a bit’s name are:

1. The name cannot begin with a number, 2. The name cannot contain punctuation marks (except underscore), 3. The name cannot contain spaces, 4. The name cannot be similar to an address, 5. Names are case sensitive.

Whenever a Contact Dialogue or Coil Dialogue opens, you can now enter the bit’s name instead of its memory address.

Page 36: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 6, page 5 of 9 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

5

Bits can also have comments. These are inserted in the same dialogue used to give the bit a name. The first few words of each comment are also displayed in the ladder diagram.

To reduce overcrowding, the comments can be turned off, by clicking on View | Show Symbol Comments, Alt-Y, or

Page 37: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 6, page 6 of 9 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

6

6.2. Exporting and Importing Symbols It would be good if we could copy some symbols or an entire symbol table from one program to another. This would save us from having to re-enter commonly used bit names like BlackPB, GreenPB, extendCyl_3. This can be done as follows: 1. Select one or more symbols in the symbol table or the entire table by clicking on

“Symbols” in the Project Workspace. 2. Copy and paste it to a new document in Word or Excel 3. This file can now be saved. To import the symbols: 1. Open the different file in CX-Programmer 2. Open the Symbol table 3. Copy and paste the Symbols from Word or Excel into the Symbol table. More details about the required formats are in the online help.

Page 38: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 6, page 7 of 9 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

7

6.3. PLC Monitoring CX-Programmer is able to display the current status of the PLC bits and the TRUTH PATHS.

To do this, click on PLC | Monitor | Monitoring , Crtl+M, or Whenever you are working online, all bits that are high and truth paths get highlighted in green. Note that it may also be necessary to turn on window monitoring

View | Monitoring or to get monitoring to work.

Page 39: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 6, page 8 of 9 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

8

When you have PLC Monitoring active, the current value of timers and counters is displyed. While the truth path is active, you can see the current value counting down from the set point to zero .

Set point

Current Value

Timer Address

Page 40: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 6, page 9 of 9 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

9

6.4. Differential Monitoring Sometimes a bit is high for only a very brief moment but, when debugging the program, we need to determine whether it went high at all. This can be done by using differential monitoring. When online and in monitor mode or run mode, click on a bit in the PLC program.

Click on PLC | Monitor | Differential Monitor or . This opens a special dialogue box. As the PLC runs, the dialogue indicates every time the selected bit goes high (or low), by flashing a coloured square, keeping a count, and making a sound. The Differential Monitor tool is useful for checking whether a bit being driven by a DIFU is working properly. See section 5.4.

Page 41: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 7, page 1 of 2 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

1

Chapter 7. More about time charts

7.1. Modelling a more complex program.

We see that this program performs a toggle function.

GB

DU_GB

DUGB_C3ext

Cylinder 3

Page 42: PLC Lecture 2

300044 Microcontrollers and PLCs 2011 Chapter 7, page 2 of 2 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.) (please turn off mobile phones)

2

7.2. The Importance of Rung Order

In an electrical circuit, every rung is executed simultaneously and continuously. In a PLC ladder program, however, the order in which rungs appear is very important. Looking at the preceding ladder diagram with the last rung moved to the top:

GB GB(L-H-Cext) Ext-C2 OldGB