Ladder Logic Fundamentals:
Contacts, Coils, Timers and Counters


Contacts

Ladder logic programs mimic the electrical circuit diagrams used for wiring control systems in the electrical industry. The basic purpose of an electrical control system is to determine whether a load should be turned ON or turned OFF,  under what circumtances and when it should happen. To understand a ladder program, just remember the concept of current flow - a load is turned ON when the current can flow to it and is turned OFF when the current could not flow to it.

The fundamental element of a ladder diagram is a "Contact". A contact has only two states: open or closed. An open contact breaks the current flow whereas a closed contact allows current to flow through it to the next element. The simplest contact is an On/OFF switch which requires external force (e.g. the human hand) to activate it. Limit switches are those small switches that are placed at certain location so that when a mechanical device moves towards it, the contact will be closed and when the device moves away from it, the contact will be open. 

If a contact is connected to a load and the contact is closed, the load will be turned ON. This simple concept can be illustrated by the most basic ladder diagram as follow:

contac4.jpg (3565 bytes)

The vertical line on the left is the "Power" line, current must flow through the "Switch" contact in order to turn ON the load "Lamp". (In fact, there should be a second vertical line on the right end of the ladder diagram to provide a return path for the current flow, but this is omitted to simplify the circuit diagram). Now, if instead of wiring the switch to the lamp directly as suggested in the above diagram, you could connect the switch to the PLC's input and connect the lamp to the PLC's output, and then write the above ladder program to perform the same job. Of course it makes little sense to use a PLC if that is all you want to do. We will see how a PLC can simplify wiring shortly.

Note: The contact "Switch" shown in the above diagram is termed a Normally-open (N.O.) contact.

Now, let's say if there are 3 switches that must work together to control the lamp. A Master switch must be ON, and one of the two control switches "controlsw1" and "controlsw2" must be ON while the other must be OFF in order to turn ON the lamp (think of three-way switches in your house and you will get the idea). We can wire all 3 switches to 3 inputs of the PLC and the lamp to the output of the PLC.  We can write the following ladder program to perform this task:

contac5.jpg (8103 bytes)

A contact with a "/" across its body is a Normally-Closed (N.C.) contact. What it means is that the ladder program is using the "inverse" of the logic state of the input to interpret the diagram. 

Hence in the above ladder diagram, if "Master" and "controlSW1" are turned ON but "controlSW2" is turned OFF, the lamp will  be turned ON since the inverse logic state of an OFF state "controlSW2" is true. Think of an imaginary current flowing through the "Master" contact, then through the "controlSW1" and finally through the normally-closed "controlSW2" contact to turn ON the lamp.

On the other hand, if "controlSW1" is OFF but "controlSW2" is ON, the Lamp is also turned ON because the current could flow via "Master" and then through the lower parallel branch via N.C. "controlSW1" and the N.O. "controlSW2".

Note: As you can see, although the switch "controlSW1" is connected to only 1 physical input to the PLC, but it appears twice in the ladder diagram. If you actually try to connect physical wires to implement the above circuits, both "controlSW1" and "controlSW2" will have to be of multiple poles type. But if you use a PLC, then these two switches only need to be of single-pole type since there is only one physical connection which is to the input terminal of the PLC. But in the ladder diagram the same contact may appear as many times as you wish as if it has unlimited number of poles.

The above example may be simple but it illustrates the basic concept of logical AND and OR very clearly. "controlSW1" and "controlSW2" are connected in series and both must be TRUE for the outcome to be TRUE. Hence, this is a logical AND connection. On the other hand, either one of the two parallel branches may be used to conduct current and hence this is a logical OR connection.

NEW! A new type of contact, available for the F-Series PLCs only, is the Rising-Edge contact, which looks like this: contac9.jpg (1489 bytes) in the ladder logic toolbar and like this: contac10.jpg (903 bytes) when placed in a ladder logic circuit. This type of contact will detect a change of status from off to on and then send a single pulse out (one shot). This contact can be used for any physical input or output or any internal bits (relay, counter, timer). In the case of physical input and output rising-edge contacts, a rising edge will be detected if the I/O has changed from off to on from one I/O scan to another (any I/O status changes that happen during a ladder logic scan wont matter for physical I/O). In the case of the internal bit rising-edge contacts, a rising edge will be detected if the internal bit has changed from off to on from one ladder logic scan to another (any internal bit status changes that happen during an I/O scan wont matter for internal bits).

