Image

What is Ladder Logic?

April 22, 2016
A basic introduction helps establish a fundamental understanding of this subject.

Programmable logic controllers (PLCs) are used extensively throughout the world. Over time, they have advanced to become more user-friendly, efficient, smaller, and less expensive. Different types of programming languages have also been developed for PLCs, but the most frequently used is known as ladder logic.

The structure of ladder logic

The structure behind ladder logic is based on the electrical ladder diagrams that were used with relay logic (see Relay Logic on page C7). These diagrams documented how connections between devices were made on relay panels. They are called “ladder” diagrams because they are constructed in a way that resembles a ladder with two vertical rails and rungs between them. The positive power rail (on the left) flows to the negative power rail (on the right) through the physical devices connected on the rungs. In the example shown in Fig. 1, “PB” stands for pushbutton,”and “CR” stands for control relay. “L1” is a light, and “M1” is a motor.

Fig. 1. Note how this electrical diagram resembles the shape of a ladder with two separate rails and rungs between them.

Similarities with ladder diagrams

Ladder logic was designed to have the same look and feel as ladder diagrams, but with ladder logic the physical contacts and coils are replaced with memory bits. Let’s run through a ladder logic example so you can see how it works.

Fig. 2. Ladder logic uses memory locations rather than hard-wired logic.

For the program shown in Fig. 2, we took the relay logic’s ladder diagram from Fig. 1 and duplicated it with ladder logic — no more hard-wired logic but memory locations instead. Some of these memory locations are used internally, and others are used with external inputs and outputs. To monitor and control real-world devices, they will need to be wired to I/O modules. For this PLC, these inputs and outputs are assigned to X and Y memory addresses like the X001 seen with PB1. This normally open contact’s state is read from the input on the I/O module where the physical pushbutton is connected. On the other hand, each Y bit will have an output device wired to it, as seen with the light controlled by Y001. All of the other locations are assigned to internal bits that we can use as needed. Note: Today’s PLC CPUs offer many types of functions, not just simple contacts and coils. Math, shift registers, drum sequencers, etc., are available to aid in your programming. However, for now, we’ll keep it simple.

Execution of ladder logic

The CPU will interpret the logic in a sequential order. Starting at the top left of the program, the CPU will work its way down the rail, executing each rung or sub-rung from left to right. So if PB1 is pressed, the CPU will turn ON CR1. Since CR1 has changed states, in rung 3 the CPU will activate CR3. CR3’s normally closed state is used in rung 4, so the CPU will then turn OFF L1. Even though we still refer to coils and contacts in ladder logic, remember that they are memory representations, not actual devices. Once the CPU reaches the last rung, it will loop back to the start of the program and run it all over again. This process will continue as long as the CPU is powered and in the RUN mode. The time it takes the CPU to loop back to the beginning is known as scan time. Scan time also includes the time it takes the CPU to read the inputs and update the outputs, and it can be important to applications where timing is critical. Subroutines and special purpose I/O modules can be used to help reduce the scan time, if needed.

The logic behind the ladder

So what logic can ladder logic actually perform? With the increasing demand for functionality and ease of use, many of today’s PLCs incorporate function blocks with ladder logic. The structure of the program is still a ladder with the more complex instructions being function blocks. So to answer the question, let’s look at a few examples:

• Boolean logic: The ON/OFF, TRUE/FALSE algebra of binary systems. The basics of which are AND, OR, and NOT operators. To put it simply, rung 5 in our code needs CR1(C1) AND CR2(C2) to turn ON motor M1 (Y002).

• Timing: Timer instructions are available to allow for ON-delayed or OFF-delayed events. Once triggered, the timer will turn its associated output ON (on-delay) or OFF (off-delay) after the set time has elapsed.

• Counting: Count-up and count-down functions increase or decrease the counter value on every transition of the input.

• Comparisons: Compare instructions are available to determine if values are less than, equal to, or greater than each other.

• Math: These instructions not only allow for the simple addition and subtraction but also for more complex operations like tangents, square roots, etc.

• Special functions: PID loops, communication instructions, shift registers, drum sequencers, ramp generators, etc.

This article was meant to serve as an introduction to ladder logic. It only begins to scratch the surface of the many functions/applications of this programming language.   

A technical marketer with AutomationDirect in Cumming, Ga., Dehner has a BS in electrical engineering and over 15 years of experience working with electrical systems, 11 of which have been focused on implementing control systems in the industrial automation field. He can be reached at [email protected].

SIDEBAR: Relay Logic

Using a combination of switches, relays coils, and contacts is referred to as relay logic. Relay logic is a dependable controls method, a method still in limited use today. But the cost associated with it in terms of time-consuming logic changes, failures over time due to mechanical switching, and extensive wiring and space requirements forced many industries to look elsewhere for their control needs. This led them to the PLC.

About the Author

Bill Dehner | Technical Marketer

A technical marketer with AutomationDirect in Cumming, Ga., Dehner has a BS in electrical engineering and over 15 years of experience working with electrical systems, 11 of which have been focused on implementing control systems in the industrial automation field. He can be reached at [email protected].

Voice your opinion!

To join the conversation, and become an exclusive member of EC&M, create an account today!

Sponsored Recommendations

Latest from Training

