PLC Programming Using RSLogix 500
PLC Programming Using RSLogix 500
Preface
Communication with SLC 500 Processors
Protocols
DF-1, Full & Half Duplex
DH-485, the Data Highway protocol
DH Plus protocol
Ethernet & Ethernet/IP
Communication Channels Chart
Adapters, Cables & Drivers Chart
Step-by-Step Configuration
Hands-On-Exercise
Specialized “Action” Instructions
The OTL & OTU
The OSR – “One-Shot-Rising”
The RTO – “retentive” timer
The CTU & CTD
Cascading Timers & Counters
Using the RTO
Math Instructions
Using Math Instructions & F8 Data
The Status File
Instruction program example
Advanced Math Instructions
Analog Scaling Instructions
Definitions & Terms
The math of linear equations.
Using the SCL & SCP
Analog Output Modules
The PID Instruction
Using Comparison Instructions
The GEQ, LES, GRT, LEQ
The LIM: “limit test”
The MEQ: “masked equal”
Concluding Comments
Preface:
In my previous book, “Basic Concepts of PLC Programming”, I focused
on many of the basic programming instructions, concepts, and their use in
ladder logic programs. These instructions included the (XIC), the (XIO),
and the (OTE) - including the (OTL) latching and (OTU) unlatch
instructions. Also covered, were “timer” and “counter” instructions, the use
of the “OSR” or “one-shot-rising” instruction, and the MCR instruction.
These will also be shown by example and covered in more detail in this
book, since they are the principle building blocks of any ladder logic
routine.
In “Advanced Concepts”, we will look into the use of many other
“specialized” instructions, such as the (RTO) “retentive timer”, the use of
the (RES) “reset” instruction, and “counters”, which are also utilized in a
wide array of applications. Also in the following chapters, we will discuss
“register type” instructions that accomplish functions such as data
comparisons or manipulation, by using entire “words” of data, either 16 or
32 bits. I’ll also cover the basic math instructions that can be used in
“scaling” for analog values, and some discussion on instructions that
provide program flow to subroutines.
Hopefully by this time, you’ve reached some degree of a “comfort zone”
in addressing the instructions we talked about in the “Basics” book. In this
second book I’ll not spend much time covering those topics again unless it
is to focus on some variation not covered by the “syntax” chart included in
the first book.
The focus for this volume should accomplish the following objectives:
To understand the use of “RSLinx” drivers and basic communication
protocols.
To understand fully the use of “timers” – the TON, TOF, RTO and the
use of the reset (RES) instructions.
To understand the use of “counters” – the CTU and CTD, and the way in
which “counters” and “timers” are often “nested” together to develop a
specific time-base for scheduled maintenance or other process related
issues.
To understand the use of the math instructions: ADD, SUB, MUL, DIV
& DDIV.
One thing I have decided to include, and in fact begin in the following
chapter, is a brief discussion with examples on using RSLinx and its
related communication protocols, drivers and physical media.
Communication between your interface devices, such as a laptop, can
sometimes be a troublesome issue. So I think it’s important to address
the whole issue of connectivity at the beginning of our programming
experience. I’ve also included the “driver & cable” chart that was
shown in book 1, simply because it’s a good reference to have handy,
and has worked well for me.
RSLinx & SLC 500 Communications
The SLC 500 family of processors is basically composed of the following
models: the 5/01, 5/02, 5/03, 5/04 and the 5/05, although I seldom see
5/01’s or /02’s anymore. Still, the 5/03’s and newer are still very much in
use, and in my opinion, a good programming tool for many applications.
Each of these employ one or two different “channels” where the interface
device cable may be connected. The communication channels are slightly
different from model-to-model so it’s necessary understand the different
Allen-Bradley communication protocols used for each model of processor.
The 5/01 and 5/02 had only a single communication channel, while the
5/03, 5/04, and 5/05 have two channels designated channel 0 and channel 1.
Following are the basic Rockwell Automation /Allen-Bradley
communication protocols, and a brief description of each. Then we can
consider the channels and their default settings for these five different
processors. As you will see, these same communication protocols are used
with other Allen Bradley processors, such as the PLC-5 models, the
Micrologix processors, and also the ControlLogix and CompactLogix
processors which use the RSLogix 5000 application software.
Understanding the difference between a “protocol”, and the language that
surrounds the descriptions of “physical media” wiring and connection
types, can at times be confusing because many of the terms are used
interchangeably. For example, someone may simply say that they are using
a RS-232 driver, but technically this refers to the physical media rather than
the drivers or protocol – which would be the DF-1. Therefore, it’s a good
idea to at least define what a protocol is, because it may work with several
different types of network connections and wiring. A specific processor
channel may work with several different drivers and configurations as well.
Protocols:
A communications protocol is simply a set of established rules for
exchanging data between computers or other electronic devices, such as a
PLC processor. These rules define details pertaining to the syntax used,
data and addressing formats, types of flow control, sequencing and size of
the data frame, error detection, acknowledgements, time-out periods, and
many other important details.
Physical characteristics of networks, on the other hand, will be designated
as RS-232, RS-422, RS-485 or Ethernet. Perhaps more importantly, these
network types will be defined by those standards which specify different
physical characteristics in terms of voltage, wiring, the number of “nodes”
or devices that can be accommodated, the length of cable runs, as well as
the speed and throughput of data transmission.
To illustrate the physical context of the RS-232 standard (EIA/TIA-232);
it defines the voltage levels for what will be interpreted as a logic “1” and
“0” during data transmission. The specified voltage range for a logic “1” is
a voltage pulse between negative (-3) and negative (-25) volts; a logic “0”
voltage is between (+3) and (+25) volts. Protocols are designed to work
with each of the physical characteristics defined by these standards. The
channel connections Allen Bradley builds into their processors are
configured to work with the following protocols:
DF-1 Protocol:
This protocol supports the EIA/TIA-232 standard. For this reason it is
usually thought synonymous with RS-232 and serial communication, and
supports data transmission rates of up to 19.2K baud, or 19,200 bits/s. It
supports “full-duplex” peer-to-peer communication, sometimes referred to
as “point-to-point” where two devices can communicate simultaneously,
and also “half-duplex” communication where devices take turns sending
and receiving data in a master / slave type of network.
DH-485 Protocol:
This is Allen Bradley’s “Data Highway” protocol, and is used for RS-485
communication (EIA/TIA-485). Once again; just as with RS-232, the RS-
485 standard defines the physical characteristics detailing wiring media and
other electrical properties.
The DH-485 protocol is designed for use with the RS-485 standard. A
DH-485 network is a LAN (local area network), designed for multi-point
connections, and used in industrial applications where electrical noise may
be a problem. These networks allow connection of up to 32 nodes or
devices, such as PLC controllers, HMI’s and personal computers. As such,
this protocol uses a multi-master, token-passing scheme which allows all
the devices on the DH-485 network to have a turn in sending and receiving
data. This protocol supports baud rates of up to 19.2K using Beldon 9842
or 3106A cable with RS-485 specifications.
DH Plus (DH+) Protocol:
The DH+ protocol is used with the PLC-5 family of Allen Bradley
processors and also the SLC 500 model 5/04. It is similar to the DH-485
with the exception that it will support up to 64 nodes or devices per network
and communication baud rates increase to 57K, 115.2K and 230.4 K.
Physical media is Beldon 9463 wiring sometimes referred to as “blue hose”
wiring.
Ethernet & Ethernet/IP Protocol:
These use standard TCP/IP protocol common to industrial networks,
operates at a data rate of 10 Mbps (10 Base-T), and can support a much
larger number of individual devices than the DH-485 or DH+ networks.
Once again, the SLC 500 processors are set up to operate with these
“default” protocols and are equipped with the “physical” connection point
to accommodate these types of networks. Here is a listing of the SLC 500
processors and their default channel configurations.
Now we will look into the steps of starting RSLinx, and selecting the
appropriate protocol and configuration for communication with a SLC-500
processor.
Generally; I first start RSLinx and establish a communication link, then
start the RSLogix 500 application software and go “online”. However, you
can often do this directly from the RSLogix application software. It will
start up RSLinx and allow you to choose the network processor, or the PLC
if you are directly connected for point-to-point communication. Starting the
RSLinx application first, is simply how I was taught, and so I continue to
use the same steps today whenever connecting to an Allen Bradley PLC or
PanelView. It allows you to know quickly if communication can be
established with a processor; and so for SLC-500, PLC-5’s, Micrologix,
ControlLogix, CompactLogix, Panel Builder 32 and Factory Talk
applications, I still start-up and link with RSLinx before starting the
application program.
At times a driver has been left in the configuration menu when RSLinx
was “closed”, I’ve found it is usually best to “stop and delete” existing
drivers from the configuration menu - and start from a “clean slate”. This
tends to be an advantage in avoiding port conflicts and such.
Also note that since most laptop computers no longer include a built-in
serial port, it is often necessary to use one of the USB ports that are now the
standard. The USB adapters listed in the following chart work well for DF-
1, DH-485, and DH+ applications. They require drivers to be installed
which are included with the RSLinx software, as well as the installation
disks that come with the adapters.
The following Cable & Adapter Chart is a listing of the cables and the
adapters which I routinely use to communicate with different Rockwell
Automation products. I stopped using the PCMK cards because it seemed
that the cards, software, or cables would always be changing, and they were
fragile at the cable connection point into the laptop. Therefore the PCMK
category is not shown on this listing. I just believe these are better options.
Step-by-Step Configuration:
Here are specific steps for connecting with a SLC-500 after starting
RSLinx. Shown below, is the initial RSLinx start-up screen showing the
dropdown from the Communications Tab. If you are using a desktop
computer in a centralized location, and have already established
communications with a network, you could select the “RSWho” option.
The RSWho option will populate a dropdown organizer window showing
all the processors on your network. At this point, you could simply select
the individual processor from this screen.
However; in most of the real-world scenarios where I’ve needed to go-
online with a PLC, this has not been the situation. It is usually a single
controller, perhaps a part of a small localized network having remote I/O
and HMI’s, and used for a specific process or machine. In this case; proceed
to and through the following steps which outline setting-up simple point-to-
point communication.
Step 1: Pick and configure the appropriate driver using the
“Communications” Tab located on the top menu bar. Select the Configure
Drivers option:
Step 2: Select from the various driver “types” for the connected
communication channel used by your processor. If connecting to a 5/04
processor, you would select either the 1784-U2DHP or the RS-232 DF1
driver; for a 5/05 you might use the Ethernet device driver but could also
use the RS-232 DF1; if connecting to a ControlLogix platform, the
EtherNet/IP driver is an option. Also shown are the options for DeviceNet
and ControlNet networks.
Once again, use the above chart, and become familiar with the default
channels for different controller models. For reference: See Rockwell Pub
1747-2-39 which covers the SLC-500 family of processors.
Step 3: Click “OK” for the default driver name, and fill in the other
applicable details to configure the driver.
Step 4: After configuring and clicking the [OK] button, RSLinx will let
you know your driver is “running”. At this point, you can just [Close] this
menu and go back to the Communications window that will show you if
you have an established connection with the PLC.
Remember that this is an example of point-to-point communication,
where only one processor is shown. If other items are on the same local
network, such as an HMI, these might be shown as well. Whatever is
shown in this network window are items with which RSLinx has an
established communications path. In any case, you simply select the PLC
processor with which you want to communicate and highlight its symbol, as
in the following example.
By selecting the Chan 0–System tab, you are given the option to change
communication settings for the channel – if you wish to do so. In my
scenario, I didn’t change any processor settings, only the settings in RSLinx
and the adapter cable I was using.
Here are two more screen captures which show the current settings of
Channel 0, and the options available for the channel should you wish to
change the configuration. There might be several reasons for making such
a change; such as needing to accommodate a device on the other channel –
like an HMI, or needing to configure for communicating with an ASCII
terminal device. At any rate, here is where those changes would need to be
made – just remember that you still need to be able to download any offline
changes into the existing processor.
Hands-On-Exercise:
1. Set-up a SLC-500 or MicroLogix project, perhaps on a test bench, and
go through the basic configuration steps for RSLinx shown in steps 1 – 6
for communication with a controller.
4. Upload a program, make some changes and download it back into the
controller.
Specialized “Action” Instructions
The OTL & OTU:
The OTL instruction operates in much the same way as an output energize
or OTE instruction, in that it sets its bit location to “1” whenever the logic
instructions that precede it become “true”. It differs however, in that it
remains “on” even after its rung conditions become “false”. The addressed
bit is turned “off” by the use of a corresponding “unlatch” instruction – the
OTU. The OTU “unlatch” works very much the same in all aspects, except
that when its rung conditions become “true”, it sets its addressed bit
location to “0”, and turning the memory location “off”, or “false”.
Once started, the Pump1 output is “latched in” through the B3:0/1 bit.
This bit is latched “on” even though the Start PB is momentary, and the
rung logic becomes “false” when the pushbutton is released. In addition;
the Low Level Float will soon change states as liquid level rises, making
rung logic false for the (OTL) instruction.
When the High Level float actuates and I:1/2 becomes “true”, or if an E-
Stop is actuated, then the (OTU) B3:0/1 bit is “unlatched” and Pump1 is
turned off.
Note that the OTL and OTU can be used as an output module point or, as
in our example, a bit from the B3 binary data file. Also note that in most
cases, these latching instructions are “retentive” and thus will retain the
current state of memory should power be lost - as long as the processor has
a good battery.
The OSR Instruction:
The OSR is an input instruction that triggers the occurrence of an action or
event to happen only one time. Use the OSR when an event must start
based on the change of state of the rung from a “false-to-true” status.
When the logic preceding the OSR goes from “false-to-true”, the OSR
goes “true” for one scan. After the scan is complete the OSR becomes
“false”, even though rung conditions that precede it may remain true. It
will only become true again if preceding rung conditions transition, once
again from false-to-true.
When addressing an OSR instruction, use a bit address from either the
“B3” data file or a bit from an “integer” file such as the “N7” data file. The
OSR uses this bit address to retain in memory its “last” state. Don’t address
the OSR using discreet bits from either the input or output file tables, which
are used by I/O modules.
The RTO Instruction:
The RTO is a “retentive” on-delay timer which functions exactly the same
as a TON, except that it “retains” its accumulated value whenever the rung
transitions to “false”, the processor is switched from “run” to “program”, or
even if power is lost. When the rung transitions back from “false-to-true”,
the RTO simply begins timing and adding to the existing accumulated
value. Just like the TON timer, the DN, TT, and EN bits are “useable” for
the addressed RTO.
Here is the bit function for the RTO or “retentive” timer, as you can see, no
real difference from the TON bit function.
Note that the RTO Accumulated value is only reset back to its original
value by the use of the reset instruction RES, having the same address as
the RTO. This is also true of the CTU and CTD counter instructions. I will
show the RES instruction and how these types of timer and counter
combinations can be used together – “cascaded” or “nested”, to build longer
measured time periods for scheduled maintenance or other production
issues.
The CTU & CTD Instructions:
Counters, aside from timers, are some of the most frequently used
instructions in ladder logic programming. Counters operate in a very
similar way to the RTO timer in that the accumulated value and status of the
“control bits” are retained when the preceding rung conditions transition
from “true-to-false”. Counters, like timers, must be addressed, and given a
Preset value (set the final count). You can set the Accumulator value if
desired – setting where the counter will begin its count, but this may also be
left at a zero value. Three registers are assigned to a counter to hold the
“Preset”, “Accumulator”, and “control” bit values.
Here is a breakdown of the control status bits which can be used within
your program.
The CU “count up enable” and CD “count down enable” bits, 15 and 14
respectively, are set when the rung conditions preceding the CTU or
CTD become “true”.
The DN bit, number 13, is set to “1” when the counter’s accumulated
value is equal to its preset value.
The OV or “overflow” bit – number 12, is set when the CTU counter’s
accumulated value increments over the maximum positive value.
The UN or “underflow” bit – number 11, is set when the CTD counter’s
accumulated value goes over from the maximum negative value.
The UA or “update ACC”, bit 10, is set when the accumulated value has
changed.
Here are a few rungs of logic using a CTU instruction and corresponding
RES that might be integrated into a program to do something as simple as
keeping a count on the number of parts that travel, via conveyor, past a
sensor on input I:1/3.
Since the “Preset” value is a signed integer value inhabiting one 16 bit
register, the largest number we can count up to is 32767, remember bit 15 is
used for the positive or negative sign and bits 0 – 14 for the number. Since
we need to count up to 50,000, we can add a second counter and make it
start counting when the first one reaches its maximum value by using the
C5:0/DN bit on the 2nd rung.
The second counter, C5:1 counts the additional 17233 parts until the total is
equal to the 50,000 parts that signals the need for the scheduled
maintenance procedure.
The C5:1/DN bit could also be used to shut the conveyor down, show an
alert message or flag on an HMI, or in any number of ways alert the
operator to the condition requiring maintenance.
In this example, both C5:0 and C5:1 are reset at the same time when the
operator does the manual reset via I:1/4 input.
Using the RTO:
In the following programming example; a scenario existed in which blast
media used in a shot-peening operation, was being used longer than the
prescribed 40 hour time period. By putting a few timer instructions into the
existing program structure, and wiring an alarm from an output to the
operator control panel – this condition was corrected. No HMI was in use
so an indicator light was installed in the control panel. This alarm would
alert management and the operator of the need to change blast media, and
also to allow the reset after the media was changed.
Remember that the RTO/ DN bit remains set after its Accumulated value
reaches the Preset value. It isn’t reset until the reset instruction is initiated
by a new count on C5:1, shown on the fourth rung.
The RTO with a 1 second time base, increments to 28800 seconds or 8
hours, then pulses the counter C5:1 with a single count to the accumulated
value. When the CTU reaches it preset value of 5, the C5:1/DN is set, the
output indicating the need for media change is turned on. Note that the 8
hour RTO is reset whenever counter C5:1 is pulsed “true” by using the
C5:1/CU bit. At this point the RTO is ready to begin the timing for the next
8 hour period of use.
The CTU is only “reset” by the use of the Maint_Res input, which could
be a key switch or simple pushbutton.
Ideally, another protective condition should be placed into this rung of
program logic. An XIC addressed to the C 5:1/DN bit, if put in series, or as
an “AND” condition with the Maint_Res input switch, would prevent a
random reset of the counter. It would only allow a “reset” if the counter
had accumulated to its full preset value – the full 40 hour time allowance.
Basic Math Instructions
At face value, using math instructions are pretty straightforward and
relatively easy to understand. Of course it is “how” you put these
instructions together to obtain results that make these instructions so
useful. The use of an ADD, SUB, MUL or DIV as separate instructions
may be quite simple, but if the algorithm you need to calculate is more
complex then keep in mind that the “order of operations” still apply - just as
you would use in working an algebraic equation. For this reason I have
found that symbols and descriptions are extremely helpful when added to
these instructions. Good descriptions may save you significant time when
trying to figure out if instructions are being used as part of a “larger”
calculation.
Here is a chart describing these basic math instructions.
In the next chapter, an example of using these instruction for scaling
analog inputs or outputs will be shown. In fact, several methods will be
shown, but I’ll start with the most basic – which involves the direct use of
math instructions – the MUL, DIV, and ADD or SUB. You may already be
familiar with easier methods of scaling using of the SCL and SCP
instructions, and these will be reviewed as well.
For SLC 5/03, /04 and /05 processors, the F8 “floating point” data file
can be used if you are working with numbers that contain decimal place
values.
The F8, or any other floating-point data files that you add to your
project, can have from 0 to 255 word elements (32 bit each). A typical
address would be something like F8:2 or F12:5, where F8 or F12
designates the particular “floating point” data file, and the 2 or 5
reference the specific two word element.
Status File Bits:
When working with math instructions, it’s important to become aware of
certain status file bits that directly monitor math registers. Doing so can
help you avoid processor faults and downtime. Here are the main “status”
bits that are linked to the math functions.
So the first instruction in this branched rung, the MUL, takes the raw
data from I:3.2 – currently at 0 and multiplies it by “source B”, a
constant of 720. It then places the result in the integer destination
N7:10. If the I: 3.2 input was at 10 vdc, the raw data translated by the
input card could be 32767. When multiplied by our constant of 720 the
generated number would far exceed the maximum for a 16 bit number,
and the S:5/0 bit is set.
The next instruction, a DDV, takes the N7:10 integer value, now residing
in the 32 bit “math register” of the Status data file, and divides it by the
constant of 32767. It places the resulting (quotient) back into the N7:10
address.
The ADD instruction then adds “source B”, which is the value in N7:10,
to a constant of 212, and once again places the answer back into the
N7:10 address.
The overflow trap bit will be set to “1” any time a math instruction is
executed that results in a number larger than 32757 or a number being
divided by 0.
Advanced Math Instructions:
In the previous chart I’ve included some of the most commonly used math
instructions – but there are many more you may find useful. Here is a chart
of some other instructions that you can use for more advanced calculations.
Analog Scaling Instructions
The use of analog devices is so common in equipment and process control
systems, that I felt an entire chapter devoted to this topic would be
beneficial. There are specific instructions that will accomplish scaling, but
at times it will be necessary to work out some math details in order to
actually program an analog application. This was how the constant of 720
was derived in the previous example of scaling using math instructions. I
also think that going through these calculations, will help you better
understand the concept of what this type of routine accomplishes within a
program.
An analog input is a “changing” voltage or current signal, sent to the PLC
input module from some type of field device. This signal varies according
to the physical conditions that act upon it, such as temperature, pressure,
level of liquid in a tank, position of a work piece, RPM or any number of
things that can be measured. The corresponding signal can be 0 to 10 Vdc,
0 to 5 Vdc, -10 to +10 Vdc, or a current signal such as 4 to 20 mA. These
types of variable signals must interface with an analog module within the
PLC rack, which then processes the input signal, and translates it into a
value the processor can understand and use. Just as with other instructions
covered thus far, the translation activity of an analog input channel places a
numeric value into a 16 bit register or “word”- in binary format. The
processor then uses this value during program execution.
The issue is that, if we happen to be using a 0 to 10 Vdc input, the
resulting 16 bit number is, by itself, not very useful until it can be
translated, used and shown in some meaningful way. For instance, if we are
receiving 5 Vdc from a pressure transducer out in the field, and our analog
input card turns this voltage into a 16,384 integer value for the processor,
we still need to establish, by programing, what that numeric value should
do. For example; we could use it to cause a pump motor to run at full or
half-speed, show some type of reading on an HMI panel, change a valve
position, or output an alarm. The creation of “meaningful” relationships
between the raw data coming into the processor - and how the program uses
this data - is really the focus of scaling. Another thing that “scaling” is all
about, is establishing a “linear” relationship between input data and output
data – this chapter will cover this in detail.
Here are some basic definitions and terms commonly used when dealing
with analog scaling and the programming issues that are involved.
Input Signal: The analog signal input to the module, for the 1746-NI4, on
one of four channels. Each of these channels is addressed on a “word”
level, for example: I:3.2 which is “slot 3”, “word element 2”.
Raw Data: The digital output from the module in binary format
representing an integer value to the processor.
Scaled Output: A converted value that will be used for display or other
purposes.
Note: Scaling is accomplished within the processor – not the input
module. Scaling depends on our programmed instructions.
Analog Output Module: Converts the digital data value from the processor
and converts this binary number into a proportional output signal. Serves as
a D/A converter for the specific type of output range selected and
configured for the module.
With these terms in mind, let’s take a good look at what scaling
instructions are all about and how they are used to establish the relationship
you desire between an input signal and its corresponding output. Usually
it’s desirable for this relationship to follow a linear pattern or equation, and
it is often helpful to begin by drawing this out on paper.
Example Application:
1746-NI4 Module, Channel 3, Address I: 3.2
Temperature Transducer: 0 to 10 vdc
Proportional Range (linear): 212 deg F to 932 deg F, (100C to 500C)
Process Temperature must stay within 500 deg F to 575 deg F.
Objective: Set a High Alarm or Low Alarm if out of range.
From this we can derive other equations to solve for the remaining values of
the basic linear equation:
Where “x” is equal to our “raw data” from the analog input module.
Where “b” is the offset of where the line crosses the “y” axis above or
below the “x” axis. This offset is often referred to as the “y-intercept”.
While there are other methods of programming for the raw input values
that will equate with a low of 500 and a high of 575 deg F, two of these
methods still require some calculations using these derived equations.
First, we can calculate the “slope” or “m” value of our equation using our
two known points: the (x, y) coordinates for our first point is (0, 212), and
the coordinates for the second point – at the far end of our range, is (32767,
932).
These two points span, not just our desired temperature range of 500 to
575 degrees, but all of the values in the proportional range of our
temperature transducer. So using the equation for “m” we can calculate the
following:
Using the math instructions, we will use the 720 and the 32767 values,
and when using the SCL instruction the decimal form for “m” will be used.
Next we can calculate the “b” offset value, even though it is pretty
obvious on our graph, by plugging in the “m” value and also the (x, y)
values for one of the points – either one will give the same answer now that
we know the value for slope “m”.
Using the point (32767, 932) for the (x, y) values, and the calculated slope
(m), we verify the “b” value. Referred to as “offset” or “y intercept” value.
At this point, we have enough to calculate the “raw input” values for our
temperature range. After doing this, we also have the data necessary to
program control logic for the high and low temperature alarms, and heating
control.
Using the derived equation to solve for “x”; we now can use our desired
output “y” values , the offset value for “b”, and slope “m”, to calculate the
following raw data values for the high and low limit alarms:
Here is our complete graph showing scaled output values with the
corresponding “raw input” integer values.
Note also the use of the S2:5/0 “overflow” unlatch discussed earlier – it
must be reset to zero before the end of scan or a processor fault will occur.
In using the DDV or “double divide” instruction, remember that it utilizes
words S:13 and S:14 - a total of 32 bits, referred to as the “math register”.
This provides a temporary holding place for math calculations and
obviously can hold a very large number. The “source” of the DDV
instruction always acts as the “divisor” for whatever is in the math register
and stores the resulting quotient into the address you designate in the
destination field.
Then we follow by using the DDV which completes the “mx” part of the
equation.
All that is necessary at this point is to account for whatever offset value
we have calculated by using the “ADD”, or in some cases a “SUB”
instruction.
Continuing with additional logic, we could use the I:3.2 input values –
now that we know what they are, to program our high and low
temperature range limits. And the N7:10 integer value, can be used for
display purposes or for some other type of analog output control
element.
Note that since the slope value is going to be divided by 10000 within the
instruction, you must multiply the “m” value (0.02197) by 10000, and enter
this value into the “rate” field. The value of the “b” offset (212) is entered
as well.
We designate the input address for the incoming signal, I:3.2, plug in the
values for the full range of raw input data – minimum 0 to a maximum of
32767. We then plug in values for the scaled output – our full proportional
or “linear” range – 212 as the minimum and 932 as the maximum. Finally,
enter the address for the scaled output value, in our example it is addressed
to N7:10.
Note that, just as in all three examples, we end up having a “scaled”
output value in the N7:10 integer data file. Once again, we can use this
value in many different ways, for display on a graphics panel or HMI, to
control the speed of a variable frequency drive motor, or to control a
heating system, are just a few possibilities.
Here is the sketch from our previous example, showing the linear
relationship for the controlled temperature range. It can be used in another
scaling routine to program a 1 to 5 Vdc output signal that controls the
variable speed of a circulation fan. This fan speed is dependent upon
temperature inside a process chamber.
Here is a different diagram for an analog output module which we can use
for the variable speed control of a circulation fan in our example heat
treating process. Note that for the output module used, the 1746-NO4V, for
a 1 to 5 Vdc output from the module, the integer range is 3,277 to 16,384.
These integer values are the input values sent to the module from the
processor, and the output voltage from the module will vary from 1 to 5
Vdc.
By using the temperature values within the desired control range along
the “x” coordinate axis, and these integer values of the module along the
“y” axis, we come up with a diagram that looks something like this.
Once again, the linear equation “y = mx + b” is calculated using the (x,y)
coordinates of the full range of the module settings. Values are obtained for
the slope “m”, and also for the “b” (y-intercept) or offset value.
The examples shown thus far, have followed scaling methods and
instruction usage which are based on maintaining a “linear” or “straight-
line” relationship between input signals and output data values. This
however is not the case with PID control, as you can see from the
following, the PV, and the CV that alters it, are anything but linear.
Most of the PID control systems that I’ve been involved throughout my
career, have been related to the controlled application of heat, pressure and
vacuum in heat treating and curing processes. These types of applications,
and many others, require “tight” control of heat and the length of time in
process; so rates of change, the amount of “overshoot”, and even the cool
down rates become very important. These are areas in which properly
tuned PID loops excel.
On the other hand, regular scaling instructions, such as the SCL, SCP or
“math” instructions, are the tools of choice when dealing with simple
relationships where values are stable or set by the operator HMI and don’t
require constant oversight by a control algorithm such as the PID.
At this point, some of the main details to remember are:
The PID normally controls a closed loop using input from an analog
input module, the “process variable” or PV, and provides an output
“control variable” CV – sometimes referred to as the “manipulated
variable”, to an analog output module.
By setting PID parameters, you can control items such as gain, whether
the control is forward or reverse action, the “timing” used to update data
tables, and many other important details related to “closed loop” PID
control.
These are the details stored within the 23 word control block for the PID
instruction.
The PV and CV will contain integer values that range from 0 to 16383,
so this is how they are “scaled” for the incoming input (PV), and for the
output module side, the (CV).
For greater detail on using this instruction and the specific programmable
parameters go to the SLC 500 / RSLogix 500 Instruction Set: PUB 1747-
RM001G-EN-P.
Using Comparison Instructions:
In the previous program example you noticed several examples of
“comparison” instructions. These “question – asking” conditions are “true”
when their conditions are met, and pass logical continuity down to whatever
“action-performing” output is at the end of the rung. Here are some
examples from the previous chapter:
Where N7:10, a scaled value for temperature input, is used to send the
speed signal to the VFD driven circulation fan. If scaled temperature is
between the low and high limits of the proportional range, the instruction is
“true” and the “high fan spd” bit is turned on.
Another usage for the LIM instruction is when the Low Limit is set to a
value higher than the High Limit. In this scenario, when the Test value is
between the High and Low values, the Limit instruction evaluates as “false”
and doesn’t pass logical continuity. When the test value is equal to either
the High or Low set-points, or outside of the Low – High range, it is
evaluated as “true”.
The MEQ, or “masked equal”, is an instruction which allows comparison
of two integer values while also allowing you to exclude certain bits from
comparison. The basic instruction looks like this:
As shown in this comparison of these instructions; the COP takes the values
of word elements N7:1, N7:2, and N7:3 and copies in the same order to
N7:5, N7:6, and N7:7. The FLL instruction, takes the value of N7:1 and
places this value into N7:8 and N7:9.
The MVM, TOD, and FRD Instructions:
The MVM instruction, or “masked move”, works just like the “MOV”
instruction shown earlier. The difference is that with the MVM it is
possible to exclude certain bits from the move by filtering through a mask
value. This performs what I would call an “AND-ing” operation, where if
the value being moved has a bit set to “1”, AND the mask bit is set to “1” –
then that bit value of “1” will be moved into the bit position of the
destination word element. A zero in the bit position of the “mask” will not
allow the move for the corresponding bit of the source value.
The TOD instruction converts an integer value into BCD or binary coded
decimal format. This is a convenient method of programming for a seven-
segment BCD display. Using the MOV instruction, a full word element or
16 bits can be moved to an output module for display of 4 digits.
Remember that with BCD, each four bits of the word are equal to 8, 4, 2, 1
values – so each four bit group can represent and output a number from 0 to
9.
The FRD instruction, not shown in the following example, does the
reverse operation as the TOD. It converts “BCD” source value into an
integer value and places it into a designated address.
Here is an example of using these instructions and the corresponding N7
data file:
Note that when using the MVM, the mask can be a constant – shown here
as a hexadecimal number “7FFFh” or 32767. It can also be an integer
address in which you have set the value.
Also note the difference between the bits of N7:2 (binary) and N7:3
(BCD), even though both 16 bit registers represent the value of “5616”.
The N7:3 bits could be moved directly into an output module to show the
number 5616 on an operator panel display or HMI.
Program Flow Instructions
Some of the most useful instructions in the SLC-500 instruction set are
the program flow instructions. This is especially so when dealing with
larger ladder programs, because these instructions allow you to write a
program in blocks or sections that pertain to specific functions. One
program I deal with from time to time has separate sections or
“subroutines”, for the equipment’s “main control”, “safety resets”, “motor
control”, “pressure control”, “temperature control” and “vacuum”.
Building a program in subroutines makes it easier to follow and
troubleshoot whenever that becomes necessary.
These instructions are used to control the sequence of execution of your
program, allowing you to bypass the execution of certain rungs or to loop
(repeat) within a certain block of programming until specific criteria is
acceptable.
Another method of program control where these instructions become
useful, is for equipment processes that can be used on different parts by
simply changing the parameters specific to that part. Each subroutine
essentially programmed as the “recipe” for a different part, containing
different values for speed and positioning controls, reference positions,
number of passes, and any other things pertaining to the process. The
“recipe” would simply be selected by the machine operator on an HMI or
some other type of control mechanism.
In this chapter we will look at three or four of the basic program flow
instructions with examples on using them in actual ladder programs.
The JSR, SBR, and RET Instructions:
The JSR instruction or “jump to subroutine”, is an action-performing
instruction that will cause the program to skip to the designated subroutine
SBR ladder routine. After the subroutine is performed the program returns
to the rung following the JSR instruction that called it, and continues
execution of the program from that point on.
An MCR controlled zone must contain only two MCR instructions. The
MCR pair encloses the rungs – a zone where outputs will be disabled
under certain conditions.
Timers and counters will cease to operate when placed within an MCR
zone – and the zone goes “false”. Although a “TOF” or “off delay”
timer will activate when the rung goes “false”, just as it would normally
when transitioned from a true-to-false condition.
Logical Register Instructions
These are “action-performing” instructions that operate on registers, and
then place the results in a destination register. They perform a bit-by-bit,
“AND”, “OR”, “XOR”, or a “NOT” on your designated source register or
word. These operations and instructions are, in general, not what you
would use for setting up “logical” rung continuity in your programming.
Rather, they are most often used to manipulate bits of a word into a desired
form. At any rate that’s my perspective, however you may find other
interesting ways to utilize these instructions in your programs. Here are
examples of each.
The AND Instruction:
Each bit of source A is “AND-ed” with the corresponding bit of source B.
This simply means that both bits must be “true” or “1” for the resultant to
be “true”. Results are placed into the register you designate as the
destination.
The OR Instruction:
Each bit of source A is “OR-ed” with the corresponding bit of source B.
If either condition (or both) is “true” or “1”, then the results are “true”.
Results are placed into the register you designate as the destination.
The XOR “exclusive or” Instruction:
Each bit of source A is “OR-ed” with the corresponding bit of source B.
Remember that the “exclusive or” only allows a single condition to be
“true” or “1”, rather than both. Results are placed into the register you
designate as the destination.
The XOR Instruction and resultant truth-table:
The NOT Instruction:
Each bit of the source word is inverted, and the results placed into the
register you designate as the destination. Therefore, the results placed into
the destination will be the opposite of the source bits.
Concluding Comments
What I’ve endeavored to present in this book, are what I consider some of
the more advanced concepts and instructions used in programming ladder
logic. Once again, the Allen Bradley family of PLC’s are very good
products, in my opinion, to use when learning to program machine controls.
Hopefully, you have access to RSLogix500 software so you can develop
and test your own programs. Most training seminars that teach PLC
programming, provide laptops and PLC racks with I/O, and may schedule
several days in the classroom. While this may be one of the best methods of
learning ladder programming skills, it is not always an option to attend a
three or four day class. The goal of this three book series is to convey these
topics, as well as possible, from the written page - along with good
illustrations and examples. I hope I’ve succeeded, on some level, in
meeting that goal.
Some of the topics and objectives we’ve covered in this “Advanced
Concepts” book have been:
The “math” instructions and how they can be used in scaling analog
applications.