1. Comparison, Forcing I/O and
Subroutines
Chapter 07 Sections 7-4 through 7-6
Chapter 08 Sections 8-1, 8-2, 8-3-3 through
8-3-5
Northampton Community College 1
3. Data Compare Instructions
Northampton Community College 3
Data compare instructions are input instructions.
Data compare instructions compare the data, or value,
stored in two words (or registers) and makes a decision
based upon those values and the type of comparison being
performed.
The SLC-500 series processors have eight and the
ControlLogix has nine comparison instructions. We will
cover seven of them.
Equal (EQU)
Not Equal (NEQ)
Less Than (LES)
Less Than or Equal To (LEQ)
Greater Than (GRT)
Greater Than or Equal To (GEQ)
Limit Test (LIM)
4. Comparison Instruction Parameters
Northampton Community College 4
Comparison instructions in the SLC500 are word level instructions and
in the ControlLogix a tag of data type SINT, INT, DINT REAL or
STRING. The instructions have two parameters:
Source A
Source B
Source A
Source B
5. Instruction Comparison Rules
Northampton Community College 5
Comparison instruction parameters have several rules:
In the SLC500, Source A and Source B can be WORD level addresses. In
the ControlLogix Source A and Source B can be a tag of data type SINT,
INT, DINT, REAL or STRING.
Source A can be a WORD level address in the SLC500 or a tag in the
ControlLogix and Source B can be a program constant.
Source A and Source B can not both be program constants.
Two WORD level
addresses
A WORD level
address and a
Constant
Two Constants
Illegal
6. Equal (EQU) Instruction
Northampton Community College 6
The EQU instruction is an input instruction that compares the value referenced
in Source A to the value referenced in source B. When the value of Source A is
equal to the value of Source B the instruction is true, otherwise it is false.
When the accumulator value of counter C5:0 (C5:0.ACC) referenced in Source
A is equal to the accumulator value of counter C5:1 (C5:1.ACC) referenced in
Source B, the instruction is true and output O:2/5 is energized, otherwise the
instruction is false and the output is de-energized.
When the program is
running, the value of the
WORD level address will
be displayed in this field.
True when Source A = Source B
7. Not Equal (NEQ) Instruction
Northampton Community College 7
The NEQ instruction is an input instruction that compares the value
referenced in Source A to the value referenced in source B. When the
value of Source A is not equal to the value of Source B the instruction is
true, otherwise it is false.
When the accumulator value of timer T4:0 (T4:0.ACC) referenced in
Source A is not equal to the program constant of 36 referenced in
Source B, the instruction is true and output O:2/5 is energized,
otherwise the instruction is false and the output is de-energized.
When the program is
running, the value of the
WORD level address will
be displayed in this field.
True when Source A ≠ Source B
8. Greater Than (GRT) Instruction
Greater Than (A>B)
Source A SetPoint
0
Source B Furnace_Temp
0
Northampton Community College 8
The GRT instruction is an input instruction that compares the value
referenced in Source A to the value referenced in source B. When the
value of Source A is greater than the value of Source B the instruction is
true, otherwise it is false.
When the value stored in tag name SetPoint referenced in Source A is
greater than the value stored in tag name Furnace_Temp referenced in
Source B, the instruction is true and the output with tag name Heater is
energized, otherwise the instruction is false and the output is de-energized.
True when Source A > Source B
GRT
Heater
<Local:3:O.Data.5>
When the program is
running, the value of the
WORD level address will
be displayed in this field.
9. Less Than (LES) Instruction
When the program is
running, the value of the
WORD level address will
be displayed in this field.
Northampton Community College 9
The LES instruction is an input instruction that compares the value
referenced in Source A to the value referenced in source B. When the
value of Source A is less than the value of Source B the instruction is
true, otherwise it is false.
When the value stored in the preset of timer T4:0 (T4:0.PRE) referenced
in Source A is less than the accumulator value of counter C5:2
(C5:2.ACC) referenced in Source B, the instruction is true and output
O:2/5 is energized, otherwise the instruction is false and the output is
de-energized.
True when Source A < Source B
10. Greater Than or Equal To (GEQ) Instruction
Northampton Community College 10
The GEQ instruction is an input instruction that compares the value
referenced in Source A to the value referenced in source B. When the
value of Source A is greater than or equal to the value of Source B the
instruction is true, otherwise it is false.
When the value stored in word B3:1 referenced in Source A is greater
than or equal to the program constant of 568 referenced in Source B, the
instruction is true and output O:2/5 is energized, otherwise the
instruction is false and the output is de-energized.
When the program is
running, the value of the
WORD level address will
be displayed in this field.
True when Source A ≥ Source B
11. Less Than or Equal To (LEQ) Instruction
Less Than or Eql (A<=B)
Source A Refrg_Temp
0
Source B SetPoint
0
Northampton Community College 11
The LEQ instruction is an input instruction that compares the value
referenced in Source A to the value referenced in source B. When the
value of Source A is less than or equal to the value of Source B the
instruction is true, otherwise it is false.
When the value of the tag name Refrg_Temp referenced in Source A is
less than or equal to the value of the tag named SetPoint referenced in
Source B, the instruction is true and the output with tag name
Refrg_at_Temp is energized, otherwise the instruction is false and the
output is de-energized.
True when Source A ≤ Source B
LEQ
Refrg_at_Temp
<Local:3:O.Data.13>
When the program is
running, the value of the
WORD level address will
be displayed in this field.
12. Limit Test (LIM) Instruction
Northampton Community College 12
The Limit Test instruction is an input instruction that tests for values that
are inside of, or outside of, a specified range. The output of the
instruction is dependent upon how the limits are set.
The LIM instruction has three instruction parameters:
Low Limit (Low Lim)
Test
High Limit (High Lim)
Low Limit (Low Lim)
Test
High Limit (High Lim)
13. LIM Parameter Rules
Northampton Community College 13
There are several rules associated with entering
parameters into the LIM instruction:
The parameter values in the SLC 500 can be WORD
level addresses or program constants and in the
ControlLogix they can be tags of data type SINT, INT,
DINT, REAL or program constants, with the following
restrictions:
If the Test parameter is a program constant, than the High Lim
and Low Lim parameters must be WORD level addresses or
tags.
If the test parameter is a WORD level address or tag, than the
Low Lim and High Lim parameters can be a program constant, a
WORD level address or tag or a combination thereof.
14. LIM Instruction Operation
O:2/7 OFF O:2/7 ON O:2/7 OFF
Northampton Community College 14
If the value referenced in the Low Lim is less than or equal
to the value referenced in the High Lim, the instruction will
be true when the value referenced in the Test parameter is
between or equal to either of the limits.
O:2/7 will be true (ON)
when T4:1.ACC is:
≥78 and ≤156
78 156
T4:1.ACC
15. LIM Instruction Operation
78 156
Heater ON Heater OFF Heater ON
Northampton Community College 15
If the value referenced in the Low Lim is greater than the
value referenced in the High Lim, the instruction will be true
when the value referenced in the Test parameter is equal to
or outside of the limits.
SetPoint
4 Limit Test (CIRC)
Low Limit LO_Temp_Lmt
156
Test SetPoint
36
High Limit HI_Temp_Lmt
78
LIM
Heater
<Local:3:O.Data.5>
Heater will be true
(ON) when the value
stored in SetPoint is:
≤78 OR ≥156
16. Performing Comparison Windows
Northampton Community College 16
Assume an output is being controlled based upon the value
of a counter accumulator, C5:0.ACC. Following is the output
operation criteria:
Output is OFF when C5:0.ACC is 0 to and including 3.
Output is ON when C5:0.ACC is 4 to and including 7.
Output is OFF when C5:0.ACC is 8 to and including 10.
Output is ON when C5:0.ACC is 11 to and including 25.
Output is OFF when C5:0.ACC is >25.
Comparison instructions can be used in combinations to
achieve the desired results.
18. Subroutines
Chapter 08
Sections 8-3-3 to 8-3-5
Supplement Document
Northampton Community College 18
19. Subroutines
Northampton Community College 19
Subroutine(s) is a group of program code that performs a specific
task. The subroutine(s) are part of a program (in our case the
MainProgram) and are not part of the MainRoutine.
A subroutine can be invoked, (called), from anyplace in the
MainRoutine or from another subroutine. When a subroutine is
called from within another subroutine it is referred to as nesting
subroutines.
Most, if not all, computer programs and PLC/PAC programs
contain subroutines.
Subroutines are used to make what would be an enormous
program more manageable by breaking up the code into smaller
tasks. Specific functions within a task should be placed in
subroutines.
Organizing a program by using subroutines makes the code
easier to read, understand and maintain.
Subroutines can also be reused in other programs that require
the same task be performed.
20. Subroutines
SLC500
The SLC500 uses
separate ladder files to
store and execute
subroutines. There are a
total of 253 subroutine
ladder files; #3 through
#255.
Northampton Community College 20
Ladder file #2 (LAD2) is
the main ladder file and is
the one we have been
using in all labs to this
date.
Scan starts at rung 0 LAD2
and ends at the End
statement in LAD2.
ControlLogix
The ControlLogix uses
separate routines to store
and execute subroutines.
The number of routines is
limited to 32 per program.
The MainRoutine is the
main ladder routine and is
the one we have been
using in all labs to this
date.
Scan starts at rung 0 in the
MainRoutine and ends at
the End statement in the
MainRoutine
21. Creating a ControlLogix Subroutine
1. To create a new subroutine right
click on MainProgram and select
New Routine… from the pop-up
menu
2. New Routine dialog box will open.
Type in the name of the subroutine
and from the Type: dropdown,
select the type of program code.
3. The new
subroutine will appear
listed under the
program that it was
created in. Double
click the subroutine to
open the ladder
editor.
Northampton Community College 21
22. Program Control Instructions
Northampton Community College 22
There are many program control instructions. Below is a list of them and the
platforms they are available on:
Instruction CL 500 Sim Instruction CL 500 Sim
JMP – Jump to Label ● ● ●
UID – User Interrupt
Disable
●
LBL – Label ● ● ●
UIE – User Interrupt
Enable
●
JXR – Jump to External Routine ●
SFR – Reset Sequential
Chart
●
JSR – Jump to Subroutine ● ● ●
SFP – Pause Sequential
Chart
●
RET – Return from Subroutine ● ● ●
EVENT – Trigger Event
Task
●
SBR – Subroutine Label ● ● ● EOT – End of Transition ●
TND – Temporary End ● ● ● AFI – Always False ●
MCR – Master Control Reset ● ● ● NOP – No Operation ●
SUS - Suspend
This course will only cover the instructions shown in Red. The instruction in
Green can be used, but they will not be discussed in class.
23. ControlLogix Program Control Instructions
Northampton Community College 23
JSR – Jump to Subroutine
The JSR is an output instruction that is used to “call” a
subroutine.
The instruction rung can be conditional or unconditional.
JSR instructions can have several parameters. The one
shown here has 3-parameters. Subroutine name to
be “called” (required)
Parameter to pass to
the subroutine
(optional)
Parameter to accept a
value returning from
the subroutine
(optional)
24. ControlLogix Program Control Instructions
Northampton Community College 24
Entering JSR parameters:
Routine Name (Required) –
Double-click this parameter field,
click the dropdown arrow and
select the subroutine name from
the dropdown list. The subroutine
name will only be in the list if the
subroutine has been created.
Input Par and Return Par
(Optional) – These parameters
will not be used in this course.
When a parameter is not used it
must be removed. Right click on
the parameter field and select
Remove Instruction Parameter
from the pop-up menu. Do this for
each parameter that is not
required. The picture on this slide
illustrates removing a parameter
field.
25. ControlLogix Program Control Instructions
Northampton Community College 25
JSR operation
When the rung containing a JSR instruction is true, the
processor scan jumps to the subroutine referenced in the
Routine Name parameter and begins program execution at
the first rung in that subroutine
A jump cannot be made into the middle of a subroutine.
Execution will always start at the first instruction on the first
rung in that ladder routine.
This rung will unconditionally jump to the
subroutine named Routine04
26. ControlLogix Program Control Instructions
Northampton Community College 26
SBR – Subroutine Label
The SBR in an input instruction that is always true and
marks the beginning of a subroutine. It must be the first
instruction on the first rung of the subroutine.
The input parameter field(s) is used to reference tags
whose data is to be used (passed) to the subroutine. (This
course will not be using these parameters).
SBR instructions can have several parameters. The one
shown here has one parameters.
Parameter that passes
data to the subroutine
(optional)
27. ControlLogix Program Control Instructions
Northampton Community College 27
For this course the Input Par parameter will need to be
removed from the SBR instruction. To remove the
parameter right-click on the parameter and select Remove
Instruction Parameter from the pop-up menu.
28. ControlLogix Program Control Instructions
Northampton Community College 28
RET – Return from Subroutine
The RET instruction is an output instruction that is used to
stop executing the subroutine and return to the ladder file
that originally “called” the subroutine.
The instruction can be conditional or unconditional and can
contain several parameters. The RET instruction shown
here has one parameter. (This course will not use these
parameters).
Parameter that passes
data back to the
ladder file that
originally “called” the
subroutine. (optional)
29. ControlLogix Program Control Instructions
Northampton Community College 29
For this course the Input Par parameter will need to be
removed from the RET instruction. To remove the
parameter right-click on the parameter and select Remove
Instruction Parameter from the pop-up menu.
30. ControlLogix Program Control Instructions
Northampton Community College 30
Several conditional RET instructions can be present in a
subroutine. As an example:
If an RET instruction becomes true that is on rung 0006 in a
subroutine containing 45-rungs, the program scan will return to the
ladder file that originally called the subroutine and rungs 0007
through 0045 will not execute.
If the RET instruction on rung 0006 becomes false another RET
instruction becomes true that is on rung 0010 in the same
subroutine, the program scan will return to the ladder file that
originally called the subroutine and rungs 0011 through 0045 will not
executed.
If the entire subroutine ladder file is to be always scanned,
placing a RET instruction on the last rung of the program is
optional. If an RET instruction is not found in the subroutine
ladder file, the END statement performs the return.
33. Using the Force I/O Function
Northampton Community College 33
The force function will only work on field I/O devices,
therefore the input and output data files in the SLC500 and
the Controller tags in the ControlLogix.
Before applying a force to any input or any output device,
an understanding of the potential effect that force(s) will
have on the machine or process operation and to the safety
of personal is essential.
DO NOT INSTALL FORCES WITHOUT FIRST
UNDERSTANDING WHAT AFFECT IT WILL HAVE ON
THE OPERATION OF THE MACHINE OR PROCESS
Most programming software provide some visible means of
alerting the user that a force is in affect or installed.
Most processor modules have an LED indicator that will be
lit if there are any forces installed.
34. Installing and Enabling Forces
Northampton Community College 34
This is an instructor led, interactive lab.
If there is no program running in the PLC at your
workstation, open a program that uses I/O field devices,
download the program to the PLC, then place the PLC in
RUN mode.
Your instructor will also switch to RSLogix and attach to
someone’s workstation to lead you through and
demonstrate the force functions.