ID 188775926 © Josepalbert13 | Dreamstime.com
Understanding General Requirements of the NEC, Part 1
ID 321335940 © Weerapat Wattanapichayakul | Dreamstime.com
Wooden blocks that spell out 'quiz' with a light bulb above it
In the typical facility, the plant manager has X amount of discretionary spending power that can be directed toward a single purchase. At each level of management down, discretionary spending is stepped down into smaller amounts. Anything beyond a given manager’s limit must be appealed to the next level up. For example, the Plant Engineer can’t quite swing a purchase of $5200 but the Plant Manager can approve it. This informal arrangement reduces corporate overhead and improves operational efficiency. It does not address whether the spending decisions would make financial sense to the Chief Financial Officer, but the cap at each level keeps any mistakes to a reasonably acceptable loss or misallocation of resources. Beyond the Plant Manager’s limit, there is usually a formal process for getting spending approval. It typically involves filling out a Capital Request (or similarly named form). In well-run companies, the form is very structured. It mostly wants some basic information that will give the reviewer(s) the ability to justify not just the purchase but also the cost of acquiring the capital to do so. Because the funds will typically be borrowed by the corporation, the cost of capital must be balanced against the return on investment. There will be at least one person crunching the numbers to make what is called “the business case” for the proposed spending. Making the business case is something you should do, in some way or another, when considering spending within your approved limits. If the spending is above your approved limits, then the manager above you will need a bit beefier of a business case. The business case must take into account the value obtained versus the money spent. Consider the purchase of a thermographic camera. If you intend to purchase a mid-range camera but nobody at your facility is trained and certified in its use, the purchase is probably a waste of money. You’d be better off getting an entry-level camera and then arranging for a path toward certification if you intend to have that ability in-house and it makes operational and financial sense to do so. And generally, it makes sense to have a person or two with Level I certification so they really understand how to get the most out of a camera system that’s beyond the basic level. On the other hand, if you were a manager at an electrical testing firm with several Level III Thermographers you would be wasting your thermographers if you decided to “save money” by equipping them with only basic or even intermediate camera systems. Your firm needs to be able to troubleshoot problems when that important client calls in a panic. Your thermographers need the tools to do that job, and “cost-saving” on camera systems won’t cut it. Presumably, your clients are smart enough to already have basic camera systems; they just don’t have the expertise to use advanced systems. Sometimes a different logic applies to other types of test equipment. In the typical plant, maintenance electricians need sophisticated DMMs. If they lack the training to use the features that are needed for most effectively keeping equipment running, simply choosing a less capable DMM they already know how to use is not the answer. They need the appropriate DMM along with the training on how to use those features correctly. So far, we haven’t looked at the need to crunch any numbers to make the business case. What we have done is think about the match between the purchase, the problem that needs to be solved, and the ability of the user to solve the problem using that purchase. This sounds like a common sense approach that everyone would naturally take, but people often lose sight of the reason for the purchase in the first place. The tendency is to either go all out on something they can’t use or don’t need, or to “save money” by shortchanging the end users with something that doesn’t allow them to do what they need to do. What about those numbers? When you do a purchase request, a bean counter is going to try to determine the cash flows involved (typically in monthly periods). If you write something like, “The payback period is three years,” they don’t find that helpful. Lenders care that a loan can be serviced, and cash flow is the critical factor in calculating whether it can. Thus, beancounters don’t use payback to determine whether they can afford to borrow. They use the Internal Rate of Return (IRR) or Modified Internal Rate of Return (MIRR). Formulas for both IRR and MIRR have been in spreadsheet programs for over two decades, but before that they were determined using a Business Math Calculator (about $150 in 1990). And before that, they were laboriously calculated by hand. The cash flows that are charted will be either additional revenue generated or losses prevented. To help the person who figuratively wears the green eye shade, tie the use of the test equipment to a revenue stream. A major appliance plant in Tennessee has several production lines that collectively produce $1,560,000 per hour of revenue. Thus each minute of unplanned downtime is quite costly. If the plant electrical engineer there wanted to upgrade test equipment in a way that exceeds the Plant Manager’s spending authority, he needs to help the green eye shade guy do the math. He can cite short case histories from the past two years and briefly explain how having X capability (present in the new equipment, absent in the existing equipment) would have saved Y minutes of downtime (which the green eye shade guy will calculate out in terms of revenue and cash flow). The green eye shade guy also needs to know whether each case history is a one-off that will never recur or if it’s representative of what to expect in the future. You can settle this question with a brief explanation. For example, “The responding technician did not have a [name of test equipment]. Consequently, he had to arrive at the same conclusion by other means to the tune of 24 minutes of downtime he would not have incurred if he’d had a [name of test equipment]. This problem occurred once on Line 2 and twice on Line 4.” Now the green eye shade guy can simply add up the downtime, monetize it, and create the cash flow analysis. And it’s really good for something like a power monitor. For example, “In this particular case the plant did not have a monitoring system capable of detecting short-term bursts of power, which we call transient spikes, and alerting us. Transients happen with no notice, and usually without being detected. The motor shop forensic report shows the main motor failed due to winding insulation failure caused by transients. With a power monitor detecting and reporting those transients, we would have been able to intervene before outright failure, on a scheduled basis. That would have reduced downtime by 57 minutes twice last year alone.” Making the business case for your smaller purchases means simply thinking about what you are trying to accomplish and then making sure you are spending the funds correctly to achieve that goal. But as you go up the food chain, you need to make the picture more clear. And when you appeal to corporate for approval, you need to provide reasonably accurate downtime savings numbers that can be converted by them to revenue loss prevention in specific dollar amounts.
Man staring at wall with hand-drawn question marks and money bags on it

Sponsored