PLC - Course Notes - 4
PLC - Course Notes - 4
Traditionally ladder logic programs have been written by thinking about the process and then
beginning to write the program. This always leads to programs that require debugging. And, the
final program is always in some doubt. Structured design technique leads to programs that are
predictable and reliable.
Structured design is very important in engineering, but many engineers will write software
without taking the time or effort to design it. This often comes from previous experience with
programming where a program was written, and then debugged. This approach is not acceptable
for mission critical systems such as industrial controls.
The time required for a poorly designed program is 10% on design, 30% on writing, 40%
debugging and testing, 10% documentation.
The time required for a high quality program design is 30% design, 10% writing software, 10%
debugging and testing, 10% documentation.
Most beginners perceive (algılamak) the writing and debugging as more challenging and
productive, and so they will rush through (acele ile geçmek) the design stage. If you are spending
time on debugging ladder logic programs, you are doing something wrong. Structured design also
allows others to verify and modify your programs.
Axiom: Spend as much time on the design of the program as possible. Resist the temptation
(cazibe) to implement an incomplete design.
35
Consider the example of a flag raising controller in Figure 7.1 and Figure 7.2. The problem
begins with a written description of the process. This is then turned into a set of numbered steps.
Each of the numbered steps is then converted to ladder logic.
Example:
A flag raiser that will go up when an up button is pushed, and down when a down button is
pushed, both push buttons are momentary (anlık buton). There are limit switches at the top and
bottom to stop the flag. When turned on at first, the flag should be lowered until it is at the
bottom of the pole (bayrak direği).
Steps:
The flag is moving down the pole waiting for the bottom limit switch.
The flag is idle at the bottom of the pole waiting for the up button.
The flag moves up, waiting for the top limit switch.
The flag is idle at the top of the pole waiting for the down button.
36
Figure 7.1 A Process Sequence Bit Design Example with Latches (switch’ler NO olacak !!)
37
The previous method uses latches, but the use of latches is sometimes discouraged. A more
common method of implementation, without latches, is shown in Figure 7.2.
Figure 7.2 Process Sequence Bits Without Latches (switch’ler NO olacak !!)
38
7.2 DESIGN WITH TIMING DIAGRAMS
Timing diagrams can be valuable when designing ladder logic for processes that are only
dependant on time. The timing diagram is drawn with clear start and stop times. Ladder logic is
constructed with timers that are used to turn outputs on and off at appropriate times.
Example:
A door opener has a button that will open two doors. When the button is pushed (momentarily)
the first door will start to open immediately, the second door will start to open 2 seconds later.
The first door power will stay open for a total of 10 seconds, and the second door power will stay
on for 14 seconds. Use a timing diagram to design the ladder logic.
39
Figure 7.3 Design with a Timing Diagram
40
8. FLOWCHART BASED DESIGN
Objectives:
• Be able to describe a process with a flowchart.
• Be able to convert a flowchart into a ladder logic.
A flowchart is ideal for a process that has sequential process steps. The steps will be executed in
a simple order that may change as the result of some simple decisions. The symbols used for
flowcharts are shown in Figure 8.1. These blocks are connected using arrows to indicate the
sequence of the steps. The different blocks imply different types of program actions. Programs
always need a start block. Other important blocks include operations and decisions.
Example:
A flowchart is shown in Figure 8.2 for a control system for a large water tank. When a start
button is pushed the tank will start to fill, and the flow out will be stopped. When full, or the stop
button is pushed the outlet will open up, and the flow in will be stopped. In the flowchart the
41
general flow of execution starts at the top. The first operation is to open the outlet valve and close
the inlet valve. Next, a single decision block is used to wait for a button to be pushed. When the
button is pushed the yes branch is followed and the inlet valve is opened, and the outlet valve is
closed. Then the flow chart goes into a loop that uses two decision blocks to wait until the tank is
full, or the stop button is pushed. If either case occurs the inlet valve is closed and the outlet valve
is opened. The system then goes back to wait for the start button to be pushed again.
42
The general method for constructing flowcharts is:
Once a flowchart has been created ladder logic can be written. There are two basic techniques
that can be used, the first presented uses blocks of ladder logic code. The second uses normal
ladder logic.
The first step is to name each block in the flowchart, as shown in Figure 8.3. Each of the
numbered steps will then be converted to ladder logic.
43
Each block in the flowchart will be converted to a block of ladder logic. To do this we will use
the MCR (Master Control Relay) instruction if the first MCR line is true then the ladder logic on
the following lines will be scanned as normal until the second MCR. If the first line is false the
lines to the next MCR block will all be turned off. If a normal output is used inside an MCR
block, it may be forced off. Therefore latches will be generally used in this method.
The first part of the ladder logic will reset the logic to an initial condition, as shown in Figure 8.4.
The line will only be true for the first scan of the PLC, and at that time it will turn on the
flowchart block F1. All other operations will be turned off.
The ladder logic for the first state is shown in Figure 8.5. When F1 is true the logic between the
MCR lines will be scanned, if F1 is false the logic will be ignored. This logic turns on the outlet
valve and turns off the inlet valve. It then turns off operation F1, and turns on the next operation
F2.
44
Figure 8.5 Ladder Logic for the Operation F1
The ladder logic for operation F2 is simple, and when the start button is pushed, it will turn off
F2 and turn on F3. The ladder logic for operation F3 opens the inlet valve and moves to
operation F4.
45
Figure 8.6 Ladder Logic for Flowchart Operations F2 and F3
The ladder logic for operation F4 turns off F4, and if the tank is full it turns on F6, otherwise F5
is turned on. The ladder logic for operation F5 is very similar.
46
Figure 8.7 Ladder Logic for Operations F4 and F5
The ladder logic for operation F6 turns the outlet valve on and turns off the inlet valve. It then
ends operation F6 and returns to operation F2.
47
Figure 8.8 Ladder Logic for Operation F6
In general there is a preference for methods that do not use MCR statements or latches. The
flowchart used in the previous example can be implemented without these instructions using the
following method.
48
Figure 8.9 Label the Flowchart Blocks and Arrows
The first section of ladder logic is shown in Figure 8.10. This indicates when the transitions
between functions should occur.
49
Figure 8.10 The Transition Logic
The logic shown in Figure 8.11 will keep a function on, or switch to the next function. Consider
the first ladder rung for F1, it will be turned on by transition T1 and once function F1 is on it will
keep itself on, unless T2 occurs shutting it off. If T2 has occurred the next line of ladder logic will
turn on F2. The function logic is followed by output logic.
50
Figure 8.11 The Function Logic and Outputs
51
Assignment: Convert the following flowchart to ladder logic.
52