Ladder logic
This article needs additional citations for verification. (May 2012) |
Ladder logic was originally a written method to document the design and construction of
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. Ladder diagrams were once the only way to record programmable controller programs, but today, other forms are standardized in IEC 61131-3. For example, instead of the graphical ladder logic form, there is a language called Structured text, which is similar to C, within the IEC 61131-3 standard.
Overview
Ladder logic is widely used to program
The motivation for representing
Ladder logic can be thought of as a
Syntax and examples
The language itself can be seen as a set of connections between logical checkers (contacts) and actuators (coils). When a path exists from the left side of the rung to the output through asserted (true or "closed") contacts, the rung is considered true, and the output coil storage bit is set to 1 or (true). If no such path exists, the output is false (0), and the "coil" by analogy to electromechanical relays is considered "de-energized". This analogy between logical propositions and relay contact status was established by 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
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
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
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
This
- Note: In this example, "Run" represents the status of a 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 = ( 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:
- Realising the function: A/C = Switch ORHumid).
----[ ]---------+----[ ]-----+----( ) Switch | HiTemp | A/C | | +----[ ]-----+ Humid
- Realising the function: Cooling = A/C NOTHeat).
----[ ]----[\]--------------------( ) 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,
Limitations and successor languages
Ladder notation is best suited to control problems where only
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
Popularity
In 2019, IEEE Spectrum ranked ladder logic as number 50 out of 52 in a list of popular programming languages.[3]
See also
References
- ^ "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.
- ISBN 0123948509, Chapter 8 Ladder Logic Diagrams and PLC Implementations
- ^ "Interactive: The Top Programming Languages". IEEE Spectrum. Archived from the original on 2019-09-18.
Further reading
- Walker, Mark John (2012-09-08). The Programmable Logic Controller: its prehistory, emergence and application (PDF) (PhD thesis). Department of Communication and Systems Faculty of Mathematics, Computing and Technology: The Open University. Archived(PDF) from the original on 2018-06-20. Retrieved 2018-06-20.
External links
- "Chapter 6: ladder logic" by Tony R. Kuphaldt