34
1 Northampton Community College 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

13 chap07 and_08_comparison_subs_force_fa14

Embed Size (px)

Citation preview

Page 1: 13 chap07 and_08_comparison_subs_force_fa14

1Northampton Community College

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

Page 2: 13 chap07 and_08_comparison_subs_force_fa14

2Northampton Community College

Comparison Instructions

Chapter 07 Sections 7-4 through 7-6

Page 3: 13 chap07 and_08_comparison_subs_force_fa14

3Northampton Community College

Data Compare Instructions

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)

Page 4: 13 chap07 and_08_comparison_subs_force_fa14

4Northampton Community College

Comparison Instruction Parameters

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

Page 5: 13 chap07 and_08_comparison_subs_force_fa14

5Northampton Community College

Instruction Comparison Rules

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 leveladdresses

A WORD leveladdress and a

Constant

Two ConstantsIllegal

Page 6: 13 chap07 and_08_comparison_subs_force_fa14

6Northampton Community College

Equal (EQU) Instruction

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

Page 7: 13 chap07 and_08_comparison_subs_force_fa14

7Northampton Community College

Not Equal (NEQ) Instruction

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

Page 8: 13 chap07 and_08_comparison_subs_force_fa14

8Northampton Community College

Greater Than (GRT) Instruction 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

2 Greater Than (A>B)Source A SetPoint 0Source B Furnace_Temp 0

GRTHeater

<Local:3:O.Data.5>

When the program is running, the value of the WORD level address will be displayed in this field.

Page 9: 13 chap07 and_08_comparison_subs_force_fa14

9Northampton Community College

Less Than (LES) Instruction 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

When the program is running, the value of the WORD level address will be displayed in this field.

Page 10: 13 chap07 and_08_comparison_subs_force_fa14

10Northampton Community College

Greater Than or Equal To (GEQ) Instruction

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

Page 11: 13 chap07 and_08_comparison_subs_force_fa14

11Northampton Community College

Less Than or Equal To (LEQ) Instruction 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

3 Less Than or Eql (A<=B)Source A Refrg_Temp 0Source B SetPoint 0

LEQRefrg_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.

Page 12: 13 chap07 and_08_comparison_subs_force_fa14

12Northampton Community College

Limit Test (LIM) Instruction

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)

Page 13: 13 chap07 and_08_comparison_subs_force_fa14

13Northampton Community College

LIM Parameter Rules

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.

Page 14: 13 chap07 and_08_comparison_subs_force_fa14

14Northampton Community College

LIM Instruction Operation

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

O:2/7 ONO:2/7 OFF O:2/7 OFF

Page 15: 13 chap07 and_08_comparison_subs_force_fa14

15Northampton Community College

LIM Instruction Operation

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

78 156Heater OFFHeater ON Heater ON

4 Limit Test (CIRC)Low Limit LO_Temp_Lmt 156Test SetPoint 36High Limit HI_Temp_Lmt 78

LIMHeater

<Local:3:O.Data.5>

Heater will be true (ON) when the value stored in SetPoint is:

≤78 OR ≥156

Page 16: 13 chap07 and_08_comparison_subs_force_fa14

16Northampton Community College

Performing Comparison Windows

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.

Page 17: 13 chap07 and_08_comparison_subs_force_fa14

17Northampton Community College

Performing Comparison Windows

Page 18: 13 chap07 and_08_comparison_subs_force_fa14

18Northampton Community College

Subroutines

Chapter 08

Sections 8-3-3 to 8-3-5

Supplement Document

Page 19: 13 chap07 and_08_comparison_subs_force_fa14

19Northampton Community College

Subroutines

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.

Page 20: 13 chap07 and_08_comparison_subs_force_fa14

20Northampton Community College

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.

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

Page 21: 13 chap07 and_08_comparison_subs_force_fa14

21Northampton Community College

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.

Page 22: 13 chap07 and_08_comparison_subs_force_fa14

22Northampton Community College

Program Control Instructions 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.

Page 23: 13 chap07 and_08_comparison_subs_force_fa14

23Northampton Community College

ControlLogix Program Control Instructions

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)

Page 24: 13 chap07 and_08_comparison_subs_force_fa14

24Northampton Community College

ControlLogix Program Control Instructions

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.

Page 25: 13 chap07 and_08_comparison_subs_force_fa14

25Northampton Community College

ControlLogix Program Control Instructions

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

Page 26: 13 chap07 and_08_comparison_subs_force_fa14

26Northampton Community College

ControlLogix Program Control Instructions

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)

Page 27: 13 chap07 and_08_comparison_subs_force_fa14

27Northampton Community College

ControlLogix Program Control Instructions

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.

Page 28: 13 chap07 and_08_comparison_subs_force_fa14

28Northampton Community College

ControlLogix Program Control Instructions

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)

Page 29: 13 chap07 and_08_comparison_subs_force_fa14

29Northampton Community College

ControlLogix Program Control Instructions

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.

Page 30: 13 chap07 and_08_comparison_subs_force_fa14

30Northampton Community College

ControlLogix Program Control Instructions

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.

Page 31: 13 chap07 and_08_comparison_subs_force_fa14

31Northampton Community College

Program Execution using Subroutines

Page 32: 13 chap07 and_08_comparison_subs_force_fa14

32Northampton Community College

Forcing I/O

Page 33: 13 chap07 and_08_comparison_subs_force_fa14

33Northampton Community College

Using the Force I/O Function

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.

Page 34: 13 chap07 and_08_comparison_subs_force_fa14

34Northampton Community College

Installing and Enabling Forces

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.