Ladder logic
From Wikipedia, the free encyclopedia
Ladder logic is a method of drawing electrical logic schematics. It is now a graphical language very popular for programming Programmable Logic Controllers (PLCs). It was originally invented to describe logic made from relays. The name is based on the observation that programs in this language resemble ladders, with two vertical "rails" and a series of "rungs" between them. In Germany and elsewhere in Europe, the style is to draw the rails horizontal along the top and bottom of the page while the rungs are drawn sequentially from left to right.
A program in ladder logic, also called a ladder diagram, is similar to a schematic for a set of relay circuits. Ladder logic is useful because a wide variety of engineers and technicians can understand and use it without much additional training because of the resemblance.
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.
Most manufacturers of programmable logic controllers also provide associated ladder logic programming systems. Typically, the ladder logic languages from two manufacturers will not be completely compatible; ladder logic is better thought of as a set of closely related programming languages rather than one language. Even different models of programmable controller within the same family may have different ladder notation such that programs cannot be seamlessly interchanged between models.
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 loop. By executing the loop fast enough, typically many times per second, the effect of simultaneous and immediate execution is obtained. In this way it is similar to other rule-based languages, like spreadsheets or SQL. However, proper use of programmable controllers requires understanding the limitations of the execution order of rungs.
Contents |
[edit] Example of a simple ladder logic program
The language itself can be seen as a set of connections between logical checkers (relay 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 inputs to the programmable controller from physical devices such as pushbuttons and limit switches, or may represent the status of internal storage bits or of output bits 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.
--( )--
a regular coil, true when its rung is true
--(\)--
a "not" coil, false when its rung is true
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.
[edit] Examples
Here is an example of what one rung in a ladder logic program might look like. In real life, there may be hundreds or thousands of rungs.
For example
1. ----[ ]---------|--[ ]--|------( )-- X | Y | S | | |--[ ]--| Z
The above realises the function: S = X AND ( Y OR Z )
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.
2. ----[ ]-----------|---[ ]---|----( )-- X | Y | S | | |---[ ]---| Z ----[ ]----[ ]-------------------( )-- S X T
2. T = S AND X where S is equivalent to #1. above
This represents a slightly more complex system for rung 2. After the first line has been evaluated, the output coil (S) is fed into rung 2, which is then evaluated and the output coil T could be fed into an output device (buzzer, light etc..) or into rung 3 on the ladder.
This system allows very complex logic designs to be broken down and evaluated.
For more practical examples see below:
------[ ]--------------[ ]----------------O--- Key Switch 1 Key Switch 2 Door Motor
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. This is a logical AND.
+-------+ ----------------------------+ +---- +-------+ Remote Receiver --|-------[ ]-------+-----------------O--- | Remote Unlock | Lock Solenoid | | |-------[ ]-------| Interior switch
This circuit shows the two things that can trigger the power door locks in my imaginary car. The remote receiver is always powered. The lock solenoid gets power when either set of contacts is closed. This is a logical OR.
Often we have a little green "start" button to turn on a motor, and we want to turn it off with a big red "Stop" button.
--+----[ ]--+----|\|----( )--- | start | stop run | | +----[ ]--+ run -------[ ]--------------( )--- run motor
This latch configuration is a common idiom in ladder logic.
[edit] 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.
[edit] 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. Since execution of rungs is sequential within a program and may be undefined or obscure within a rung, some logic "race" conditions are possible which may produce unexpected results; complex rungs are best broken into several simpler steps to avoid this problem. 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. As microprocessors have become more powerful, notations such as sequential function charts and function block diagrams can replace ladder logic for some applications. Very large programmable controllers may have all or part of the programming carried out in a dialect of BASIC or C or other programming language with bindings appropriate for a real-time application environment.
[edit] See also
[edit] External links
- "Chapter 6: ladder logic" by Tony R. Kuphaldt (Design Science License); also see "Chapter 10: Multivibrators" (mirror site)
- controlling motors with ladder logic
- multivibrators
- PLC Ladder logic examples