Ladder Logic for Dummies

No Room For Dummies in Ladder Logicbook-background-003

NOTICE!

I have written a book that will teach you how to program and troubleshoot ladder logic. It  is an excellent way to learn about PLC,s and starting 2/9/2015 it is free for a very limited time, so go ahead and grab a copy for yourself while it is free!

The free period is over, however the book is still available to buy on Amazon. It’s worth it!

Ladder Logic is a graphical based industrial programming language used to program and configure Programmable Logic Controllers, or PLC’s. Ladder programs consist of rungs that house instructions. Once compiled and downloaded to a PLC the ladder program is scanned like a book; from top-to-bottom, left-to-right.

The following illustration is a common “latching circuit” used to turn devices such as motors on and off. If you are familiar with electrical schematics you will notice the relay and coil symbols.

Ladder latch circuit

 What Makes Up a Ladder Logic Program?

Coils, relays, timers as well as other instructions can be placed on rungs. Variables store data that is checked and manipulated by instructions. How and where these instructions are placed on rungs determine the output logic of a rung. The software has a programming instruction set that covers bit instructions, timers, counters, string instructions, and file instructions just to name a few.

Ladder instructions are unique. They have built in watch windows. For example let’s take a look at the Timer On or TON instruction. Notice the three variable fields:Timer On Instruction

  1. Timer                    Name of the timer
  2. Preset                   Set time like a stop watch
  3. Accum                  How much time has accumulated?

Now let’s look at the –(EN)- and –(DN)- symbols on the right side of the instruction. If the timer is timing the –(EN)- is highlighted green. If the timer is done timing the –(DN)- symbol is highlighted green. This is atypical of programming languages. Most languages require a programmer to configure a watch-window to monitor variables at run time. Having feedback directly on the instructions makes for some quick and easy troubleshooting.

Making PLC Programs is Easy.

Most programs use a combination of just a few of the basic instructions. Master the following list of instructions and associated variables and you will have the basics mastered.

  1. XIC                        Examine If Open
  2. XIO                        Examine If Closed
  3. OTE                        Output Energize
  4. OTL & OUT          Output Latch & Unlatch
  5. MOV                      Move data into a variable
  6. COP                        Copy data into an array of variables

Online PLC Training For Dummies

This site is dedicated to teaching the novice, the dummy,  how to program. How do we accomplish that? We offer online training. Put your credit card away most of the material you will find here is completely free. Free doesn’t mean you won’t learn, quite the contrary. Take a look around the site and I think you will agree there is a bunch of useful material. Check out the main page and be sure to watch the tutorial you will learn more from this than a month of lectures.

Be sure to check out our online training videos. Here you will find a series of videos that teach you how to program. Make sure to watch them all, and if you get hung up on instructions you can get definitions and examples here.

If you’re hungry for more, check out this, and this, and this. 

Bit Instructions

The XIC and XIO instructions are input instructions.

Input instructions do not alter data. The instructions simply check the data referenced by the associated tag and executes logic based on the data.

In the case of the XIC instruction

when the tags value is 1 the instruction is true enabling instructions to the right to execute. If the tags value is 0 the instruction is false disabling instructions to the right.

In the case of the XIO instruction

when the tags value is 0 the instruction is true enabling instructions to the right to execute. If the tags value is 1 the instruction is false disabling instructions to the right. Read More

Tags And Constants

The basic building blocks of all ladder programs are variables and instructions.

With that said it’s important to understand variables, types and constants. All higher level programming languages utilize variables and constants. This is true whether programming in a language like C, or ladder logic. Variables are created in RSLogix 5000 using an editor and are called Tags.
When tags are created, the software associates the tag name to a physical memory location or address. An instruction executes logic referencing data addressed by a tag. Input instructions read data while output instructions manipulate data. Simple right? Read More

Ladder Logic Rungs

Rungs are the building blocks of code in Ladder Logic.

Think of a rung as a wire that is connected to opposing voltage sources. If a rung is placed between the left and right rails it would behave the same as connecting a wire to the negative and positive terminals of a battery. If you did that what would happen? The wire would probably burn up, the battery would overheat and the result would be a direct short. A load is necessary, a light, horn, motor or anything that would add resistance. Ladder Logic behaves the same way, only without the heat and possible fireworks. The light, horn, or motor would be an instruction like a timer, counter, or latch. Read More

Hello World, so what is Ladder Logic?

