Professional Documents
Culture Documents
A Programmable Logic Controller (PLC) is a specialized computer designed to interact with machinery.
They are ideally suited for performing repetitive, predictable operations. Typically, PLCs are designed to
endure harsh environments, and perform instructions within tight time constraints.
1. Inputs: Tell the PLC about its environment. They connect to temperature sensors, position
detectors, limit switches etc. Gathering environmental data from inputs, PLCs decide what actions to
take.
2. Outputs: Tell things what to do. Outputs may instruct motors to go to a position, a valve to open or
a door to lock.
3. Connections to Other Electronics: Many PLCs include communication ports including USB, Ethernet,
RS485 and RS232. These allow the PLC to talk to other PLCs, PCs, barcode scanners, Operator Panels
etc.
1. Inputs: Connected to temperature sensors in Egg and Butter chutes, Position detectors
monitoring when the bowl has reached station, scale under bowl confirming correct amount of
ingredients have fallen from chutes.
2. Outputs: Connected to motor that moves conveyor belt, refrigeration unit in Egg chute,
warming unit in Butter chute, actuator that causes chutes to open/close, and motors that drive
the mixer.
3. PLC: Using the temperature inputs, it decides when to turn on refrigeration/warming units.
Position detectors and scale under bowl are used to determine when to advance the conveyor,
and when to lower and turn on the mixer. Along with doing the routine, the PLC will provide
error warnings when things go wrong, so an operator can investigate.
Connections to Other Electronics: An operator panel could show the operator current status of
the cookie batch, as any errors that have occurred. The PLC may also be connected to the
buildings Ethernet system, so a manager can monitor progress from a remote office.
4. Reliability: PLCs often control highly critical devices, and as a result they are built to be reliable.
5. Harsh Enviroments: They are designed to endure temperature extremes and vibration.
6. Real Time: They dont have the luxury of crashing occasionally like PCs do. Also, they must
perform operations at precise times(something that isnt standard with many PC operating
systems).
Backplane Based: Consist of a CPU, a Backplane (also called Rack) and IO Cards that slide into the
Backplane.
Bricks (Non-Backplane Based): Have CPU and IO built into them. Often, you can connect additional IO
to their sides.
Programmable relays: Low end modules with built in screen and buttons used for programming.
They connect a CPU to IO and are available in different sizes to accommodate IO requirements.
Backplanes add expense to a system, while often adding little additional functionality. In some cases
they allow for components to be hot swap-able. Because of the considerable expense, many PLC
manufacturers are moving away from Backplane Based systems in favor of Brick systems.
In Brick based system, like the one to the right, each brick has connectors on its left and right that allows
CPUs and IO to connect.
In this example: leftmost is a power supply, then a CPU with built in IO, followed by 6 IO units.
Wiring PLCs
1. Physical Connections
Most PLC connections involve connecting to something like the terminal block shown on the right.
Slide the wires into the slots on the bottom, and using the screws found on top, you secure the wires.
Some connectors are like the one shown, and disconnect from the PLC, while others are fixed to the the
PLC.
This kind of connection is common for Inputs, Outputs and power supplies.
2. Internal Connections
The inputs and outputs of PLCs are connected internally in 1 of 3 ways: Relays, Source or Sink. PLC
manufacturers often produce all 3 versions, so you can select the version that best fits your application.
Below are descriptions of each variety and what their advantages/disadvantages are.
Switch. It represents an input. Could be as simple as a light switch that youre monitoring to see if its
on or off.
Juggling balls. (just kidding) Connections. They are the physical connections to the PLC discussed at the
top of this page.
PLC. This just tells you where the PLC fits into the equation. Everything inside the dashed box happens
inside the PLC.
Power Flow. Shows which direction power flows through the circuit.
Commons
In order to increase IO points on PLCs without increasing the number of connections, Commons are
used. The picture to the right shows an example of what the wiring of a PLC with 4 inputs would look
like. In the picture Without Common, the green points all lead to the same voltage source. Commons
take advantage of this frequent situation, grouping one side of connections together. In this case we go
from requiring 8 pins to requiring 5 pins, with no loss of functionality (assuming you wanted them tied to
the same sources). Commons are used in Relays, Sink and Source Circuits.
Relays
Relays are the simplest Connection type. They act like light switches that are turned on or off by the
PLC. They physically connect/disconnect 2 pins on the PLC.
Advantages: Use for both AC and DC connections, handle higher current than Source/Sink models.
Disadvantages: There are 2 kinds of Relays, Mechanical and Solid State. Mechanical involve moving
parts, and thus have a limited lifespan. Solid State have no moving parts, but are very expensive.
Source & Sinking is used exclusively with Digital DC circuits. If the common pin is + polarity, its called a
sourcing circuit. If its polarity, its called a sinking circuit.
Advantages: No moving parts, so lifespan is long
Disadvantages: No AC support. Cant handle significant current.
Think of PLC memory as a cabinet with drawers called Registers. Data is held in these Registers.These
Registers come in different sizes, and hold different kinds of data.
Bits: Can have values 1 or 0. 1 typically represents On while 0 represents Off. Bits are the building block
for all other types of data.
Integers: Whole numbers (no decimal points). Called: Characters (char), Integers (int), long Integers
(long int) or Words. Look for the bit size and whether they are signed or unsigned. Unsigned are
positive numbers, while signed are positive or negative.
Floating point numbers: Numbers with decimal points, and can be positive or negative.They are called
floating point numbers (Float), with their larger variety called double floats.
Bit 1 0 1
Unsigned 0 255
Unsigned 0 65,535
Unsigned 0 4,294,967,295
Addresses/Tags: The Registers are all stacked side by side in the PLCs memory. Each location has an
Address that lets the PLC know what data youre talking about. Older PLC software requires the user to
refer to data by this Address (example x1023 could mean the 1023d register). Some newer software
makes the Addresses transparent. The user gives a piece of data a name (example
Oven2Temperature), and the PLC keeps track of where the register is located. If the software uses
Addresses to refer to data its called Address Based, if it uses named data its called Tag Based. Some
programming packages are Address Based, but allow Addresses to have Nicknames or something
similar. Their benefits over standard Address Based systems tend to be limited. Advantages to Tag based
systems become evident as programs grow, and remembering whats stored in x1023 becomes difficult.
If your program is going to have any complexity at all using a Tag Based System simplifies the design.
Diving Deeper
Inside the Data Types: As stated earlier, all Data Types are made of Bits (1s and 0s). An 8 bit number is
written like bbbbbbbb (where b can represent a 0 or 1), so you may have 00000000, 11111111 or
01011110. any combo will do. What these Bits mean is determined by the Data Type.
Unsigned Integers: The least valuable bit is the rightmost bit and double in value each position you move
left. The right-most bit is 1 its worth 1 next bit to the left 2 4 8 16 32 64 128 256 (this goes on
for as many bits as the Data Type calls for). Heres what is looks like for an Unsigned 8-bit Integer:
Signed Integers: Theyre a tad more complicated check out wikipedias article on 2s compliment for a
good explination.
Hexadecimal Format (Hex): Instead of writing every bit out, it is common to group sets of 4 bits
together. Each group can have a value of 0 15, which causes a problem since our number system goes
from 0 9, so we also use A, B, C, D, E and F to get a total of 16 values. (0, 1, 2, 3, 4, 5, 6, 7, 8, 9 , A, B, C,
D, E, F)
Characters: (typically 8 bit unsigned integers) are often used to reprent letter or symbols. Example: you
may use them to display text on an operator panel. Use an ASCII table to see how values are mapped to
symbols.
What about the bits in Floating Point numbers, how do they break out? It gets a bit complicated, I dont
really want to get into that in this tutorial. It is unlikely as a PLC user that you will ever need to know
how their bits translate to values, so dont worry about it.
PLC Math
This page assumes you understand the principles discussed on the Data Inside PLCs page.
The Basics
Addition, Subtraction, Multiplication and Division are what youd expect. If you havent done math in a
programming language before, there are a couple of things you should be aware of.
Overflow: Integers and Floating Point Numbers have size limits. When you go beyond their size
youll cause yourself problems.
Example: 8 bit Unsigned Int with value 255 in bits looks like 11111111. If we add 1 to it we get
100000000. There isnt storage for a 9th bit, so were left with 00000000 or 0. So in this case
255 + 1 = 0
Another Example: 8 bit Unsigned Int with value 0 in bits looks like 00000000. If we subtract 1 to
it we get 11111111. So, we can get the opposite problem 0 1 = 255
Rounding: Floating Point numbers arent perfect. For this reason, you shouldnt check to see if
Floating point numbers are equal to a value, you should check to see if its within a range of
numbers.
Example: 2 * 3 performed with Floating Point numbers may not result in exactly 6.
It could be 5.9999999999998 or something similar. So instead of asking is Example = 6, ask is
Example greater than 5.9 and less than 6.1. Dont worry about how to ask these questions, well
talk about that later in the tutorial
Boolean Math
Some programming packages allow bit manipulation by using Boolean Math. The main operations are:
AND (symbol &): A = B & C. If both B and C are 1, then A is 1. If either B of C are 0, then A is 0.
The most common PLC programming language is Ladder Logic. They consist of a series of electrical
drawings that control how the PLC functions. Well go through the basics of Ladder Logic starting with
Coils and Contacts.
Contacts stand between power and Coils, asking questions. If the answer to the question is true, then
power is allowed to flow through the contact, if not the path is blocked.
Note: Were about to use the & (AND) and | (OR) symbol. They are discussed on the Math page.
Coils
Each Coil is tied to a specific Bit of data. Here are the standard Coil Types and what they to the specified
Bit.
Out: If the Coil is powered, the bit is assigned a 1. If not its assigned a 0.
Set: If the Coil is powered, the bit is assigned a 1. If not, the value remains whatever it was.
Reset: If a Coil is powered, the bit is assigned a 0. If not, the value remains whatever it was.
Contacts and coils are often associated with the physical Inputs & Outputs on the PLC.
If a contact is tied to an Input, then when the power at the input changes its contact value in the Ladder
Logic will Change. If a coil is tied to an output and the coil changes its value, then the voltage (or
contact state) at the output will change.
Functions: As Ladder Logic has evolved, additional functionality has been added. In many Ladder Logic
packages the Coil location can be replaced by function blocks that do specific tasks.
The Math function has already been discussed. The tutorials that follow focus on other common
functions.
Counter
Timer
Drum
Ramp
Filter
PID
Loop
Subroutine
# of
Source Destination What Happens
Bits
= Data is copied.
< Source is copied into lower bits. Upper bits are typically left in their
previous state. Verify with PLC manual.
Unpack functions copy an integers individual bits into specific bit registers.
Why : An integer may represent many On Off values and now you need to break them out
Rotate functions rotate bits within an Integer Register. There are typically 2 options:
Rotate Left:
Rotate Right:
What value would you like shifted in? This can be a fixed value (0 or 1) or may come from a
register.
Shift Left:
Shift Right:
PLC Counters
Counters keep a tally of things. They come in 3 varieties:
Up Down Counter: Has 2 inputs, One input causes count to increment, the second input causes
the count to decrement.
Turnstiles found at stadiums are good examples of Up Counters. Every time a person enters a count
increases. This count may represent the number of tickets redeemed.
If an entrance turnstile was combined with an exit turnstile, they would form an Up Down Counter, and
could be used to know how many people were inside the stadium at any given time.
Counters often allow users to set targets that set specified bits when the targets are met.
Example: The fire department may only allow 10,000 people in your stadium at any given time, so you
set a target of 10,000. When the target is met, a bit controlling a light, seen by the turnstile attendants, is
set This tells the attendants that capacity has been reached and that they cannot allow additional
patrons to enter. A lower target of 0 could be set up and used at the end of the event to verify that all
patrons have exited the building.
PLC Timers
Timers wait a set duration of time then do something. An input tells the timer when to start timing.
While timer may be explained differently depending on the PLC line youre working with, well go over a
good solution, knowing other solutions will follow similar concepts:
Duration (also called time-delay) defines the amount of time to wait before doing something. (1
internal integer)
Timer Value keeps track of how much time has passed since timing began. (1 internal integer)
On Timer waits a Duration after an Enable input goes high before turning the Timer Bit on. The Timer
Bit goes low when the Enable input goes low.
On Timers may have a Cumulative Timer options. If so, you can specify whether you want the Timer
Value to reset when Enable goes low.
Off Timer causes Timer Bit to go high when an Enable input goes high
and keeps it high for a Duration after the Enable input goes low.
PLC Drum
Drums are a great tool when youve got a simple sequence of events that need to occur at set time
intervals or as a result of predefined events.
Time Sequenced Drums turn bits on or off for set amounts of time. Below is one such drum.
Time that bits are held for is listed on the left side of the chart.
Bits that are turned on or off are listed on the top of the chart (A, B, C, D, E & F).
The sequence starts on from the top (the 9 second interval) and works its way down.
If this Drum were turned and left on it would operate for 54 seconds (9+15+5+7+6+12).
Lets look at what happens during those 54 seconds. The * indicates that all values not mentioned are
held at the value they had in the previous time interval:
Some drums have a Continuous Mode option that causes the Drum to start over after it has reached the
end of its sequence.
PLC Ramp
Acceleration Input
Deceleration Input
In this example we see that:
Output remains steady nothing when both Acceleration and Deceleration Input are low or high.
Though not obvious in this example, Acceleration/Deceleration Rate controls the steepness of
the rise & fall in output value.
Now lets look at a more sophisticated Ramp. Well add the following options:
Soft Start Time (Integer or Float) typically measured in ms. This is the time taken to transition
from steady state to Acceleration/Deceleration Rate. This can reduce the stress on motors.
I
n this example we see:
Once the Maximum is reached, the Output quits Rising, even when the Acceleration Input is
High. Similar behavior would occur for Minimum if it were included in the example.
Including Soft Start Time lengthens the amount of time it takes to reach a value.
PLC Filter
Filters help to clear noise from signals. They are often used to clean up Analog Inputs.
To accomplish this, they take the input signal value and average it with past values.
Weight is how much influence you want past values to hold. Higher numbers place more
importance on past values. Weight must be greater than 1.
With Filters, its a balancing act, where these considerations must be balanced to arrive at an ideal
Weight for your situation.
One option that isnt in the equation but matters a great deal: The frequency samples are taken. This
will effect how fast the Filter responds to changes in amplitude. In this example we took 36 samples for
the single wave.
For those of you who would like to see some numbers, here they are for the example above:
PLC PID
PID controls are used to bring things to a desired level. Maybe its the temperature of
a liquid or the speed of a motor. Using the PIDs 3 components (Proportional, Integral & Derivative),
users can adjust how quickly and cleanly a desired level are achieved.
Example: Lets say weve got a pot of water on a burner and want to bring it up to 90C quickly, without
overshooting the temperature by more than 1. How would you do this? Youd probably turn the burner
on high until the temperature gets within a few degrees of 90, then scale back the burner so the
temperature rises slower to prevent overheating. This scaling back the burner would likely happen in
several stages until you reach a steady 90. A PLC could do this process for you using PID. First a couple
terms:
Set Point: 90C. The value were trying to reach and hold
Input (also called Process Variable): the water temperature. What were trying to get to the Set
Point.
Output (also called Control Variable): the Burner. What we adjust to reach our Set Point.
Error: the difference between the Output and the Set Point.
So, PIDs watch Inputs to decide how to change their Output to reach the Set Point.
Proportional: Looks at the present. It uses the current error to determine Input. Typically it is in charge
of most of the error reduction.
Integral: Looks at the past. It uses a sum of past errors to eliminate long term error.
Derivative: Looks at the future. Trying to predict where the signal is going, it can be used to prevent
both overshooting Set Points and output ringing.
Instead of going into detail on this subject, we point you to a great article written by Tim Wescott on the
subject: PID without a PHD.
PLC Loop
Loop specifies the number of times a section of Ladder Logic should be performed. It is placed
just above the section you would like repeated.
o If the loop hasnt been performed as many times as specified in the loop instruction, it
will jump to the first rung inside the loop.
o If it has performed the maximum number of times, the loop will end and the program
will jump to the first statement after the loop.
Break forces the loop to end. The program will jump to the first statement after the loop.
Loops must always have 1 Loop statement and 1 Next statement. They dont need to have a break
statement, but may have several if desired.
PLC Subroutine
Subroutines improve Ladder Logic code re-usability and readability. They do this by allowing you to
break apart your code into manageable pieces. Subroutines can then be used multiple times inside a
program and easily brought into new programs.
2 routines envolved:
Calling Routine: the routine requesting a Subroutine to run. It can be the main program, or
another subroutine.
Subroutines act as a separate Ladder Logic that can be called whenever needed. Many times youll need
to provide it data from the calling routine. To do this, you setup input Tags for the Subroutine that will
receive data from the Calling Routine. Wherever you call the Subroutine you match up the Tags you
want to pass from the Calling Routine to the Tags in the Subroutine that will receive the data. Passing a
Tag can be done in 1 of 2 ways.
Pass by Value: is a 1 way street for data to go From the Calling Tag to the Subroutine Tag. The Calling Tag
will be unaffected by the pass.
Pass by Reference: is a 2 way street. The Calling Tag passes the Subroutine Tag its value. When the
Subroutine Returns, the Subroutine Tag passes the Calling Tag its value.
Example:
Heres the order what happens in a subroutine:
4. Data passed by reference is passed from Subroutine Tags to Calling Routine Tags (optional)
5. The Calling Routine continues with the rung that follows the Subroutine Call.
Inside the Subroutine you must have at least 1 Return statement. This tells the Subroutine to return to
the Calling Routine. It is possible to have more than one Return statement, if you need more than one
thing to trigger a return.
Often it is possible to use Tags inside the Subroutine that come from the Main Program without passing
them. This is using Global Tags. While this is allowed, they will make your Subroutine less re-usable. If
you want to bring the Subroutine into another project it will be necessarily that the project has all the
Global Tags used in your Subroutine(s).
A word of caution: PLC makers describe a range of functionality as Subroutines, while often missing key
elements. On our sister site PLCCompare.com you can find our assessments of which PLC lines provide
true Subroutines.
Continue?
So, youve finished this tutorial and want more. Here are a few suggestions on where to go next.
Check out our sister site PLCCompare.com to get a feel for differences between PLC Lines. Each product
has its own page where you can find further information including free software downloads (if they
exist), brochures and online vendors to purchase from.
You could pick up an inexpensive PLC to get started. You can find a high quality, cheap PLC from
Velocio.net. Otherwise, Automationdirect.com offers some decent, inexpensive PLCs. If you need to
stick with Rockwell or Siemens, you can easily pick one up form PLCCenter.com, PLCHardware.com or
EBay without the hassle of dealing with a local rep.
There are some good forums out there. PLCTalk and MrPLC are 2 of the best.
Tim Young has some nice product specific walk-throughs at PLC Dev