Here are some examples of this for the physical I/O:

Ex1. In the circuit shown below, if Input1 is off for an I/O scan and then on for the next I/O scan, a single pulse (one shot) will be sent to Output1 and Output1 will be turned on for one program scan time (turned off on the next I/O scan). On the same I/O scan that Output1 is turned off and all following I/O scans, whether Input1 is still on or has been turned off, a rising edge will not have been detected and Output1 will remain off. For a new rising edge to be detected, Input1 must be scanned as off first and then scanned as on in a following I/O scan.

contac7.jpg (4087 bytes)

Ex2. In the circuit below, when Input1 goes from the off status to on status (as described previously), a single pulse will be sent to a [Latch] function that will latch Output1 to the on status. The actual Latch function will only be activated for a single scan time (just as Output1 was in the previous example), but it will permanently latch Output1 to on until Output1 is unlatched using the [Clear] function. This way Output1 will remain on even though Input1 has only sent a single pulse and Output1 will not be affected by any further rising-edge detections from Input1 (can only be latched once until it is unlatched).

contac8.jpg (4105 bytes)

The same principles can be applied to internal bits and coils as were previously described for physical input contacts and output coils.

Once you understand these fundamental principles of interpretting a ladder diagram, everything should become clearer and simpler. Ladder diagram programming can be used to create a rather sophisticated control system. However, In i-TRiLOGI we augment its power further by allowing a ladder program to activate customized functions created in TBASIC.


Relay Coils

A contact can also be activated by the presence of an electrical current. This makes it possible for a control system to control the turning ON or OFF of a large load by using electrical current to activate a switch that can conduct high current. The simplest form of this type of contact is a relay.

In traditional electromagnetic relay, a coil of wire is wound around an iron core which turns it into an electromagnet. When current passes through the "coil" the magnet is "energized" and the force is used to either close a contact (that makes it a normally-open contact, closed only when energized) or open it (that will be a normally-closed contact since it is closed when not energized).

Ladder Logic programming language borrows some of those terms used to describe the electromagnetic relay for its own use. You connect a relay coil to the right end of the ladder diagram just like an output, as follows:

contac6.jpg (7771 bytes)

In a PLC, there are hundreds of internal "relays" which are supposed to behave  like the typical electromagnetic relay. Unlike an output (e.g. the"Lamp" output) which has a physical connection out of the PLC, when an internal relay is turned ON, it is said to be "energized" but you will not see any changes in the PLC's physical I/Os. The logic state is kept internally in the PLC. The contact of the relay can then be used in the ladder diagram for turning ON or OFF of other relays or outputs. A relay contact in the ladder diagram can be Normally-Open or Normally-Closed and there is no limit to the number of contacts a relay can have.

Out Coils

A PLC output is really just an internal relay with a physical connection that can supply electrical power to control an external load. Thus, like a relay, an output can also have unlimited number of contacts that can be used in the ladder program.

Timer Coils

A timer is a special kind of relay that, when its coil is energized, must wait for a fixed length of time before closing its contact. The waiting time is dependent on the "Set Value" (SV)of the timer. Once the delay time is up, the timer's N.O. contacts will be closed for as long as its coil remains energized. When the coil is de-energized (i.e. turned OFF),  all the timer's N.O. contacts will be opened immediately.

However, if the coil is de-energized before the delay time is up, the timer will be reset and its contact will never be closed. When a last aborted timer is re-energized, the delay timing will restart afresh using the SV of the timer and not continue from the last aborted timing operation.

Counter Coils

A counter is also a special kind of relay that has a programmable Set Value (SV). When a counter coil is energized for the first time after a reset, it will load the value of SV-1 into its count register. From there on, every time the counter coil is energized from OFF to ON, the counter decrement its count register value by 1. Note that the coil must go through OFF to ON cycle in order to decrement the counter. If the coil remain energized all the time, the counter will not decrement. Hence counter is suitable for counting the number of cycles an operation has gone through.

When the count register hits zero, all the counter's N.O. contacts will be turned ON. These counter contacts will remain ON regardless of whether the counter's coil is energized or not. To turn OFF these contacts, you have to reset the counter using a special counter reset function [RSctr].