Ladder logic

Last updated

Ladder logic was originally a written method to document the design and construction of relay racks as used in manufacturing and process control. [1] Each device in the relay rack would be represented by a symbol on the ladder diagram with connections between those devices shown. In addition, other items external to the relay rack such as pumps, heaters, and so forth would also be shown on the ladder diagram.

Contents

Ladder logic has evolved into a programming language that represents a program by a graphical diagram based on the circuit diagrams of relay logic hardware. Ladder logic is used to develop software for programmable logic controllers (PLCs) used in industrial control applications. The name is based on the observation that programs in this language resemble ladders, with two vertical rails and a series of horizontal rungs between them. While ladder diagrams were once the only available notation for recording programmable controller programs, today other forms are standardized in IEC 61131-3 (For example, as an alternative to the graphical ladder logic form, there is also a language more like C called Structured text within the IEC 61131-3 standard).

Overview

Part of a ladder diagram, including contacts and coils, compares, timers and monostable multivibrators Ladder diagram.png
Part of a ladder diagram, including contacts and coils, compares, timers and monostable multivibrators

Ladder logic is widely used to program PLCs, where sequential control of a process or manufacturing operation is required. Ladder logic is useful for simple but critical control systems or for reworking old hardwired relay circuits. As programmable logic controllers became more sophisticated it has also been used in very complex automation systems. Often the ladder logic program is used in conjunction with an HMI program operating on a computer workstation.

The motivation for representing sequential control logic in a ladder diagram was to allow factory engineers and technicians to develop software without additional training to learn a language such as FORTRAN or other general-purpose computer language. Development and maintenance were simplified because of the resemblance to familiar relay hardware systems. [2] Implementations of ladder logic may have characteristics, such as sequential execution and support for control flow features, that make the analogy to hardware somewhat inaccurate.

Ladder logic can be thought of as a rule-based language rather than a procedural language. A "rung" in the ladder represents a rule. When implemented with relays and other electromechanical devices, the various rules execute simultaneously and immediately. When implemented in a programmable logic controller, the rules are typically executed sequentially by software in a continuous loop, or "scan". By executing the loop fast enough, typically many times per second, the effect of simultaneous and immediate execution is achieved. Proper use of programmable controllers requires an understanding of the limitations of the execution order of rungs.

Syntax and examples

The language itself can be seen as a set of connections between logical checkers (contacts) and actuators (coils). If a path can be traced between the left side of the rung and the output, through asserted (true or "closed") contacts, the rung is true and the output coil storage bit is asserted (1) or true. If no path can be traced, then the output is false (0) and the "coil" by analogy to electromechanical relays is considered "de-energized". The analogy between logical propositions and relay contact status is due to Claude Shannon.

Ladder logic has contacts that make or break circuits to control coils. Each coil or contact corresponds to the status of a single bit in the programmable controller's memory. Unlike electromechanical relays, a ladder program can refer any number of times to the status of a single bit, equivalent to a relay with an indefinitely large number of contacts.

So-called "contacts" may refer to physical ("hard") inputs to the programmable controller from physical devices such as pushbuttons and limit switches via an integrated or external input module, or may represent the status of internal storage bits which may be generated elsewhere in the program.

Each rung of ladder language typically has one coil at the far right. Some manufacturers may allow more than one output coil on a rung.

Rung input
Checkers (contacts)
  • —[ ]— Normally open contact, closed whenever its corresponding coil or an input which controls it is energized. (Open contact at rest.)
  • —[\]— Normally closed ("not") contact, closed whenever its corresponding coil or an input which controls it is not energized. (Closed contact at rest.)
Rung output
Actuators (coils)
  • —( )— Normally inactive coil, energized whenever its rung is closed. (Inactive at rest.)
  • —(\)— Normally active ("not") coil, energized whenever its rung is open. (Active at rest.)

The "coil" (output of a rung) may represent a physical output which operates some device connected to the programmable controller, or may represent an internal storage bit for use elsewhere in the program.

A way to recall these is to imagine the checkers (contacts) as a push button input, and the actuators (coils) as a light bulb output. The presence of a slash within the checkers or actuators would indicate the default state of the device at rest.

Logical AND

 -----[ ]-------------[ ]------------------( )    Key switch 1    Key switch 2        Door motor 

The above realizes the function: Door motor = Key switch 1 AND Key switch 2

This circuit shows two key switches that security guards might use to activate an electric motor on a bank vault door. When the normally open contacts of both switches close, electricity is able to flow to the motor which opens the door.

