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

The text of a manual · part 25 of 70

SLC 500 Instruction Set Reference Manual, pages 241 to 250

Pages 241 to 250 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 241

Understanding Interrupt Routines

Operation

11-9

After you download your program and enter the REM Run mode, the STI begins operation as follows. 1. The STI timer begins timing. 2. When the STI interval expires, the STI timer is reset, the processor scan is interrupted and the STI subroutine file is scanned. 3. If while executing the STI subroutine, another STI interrupt occurs, the STI Pending bit (S:2/0) is set. 4. If while an STI is pending, the STI timer expires, the STI Lost bit (S:36/9) is set. (For SLC 5/02 processors, the Overflow (S:5/10) bit is set.) 5. When the STI subroutine scan is completed, scanning of the main program file resumes at the point where it left off, unless an STI is pending. In this case, the subroutine is immediately scanned again. 6. The cycle repeats. For identification of your STI subroutine, include an INT instruction as the first instruction on the first rung of the file.

STI Subroutine Content The STI subroutine contains the rungs of your application logic. You can program any instruction inside the STI subroutine except a TND, REF, or SVC instruction. IIM or IOM instructions are needed in an STI subroutine if your application requires immediate update of input or output points. End the STI subroutine with an RET instruction. JSR stack depth is limited to 3. You may call other subroutines to a level 3 deep from an STI subroutine.

Interrupt Latency and Interrupt Occurrences Interrupt latency is the interval between the STI time-out and the start of the interrupt subroutine. STI interrupts can occur at any point in your program, but not necessarily at the same point on successive interrupts. The tables below show the interaction between an interrupt and the processor operating cycle.

Publication 1747-RM001G-EN-P - November 2008

Page 242

11-10

Understanding Interrupt Routines

SLC 5/02 STI

SLC 5/03 and Higher STI with Bit S:33/8 set

SLC 5/03 and Higher STI with Bit S:33/9 cleared

Input Scan

Between slot updates

Between word updates

Between slot updates

Program Scan

Between instruction updates

Between word updates

Between rung updates

Output Scan

Between slot updates

Between word updates

Between slot updates

Communications

Between communication Between word packet packets updates

Between communication packets

Processor Overhead

At start and end

Between word updates

Between word updates

Events in the Processor Operating Cycle

Note that STI execution time adds directly to the overall scan time. During the latency period, the processor is performing operations that cannot be disturbed by the STI interrupt function. Latency periods are: • SLC 5/02 processors interrupts are serviced within 2.4 ms maximum. • SLC 5/03 and higher processors: If an interrupt occurs while the processor is performing a multi-word slot update and your interrupt subroutine accesses that same slot, the multi-word transfer finishes to completion prior to performing the interrupt subroutine slot access. The Interrupt Latency Control bit (S:33/8) functions: • when the bit is set (1), interrupts are serviced within the interrupt latency time. • when the bit is clear (0), INTs are serviced per rung, slot, and packet execution time. The default state is cleared (0). To determine the interrupt latency with S:33/8 clear, you must calculate the execution time of each and every rung in your program. Use the longest calculated execution time plus your maximum interrupt latency.

Publication 1747-RM001G-EN-P - November 2008

Page 243

Understanding Interrupt Routines

11-11

Interrupt Priorities

Table 11.3 Interrupt Priorities SLC 5/02 Processor

SLC 5/03 and Higher Processors

1. User Fault Routine

1. User Fault Routine

2. Selectable Timed Interrupt Subroutine

2. Discrete Input Interrupt (DII)

3. Interrupt Subroutine (ISR)

3. Selectable Timed Interrupt Subroutine 4. Interrupt Subroutine (ISR)

An executing interrupt can only be interrupted by an interrupt having higher priority.

TIP

Under certain conditions, though, it is possible for a lower priority task to run during the DII execution.

Status File Data Saved Data in the following words is saved on entry to the STI subroutine and re-written upon exiting the STI subroutine. • S:0 Arithmetic flags • S:13 and S:14 Math register • S:24 Index register

Publication 1747-RM001G-EN-P - November 2008

Page 244

11-12

Understanding Interrupt Routines

STI Parameters

