Академический Документы
Профессиональный Документы
Культура Документы
Table of Contents
Legal Notice ........................................................................................................................... 2
Preface ...................................................................................................................................... 3
Chapter 1 Establish a Base ........................................................................................................ 5
Rails & Rungs......................................................................................................................... 6
Understanding the logical flow of rungs .................................................................................. 8
A bit about instructions ..........................................................................................................12
Tags, an address to memory .................................................................................................15
Creating Tag Names ..........................................................................................................15
Tag Data Types .................................................................................................................16
Project Structure....................................................................................................................18
Project Tasks .....................................................................................................................18
Programs ...........................................................................................................................19
Program Routines ..............................................................................................................19
End of Chapter Review ..........................................................................................................20
Putting it all together ..............................................................................................................20
End of chapter review Questions. ..........................................................................................21
Test Answers.........................................................................................................................25
Page |1 www.LADDER-LOGIC.com
Learn Ladder Logic
Legal Notice
All rights reserved. No part of the contents of the book may be reproduced or
transmitted in any form or by any means without the written permission of the
publisher..
This book expresses the author’s views and opinions. The infomration
contained in this book is provided without any express, statutory, or implied
warranties. Neither the author, nor its resellers or distributors will be held
liable for any damages caused or alleged to be caused either directly or
indirectly by this book.
Page |2 www.LADDER-LOGIC.com
Learn Ladder Logic
Preface
T
his eBook is for anyone who wants to learn ladder logic. Whether your
goal is to trouble-shoot logic, write programs, or simply learn how to
make changes to a process, you’re on the right track. The best way to
accomplish these goals, you the future programmer/technician, must
understand the intent and architecture of ladder logic. Identifying the various
parts and pieces of a ladder logic project, and how these pieces relate to one
another is the forefront to learning the language. It’s all but impossible to
troubleshoot and write code without first being able to identify the various
components and understand the logical flow of the language.
The material in this book is not an attempt to regurgitate datasheets which are
readily available. It’s a roadmap for successfully mastering ladder logic. It’s
written by a programmer working in the field, not a technical-writer in a
cubicle collecting a paycheck. Publications churned out by corporations have a
place, and that is to provide specific information when and where it’s needed
for both technical and legal reasons. If you have unsuccessfully tried to decode
ladder logic from material like this, as I have, don’t fret it’s not your fault; the
material is dry and not intended to teach the language. Rockwell Software has
extensive libraries covering technical material. Datasheets, help files, and
programming publications are freely available. Don’t misunderstand; technical
information is necessary, but necessary when you need it. It’s not a good read
and probably doesn’t belong in a book, certainly not this one.
Page |3 www.LADDER-LOGIC.com
Learn Ladder Logic
logic takes time, dedication, effort, and practice. This eBook is an excellent
start, so free yourself from distractions and dig in.
Page |4 www.LADDER-LOGIC.com
Learn Ladder Logic
T
his book is about learning ladder logic. If you’re reading this book then
it’s assumed that you at least have a basic understanding of
Programmable Logic Controllers. If not you should.
Page |5 www.LADDER-LOGIC.com
Learn Ladder Logic
Ladder logic is similar to a ladder; you know the kind you climb. I’m not
kidding stick with me here. There are two major components two a ladder, rails
and rungs, Ladder logic is structured similarly. A ladder diagram has rails and
rungs. The rails represent the opposing polarities of an electrical circuit and
the rungs represent wires connected between the two.
Let’s back up just a little. It’s important to point out that most programming
languages are textual. That is the code is written out. Compare the following
code written in a textual based programming language with the equivalent code
created with ladder logic.
If Button_Pressed Then
Structured Text is a
Light := 1;
Else textual PLC programming
Light := 0; language.
End_IF;
The above example is a textual language called Structured Text. Note that the
code is written in a structured format. Below is the equivalent statement
written using ladder logic.
Rails
Rung
Contact Coil
Using the same rung example let’s explore how the graphical based ladder logic
programming software emulates industrial electrical circuits made up of
Page |6 www.LADDER-LOGIC.com
Learn Ladder Logic
Below is an example of how the circuit could be created with ladder logic
software. The left and right rails represent the opposing polarities of the power
source. Think of the left and right rails as the positive and negative terminals of
the battery as shown above. The rung represents the wires that connect the
components together. This rung behaves just like the electrical circuit
described above.
Note the green highlighting of the rails; this indicates that the PLC is in active
scan mode. In the first rung, only the rails are highlighted. The Switch contact
is not highlighted indicating that the Switch contact is open. The path from one
rail to the other is open resulting in the Load coil being off. In the second rung
Page |7 www.LADDER-LOGIC.com
Learn Ladder Logic
Green Highlighting is used to indicate the state of contacts, coils, and rails.
Green highlighting on a contact indicates the contact is closed; a path to the
right of the contact is present. The absence of highlighting indicates the
contact is open; no path to the right of the contact exists.
In the case of the coil green highlighting indicates the coil is on while the
absence of highlighting indicates the coil is off.
Rather than thinking in terms of If Then Else statements ladder logic can be
thought of in terms of contacts, coils and wires. Consider a contact as an input
and a coil as an output. If the contact is closed an electrical path is created via
the rung which energizes the coil. If the contact is open the electrical path is
removed and the coil is de-energized. Contacts, or rung inputs, create a logical
path that energizes coils, or rung outputs.
Page |8 www.LADDER-LOGIC.com
Learn Ladder Logic
Page |9 www.LADDER-LOGIC.com
Learn Ladder Logic
The example above is another conditional rung with two contacts. In this
scenario only one contact needs to be closed in order to create a logical path to
the output coil. This type of circuit is known as or logic. Either contac1 or
contact 2 is required to be closed to turn on the output coil. Notice that this
circuit has the same number of inputs and outputs as the previous circuit. The
only difference between the rungs is where the inputs have been placed. The
placement of contacts and coils determines the logic of the rung. The virtual
wire that connects Input_2 to the rung is known as a branch. The inputs of this
circuit are in parallel while the inputs of the previous and logic circuit are in
series.
P a g e | 10 www.LADDER-LOGIC.com
Learn Ladder Logic
The above rung is a conditional rung with two contacts and two coils. Notice
the contacts reside on the right side of the rung, but still left of their respective
output coils. If contact 1 is closed, Output_1 coil is on. If contact 2 is closed
Output_2 coil is on. This rung has two circuits in parallel. The circuits are
independent of one another; therefore the rung has two possible outputs.
Recall that the previous rung contained a branch that was described as or
logic. Would this rung be described similarly? Not necessarily, because the
output coils are not part of or logic in respect to the input contacts. Observe
the Output_2 coil; it turns on only when Input_2 is closed, not Input_1 or
Input_2. Output_1 behaves similarly with respect to the Input_1 contact.
Once again, determining the logic of the rung is all about where contacts and
coils are placed. When determining the rung output remember the logical flow
is always from left to right or input to output. Incidentally the flow is always
from top to bottom as well. That means that Input_1 and Ouput_1 are solved
before Input_2 and Output_2.
The above rung looks similar to the previous rung with the exception of the
first conditional contact. Adding this contact creates two and logic circuits.
The two circuits still act independently in respect to one another.
Circuit 2 – Input_1 and Input_3 must be closed in order to turn on Output_2 coil.
P a g e | 11 www.LADDER-LOGIC.com
Learn Ladder Logic
The above rung may be confusing and seem to break the left to right rule at
first however it can also be broken down into two logical circuits.
Again the input is always on the left in respect to the output of the circuit.
Complex rungs like the one above can be broken down into individual circuits
to decipher the appropriate logical flow to the outputs. As a side note rungs
written like this are completely legitimate and completely confusing. There are
several ways to write this circuit that would cause less confusion. Can you
think of any?
RSLogix 5000 has numerous symbolic instructions from very simple to very
complex. You can even create your own custom instructions called Add On
Instructions. Instructions define logical statements. Let’s take a look at a basic
instruction called the Examine If Closed or XIC instruction. Think of an XIC
instruction is a contact; it’s either open or closed. When the contact is closed a
path is created and “current” is allowed to flow from left to right through the
contact. When the contact is open the path is removed removing “current” flow
through the contact. Take a look at the rung below.
P a g e | 12 www.LADDER-LOGIC.com
Learn Ladder Logic
When the input contact (XIC instruction) is closed a path is created allowing
“current” to flow to the output coil. In a real electrical circuit the contact might
be a mechanical switch/button which is closed with a hand. The action of
closing the switch would allow electrons to flow through the circuit resulting in
the output, maybe a light, turning on.
In an electrical circuit the contact and coil are real devices, something which
can be mechanically triggered. In the ladder rung circuit the
contact and coil are symbols. So, how does one press a symbol,
or turn a virtual coil on?
The XIC instruction checks the Operand for its value. If the value is one the
XIC is “closed” and a path is created allowing “current” to flow to the output
coil. If the value is zero the XIC is “open” removing the path of “current” to the
output coil.
P a g e | 13 www.LADDER-LOGIC.com
Learn Ladder Logic
The table below shows the XIC and OTE instructions displaying both possible
states. The XIC instruction has an operand named XIC_Argument and the OTE
instruction has an operand named OTE_Argument.
Instruction
Operand Name Graphics Value Alternate Name
Instruction
Operand Name Graphics Value Alternate Name
In order to fully understand the language it must be broken down into logical
components. An instruction is a graphical symbol that instructs the PLC to do
a specific task. In the case of the XIC instruction that task is to check the value
of the associated argument. In the case of the OTE instruction that task is to
set the value of the associated argument.
P a g e | 14 www.LADDER-LOGIC.com
Learn Ladder Logic
RSLogix 5000 software requires users to define tags. Tags are addresses to
memory locations. Picture this, somewhere in the deep dark depths of the PLC
exists a vast array of empty warehouses. These warehouses are memory banks,
one after another, as far as the eye can see. Their sole purpose is to store data.
Accessing these memory locations is simple. All you need to do is create a tag.
To create a tag you simply give it a name and define the amount of memory the
tag will access. The software automatically associates your new tag name to a
spot in the warehouse of memory. To access this memory simply use the tags
name. Easy.
For instance, suppose you were writing a program that required a door to be
closed in order for a process to start. Your job is to give descriptive names to
tags. What would you call them? You could name it after your nephew,
girlfriend, boyfriend, or dog. What if you could give it a descriptive name that
makes your code more readable? Look at the following examples, which one is
more readable rung -1 or rung-2?
Obviously rung-2 makes much more sense, it’s more readable. If the door is
closed then go ahead and start the machine. Rung-1 is the exact same logic as
Rung-2 however what is the objective of the rung? Why did the programmer
write the rung? The logic does the same thing as Rung-2 but because the tag
P a g e | 15 www.LADDER-LOGIC.com
Learn Ladder Logic
names are irrelevant to the logic who knows what the rung is supposed to
accomplish.
Believe it or not programmers do this all the time. Take this scenario for
example. Alexander works the night shift at the bubble gum plant. The bubble
gum expander machine locks up and won’t run. Alexander, being the savvy
programming type, opens up the program and adds an XIC instruction. All
good, but rather than creating a tag that makes sense he uses his name.
To him this made sense, think about it, if anyone needed to see what he had
done they could simply search for his name and they would surely be
impressed by his witty contribution to the bubble gum expander. In reality
Alexander just made the code hard to read. Don’t be an Alexander, make your
code readable.
In all the previous rung examples the XIC and OTE instructions used are
binary. They have two states, on and off. Another way of saying binary is
Boolean. According to Google the definition of Boolean is: a binary variable,
having two possible values called “true” and “false”. Incidentally a binary
instruction will only accept binary arguments (tags).
P a g e | 16 www.LADDER-LOGIC.com
Learn Ladder Logic
RSlogix 5000 has several native data types which are referred to as Atomic
Data Types. The software has numerous instructions that require operands of
one or more of the following data types.
P a g e | 17 www.LADDER-LOGIC.com
Learn Ladder Logic
Project Structure
Now that you have a better understanding of how the code components of the
language works let’s take a look at an overall project. Specifically where does
the code reside and why? What initiates code execution?
Code and tags make up programs. A program is nothing more than a set of
instructions that execute step by step. RSLogix 5000 has a hierarchy type of
organizational method.
Project Tasks
Programs are assigned to tasks. A task is nothing more than a way to schedule
programs. Every program needs a mechanism to initiate the execution of logic
contained in the program. There are three types of tasks available, the
Continuous Task, the Periodic Task and the Event task.
Continuous Task
The continuous task is initiated when the processor is placed in run mode.
Programs assigned to the continuous task will execute from start to finish.
Once a program in the task completes it immediately starts again.
Periodic Task
A periodic task is triggered at a user selectable time. Programs in this task are
triggered first when the processor is placed in run mode, then at the selected
interval. If the interval is set to 100 milliseconds and the program assigned to
the task takes 10 milliseconds to execute the program will not run again until
the 100 millisecond time interval has expired.
Event Task
An event task is triggered from an event. The event is selectable; it can be
triggered by an instruction, from an input, consumed tag, or motion
operations. In other words there are plenty of selectable triggers to start a
P a g e | 18 www.LADDER-LOGIC.com
Learn Ladder Logic
program. Once a program has completed its execution it waits for another
trigger to start again.
Programs
Programs are nothing more than a logical group of components. These
components are code, variables, and routines. Refereeing to a program is
referring to a group of components with the same schedule (task). A single PLC
can have multiple programs. Each program can operate independently or in
conjunction with one other.
If a program already exists that controls a process why create a new one?
Simply import an existing program into a new project. Placing code in
programs makes the code portable. It can be transferred from one process to
another with little or no modifications if it was written and grouped correctly.
Program Routines
Routines serve several purposes they can up a program, make it more
readable. They can give sections of code that ability to be conditional. They can
be used to pass parameters allowing code to be called again and again
crunching different data. This can make code smaller and is covered in later
material.
It’s possible to write an entire program in one routine although not advised.
Every program has at least one routine, the main routine. It is executed
unconditionally, meaning it is called when the program is triggered. All code in
the main routine is scanned when the program is triggered.
P a g e | 19 www.LADDER-LOGIC.com
Learn Ladder Logic
When a rung is scanned it is done so from top to bottom, left to right never in
reverse. A single rung can have multiple circuits or outputs. The output of a
rung is dependent on the placement of instructions and branches.
PLC projects are made up of at least one program scheduled in one task. The
code is made up of various components dispersed in logical routines.
These basic components serve as the base of ladder logic. As you will soon
discover there are more complex instructions and tags. Some instructions are
dedicated to managing program flow rather than manipulating data. Tags can
get more complex with aliasing, arrays, and visibility. The important thing to
remember is that regardless of the complexity of the components they all follow
the same basic rules.
P a g e | 20 www.LADDER-LOGIC.com
Learn Ladder Logic
a) H
b) F1
c) F
d) CTL + H
P a g e | 21 www.LADDER-LOGIC.com
Learn Ladder Logic
9. Using the following input tag values, find the values of the tags
referenced to the OTE instructions.
a) Tags
b) Rungs
c) Routines
d) Programs
P a g e | 22 www.LADDER-LOGIC.com
Learn Ladder Logic
12. There are ____ different types of tasks available for scheduling
programs.
14. Every program has a default main routine which is triggered when
the program is run. How are subsequent routines called?
P a g e | 23 www.LADDER-LOGIC.com
Learn Ladder Logic
P a g e | 24 www.LADDER-LOGIC.com
Learn Ladder Logic
Test Answers
1. True, PLC’s can run multiple programs scheduled in a continuous,
periodic or event task.
2. b) F1 key. Highlighting an instruction and pressing the F1 key will bring
up a context sensitive help file. Use it.
3. False, Ladder Logic is a graphical based programming language, unlike
popular PC based programming languages such as Java and C++.
4. d) A rung with an output instruction only. Note the question asked which
selection best describes an unconditional rung. An unconditional rung
could have several outputs.
5. a) Left to Right.
6. b) Right. Outputs will always be right of their respective inputs.
7. a) An OTE instruction is an output instruction that sets or clears data
addressed by an associated tag.
8. True, an XIC or Examine If Closed instruction examines the data of the
operand or tag.
9. Output_1 = 1, Output_2 = 1, Output_3 = 1, Output_4 = 1, Output_5 = 0
10. a) Tags
11. b) Address
12. Three available tasks. Continuous, Periodic, and Event.
13. False, multiple programs can be scheduled in each task.
14. b) With a JSR or Jump To Subroutine instruction.
P a g e | 25 www.LADDER-LOGIC.com