Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeContact

The text of a manual · part 13 of 70

SLC 500 Instruction Set Reference Manual, pages 121 to 130

Pages 121 to 130 of 694

The original document is the PDF (7.2 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

For the Allen-Bradley 1747-L514

Page 121

Data Handling Instructions

FIFO and LIFO Instructions Overview

5-25

FIFO (First in First out) instructions load words into a file and unload them in the same order as they were loaded. The first word in is the first word out. LIFO (Last in First out) instructions load words into a file and unload them in the opposite order as they were loaded. The last word in is the first word out.

Entering Parameters Enter the following parameters when programming these instructions. • Source is a word address or constant (-32,768 to 32,767) that becomes the next value in the stack • Destination is a word address that stores the value that exits from the stack

Table 5.18 Instruction Function This Instruction

Unloads the Value from

FIFO’s FFU

First word

LIFO’s LFU

The last word entered

• FIFO/LIFO is the address of the stack. It must be an indexed word address in the bit, input, output, or integer file. • Length specifies the maximum number of words in the stack. This is 128 words. Address the length value by mnemonic (LEN). • Position is the next available location where the instruction loads data into the stack. This value changes after each load or unload operation. Address the position value by mnemonic (POS). • Control is a control file address. The status bits, the stack length, and the position value are stored in this element. Use the same control file address for the associated FFL and FFU instructions; use the same control file address for the associated LFL and LFU instructions. Do not use the control file address for any other instruction. Status bits of the control structure are addressed by mnemonic. These include: • Empty Bit EM (bit 12) is set by the processor to indicate the stack is empty. • Done Bit DN (bit 13) is set by the processor to indicate the stack is full. This inhibits loading the stack. • FFU/LFU Enable Bit EU (bit 14) is set on a false-to-true transition of the FFU/LFU rung and is reset on a true-to-false transition. • FFL/LFL Enable Bit EN (bit 15) is set on a false-to-true transition of the FFL/LFL rung and is reset on a true-to-false transition.

Publication 1747-RM001G-EN-P - November 2008

Page 122

5-26

Data Handling Instructions

Effects on Index Register S:24 The value present in S:24 is overwritten with the position value when a false-to-true transition of the FFL/FFU or LFL/LFU rung occurs. For the FFL/LFL, the position value determined at instruction entry is placed in S:24. For the FFU/LFU, the position value determined at instruction exit is placed in S:24. When the DN bit is set, a false-to-true transition of the FFL/LFL rung does not change the position value or the index register value. When the EM bit is set, a false-to-true transition of the FFU/LFU rung does not change the position value or the index register value.

FIFO Load (FFL) and FIFO Unload (FFU) FFL FIFO Load Source N7:69 FIFO #N7:76 Control R6:0 Length 48< Position 0<

Instruction parameters have been programmed in the FFL-FFU instruction pair shown on page 5-27.

EN DN EM

FFU FIFO Unload FIFO #N7:76 Dest N7:70 Control R6:0 Length 48< Position 0<

EU DN EM

Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •

•

FFL and FFU instructions are used in pairs. The FFL instruction loads words into a user-created file called a FIFO stack. The FFU instruction unloads words from the FIFO stack, in the same order as they were entered.

•

•

Output Instructions

Publication 1747-RM001G-EN-P - November 2008

Page 123

Data Handling Instructions

5-27

Table 5.19 Instruction Function Destination FFL FIFO LOAD Source FIFO Control Length Position

FFU FIFO UNLOAD FIFO Dest Control Length Position

N7:10 #N7:12 R6:0 34 9

#N7:12 N7:11 R6:0 34 9

(EN) (DN) (EM)

(EU) (DN) (EM)

N7:11

FFU instruction unloads data from stack #N7:12 at position 0, N7:12

Position N7:12

0

N7:13

1

N7:14

2 3 4 5 6

34 words are allocated for FIFO stack starting at N7:12, ending at N7:45

7 Source

8

N7:10

9

FFL instruction loads data into stack #N7:12 at the next available position, 9 in this case.

N7:45

33

FFL Instruction Operation When rung conditions change from false-to-true, the FFL enable bit (EN) is set. This loads the contents of the source, N7:10, into the stack element indicated by the position number, 9. The position value then increments. The FFL instruction loads an element at each false-to-true transition of the rung, until the stack is filled (34 elements). The processor then sets the done bit (DN), inhibiting further loading.

FFU Instruction Operation When rung conditions change from false-to-true, the FFU enable bit (EU) is set. This unloads the contents of the element at stack position 0 into the destination, N7:11. All data in the stack is shifted one element toward position zero, and the highest numbered element is zeroed. The position value then decrements. The FFU instruction unloads an element at each false-to-true transition of the rung, until the stack is empty. The processor then sets the empty bit (EM).

Publication 1747-RM001G-EN-P - November 2008

Page 124

5-28

Data Handling Instructions

LFL and LFU instructions are used in pairs. The LFL instruction loads words into a user-created file called a LIFO stack. The LFU instruction unloads words from the LIFO stack in the opposite order as they were entered.

LIFO Load (LFL) and LIFO Unload (LFU) LFL LIFO Load Source N7:71 LIFO #N7:80 Control R6:1 Length 10< Position 0<

Instruction parameters have been programmed in the LFL - LFU instruction pair shown below.

EN DN EM

LFU LIFO Unload LIFO #N7:80 Dest N7:72 Control R6:1 Length 10< Position 0<

EU DN EM

Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •

•

•

•

Output Instruction

Table 5.20 Instruction Function Destination LFL LIFO LOAD Source LIFO Control Length Position

LFU LIFO UNLOAD LIFO Dest Control Length Position

N7:10 #N7:12 R6:0 34 9

#N7:12 N7:11 R6:0 34 9

(EN) (DN) (EM)

(EU) (DN) (EM)

N7:11

LFU instruction unloads data from stack #N7:12 at position 8.

Position N7:12

0

N7:13

1

N7:14

2 3 4 5 6

34 words are allocated for FIFO stack starting at N7:12, ending at N7:45

7 Source

8

N7:10

9

LFL instruction loads data into stack #N7:12 at the next available position, 9 in this case.

N7:45

33

Loading and Unloading of Stack #N7:12

Publication 1747-RM001G-EN-P - November 2008

Page 125

Data Handling Instructions

5-29

LFL Instruction Operation When rung conditions change from false-to-true, the LFL enable bit (EN) is set. This loads the contents of the source, N7:10, into the stack element indicated by the position number, 9. The position value then increments. The LFL instruction loads an element at each false-to-true transition of the rung, until the stack is filled (34 elements). The processor then sets the done bit (DN), inhibiting further loading.

LFU Instruction Operation When rung conditions change from false-to-true, the LFU enable bit (EU) is set. This unloads data from the last element loaded into the stack (at the position value minus 1), placing it in the destination, N7:11. The position value then decrements. The LFU instruction unloads one element at each false-to-true transition of the rung, until the stack is empty. The processor then sets the empty bit (EM).

Publication 1747-RM001G-EN-P - November 2008

Page 126

5-30

Data Handling Instructions

Notes:

Publication 1747-RM001G-EN-P - November 2008

Page 127

Chapter

6

Program Flow Instructions

This chapter contains general information about the program flow instructions and explains how they function in your application program. Each of the instructions includes information on: • what the instruction symbol looks like. • how to use the instruction.

Table 6.1 Program Flow Instructions Instruction Mnemonic

Instruction Name

Purpose

Page

JMP and LBL

Jump to Label and Label

Jump forward or backward to the specified label instruction.

6-2

JSR, SBR, and RET

Jump to Subroutine, Subroutine, Jump to a designated subroutine 6-3 and Return from Subroutine and return.

MCR

Master Control Reset

Turn off all non-retentive outputs 6-6 in a section of ladder program.

TND

Temporary End

Mark a temporary end that halts program execution.

6-7

SUS

Suspend

Identifies specific conditions for program debugging and system troubleshooting.

6-8

IIM

Immediate Input with Mask

Program an Immediate Input with Mask.

6-8

IOM

Immediate Output with Mask

Program an Immediate Output with Mask.

6-9

REF

Refresh

Interrupt the program scan to 6-10 execute the I/O scan and service communications.

About the Program Flow Control Instructions

Use these instructions to control the sequence in which your program is executed. Control instructions allow you to change the order in which the processor scans a ladder program. Typically, these instructions are used to minimize scan time, create a more efficient program, and troubleshoot a ladder program.

1

Publication 1747-RM001G-EN-P - November 2008

Page 128

6-2

Program Flow Instructions

Jump to Label (JMP) and Label (LBL)

Use these instructions in pairs to skip portions of the ladder program.

(JMP)

Table 6.2 Program Function ]LBL[

Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •

•

•

•

•

•

If the Rung Containing the Jump Instruction is

Then the Program

True

Skips from the rung containing the JMP instruction to the rung containing the designated LBL instruction and continues executing. You can jump forward or backward.

False

Does not execute the JMP instruction.

Jumping forward to a label saves program scan time by omitting a program segment until needed. Jumping backward lets the controller execute program segments repeatedly.

TIP

Be careful not to jump backwards an excessive number of times. The watchdog timer could time out and fault the controller. Use a counter, timer, or the program scan register (system status register, word S:3, bits 0 to 7) to limit the amount of time you spend looping inside of JMP/LBL instructions.

Entering Parameters Enter a decimal label number from 0 to 255 in each subroutine file.

Using JMP The JMP instruction causes the controller to skip rungs. You can jump to the same label from one or more JMP instructions.

Publication 1747-RM001G-EN-P - November 2008

Page 129

Program Flow Instructions

6-3

Using LBL This input instruction is the target of JMP instructions having the same label number. You must program this instruction as the first instruction of a rung. This instruction has no control bits. You can program multiple jumps to the same label by assigning the same label number to multiple JMP instructions. However, label numbers must be unique.

TIP

Jump to Subroutine (JSR), Subroutine (SBR), and Return (RET)

The JSR, SBR, and RET instructions are used to direct the controller to execute a separate subroutine file within the ladder program and return to the instruction following the JSR instruction.

JSR JUMP TO SUBROUTINE SBR file number . . .

TIP SBR SUBROUTINE

RET RETURN

Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •

•

•

•

•

•

Do not jump (JMP) into an MCR zone. Instructions that are programmed within the MCR zone starting at the LBL instruction and ending at the END MCR instruction are always evaluated as though the MCR zone is true, regardless of the true state of the Start MCR instruction.

If you use the SBR instruction, the SBR instruction must be the first instruction on the first rung in the program file that contains the subroutine.

Use a subroutine to store recurring sections of program logic that must be executed from several points within your application program. A subroutine saves memory because you program it only once. Update critical I/O within subroutines using immediate input and/or output instructions (IIM, IOM), especially if your application calls for nested or relatively long subroutines. Otherwise, the controller does not update I/O until it reaches the end of the main program (after executing all subroutines). ATTENTION

Outputs controlled within a subroutine remain in their last state until the subroutine is executed again.

Publication 1747-RM001G-EN-P - November 2008

Page 130

6-4

Program Flow Instructions

Nesting Subroutine Files Nesting subroutines allows you to direct program flow from the main program to a subroutine and then on to another subroutine. The following rules apply when nesting subroutines. • With Fixed and SLC 5/01 processors, you can nest subroutines up to four levels • With SLC 5/02 and higher processors, you can nest subroutines up to eight levels. If you are using an STI subroutine, DII subroutine, I/O event-driven interrupt subroutine, or user fault routine, you can nest subroutines up to three levels from each subroutine. The following figure illustrates how subroutines may be nested.

Main Program

Level 1 Subroutine File 6 6 JSR

SBR

Level 2 Subroutine File 7 SBR

Level 3 Subroutine File 8 SBR

7 JSR

8 JSR

RET

RET

RET

An error occurs if more than the allowable levels of subroutines are called (subroutine stack overflow) or if more returns are executed than there are call levels (subroutine stack underflow).

Using JSR When the JSR instruction is executed, the controller jumps to the subroutine instruction (SBR) at the beginning of the target subroutine file and resumes execution at that point. You cannot jump into any part of a subroutine except the first instruction in that file.

Publication 1747-RM001G-EN-P - November 2008