The following parameters are associated with the STI function. These parameters have status file addresses that are described here. • STI file number (Word S:31) - This can be any number from 3 to 255. A value of zero disables the STI function. An invalid number generates fault 0023h. • Setpoint (Word S:30) - This is the time between the starting point of successive scans of the STI file. It can be any value from 10 to 2550 milliseconds. (For SLC 5/02 see page 11-8.) You enter a value of 1 to 255, which results in a 10 to 2550 ms setpoint. A value of zero disables the STI function. An invalid time generates fault 0024h. SLC 5/03 and higher processors: If S:2/10 is set, time is in 1 ms increments. If this bit is clear, time is in 10 ms increments. If the STI is initiated while in the REM Run mode by loading the status registers, the interrupt starts timing from the end of the program scan in which the status registers were loaded. If the STI has been previously configured (with a different setpoint), the new setpoint takes effect only after the previously-configured STI has timed out. • STI Pending Bit (S:2/0) - This bit is set when the STI timer has timed out and the STI routine is waiting to be executed. This bit is reset upon starting the STI routine, execution of a true STS instruction, power-up, or exit from the REM Run or Test mode. SLC 5/02 specific: The STI pending bit is not set if the STI timer expires while executing the fault routine. SLC 5/03 and higher processors: This bit is set if the STI timer expires while executing the DII subroutine or fault routine. • STI Enable Bit (S:2/1) - The default value is 1 (set). When a file number between 3 and 255 is present in word S:31 and a setpoint value between 1 and 255 is present in word S:30, a set enable bit allows scanning of the STI file. If the bit is reset by an STD instruction, scanning of the STI file no longer occurs. If the bit is set by an STE or STS instruction, scanning is again allowed. The enable bit only enables/disables the scanning of the STI subroutine. It does not affect the STI timer. The STS instruction affects both the enable bit and the STI timer. The default state is enabled. If this bit is set or reset using the STE, STD, or STS instruction, enable/disable takes effect immediately. If this bit is set in the user program using an instruction other than STE, STD, or STS, it takes effect at the next end of scan. SLC 5/02 specific: If this bit is set or reset by the user program or communications, it does not take effect until the next end of scan.

Publication 1747-RM001G-EN-P - November 2008

Page 245

Understanding Interrupt Routines

11-13

SLC 5/03 and higher processors: If this bit is set or reset by the user program or communications, it takes effect upon the STI timer expiration or next end of scan (whichever occurs first). • STI Executing Bit (S:2/2) - This bit is set when the STI file is being scanned and cleared when the scan is completed. The bit is also cleared on power-up and entry into the REM Run mode. • STI Resolution Selection Bit (S:2/10) - This bit is clear by default. When clear, this bit selects a 10 ms increment for the STI Setpoint (S:30) value. When set, this bit selects a 1 ms increment for the STI Setpoint (S:30) value. To program this feature, use the data monitor function to set/clear this bit, or address this bit with your ladder program. This bit is user configurable and takes effect on a REM PROG to REM RUN mode transition. • Overflow Bit (S:5/10) - This minor error bit is set whenever the STI timer expires while the STI routine is executing or disabled while the pending bit is set. When this occurs, the STI timer continues to operate at the rate present in word S:30. If the overrun bit becomes set, take the corrective action your application dictates, then clear the bit. • STI Lost Bit (Word S:36/9) - This bit is set anytime an STI interrupt occurs while the STI Pending bit is also set. When set, you are notified that a STI interrupt has been lost. For example, the interrupt is lost because a previous interrupt was already pending and waiting execution. Examine this bit in your user program and take appropriate action if your application cannot tolerate this condition. Then clear this bit with your user program in order to prepare for the next possible occurrence of this error. Use the following rungs to initialize and measure the amount of time between two consecutive STI subroutine executions. The 10 µs timer is also available in the DII interrupt and I/O interrupt. This application example can also be used for the Event I/O interrupt or the DII interrupt by replacing S:43 with either S:44 or S:45 respectively.

Publication 1747-RM001G-EN-P - November 2008

Page 246

11-14

Understanding Interrupt Routines

STI Example The following program will demonstrate a STI. The follwoing values need to be loaded into S:30 (1), S:31 (4) and S:2/10 (0) in STI setup. This will guarantee that subroutine (4) will be executed every 10 ms. The subroutine program will calculate the time difference from its last execution. The following rung will ensure that the interrupt measurement is initialized each time the run mode is entered

Indicate Valid Measurement B3:0 U 0

First Pass S:1 0000 15 MOV Move Source

0 0< N10:2 0<

Dest

The following rung will allow a timer to self reset every 1/2 second. T4:0 0001 DN

TON Timer On Delay Timer Time Base Preset Accum

EN T4:0 0.01 50< 0<

DN

Each time the timer completes, a reading will be displayed for visual purposes. T4:0 0002 DN

MOV Move Source Dest

0003

Publication 1747-RM001G-EN-P - November 2008

N10:2 0< N10:3 0<

END

Page 247

Understanding Interrupt Routines

11-15

The following rung will measure the time difference between consecutive interrupt subroutine executions. Integer N10.2 contains the number of microsecond "ticks" that have occured.

Indicate Valid Measurement B3:0

SUB Subtract Source A

0000 0

S:43 0< N10:1 0< N10:2 0<

Source B Dest

Processor Arithmetic Sign Flag S:0 3

ADD Add Source A Source B Dest

32767 32767< N10:2 0< N10:2 0<

MOV Move Source Dest

S:43 0< N10:1 0< Overflow Trap S:5 U 0

The following rung will set B3:0/0 to indicate that the value in N10.2 is valid. 0001

Indicate Valid Measurement B3:0 L 0 END

0002

TIP

The math overflow selection bit (S:2/14) must be set prior to entering RUN mode.

Publication 1747-RM001G-EN-P - November 2008

Page 248

11-16

Understanding Interrupt Routines

STD and STE Instructions

