PLC Ladder Logic Programs

PLC Ladder Logic Programs

For ease of understanding, ladder logic programs can be compared to relay schematics. In this article, I will explain how traditional relay schematics are converted into PLC ladder logic programs.

Latching Relays: Electromagnetic latching relays are designed to hold the relay closed after power has been removed from the coil. Latching relays are used where it is necessary for contacts to stay open and/or closed even though the coil is energized only momentarily.

Fig. 1

Figure shows a latching relay that uses two coils. The latch coil is momentarily energized to set the latch and hold the relay in the latched position. The unlatch or release coil is momentarily energized to disengage the mechanical latch and return the relay to the unlatched position.

plc ladder logic programs
Fig. 2

Figure 2 shows a hardwired control circuit for an electromagnetic latching relay. The operation of the circuit can be summarized as follows:

  • The contact is shown with the relay in the unlatched position.
  • In this state the circuit to the pilot light is open and so the light is off.
  • When the ON button is momentarily actuated, the latch coil is energized to set the relay to its latched position.
  • The contacts close, completing the circuit to the pilot light, and so the light is switched on.
  • The relay coil does not have to be continuously energized to hold the contacts closed and keep the light on.
  • The only way to switch the lamp off is to actuate the OFF button, which will energize the unlatch coil and return the contacts to their open, unlatched state.
  • In cases of power loss, the relay will remain in its original latched or unlatched state when power is restored.

An electromagnetic latching relay function can be programmed on a PLC to work like its real-world counterparts. The instruction set for the SLC 500 includes a set of output instructions that duplicates the operation of the mechanical latch. A description of the output latch (OTL) and output unlatch (OTU) instruction is given in Figure 3 .

Fig. 3

The OTL and OTU instructions differ from the OTE instruction in that they must be used together. Both the latch and unlatch outputs must have the same address. The OTL (latch) instruction can only turn a bit on and the OTU (unlatch) instruction can only turn a bit off.

Fig. 4

The operation of the output latch and output unlatch coil instruction is illustrated in the ladder program of Figure 4. The operation of the program can be summarized as follows:

  • Both the latch (L) and the unlatch (U) coil have the same address (O:2/5).
  • When the on pushbutton (I:1/0) is momentarily actuated, the latch rung becomes true and the latch status bit (O:2/5) is set to 1, and so the light output is switched on.
  • The status bit will remain set to 1 when the pushbutton is released and logical continuity of the latch rung is lost.
  • When the off pushbutton (I:1/1) is momentarily actuated, the unlatch rung becomes true and the latch status bit (O:2/5) is reset back to 0 and so the light is switched off.
  • The status bit will remain reset to 0 when the pushbutton is released and logical continuity of the latch rung is lost.

Output latch is an output instruction with a bit-level address. When the instruction is true, it sets a bit in the output image file. It is a retentive instruction because the bit remains set when the latch instruction goes false. In most applications it is used with an unlatch instruction.

The output unlatch instruction is also an output instruction with a bit-level address. When the instruction is true, it resets a bit in the output image file. It, too, is a retentive instruction because the bit remains reset when the instruction goes false.

Fig. 5

The process shown in Figure 5 is to be used to control the level of water in a storage tank by turning a discharge pump on or off. The modes of operation are to be programmed as follows:

OFF Position: The water pump will stop if it is running and will not start if it is stopped.

Manual Mode: The pump will start if the water in the tank is at any level except low.

Automatic Mode: If the level of water in the tank reaches a high point, the water pump will start so that water can be removed from the tank, thus lowering the level. When the water level reaches a low point, the pump will stop.

Status Indicating Lights:

  • Water pump running light (green)
  • Low water level status light (red)
  • High water level status light (yellow)
Fig. 6