Logical AND with NOT

 ------[ ]--------------[\]----------------( )    Close door      Obstruction         Door motor 

The above realizes the function: Door motor = Close door AND NOT(Obstruction).

This circuit shows a push button that closes a door and an obstruction detector that senses if something is in the way of the closing door. When the normally open push button contact closes and the normally closed obstruction detector is closed (no obstruction detected), electricity is able to flow to the motor which closes the door.

Logical OR

 --+-------[ ]-------+-----------------( )    | Exterior unlock |                 Unlock    |                 |    +-------[ ]-------+      Interior unlock 

The above realizes the function: Unlock = Interior unlock OR Exterior unlock

This circuit shows the two things that can trigger a car's power door locks. The remote receiver is always powered. The unlock solenoid gets power when either set of contacts is closed.

Industrial STOP/START

In common industrial latching start/stop logic we have a "Start" button to turn on a motor contactor, and a "Stop" button to turn off the contactor.

When the "Start" button is pushed the input goes true, via the "Stop" button NC contact. When the "Run" input becomes true the seal-in "Run" NO contact in parallel with the "Start" NO contact will close maintaining the input logic true (latched or sealed-in). After the circuit is latched the "Stop" button may be pushed causing its NC contact to open and consequently the input to go false. The "Run" NO contact then opens and the circuit logic returns to its inactive state.

 --+----[ ]--+----[\]----( )    |   Start |   Stop    Run    |         |    +----[ ]--+         Run 
 -------[ ]--------------( )         Run             Motor 

The above realizes the function: Run = (Start OR Run) AND (NOT Stop)

This latch configuration is a common idiom in ladder logic. It may also be referred to as seal-in logic. The key to understanding the latch is in recognizing that the "Start" switch is a momentary switch (once the user releases the button, the switch is open again). As soon as the "Run" solenoid engages, it closes the "Run" NO contact, which latches the solenoid on. The "Start" switch opening up then has no effect.

Note: In this example, "Run" represents the status of a bit in the PLC, while "Motor" represents the actual output to the real-world relay that closes the motor's real-world circuit.

For safety reasons, an emergency stop ("ES") may be hardwired in series with the "Start" switch, and the relay logic should reflect this.

 --[\]----[\]----+--[ ]--+---------( )    ES    Stop    | Start |        Run                  |       |                  +--[ ]--+                     Run 
 -------[ ]--------------( )         Run             Motor 

The above realizes the function: Run = (NOT ES) AND (NOT Stop) AND (Start OR Run)

Complex logic

Here is an example of what two rungs in a ladder logic program might look like. In real-world applications, there may be hundreds or thousands of rungs.

Typically, complex ladder logic is "read" left to right and top to bottom. As each of the lines (or rungs) are evaluated the output coil of a rung may feed into the next stage of the ladder as an input. In a complex system there will be many "rungs" on a ladder, which are numbered in order of evaluation:

  1. Realising the function: A/C = Switch AND (HiTemp OR Humid).
        ----[ ]---------+----[ ]-----+----( )       Switch        |   HiTemp   |    A/C                     |            |                     +----[ ]-----+                         Humid 
  2. Realising the function: Cooling = A/C AND (NOT Heat).
        ----[ ]----[\]--------------------( )         A/C    Heat                 Cooling 

This represents a slightly more complex system for rung 2. After the first line has been evaluated, the output coil "A/C" is fed into rung 2, which is then evaluated and the output coil "Cooling" could be fed into an output device "Compressor" or into rung 3 on the ladder. This system allows very complex logic designs to be broken down and evaluated.

Additional functionality

Additional functionality can be added to a ladder logic implementation by the PLC manufacturer as a special block. When the special block is powered, it executes code on predetermined arguments. These arguments may be displayed within the special block.

                              +-------+   -----[ ]--------------------+  A    +----    Remote unlock              +-------+                            Remote counter 
                              +-------+       -----[ ]--------------------+  B    +----    Interior unlock            +-------+                                 Interior counter  
                      +--------+   --------------------+ A + B  +-----------                       | into C |                       +--------+                          Adder 

In this example, the system will count the number of times that the interior and remote unlock buttons are pressed. This information will be stored in memory locations A and B. Memory location C will hold the total number of times that the door has been unlocked electronically.

PLCs have many types of special blocks. They include timers, arithmetic operators and comparisons, table lookups, text processing, PID control, and filtering functions. More powerful PLCs can operate on a group of internal memory locations and execute an operation on a range of addresses, for example, to simulate a physical sequential drum controller or a finite-state machine. In some cases, users can define their own special blocks, which effectively are subroutines or macros. The large library of special blocks along with high-speed execution has allowed use of PLCs to implement very complex automation systems.

