/ docs / src / ladder / ladder-intro.txt
ladder-intro.txt
  1  [[cha:classicladder-introduction]]
  2  
  3  = Classicladder Introduction
  4  
  5  == History
  6  
  7  Classic Ladder is a free implementation of a ladder interpreter,
  8  released under the LGPL. It was written by Marc Le Douarain.
  9  
 10  He describes the beginning of the project on his website:
 11  
 12  [quote,Marc Le Douarain, from "Genesis" at the Classic Ladder website]
 13  _____________________________________________________________________
 14  I decided to program a ladder language only for test purposes at the
 15  start, in February 2001. It was planned, that I would have to
 16  participate to a new product after leaving the enterprise in which I
 17  was working at that time. And I was thinking that to have a ladder
 18  language in those products could be a nice option to considerate. And
 19  so I started to code the first lines for calculating a rung with
 20  minimal elements and displaying dynamically it under Gtk, to see if my
 21  first idea to realize all this works.
 22  
 23  And as quickly I've found that it advanced quite well, I've continued
 24  with more complex elements: timer, multiples rungs, etc...
 25  
 26  Voila, here is this work... and more: I've continued to add features
 27  since then.
 28  _____________________________________________________________________
 29  
 30  Classic Ladder has been adapted to work with LinuxCNC's HAL, and is
 31  currently being distributed along with LinuxCNC. If there are
 32  issues/problems/bugs please report them to the Enhanced Machine
 33  Controller project.
 34  
 35  
 36  == Introduction
 37  
 38  Ladder logic or the Ladder programming language is a method of drawing
 39  electrical logic schematics. It is now a graphical language very
 40  popular for programming Programmable Logic Controllers (PLCs). It was
 41  originally invented to describe logic made from relays. The name is
 42  based on the observation that programs in this language resemble
 43  ladders, with two vertical 'rails' and a series of horizontal 'rungs' 
 44  between them. In Germany and elsewhere in Europe, the style is to 
 45  draw the rails horizontally along the top and bottom of the page 
 46  while the rungs are drawn vertically from left to right.
 47  
 48  A program in ladder logic, also called a ladder diagram, is similar to
 49  a schematic for a set of relay circuits. Ladder logic is useful because
 50  a wide variety of engineers and technicians can understand and use it
 51  without much additional training because of the resemblance.
 52  
 53  Ladder logic is widely used to program PLCs, where sequential control
 54  of a process or manufacturing operation is required. Ladder logic is
 55  useful for simple but critical control systems, or for reworking old
 56  hardwired relay circuits. As programmable logic controllers became more
 57  sophisticated it has also been used in very complex automation systems.
 58  
 59  Ladder logic can be thought of as a rule-based language, rather than a
 60  procedural language. A 'rung' in the ladder represents a rule. When
 61  implemented with relays and other electromechanical devices, the
 62  various rules 'execute' simultaneously and immediately. When
 63  implemented in a programmable logic controller, the rules are typically
 64  executed sequentially by software, in a loop. By executing the loop
 65  fast enough, typically many times per second, the effect of
 66  simultaneous and immediate execution is obtained.
 67  
 68  Ladder logic follows these general steps for operation.
 69  
 70  * Read Inputs
 71  * Solve Logic
 72  * Update Outputs 
 73  
 74  == Example
 75  
 76  The most common components of ladder are contacts (inputs), these
 77  usually are either NC (normally closed) or NO (normally open), and
 78  coils (outputs).
 79  
 80   - the NO contact image:images/ladder_action_load.png[]
 81   - the NC contact image:images/ladder_action_loadbar.png[]
 82   - the coil (output) image:images/ladder_action_out.png[]
 83  
 84  Of course there are many more components to a full ladder language, 
 85  but understanding these will help you grasp the overall concept.
 86  
 87  The ladder consists of one or more rungs. These rungs are horizontal
 88  traces (representing wires), with components on them (inputs, 
 89  outputs and other), which get evaluated left to right.
 90  
 91  This example is the simplest rung:
 92  
 93  image::images/example_link_contact_coil.png[align="center"]
 94  
 95  The input on the left, B0, a normally open contact, is connected to the
 96  coil (output) on the right, Q0. Now imagine a voltage gets applied to the
 97  leftmost end, because the input B0 turns true (e.g. the input is
 98  activated, or the user pushed the NO contact). The voltage has a direct 
 99  path to reach the coil (output) on the right, Q0. 
100  As a consequence, the Q0 coil (output) will turn from 0/off/false 
101  to 1/on/true. 
102  If the user releases B0, the Q0 output quickly returns to 0/off/false. 
103  
104  == Basic Latching On-Off Circuit
105  
106  Building on the above example, suppose we add a switch that closes 
107  whenever the coil Q0 is active. This would be the case in a relay, 
108  where the coil can activate the switch contacts; or in a contactor, 
109  where there are often several small auxilliary contacts 
110  in addition to the large 3-phase contacts that are the 
111  primary feature of the contactor. 
112  
113  Since this auxilliary switch is driven from coil Q0 in our earlier 
114  example, we will give it the same number as the coil that drives it. 
115  This is the standard practice followed in all ladder programming, 
116  although it may seem strange at first to see a switch labeled the 
117  same as a coil. So let's call this auxilliary contact Q0 and 
118  connect it across the B0 'pushbutton' contact from our earlier example. 
119  
120  Let's take a look at it: 
121  
122  image::images/example_link_contact_coil2.png[align="center"]
123  
124  As before, when the user presses pushbutton B0, coil Q0 comes on. 
125  And when coil Q0 comes on, switch Q0 comes on. Now the interesting 
126  part happens. When the user releases pushbutton B0, coil Q0 
127  does not stop as it did before. This is because switch Q0  
128  of this circuit is effectively holding the user's pushbutton 
129  pressed. So we see that switch Q0 is still holding coil Q0 on 
130  after the 'start' pushbutton has been released. 
131  
132  This type of contact on a coil or relay, used in this way, is 
133  often called a 'holding contact', because it 'holds on' the 
134  coil that it is associated with. It is also occasionally called 
135  a 'seal' contact, and when it is active it is said that the 
136  circuit is 'sealed'. 
137  
138  Unfortunately, our circuit so far has little practical use, 
139  because, although we have an 'on' or 'start' button in the form of 
140  pushbutton B0, we have no way to shut this circuit off once 
141  it is started. But that's easy to fix. All we need is a way to 
142  interrupt the power to coil Q0. So let's add a normally-closed 
143  (NC) pushbutton just ahead of coil Q0. 
144  
145  Here's how that would look: 
146  
147  image::images/example_link_contact_coil3.png[align="center"]
148  
149  Now we have added 'off' or 'stop' pushbutton B1. If the user 
150  pushes it, contact from the rung to the coil is broken. 
151  When coil Q0 loses power, it drops to 0/off/false. When 
152  coil Q0 goes off, so does switch Q0, so the 'holding contact' 
153  is broken, or the circuit is 'unsealed'. When the user releases 
154  the 'stop' pushbutton, contact is restored from the rung to 
155  coil Q0, but the rung has gone dead, so the coil doesn't 
156  come back on. 
157  
158  This circuit has been used for decades on virtually every 
159  machine that has a three-phase motor controlled by 
160  a contactor, so it was inevitable that it would be 
161  adopted by ladder/PLC programmers. It is also a very safe 
162  circuit, in that if 'start' and 'stop' are both pressed at 
163  the same time, the 'stop' function always wins. 
164  
165  This is the basic building block of much of ladder programming, 
166  so if you are new to it, you would do well to make sure that 
167  you understand how this circuit operates. 
168  
169