Figure 6 shows a program that can be used to implement control of the water level in the storage tank. The latch and unlatch instructions form part of the program. The operation of the program can be summarized as follows:

  • An internal storage bit is used for the latch and address rather than an actual discrete output address. Both have the same addresses.
  • The rung 1 Examine-on instruction addressed to the off/on switch prevents the pump motor from starting under any condition when in the off (open) state.
  • In the MAN mode, the rung 1 Examine-on instruction addressed to the low sensor switch allows the pump motor to operate only when the low level sensor switch is closed.
  • In the AUTO mode, whenever the high sensor switch is momentarily closed the Examine-on instruction of rung 1 addressed to it will energize the latch coil. The pump will begin running and continue to operate until the unlatch coil is energized by the rung 3 Examine-off instruction addressed to the low sensor switch.
  • The pump running status light is controlled by the rung 4 Examine-on instruction addressed to the motor output.
  • The low level status light is controlled by the rung 5 Examine-off instruction addressed to the low sensor switch.
  • The high level status light is controlled by the rung 6 Examine-on instruction addressed to the high sensor switch.
Fig. 7

Figure 7 shows a typical I/O module wiring diagram and addressing format for the water level control program implemented using an Allen-Bradley modular SLC 500 controller. The chassis power supply has a relatively small power rating and is used to supply DC power to all devices physically mounted in the backplane of the PLC rack.

In this application a 24 VDC field power supply is used for the input devices and a 120 VAC field power supply for the output devices. This allows a low-voltage 24-volt control signal to control 240-volt output devices. SLC 500 controllers use a rack/slot-based address system where the slot location of the I/O modules in the rack establishes the PLC address. The addresses for the field devices of this particular application are shown below:

Convert Relay Schematics into PLC Ladder Logic Programs

The best approach to developing a PLC program from a relay schematic is to understand first the operation of each relay ladder rung. As each relay ladder rung is understood, an equivalent PLC rung can be generated. This process will require access to the relay schematic, documentation of the various input and output devices used, and possibly a process flow diagram of the operation.

Most control processes require the completion of several operations to produce the required output. Manufacturing, machining, assembling, packaging, finishing, or transporting of products requires the precise coordination of tasks. A sequential control process is required for processes that demand that certain operations be performed in a specific order.

Fig. 8

Figure 8 illustrates part of a bottle filling process. In the filling and capping operations, the tasks are (1) fill bottle and (2) press on cap. These tasks must be performed in the proper order. Obviously we could not fill the bottle after the cap is pressed on. This process, therefore, requires sequential control. Combination controls require that certain operations be performed without regard to the order in which they are performed.

Fig. 9

Figure 9 illustrates another part of the same bottle filling process. Here, the tasks are (1) place label 1 on bottle and (2) place label 2 on bottle. The order in which the tasks are performed does not really matter. In fact, however, many industrial processes that are not inherently sequential in nature are performed in a sequential manner for the most efficient order of operations.

Automatic control involves maintaining a desired set point at an output. One example is maintaining a certain set-point temperature in a furnace as illustrated in Figure 10 .

Fig. 10

If there is deviation from that set point, an error is determined by comparing the output against the set point and using this error to make a correction. This requires feedback from the output to the control for the input.

Fig. 11

The converting of a simple sequential process can be examined with reference to the process flow diagram illustrated in Figure 11. The sequential task is as follows:

  1. Start button is pressed.
  2. Table motor is started.
  3. Package moves to the position of the limit switch and automatically stops.

Other auxiliary features include:

  • A stop button that will stop the table, for any reason, before the package reaches the limit switch position
  • A red pilot light to indicate the table is stopped
  • A green pilot light to indicate the table is running
Fig. 12

A relay schematic for the sequential process is shown in Figure 12 . The operation of this hardwired circuit can be summarized as follows:

  • Start button is actuated; CR is energized if stop button and limit switch are not actuated.
  • Contact CR-1 closes, sealing in CR when the start button is released.
  • Contact CR-2 opens, switching the red pilot light from on to off.
  • Contact CR-3 closes, switching the green pilot light from off to on.
  • Contact CR-4 closes to energize the motor starter coil, starting the motor and moving the package toward the limit switch.
  • Limit switch is actuated, de-energizing relay coil CR.
  • Contact CR-1 opens, opening the seal-in circuit.
  • Contact CR-2 closes, switching the red pilot light from off to on.
  • Contact CR-3 opens, switching the green pilot light from on to off.
  • Contact CR-4 opens, de-energizing the motor starter coil to stop the motor and end the sequence.
Fig. 13