Limitations and successor languages

Ladder notation is best suited to control problems where only binary variables are required and where interlocking and sequencing of binary is the primary control problem. Like all parallel programming languages, the sequential order of operations may be undefined or obscure; logic race conditions are possible which may produce unexpected results. Complex rungs are best broken into several simpler steps to avoid this problem. Some manufacturers avoid this problem by explicitly and completely defining the execution order of a rung, however, programmers may still have problems fully grasping the resulting complex semantics.

Analog quantities and arithmetical operations are clumsy to express in ladder logic and each manufacturer has different ways of extending the notation for these problems. There is usually limited support for arrays and loops, often resulting in duplication of code to express cases that in other languages would call for use of indexed variables.

As microprocessors have become more powerful, notations such as sequential function charts and function block diagrams can replace ladder logic for some limited applications. Some newer PLCs may have all or part of the programming carried out in a dialect that resembles BASIC, C, or other programming language with bindings appropriate for a real-time application environment.

Popularity

In 2019, IEEE Spectrum ranked ladder logic as number 50 out of 52 in a list of popular programming languages. [3]

See also

Related Research Articles

<span class="mw-page-title-main">Logic gate</span> Device performing a Boolean function

A logic gate is an idealized or physical device that performs a Boolean function, a logical operation performed on one or more binary inputs that produces a single binary output.

<span class="mw-page-title-main">Programmable logic controller</span> Programmable digital computer used to control machinery

A programmable logic controller (PLC) or programmable controller is an industrial computer that has been ruggedized and adapted for the control of manufacturing processes, such as assembly lines, machines, robotic devices, or any activity that requires high reliability, ease of programming, and process fault diagnosis.

<span class="mw-page-title-main">Relay</span> Electrically-operated switch

A relay is an electrically operated switch. It consists of a set of input terminals for a single or multiple control signals, and a set of operating contact terminals. The switch may have any number of contacts in multiple contact forms, such as make contacts, break contacts, or combinations thereof.

<span class="mw-page-title-main">Digital electronics</span> Electronic circuits that utilize digital signals

Digital electronics is a field of electronics involving the study of digital signals and the engineering of devices that use or produce them. This is in contrast to analog electronics and analog signals.

In engineering, a fail-safe is a design feature or practice that, in the event of a specific type of failure, inherently responds in a way that will cause minimal or no harm to other equipment, to the environment or to people. Unlike inherent safety to a particular hazard, a system being "fail-safe" does not mean that failure is impossible or improbable, but rather that the system's design prevents or mitigates unsafe consequences of the system's failure. That is, if and when a "fail-safe" system fails, it remains at least as safe as it was before the failure. Since many types of failure are possible, failure mode and effects analysis is used to examine failure situations and recommend safety design and procedures.

<span class="mw-page-title-main">Combinational logic</span> Type of digital logic which is implemented by boolean circuits

In automata theory, combinational logic is a type of digital logic which is implemented by Boolean circuits, where the output is a pure function of the present input only. This is in contrast to sequential logic, in which the output depends not only on the present input but also on the history of the input. In other words, sequential logic has memory while combinational logic does not.

<span class="mw-page-title-main">Automation</span> Use of various control systems for operating equipment

Automation describes a wide range of technologies that reduce human intervention in processes, mainly by predetermining decision criteria, subprocess relationships, and related actions, as well as embodying those predeterminations in machines. Automation has been achieved by various means including mechanical, hydraulic, pneumatic, electrical, electronic devices, and computers, usually in combination. Complicated systems, such as modern factories, airplanes, and ships typically use combinations of all of these techniques. The benefit of automation includes labor savings, reducing waste, savings in electricity costs, savings in material costs, and improvements to quality, accuracy, and precision.

<span class="mw-page-title-main">Control system</span> System that manages the behavior of other systems

A control system manages, commands, directs, or regulates the behavior of other devices or systems using control loops. It can range from a single home heating controller using a thermostat controlling a domestic boiler to large industrial control systems which are used for controlling processes or machines. The control systems are designed via control engineering process.

<span class="mw-page-title-main">Remote terminal unit</span> Computer peripheral to collect telemetry data

A remote terminal unit (RTU) is a microprocessor-controlled electronic device that interfaces objects in the physical world to a distributed control system or SCADA system by transmitting telemetry data to a master system, and by using messages from the master supervisory system to control connected objects. Other terms that may be used for RTU are remote telemetry unit and remote telecontrol unit.