Hello WorldLadder logic is a visual programming language used to program PLC’s (Programmable Logic Controllers).

Ladder logic consists of horizontal Rungs  and Instructions embedded between vertical Rails on either side. Rungs house instructions which are referenced by tags or variables. The rails represent the opposing polarity of power rails as shown on an electrical schematic. The rungs and subsequent instructions represent the “load” between the rails.
Rungs and rails are graphical representations of electrical schematics. The real magic behind ladder logic is the instructions, and there are a bunch of them. There are Boolean, Math, Timer, Counter, and Specialty instructions just to name a few. All instructions reference a tag or variable which is an address to a memory location. Got all that? Good.

Why ladder logic? I mean really, what advantage is there to programming in ladder logic?

Take a look at the picture below. On the left is Structured Text and on the right is Ladder Logic. Both programs accomplish the same thing just with different languages. Notice the green vertical rails in the ladder logic example and the green vertical bar in the structured text example. The green lets you know that the logic is enabled and running.

Rung_Off_C

Take a look at the rung on the right. Instantly you know the values of the tags are zero. How? That’s easy, because if either of them had a value of 1 they would be green just like the rails.

Now take a look at the code on the left. It’s impossible to determine the input and output tag values without bringing up a watch window and checking the value of the tags. Incidentally all values in both programs are set to 0 in this example.

The picture below shows the exact same logic, however something is different on the rung example. The instructions are now highlighted in green the same way the rails are in the last example. Both tag values are now set to 1 as indicated by the green highlighting of the instructions.

Rung_On_C

In the Structured Text program both values are 1, however the code is just that, code. The code does not provide feedback like the ladder logic example does.

It’s possible to open a watch window to see the value of the two variables, for that matter the same watch window could be opened for the ladder logic program as well. The major difference being is it’s unnecessary for the ladder program. Just a quick glance lets you know what is on and what is off.

This kind of feedback is undoubtedly the major advantage of using ladder logic. Ladder logic places all the information you need where you need it. It makes troubleshooting quick and easy, and this functionality isn’t limited to just bit instructions. Variables are displayed on instructions as well. Most ladder instructions will show the value of tags in real time. Take a look at the Equal To instruction below. If the value of Source A is equal to the value of Source B turn on the output bit. In this case they are not equal and the output bit is off.

Variable Example

Now imagine you have been tasked to find out why the variable “Output_Bit” is off. Just a quick glance at the ladder rung and it’s easy to determine why the bit is off. The two variables in the comparison instruction are not equal therefore the “Output_Bit” if off. From there you can do a simple cross reference on the variables to discover why the variables are not equal.

Programming ladder logic entails dragging and dropping instructions, rungs and branches. Programming structured text entails knowing the correct syntax. Take another look at the structured text examples above. Notice the Semicolons and Colons. This is representative of the Pascal programming language. Instructions are in Blue and tags are in Red. Setting a value is done with the :=  operator while comparing values is done with just the = operator.

Ladder logic is scanned the same as a book is read, from top to bottom left to right.

So, if you had a program with 10 rungs the top rung would be scanned first starting with the left most instruction and proceeding to the right most instruction of the rung. All subsequent rungs would be scanned the same way, and upon completion the scan would start over at the top most rung again. I say typically because most ladder programs are scanned this way however they can be event or time driven as well.

Ladder logic is but one of five standard PLC programming languages as defined by IEC 61131-3 and are as follows.

  1. Ladder Logic
  2. Structured Text
  3. Sequential Function Chart
  4. Instruction List
  5. Function Block Diagram

The RSLogix 5000 platform accommodates all the standard programming languages with the exception of  Instruction List in any combination. That is, it is possible for a single project to contain all of the different languages.

If you don’t already have RSlogix 5000 programming software you can get a free copy here.

This demo software is version 17 and is for offline programming only, which is a heck of a lot better than nothing. The demo software is good for 90 days. Follow the instructions on Allen Bradley’s website to install the software Update! The software is no longer available from Rockwell. When and if it becomes available again I will link to it from here. You can still follow along with the video tutorials. After completing this tutorial you should be able to add Rails, Rungs, Branches, Instructions and Tags.

I recently released a book on Amazon titled “Learn How to Program and Troubleshoot Ladder Logic“. If you are new to programming PLC’s grab a copy and jump start your journey into the rewarding world of controls.Book-Page-002