PLC Lecture 2
PLC Lecture 2
Chapter 4,
page 1 of 14
Chapter 4.
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 4,
page 2 of 14
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. CXprogrammer 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).
2
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 4,
page 3 of 14
4.2.
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.
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 4,
page 4 of 14
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 cant 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 1103
0002
0010
0003 1104
1103 1105
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 4,
page 5 of 14
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 1103
0002
0010
0003 1104
1103 1105
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 4,
page 6 of 14
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 1103
0002
0010
0003 1104
1103 1105
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 4,
page 7 of 14
BLACK
100.0
Looking at the logic of this program: RED BLACK 100.02 State of Cylinder 1 1 0 0 1 0 1 1 0
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.
7
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 4,
page 8 of 14
A better solution is: (extend cylinder 1 when either the red button or the black button is pressed)
RED BLACK
100.0
Looking at the logic of this program: RED BLACK 100.02 State of Cylinder 1 1 0 0 1 0 1 1 0
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 4,
page 9 of 14
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:
RED 100.04
BLACK
100.03
1 0
9
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 4,
page 10 of 14
A better solution is: (extend cylinder 2 when the red button is pressed, but retract it whenever the black button is pressed)
100.04
RED
BLACK
100.03
10
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 4,
page 11 of 14
11
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 4,
page 12 of 14
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 rungs 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
12
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 4,
page 13 of 14
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 RetC2
13
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 4,
page 14 of 14
Example
14
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 1 of 17
Chapter 5.
CX-Programmer II
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 2 of 17
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 3 of 17
To access one of these, click on the New PLC Instruction icon The New Instruction dialogue opens.
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 4 of 17
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 instructions name and operands separated by spaces.
4
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 5 of 17
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.
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 6 of 17
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.
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 7 of 17
5.4.
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 dont 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.
7
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 8 of 17
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
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 9 of 17
Differentiate up DIFU(13)
00.09
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.
GB 00.11 RB W0.03 DU
W0.03
W0.01
The argument of this instruction goes high for one program scan after a truth path has been established to the GB instruction and then goes low again. RB DU
9
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 10 of 17
00.09
The argument of this instruction goes high for one GB program scan after a truth path that did exist is 00.11 broken. Its time chart looks as follows:
RB W0.03 DD
DIFD(14 )
W0.03 00.08 BB
W0.01
GB RB BB DD
10
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 11 of 17
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 and selecting the instruction name TIM.
icon
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 #.
11
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 12 of 17
A timer can then drive other PLC bits, by being used as an input/contact to another rung.
00.09 TIM
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
7.5d
GB
025 #0075
100.0 Ext-C3
The timer goes low again as soon as the truth path activating it goes low.
12
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 13 of 17
If the truth path goes low before the timer has gone high, the timer wont go high at all, and any time that been accumulated is lost.
GB T25 Ext-C3
7.5d 7.5d
13
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 14 of 17
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 #).
00.09
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.
CNT GB
00.08
027 #003
BB
14
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 15 of 17
When used as a rung input/contact, the counter is identified by Cn where n is its identification number.
00.09
For example,
GB
00.08
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.
BB
C27 100.05
3 times
Ext-C3
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.
15
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 16 of 17
00.09
CNT GB
00.08
027 #003
BB
C27 100.05
GB BB C27
Counter value
16
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 5,
page 17 of 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 cant be used.
17
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 6,
page 1 of 9
Chapter 6.
CX-Programmer III
This makes programs easier to write and, easier to follow (particularly for someone else).
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 6,
page 2 of 9
Double click on symbols in the Project Workspace. This will open the symbol table.
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 6,
page 3 of 9
This will open the New Symbol dialogue. Enter the bits 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.
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 6,
page 4 of 9
The rules for a bits 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 bits name instead of its memory address.
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 6,
page 5 of 9
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
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 6,
page 6 of 9
6.2.
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.
6
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 6,
page 7 of 9
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.
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 6,
page 8 of 9
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 .
Timer Address
Current Value
Set point
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 6,
page 9 of 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 dialogue box. . This opens a special
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.
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 7,
page 1 of 2
Chapter 7.
300044 Microcontrollers and PLCs 2011 Written by Dr Jonathan Vincent (Robotic and Mechatronic Eng.)
Chapter 7,
page 2 of 2
7.2.
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:
2