A motor controller is a device or group of devices that can coordinate in a predetermined manner the performance of an electric motor. A motor controller might include a manual or automatic means for starting and stopping the motor, selecting forward or reverse rotation, selecting and regulating the speed, regulating or limiting the torque, and protecting against overloads and electrical faults. Motor controllers may use electromechanical switching, or may use power electronics devices to regulate the speed and direction of a motor.

<span class="mw-page-title-main">Contactor</span> Electronic circuit element serving as a switch

A contactor is an electrically controlled switch used for switching an electrical power circuit. A contactor is typically controlled by a circuit which has a much lower power level than the switched circuit, such as a 24-volt coil electromagnet controlling a 230-volt motor switch.

<span class="mw-page-title-main">Wire spring relay</span>

A wire spring relay is a type of relay, that has springs made from drawn wires of nickel silver, rather than cut from flat sheet metal as in the flat-spring relay. This class of relays provided manufacturing and operating advantages over previous designs. Wire spring relays entered mass production in the early 1950s.

<span class="mw-page-title-main">Reed relay</span> Electromagnetic switching device

A reed relay is a type of relay that uses an electromagnet to control one or more reed switches. The contacts are of magnetic material and the electromagnet acts directly on them without requiring an armature to move them. Sealed in a long, narrow glass tube, the contacts are protected from corrosion. The glass envelope may contain multiple reed switches or multiple reed switches can be inserted into a single bobbin and actuate simultaneously. Reed switches have been manufactured since the 1930s.

An industrial control system (ICS) is an electronic control system and associated instrumentation used for industrial process control. Control systems can range in size from a few modular panel-mounted controllers to large interconnected and interactive distributed control systems (DCSs) with many thousands of field connections. Control systems receive data from remote sensors measuring process variables (PVs), compare the collected data with desired setpoints (SPs), and derive command functions that are used to control a process through the final control elements (FCEs), such as control valves.

<span class="mw-page-title-main">CircuitLogix</span> Electronic circuit simulator software

CircuitLogix is a software electronic circuit simulator which uses PSpice to simulate thousands of electronic devices, models, and circuits. CircuitLogix supports analog, digital, and mixed-signal circuits, and its SPICE simulation gives accurate real-world results. The graphic user interface allows students to quickly and easily draw, modify and combine analog and digital circuit diagrams. CircuitLogix was first launched in 2005, and its popularity has grown quickly since that time. In 2012, it reached the milestone of 250,000 licensed users, and became the first electronics simulation product to have a global installed base of a quarter-million customers in over 100 countries.

Relay logic is a method of implementing combinational logic in electrical control circuits by using several electrical relays wired in a particular configuration.

<span class="mw-page-title-main">Magnetic starter</span>

A magnetic starter is an electromagnetically operated switch which provides a safe method for starting an electric motor with a large load. Magnetic starters also provide under-voltage and overload protection and an automatic cutoff in the event of a power failure.

Automatic test system switching test equipment allows for high-speed testing of a device or devices in a test situation, where strict sequences and combinations of switching must be observed. By automating the process in this way, the possibility of test errors and inaccuracies is minimized, and only systematic errors would generally be encountered due to such as an incorrect programmed test condition. This eliminates error due to human factors and allows application of a standard test sequence repetitively. The design of a test system’s switching configuration is governed by the test specification, which is derived from the functional tests to be performed.

<span class="mw-page-title-main">Function block diagram</span> Graphical language for PLC design

The Function Block Diagram (FBD) is a graphical language for programmable logic controller design, that can describe the function between input variables and output variables. A function is described as a set of elementary blocks. Input and output variables are connected to blocks by connection lines.

SIMATIC is a series of programmable logic controller and automation systems, developed by Siemens. Introduced in 1958, the series has gone through four major generations, the latest being the SIMATIC S7 generation. The series is intended for industrial automation and production.

References

  1. "The Basics of Ladder Logic". Ladder logic uses switch or relay contacts to implement Boolean expressions. In years past, ladder logic was made possible with discrete relays and was sometimes termed relay logic.
  2. Edward W. Kamen Industrial Controls and Manufacturing, (Academic Press, 1999) ISBN   0123948509, Chapter 8 Ladder Logic Diagrams and PLC Implementations
  3. "Interactive: The Top Programming Languages". IEEE Spectrum. Archived from the original on 2019-09-18.

Further reading