The STD and STE instructions are used to create zones in which STI ladder execution cannot occur. The STI timer continues to operate at the rate present in word S:30.

Selectable Timed Disable - STD Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •

•

•

•

When true, this instruction resets the STI enable bit and prevents the STI subroutine from executing. When the rung goes false, the STI enable bit remains reset until a true STS or STE instruction is executed. The STI timer continues to operate while the enable bit is reset.

Selectable Timed Enable - STE This instruction, upon a false-true transition of the rung, sets the STI enable bit and allows execution of the STI subroutine. When the rung goes false, the STI enable bit remains set until a true STD instruction is executed. This instruction has no effect on the operation of the STI timer or setpoint. When the enable bit is set, the first execution of the STI subroutine can occur at any fraction of the timing cycle up to a full timing cycle later.

STD/STE Zone Example In the program that follows, the STI function is in effect. The STD and STE instructions in rungs 6 and 12 are included in the ladder program to avoid having STI subroutine execution at any point in rungs 7 through 11. The STD instruction (rung 6) resets the STI enable bit and the STE instruction (rung 12) sets the enable bit again. The STI timer increments and may time out in the STD zone, setting the pending bit S:2/0 and overrun bit S:5/10. The first pass bit S:1/15 and the STE instruction in rung 0 are included to insure that the STI function is initialized following a power cycle. You should include this rung any time your program contains an STD/STE zone or an STD instruction.

Publication 1747-RM001G-EN-P - November 2008

Page 249

Understanding Interrupt Routines

11-17

Program File 3 STI Example

3

The following program will demonstrate a STE and a STD. First Pass S:1

STE Selectable

0000

Timed Enable

15 Any Bit B3:0

Any Bit B3:2

0001 0

0

Any Bit B3:0

Any Bit B3:2

0002 1

0 STD Selectable

0003

STI interrupt execution does not occur between STD and STE.

Any Bit B3:0

Any Bit B3:1

2

2

Timed Disable

Any Bit B3:2

0004 0

Any Bit B3:0

Any Bit B3:2

0005 3

0 STE Selectable

0006

Timed Enable

Any Bit B3:0

Any Bit B3:2

4

0

Any Bit B3:0

Any Bit B3:2

5

0

0007

0008

0009

END

Use the STS instruction to condition the start of the STI timer upon entering the REM Run mode - rather than starting automatically. You can also use it to set up or change the file number or setpoint/frequency of the STI routine that is executed when the STI timer expires.

Selectable Timed Start (STS)

This instruction is not required to configure a basic STI interrupt application. STS Selectable File Time

Timed Start

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

•

•

•

The STS instruction requires you to enter two parameters, the STI file number and the STI setpoint. Upon a true execution of the rung, this instruction enters the file number and setpoint in the status file (S:31, S:30), overwriting the existing data. At the same time, the STI timer is reset and begins timing; at timeout, the STI subroutine execution occurs. When the rung goes false, the STI function remains enabled at the setpoint and file number you’ve entered in the STS instruction. TIP

SLC 5/03 and higher processors: The STS instruction uses the setting of the STI resolution bit S:2/10 to determine the timebase to be used upon STS instruction execution.

Publication 1747-RM001G-EN-P - November 2008

Page 250

11-18

Understanding Interrupt Routines

Use the Discrete Input Interrupt (DII) for high-speed processing applications or any application that needs to respond to an event quickly. This instruction allows the processor to execute a ladder subroutine when the input bit pattern of a discrete I/O card matches a compare value that you programmed.

Discrete Input Interrupt Overview

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

•

•

The status file contains six bit values and six word values used to program and monitor the DII function. The DII does not require ladder logic instructions for configuration. You program the DII to examine the input bit pattern of the first bits of any single I/O slot, which contains any discrete input card (such as IG16, IV16, IB8, IB32). When the input bit pattern matches the compare value, the accumulator is incremented. The DII accumulator counts to the preset value and, once the interrupt is generated, it immediately wraps around and begins counting again at zero. While scanning the DII subroutine, you can reconfigure the DII to look for an entirely different event. This facilitates DII sequencing. The DII can be programmed to compare each input point to either a high (1) or low (0) state. The accumulator is incremented on the input transition that causes the input points to match the compare value. IIM or IOM instructions are needed in the DII subroutine if your application requires immediate update of input or output points. End the DII subroutine with an RET instruction.

Basic Programming Procedure for the DII Function To use the DII function with your main program file: 1. Create a subroutine file (range is from 3 to 255) and enter the desired ladder rungs. This is your DII subroutine file. (Project Tree - Controller Folder - Processor Status File - DII Tab) 2. Enter the Input Slot number (word S:47). 3. Enter the Bit Mask (word S:48). Valid Bit Masks range from 0 to 255. 4. Enter the Compare Value (word S:49). Valid Compare Values range from 0 to 255. 5. Enter the Preset Value (word S:50). Valid Preset Values range from 0 to 32,767. 6. Enter the DII subroutine File Number in word S:46 of the status file. (See page B-55.) A zero value disables the DII function.

Publication 1747-RM001G-EN-P - November 2008