Ladder Logic & Programmable Controllers Using Ladder Diagrams with PLC’s for Machine Tools and Industrial Processes. by Frederick Hoehn, copyright 2014, all rights reserved. Chapter 1 PLC’s are Programmable Logic Controllers. They are used in many industrial machine tool applications, and in manufacturing process control. For example, you can control a complex conveyor system with PLC’s. FedEx and UPS package shipping companies have package sorting hubs in major cities of the U.S. The packages come into the building and go onto the conveyor system. As the packages move along, their bar codes are electronically read by machines. The appropriate gates will open to divert the package to where it will be loaded onto the right outgoing truck that will go to the correct destination city. This is a very good application for PLC’s. And they’re used for industrial machine tool control. PLC’s are programmed by Ladder Diagrams. Ladder Diagrams use Ladder Logic, which basically is Relay Logic. The program for the PLC is the Ladder Diagram. Relay logic has “and” functions, and “or” functions. These will be defined a little later in this book. We’ll be getting into ladder diagrams and ladder logic in this book. When we speak of logic here it doesn’t mean the kind of reasoning used in college debate class. We’re talking about the way decisions are made for best control of the machine or process. The Ladder Logic programmer (you, perhaps) writes his instructions into the program. Ladder diagrams are so called because the diagram looks rather like a ladder, with two vertical pieces, and horizontal rungs. Each rung usually has a circle toward the right side of the rung, representing a relay coil. The ladder diagram could be built using actual physical relays, but there’s a better way. You don’t need fifty actual physical relays to do the logic calculations, although some of the early NC (numerical control) Machine Tools actually did that very thing. Giddings and Lewis manufactured NC Machine Tools that were controlled by large cabinets with perhaps two hundred relays. But that was in the days before PLC’s. Now, those hundreds of relays would be replaced with a comparatively small Programmable Controller (PLC.) NC stands for numerical control. CNC stands for computer numerical control. Once the ladder diagram has been created and then downloaded to the PLC over a cable, the PLC performs most of those specified ladder logic functions without physical relays, but by keeping track of what’s happening with the “relays” using bits in memory. A bit is a binary digit. It can have the value of either 1 or 0. A one represents an energized relay, a relay having electrical current flowing through its coil. A zero would represent a deenergized relay, a relay with no electrical current flowing through its coil. If you go on the Internet to Wikipedia.com, an online encyclopedia, and at the search box type “electrical relay,” and then press “Enter,” it will come back with photos of relays and a write-up about how relays operate. A relay is an electro-magnetic device that acts like a remotely controlled switch. We used to make electro-magnetic devices back in Electric Shop, an elective class available in junior high school (middle school). You take a piece of brass tubing about ¼ inch in diameter, and perhaps six inches long, and wind enameled copper wire around the upper part. Inside the brass tube is an iron slug attached to a metal rod sharpened to a point at the bottom. The device is used for engraving your initials on your wrenches and screwdrivers that you own. You hold the engraver like a pen to write your initials on your tool. One wire of the coil is connected to the brass tube. The other end of the coil is connected to a dry cell battery. The other terminal of the battery is connected to your wrench that you’re engraving. When the metal stylus makes contact with your tool, electrical current flows through the coil. The magnetic field produced by the current in the coil pulls the iron slug and stylus upward against a compression spring. The upward movement of the slug and stylus causes an open circuit, and current flow stops. Then, the spring pushes the slug and stylus downward, and the process repeats itself. Move the stylus to write your initials. A relay works like that except no slug and stylus. The magnetic field created when the coil is energized pulls an armature toward the coil against a spring. When the coil current stops flowing, the spring returns the armature to its deenergized position. The movement of the armature toward the coil causes movable electrical contacts attached to the armature to close normally open contacts and to open normally closed contacts. Closed contacts means electrical current can flow through them. Open contacts allow no current to flow. The two verticals in the ladder diagram represent your power source. It might be a.c. or d.c. You would use alternating current if the relays are a.c. relays. You would use a direct current power source if the relays were d.c. relays. Relays are also rated as to their coil voltage, which should agree with the power source. I’m talking about a ladder diagram if it were to be built using actual physical relays. Your two rails of power are like the two terminals on your car battery that power the car’s whole electrical system. Current flows out the negative terminal of the battery, through the external circuits, and back into the positive terminal of the battery. The word circuit comes from the same root word as circle. The current flows in a circle. Break the circle of flow, and the current stops flowing. Break the current to the relay coil, and the relay deenergizes, and its n.o. contacts open, and its n.c. contacts close. Houston, TX is rather an oil town. Many major oil companies have facilities there, including refineries in Houston, and next door in Pasadena, TX. I worked at a company in Houston where they manufactured large cabinets of relays that were used for relay logic for some of the oil companies. The schematic diagram for those relays that were doing the relay logic would be a ladder diagram. When I saw that they were using all these relays for logic functions, I went to my boss and told him that the TTL 7400 family of integrated circuit logic devices using the older bipolar, junction transistors, would do the same job in a lot less space, and for a small fraction of the cost. A newer kind of transistor is the field effect transistor, from which we get the CMOS logic chips. (Complementary Metal Oxide Semiconductor.) My boss answered that the relays were what the customer wanted, and so we would give the customer what they wanted. I guess the customer’s Engineers were old-school fellows who had learned relay logic in college, but then graduated before TTL integrated circuits became available. TTL stands for transistor-transistor logic. Programmable Controllers are just the kind of thing that I was trying to tell my boss about, although at the time, I don’t think they were available yet. But the TTL logic integrated circuits were available. Machine tools and manufacturing processes can of course be controlled by computers. You would need an interface to the input/output circuits of the computer so that it can turn on motors and solenoids and solenoid valves, and also receive information back from the machine or process. But machine control by computer program isn’t done so much. A better way is to use a Programmable Controller, the reason being that Plant Maintenance Personnel are usually not also Computer Programmers, and would therefore not be able to understand the computer program that controls the machine or process. But a decent Plant Maintenance Electrician should be able to understand a ladder diagram because it’s just relay coils and contacts and switches, which Electricians are supposed to understand, and generally do. The PLC is somewhat like a computer in that it has its own microprocessor that is executing a program that is stored in ROM (read only memory). That microprocessor program is for the purpose of executing the program that is the ladder diagram. It goes down the ladder rung by rung. There is a bit in memory for each relay coil represented in the ladder diagram. Each of those bits show whether a relay coil is energized or deenergized. To the left of the coil on a particular rung are the contacts and switches that determine whether current will flow through the coil on that rung. If the various contacts and switches on that rung are in a condition that will allow current flow, then the relay coil on that rung is energized, and its bit in memory will be set to “1” to show an energized relay. Otherwise, the bit will be reset to “0” to show a deenergized relay. But remember that just because you see on the ladder diagram a set of normally open contacts, that doesn’t mean that no current can flow because the contacts are open. Actually, those contacts are closed, if at that time the coil controlling those contacts is energized. So, the microprocessor goes and looks at the bit for that coil to see whether it’s energized or deenergized. Similarly, a set of normally closed contacts is open if its coil is energized. Then the PLC looks at the next rung. If the contacts in their present condition allow current flow, the bit will be set for that coil. Then the next rung. After the microprocessor program has looked at all the rungs, it goes back and starts over with the first rung, in a continuous loop. Chapter 2 Although many of the relays represented on the ladder diagram are not actual physical relays, but just bits in memory, a few of the relays are actual physical relays to provide outputs to the outside world, the world outside the PLC, which would be the machine or process being controlled. I referred to “and” gates, and “or” gates. The “and” function is where two or more conditions must be met before a relay can be energized. The “or” function is where either of two conditions, or any one of several conditions can be met to energize a relay. Now please take a blank sheet of paper and a pencil. Along the left side of the paper draw a vertical line. Using a ruler for a straightedge should give a straighter line. Do the same at the right side of the paper. Those are your power rails that would supply operating voltage for the coils of the relays if actual physical relays were being used. Now in the middle of the sheet of paper, draw a horizontal line making a large capital “H” on the paper. You wouldn’t want to actually do this with copper wire, or you would short-circuit the power source probably producing sparks. Safety glasses of glass or plastic should be worn when working around electrical and mechanical apparatus. Now erase a little of the horizontal line toward the right rail, and insert a circle like a capital “O”. That circle represents the coil for that rung. Now erase a little of the horizontal line toward the left rail, and insert two vertical parallel lines like they have on the “pause” button of a compact disk player. Those two parallel lines represent a set of normally open contacts that would be available on a relay. The other kind of relay contacts is the normally closed contacts. We make the symbol for normally closed contacts by starting with the symbol for normally open contacts, and then crossing it with a short diagonal line from lower left to upper right across the normally open symbol. On your drawing of a ladder diagram, even though there’s power on the rails, that set of normally open contacts in series with the coil will prevent the coil on that rung from energizing if the coil for those normally open contacts is deenergized. But when those normally open contacts close, then the coil on that rung will energize, current will flow, its armature will change positions, and that relay’s normally open contacts will close, and its normally closed contacts will open. Open contacts stop current flow. Closed contacts allow current flow. Your rung shows the normally open contacts and the coil connected “in series.” Now let’s erase a little of the horizontal line at the middle of the sheet of paper, and insert another set of normally open contacts. So now, two sets of normally open contacts are “in series” with the coil. What we have then, is an “and” function. Both sets of contacts must be closed to energize the coil. Either set of contacts open will prevent current through the coil. Now, on your diagram, let’s draw another set of normally open contacts a little above that middle set of normally open contacts. Now add a short horizontal line extending to the left from this newest set of contacts, and another extending to the right. Now add two short vertical lines to connect these latest horizontal lines down to the rung. You’ve just drawn a set of contacts in parallel with the previous middle set of normally open contacts. This gives us the “or” function. Either set of those two parallel sets of contacts being closed will provide a current flow path. But of course, the single set of normally open contacts to the left must also be closed to energize the relay coil. So, we have an “and” function and an “or” function on the same rung. In an actual physical circuit, you could take a voltmeter and measure the voltage between the two rails. The voltmeter has two probes. One probe to the metal of the left rail, and one probe to the metal of the right rail. On the voltmeter, select a.c. or d.c., as appropriate. Some voltmeters are auto-ranging, they will automatically select the range for you. If yours doesn’t do that, it’s usually best to start with the highest range (perhaps 500 volts) and then gradually go to a lower range. The use of the word “normally” regarding relay contacts means the condition of the contacts when the relay is deenergized. Normally open contacts are open when there’s no current passing through the coil that operates those contacts. In the ladder diagram, the various n.o. and n.c. contacts are identified with a number that is the number of the relay that they are a part of so that we can tell which coil is operating which contacts. Designations for relays will often start with a capital “K”. The ladder diagram is created using a “personal computer,” either desktop or laptop, with the software installed on the computer from the manufacturer of the PLC that you’re programming. Software that allows you to write the ladder diagram, and modify ladder diagrams, and download them to the PLC over an electrical cable. Read the instruction manual for that software. And read the instruction manual for the PLC. I worked at a factory where one of the production machines had been refurbished by an outside contractor. They had converted an older machine to be controlled by one of the newer PLC’s. But the machine operator complained that the machine was taking too much time to warm up. The PLC included count-down timers that could be used by the programmer. This is like a set of normally open contacts on a rung that will close to allow current flow after the specified period of time. If you tell it to count down for nine hundred seconds, then you have a fifteen minute delay. All I had to do was decrease the number to allow a shorter warm up period. Another thing the production people didn’t like (Machine Operators are usually Machinists) was that when the machine’s carriage would travel to and activate any of the four limit switches in either of two axes of travel, X or Y, the carriage would also not travel along the other axis of travel. The axis of travel, X axis or Y axis, was selected by a mechanical lever that the operator would use. A limit switch at the lever would show whether the X or Y axis had been selected. That particular limit switch was connected to an input at the PLC, but the ladder diagram showed that its input was not being used. I changed the ladder diagram so that that limit switch would select the travel limit switches for the X axis when the carriage was traveling the X axis, or the travel limit switches for the Y axis when traveling the Y axis. My lead man said, “You catch on fast.” But of course, I had studied relay logic, ladder diagrams, and was quite computer literate. My main electronics education was as a student of U.S. Navy Electronics Technician “A” School, where the Navy sent me after Boot Camp. The U.S. Navy has training books for Electronics Tecnician 3rd class, Electronics Technician 2nd class, and Electronics Technician 1st class. If you don’t find them at the Public Library, I think they’re available from the U.S. Government Printing Office. But I had some prior knowledge of electrical theory from reading the Radio Amateur’s Handbook, published by the American Radio Relay League. I’ve seen that at Public Libraries. I had also been a Ham Radio Operator in my youth, and you had to learn a little electronic theory to pass the test to get the F.C.C. license. They had a free class for that at an electronics store on Magnolia Blvd. in Burbank, CA. Perhaps it was “Valley Electronics.” Public libraries often have free classes on computers. You can get a library card and read up on what will help your career. At the library, the Dewey decimal number for electronics books is 621.38. But in Chicago, they use the Library of Congress numbering system instead of the Dewey. Ask the Librarian where the electronics books are. Chapter 3 But you don’t have to be an expert at electrical theory to work with ladder diagrams. You’ve used flashlights, haven’t you? It’s good to have a flashlight in your car for use at night. Beside the case of the flashlight, the three electrical components are the light bulb, the switch, and the batteries. Also, the metal strips that conduct the current flow from the batteries. When you turn on the flashlight’s switch, current flows out the negative terminal of the battery, through the switch and light bulb, and back into the positive terminal of the battery (often, two batteries in series.) It’s very simple. And that’s what we’re doing with ladder diagrams. You get the contacts closed to the left of the coil on a rung, and then the coil energizes, changing the state of the contacts that it operates. Its n.o. contacts close, and its n.c. contacts open. Where things get a little bit tricky is when tracing back contacts to their coils to see how the process operates. Just be careful, be diligent, don’t get in a big hurry. You’ll figure it out. And I believe it helps if I ask God to help me. I’ve been to schools for, and done maintenance on million dollar machine tools controlled by computers. But those very complex machines usually have a ladder diagram that can be displayed at the machine tool, so that people can understand what’s going on without being computer programmers. On many of the ladder displays, a contact or relay will be highlighted to show that it’s open or closed. This is a significant help in troubleshooting a problem. At one employer, I worked with an Allen-Bradley PLC that had ten inputs and six outputs. But you can have many more inputs and outputs if needed, depending on the complexity of the machine or process being controlled. Outputs from the PLC can turn on small motors, energize solenoids, operate solenoid valves, and about anything else that can be turned on or off electrically. Large horsepower motors require more current, and are turned on by a large relay called a contactor, external to the PLC. But that contactor can be turned on by a physical relay in the PLC. Inputs to the PLC can be limit switches, pressure switches, humidity sensors, photocells, whose inputs have been programmed into the ladder diagram. On some ladder diagrams, dashed lines have been used between a relay coil and sets of contacts to show that those contacts get operated by that coil. At one employer, I wrote a ladder diagram to control the air compressors that provided approximately one hundred pounds per square inch air for use in the plant . Some of the machines needed the compressed air to work right. My program would alternate the two large compressors each week, and use the smaller compressor on weekends, when not as much compressed air was needed. But if a fault developed with the operating compressor, the program would automatically switch over to a different compressor. In working with PLC’s, if one of the relays in the ladder diagram is an actual, physical relay to provide an output to the outside world, you can use a multimeter to see what’s happening with that output. One does not use an ohmmeter in any energized circuit. If there’s power in a circuit, it could damage your ohmmeter. If there’s power, use the voltmeter function for a.c. or for d.c. as appropriate. If there are two terminals at the PLC for that output, if the same voltage is present at both terminals (with reference to ground or common), you have a closed set of contacts at that output. If there are two different voltages at the two terminals (with reference to ground or common) then you have an open set of contacts. But if you just have a set of “dry” contacts (no voltage), then you could use the ohmmeter function. Zero ohms between the two terminals would mean closed contacts. A high resistance reading would mean open contacts. You can also measure inputs to the PLC. For example, that limit switch I mentioned that would show whether X or Y axis was selected. You would go to the switch and use an ohmmeter to see whether the contacts are closed for X axis and open for Y axis, or vice versa. Then write it down for future reference. A good place to write it down would probably be a printout of the Ladder Diagram for that Machine Tool. I was troubleshooting a machine at one employer where the problem seemed to be with a certain relay or solenoid. One side of the power source was connected to ground. Voltage could be measured at one coil terminal of the relay or solenoid, and then the same voltage was present at the other terminal. What does it mean? Like most machines, the switching of the relay or solenoid on was done on the power side, not the ground side. The fact that I was measuring the same voltage on both sides of the coil meant that the device had lost its ground. The ground wire for the coil had come loose from a clamp that was supposed to hold it. On another machine, using an oscilloscope to check waveforms, there were no waveforms where there should have been. Crystal oscillators were supposed to generate timing signals used to control the machine. I noticed that the quartz crystals were the plug-in kind. They plugged into sockets. I moved them up and down a few times in their sockets, and the machine started working. The metal on the pins on the crystals can begin to oxidize from oxygen in the air. Oxidized metal doesn’t make good electrical connections. A Maintenance Mechanic at one place had been working on a lathe for probably more than an hour to solve a problem. He came and got me. I was the Electrician. I noticed that the control for the lathe used a plug-in relay, with an octal socket, I think (eight pins). I moved the relay up and down a few times in the socket, and the lathe started to work. Electricians are able to understand ladder diagrams because the diagrams follow the rules of electrical current flow. A co-worker of mine and I were sent by our employer in California to a CNC machine tool school at the manufacturer in Wisconsin. Sometimes people who try to write ladder diagrams are not familiar with the rules of electrical current flow. Some programmer there, not understanding current flow, tried to make a rule for the ladder diagram that violated the rules of electrical current flow. When the instructor tried to explain it to us, both my co-worker and I burst out laughing. You don’t change the rules of current flow. God has already established those rules. Best thing to do is try to learn those rules and then apply them. And it’s not really that difficult. Speaking of classes, I took a college class on relay logic, and we used an excellent textbook titled, “Arithmetic Operations in Digital Computers.” Don’t remember the author, but I recommend that book. Author Malvino has written some excellent electronics books. He is apparently a professor at one of the colleges in the U.S. A CNC machine tool uses ladder logic to control a very sophisticated million dollar machine tool. For each part that will be manufactured using a CNC machine tool, a Part Program is written for the machine to make that part. The machine operator mounts a solid block of steel or aluminum or titanium on the machine’s table. Milling bits remove areas of metal. Drill bits drill holes. Taps are used to thread holes that have been drilled. Many of the machines have automatic tool changing. After a milling operation has completed, perhaps the next step is to drill a hole. The machine will automatically remove the tool holder with the milling bit, and put it back in the tool holder rack, and get the tool holder with the drill bit and place the tool holder in the chuck of the machine. The Part Program tells the CNC machine tool how many revolutions per minute the chuck should rotate at. A CNC machine tool can be as productive as ten conventional (non-CNC) milling machines with their Machinist operators. DNC is Direct Numerical Control. That’s where a central computer at a machine shop downloads Part Programs to the CNC Machine Tools when the next Part Program is needed for the next part to be manufactured by the machine. Care must be used in troubleshooting machines. I heard of a maintenance man who was trying to find an electrical problem. He climbed into the machine looking for the bad connection. He found the bad connection, and made it a good connection, and the machine began to operate and crushed him to death. He should have been following the lockout, tag out procedures for safety. You padlock the three phase, 440 volts a.c. disconnect for that machine. But wait! Don’t trust the disconnect switch to do the right thing when you move the lever from “On” to “Off.” In at least one case, I heard of a disconnect that was placed in the “Off” position, but the knife switches inside didn’t open as they should have. After throwing the disconnect switch to the off position, open the door and use your eyes to make sure that the knife switches have opened. While the door is open, use your voltmeter to measure the incoming voltage at the top of the disconnect switch inside the box. You should be able to measure voltage coming in there. If you can’t measure voltage there, you may have a bad voltmeter. If you rely on a bad voltmeter, you could get hurt. Find a good voltmeter that will measure the voltage. Now close the disconnect switch door, and padlock the switch in the “Off” position. Now go back to the machine you’re working on, and use the same voltmeter that you just proved was working, and measure the three phases of incoming power. Three phase power will come into the machine’s electrical box on three wires. There’s probably also a green ground wire. When you have three wires, you have three pairs of wires. Let’s call the three wires A, B, and C. With your a.c. voltmeter, measure between A and B. Then measure between A and C. Then measure between B and C. All three measurements should be zero. And don’t forget that just because you’ve locked out the 440 volt three phase power, you might also have some single phase 115 v.a.c. power coming into the machine. If you find where it’s coming into the machine, you might just temporarily disconnect that wire. 440 volts can kill a man, so use caution. For that matter, ordinary house voltage of 115 volts a.c. can kill people. A related subject to the “and” and “or” functions and logic circuits is Boolean Algebra that you might want to read up on. Every prudent man deals with knowledge.