Figure 13 shows an I/O connection diagram for a programmed version of the sequential process. Each input and output device is represented by its symbol and associated address. These addresses will indicate what PLC input is connected to what input device and what PLC output will drive what output device. The address code, of course, will depend on the PLC model used.

This example uses SLC 500 addressing for the process. Note that the electromagnetic control relay CR is not needed because its function is replaced by an internal PLC control relay. The hardwired relay schematic for the sequential process can be converted to the PLC ladder logic program shown in Figure 14 .

Fig. 14

In converting the process to a program the operation of each rung must be understood. The pushbuttons PB1, PB2 as well as limit switch LS are all programmed using the examine-closed (–] [–) instruction to produce the desired logic control.

Also, internal relay B3:1/0 is used to replace control relay CR. To obtain the desired control logic, all internal relay contacts are programmed using the PLC contact instruction that matches the coil de-energized state. The internal relay implemented in software requires one coil address the contacts of which can be examined for an ON or OFF condition as many times as you like.

There is more than one method to correctly design the ladder logic program for a given control process. In some cases one arrangement may be more efficient in terms of the amount of memory used and the time required to scan the program.

Fig. 15

Figure 15 illustrates an example of an arrangement of series instructions of a rung programmed for optimum scan time. The series instructions are programmed from the most likely to be false (far left) to the least likely to be false (far right). Once the processor sees a false input instruction in series, the processor stops checking the rung at the false condition and sets the output false.

Fig. 16

Figure 16 illustrates an example of an arrangement of parallel instructions of a rung programmed for optimum scan time. The parallel path that is most often true is placed on the top of the rung. The processor will not look at the others unless the top path is false.

Fig. 17

Figure 17 shows a hardwired jog control circuit that incorporates a jog control relay. The operation of the circuit can be summarized as follows:

  • Pressing the start pushbutton completes a circuit for the CR coil, closing the CR1 and CR2 contacts.
  • The CR1 contact completes the circuit for the M coil, starting the motor.
  • The M maintaining contact closes; this maintains the circuit for the M coil.
  • Pressing the jog button energizes the M coil only, starting the motor. Both CR contacts remain open, and the CR coil is de-energized. The M coil will not remain energized when the jog push button is released.
Fig. 18

Figure 18 shows a PLC program equivalent of the hardwired relay jog circuit. Note that the function of the control relay is now accomplished using an internal PLC instruction (B3:1/0).

Writing PLC Ladder Logic Program from Description

In most cases, it is possible to prepare a ladder logic program directly from the narrative description of a control process. Some of the steps in planning a program are as follows:

  • Define the process to be controlled.
  • Draw a sketch of the process, including all sensors and manual controls needed to carry out the control sequence.
  • List the sequence of operational steps in as much detail as possible.
  • Write the ladder logic program to be used as a basis for the PLC program.
  • Consider different scenarios where the process sequence may go astray and make adjustments as needed.
  • Consider the safety of operating personnel and make adjustments as needed.

The following are examples of ladder logic programs derived from narrative descriptions of control processes.

FIg. 19

Example 1: Figure 19 shows the sketch of a drilling process that requires the drill press to turn on only if there is a part present and the operator has one hand on each of the start switches. This precaution will ensure that the operator’s hands are not in the way of the drill. The sequence of operation requires that switches 1 and 2 and the part sensor all be activated to make the drill motor operate. Figure 20 shows the ladder logic program required for the process implemented using an SLC 500 controller.

Fig. 20
Fig. 21

Example 3: Figure 21 shows the sketch of a continuous filling operation. This process requires that boxes moving on a conveyor be automatically positioned and filled. The sequence of operation for the continuous filling operation is as follows:

  • Start the conveyor when the start button is momentarily pressed.
  • Stop the conveyor when the stop button is momentarily pressed.
  • Energize the run status light when the process is operating.
  • Energize the standby status light when the process is stopped.
  • Stop the conveyor when the right edge of the box is first sensed by the photosensor.
  • With the box in position and the conveyor stopped, open the solenoid valve and allow the box to fill. Filling should stop when the level sensor goes true.
  • Energize the full light when the box is full. The full light should remain energized until the box is moved clear of the photosensor.
Fig. 22

Figure 22 shows the ladder logic program required for the operation.

Leave a Comment

Your email address will not be published. Required fields are marked *