The text of a manual · part 26 of 70
SLC 500 Instruction Set Reference Manual, pages 251 to 260
Pages 251 to 260 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 251
Understanding Interrupt Routines
TIP
11-19
PLC users: The main difference between the DII and the PLC 5/40 PII is that the DII requires all stated transitions to occur prior to generating a count, while the PII requires that only one of the stated transitions occur. Also, the PLC term “count” is referred to as “preset” in the DII.
Example The DII can be programmed to count items on a high-speed conveyer. Each time 100 items pass a photo-switch, the DII subroutine is executed. The DII subroutine then uses Immediate I/O instructions to package the products.
Operation
After you download your program and enter the REM Run mode, the DII begins operation as follows.
Counter Mode This mode is active when the Preset Value (S:50) contains a value greater than 1. 1. The DII reads the first byte of input data of a selected discrete input card at least once every 100µs.(1) Note that this “polling” of the input data has no effect on processor scan time. 2. When the input data matches the programmed masked value, the accumulator is incremented by one. The next count occurs when input data transitions to non-matched and then back to matched. 3. When the accumulator reaches or exceeds the preset value, between 1 and 32,767, the interrupt is generated and the accumulator is reset to zero. 4. The DII subroutine is executed. 5. The cycle repeats.
(1)
You must add interrupt latency time to the final transition or count that causes the interrupt subroutine to execute.
Publication 1747-RM001G-EN-P - November 2008
Page 252
11-20
Understanding Interrupt Routines
Event Mode This mode is active when the preset value (S:50) contains a 0 or 1. 1. The DII reads the first byte of input data of a selected discrete input card at least once every 100µs.(1) Note that this “polling” of the input data has no effect on processor scan time. 2. When the input data matches the programmed masked value, the interrupt is generated. 3. The DII subroutine is executed.(2) 4. The cycle repeats.(1)
DII Subroutine Content For identification of your DII subroutine, use the INT instruction as the first instruction in your first rung. The DII subroutine contains the rungs of your application logic. You can program any instruction inside the DII subroutine except a TND, REF, or SVC instruction. IIM or IOM instructions are needed in a DII subroutine if your application requires immediate update of input or output points. End the DII subroutine with an RET instruction. JSR stack depth is limited to 3. You may call other subroutines to a level 3 deep from an DII subroutine.
Publication 1747-RM001G-EN-P - November 2008
(1)
You must add interrupt latency time to the final transition or count that causes the interrupt subroutine to execute.
(2)
The DII continues to compare the input data to the programmed masked value while executing the DII subroutine.
Page 253
Understanding Interrupt Routines
11-21
Interrupt Latency and Interrupt Occurrences Interrupt latency is the interval between DII detection and the start of the interrupt subroutine. DII interrupts can occur at any point in your program, but not necessarily at the same point on successive interrupts. Interrupts can occur between instructions in your program, inside the I/O scan (between slots), or between the servicing of communications packets. The table below shows the interaction between an interrupt and the processor operating cycle.
DII
DII with Bit S:33/8 set
DII with Bit S:33/8 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
Processor Overhead
At start and end
Between communication packets
Between word updates Between word updates
Events in the Processor Operating Cycle
If an interrupt occurs while the SLC 5/03 (or higher) processor is performing a multi-word slot update and your interrupt subroutine accesses that same slot, the multi-word transfer completes prior to performing the interrupt subroutine slot access. Note that DII execution time adds directly to the overall scan time. During the latency period, the processor is performing operations that cannot be disturbed by the DII interrupt function. The Interrupt Latency Control Bit (S:33/8) functions as follows. • When the bit is set (1) interrupts are serviced within the minimum time possible. The time will vary depending upon which processor and communication protocol you are using. • The default state is cleared (0). When S:33/8 is clear (0), user interrupts occur between rungs and I/O slot updates. To determine the interrupt latency with S:33/8 clear, you must calculate the execution time of each and every rung of your program, then the add the execution time of the longest rung to the latency time.
Publication 1747-RM001G-EN-P - November 2008
Page 254
11-22
Understanding Interrupt Routines
Interrupt Priorities Interrupt priorities for the SLC 5/03 and higher processors are: 1. User fault routine. 2. Discrete Input Interrupt (DII). 3. STI Subroutine. 4. I/O Interrupt Subroutine. An executing interrupt subroutine can only be interrupted by the fault routine.
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 DII subroutine and re-written upon exiting the DII subroutine. • S:0 Arithmetic flags • S:13 and S:14 Math register • S:24 Index register
Reconfigurability You can reconfigure the DII entirely or in part, depending on the particular parameter(s) you choose. You can reconfigure some of the parameters simply by writing the new value over the old value. Other values require you to set the reconfiguration bit in addition to writing the new value. The DII is non-retentive and always reconfigures itself upon entry into the REM Run mode. Refer to "DII Parameters" for details on reconfiguring each parameter.
Example The DII can be programmed to count items on a high-speed conveyer. Each time 100 items pass a photo-switch, the DII subroutine is executed. The DII subroutine then uses Immediate I/O instructions to package the products.
Publication 1747-RM001G-EN-P - November 2008
Page 255
Understanding Interrupt Routines
11-23
If you want to vary the number of items that are packaged together, simply change the number in the DII preset parameter using a MOV instruction.
DII Parameters
The following parameters are associated with the DII function. These parameters have status file addresses that are described here. • DII Pending Bit (S:2/11) - When set, this bit indicates that the DII Accumulator (S:52) equals the DII preset (S:50) and the ladder file number specified by the DII File Number (S:46) is waiting to be executed. It is cleared when the DII File Number (S:46) begins executing, or on exit from the REM Run or REM Test mode. • DII Enable Bit (S:2/12) - 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 set in its default condition. If set, it allows execution of the DII subroutine if the DII File Number (S:46) is non-zero. If clear, when the interrupt occurs, the DII subroutine will not execute and the DII Pending bit is be set. The DII function continues to run anytime the DII file (S:46) is non-zero. If the pending bit is set, the enable bit is examined at the next end of scan. • DII Executing Bit (S:2/13) - When set, this bit indicates that the DII interrupt has occurred and the DII subroutine is currently being executed. This bit is cleared on completion of the DII routine, power-up, or REM Run mode entry. • DII Overflow Bit (S:5/12) - This bit is set whenever the DII interrupt occurs while still executing the DII subroutine or whenever the DII interrupt occurs while pending or disabled. • Reconfigure Bit (S:33/10) - When this bit is set (1), it indicates that at the next end of scan (END, TND, or REF), fault routine exit, STI ISR exit, Event ISR exit, or next DII ISR exit the: – DII accumulator is cleared, – values at status words S:47 to S:50 are applied, – the pending bit is cleared, and – the DII Reconfigure bit is cleared. • DII Lost Bit (S:36/8) - This bit is set if a DII interrupt occurs while the DII Pending bit is set. • File Number (Word S:46) - Enter a program file number (3 to 255) to be used as the discrete input interrupt subroutine. Write a 0 value to disable the function. This value is applied upon detection of a DII Reconfigure bit, each DII ISR exit, and each end of scan (END, TND, or REF). • Slot Number (Word S:47) - You enter the slot number (1 to 30) to be used as the discrete input interrupt subroutine. A zero value disables the function. This value is applied on detection of the DII Reconfigure bit, or on entry into the REM Run mode.
Publication 1747-RM001G-EN-P - November 2008
Page 256
11-24
Understanding Interrupt Routines
• Bit Mask (Word S:48) - You enter the bit-mapped value that corresponds to the bits you wish to monitor on the discrete I/O module (0 to 255). Only bits 0 to 7 are used in the DII function. Setting a bit indicates that you wish to include the bit in the comparison of the discrete I/O card’s bit pattern to the DII compare value (S:49). This value is applied on detection of the DII Reconfigure bit, each DII ISR exit, and at each end of scan (END, TND, or REF). • Compare Value (Word S:49) - You enter a bit-mapped value that corresponds to the bit pattern that must occur on the discrete I/O card for a count or interrupt to occur (0 to 255). Only bit 0 to 7 are used in the DII function. The bit must be set (1) or cleared (0) in order to satisfy the compare condition for that bit. An interrupt or count is generated upon the last bit transition of the compare value. This value is applied on detection of DII Reconfigure bit, each DII ISR exit, and at each end of scan (END, TND, or REF). To provide protection from inadvertent data monitor alteration of your selection, program an unconditional MOV instruction containing the compare value of the DII to S:49. • Preset (Word S:50) - When this value is equal to 0 or 1, an interrupt is generated each time the comparison specified in words S:48 and S:49 is satisfied. When this value is between 2 and 32767, a count occurs each time the bit comparison is satisfied. An interrupt is generated when the accumulator value reaches 1 or exceeds the preset value. This value is applied on detection of DII Reconfigure bit, each DII ISR exit, and at each end of scan (END, TND, or REF). To provide protection from inadvertent data monitor alteration of your selection, program an unconditional MOV instruction containing the preset value of the DII to S:50. • Return Mask (Word S:51) - The Return Mask is updated immediately preceding entry into the DII subroutine. This value contains the bit map of the last bit transition that caused the interrupt. If more than one bit transitions in the same 100µs DII sample period, it is included in the return mask. This bit is cleared by the processor on exit from the DII subroutine. Use this value to validate the last interrupt transition that caused the input pattern to match the compare value. Or when dynamically reconfiguring (sequencing) the DII, use this value inside of your DII’s subroutine to help determine/validate its position of the sequence. • Accumulator (Word S:52) - The DII accumulator contains the number of counts that have occurred. When a count occurs and the accumulator is greater than or equal to the preset value, a DII interrupt is generated and the accumulator is cleared.
Publication 1747-RM001G-EN-P - November 2008
Page 257
Understanding Interrupt Routines
11-25
For applications that measure the rate of incoming DII pulses while using a STI (Selectable Timed Interrupt), SLC 5/03 OS301 and above updates the DII accumulator prior to executing the first rung of the STI subroutine.
Discrete Input Interrupt Application Example The following example shows how to use the Discrete Input Interrupt to control a high-speed application. In the example, the DII is used to ensure that all bottles exiting a filling and capping machine have their caps installed. The bottle proximity switch is used as the DII input. When a bottle passes the proximity switch, the processor executes the DII subroutine. In the subroutine the processor reads the state of the cap proximity switch. If the cap is installed, the chute solenoid does not energize; allowing the bottle to continue down the line. If the cap is missing, the chute solenoid energizes, causing the defective bottle to divert down the chute and into the reject bin.
Cap Proximity (I:1/8) Bottle Proximity (I:1/0)
Chute (O:2/0)
Reject Bin
The following parameters are used to program the DII for the above application. • S:33/8 Interrupt Latency Control Bit = 1 • S:46 File = 3 • S:47 Slot = 1 • S:48 Mask = 00000001 • S:49 Compare = 00000001 • S:50 Preset = 1 Publication 1747-RM001G-EN-P - November 2008
Page 258
11-26
Understanding Interrupt Routines
Ladder Diagram for the Bottling Application
DII Example
4
The following program will demonstrate a DII. The following values need to be loaded into S:33/8 (1), S:46 (3), S:47 (1), S:49 (1) and S:50 (1) in the DII setup. This will guarantee that subroutine (3) will be executed every time that I:1.0/0 is true. 0000
INT I/O Interrupt
IIM Immediate Slot Mask Length
Cap Proximity I:1
Bottle Proximity I:1
8 1746-IA16
0 1746-IA16
Chute Open O:2 U 0 1746-OW8
0001
IOM Immediate Slot Mask Length
0002 8 1746-IA16 IOM Immediate Slot Mask Length
0004
Publication 1747-RM001G-EN-P - November 2008
Output w/Mask O:2.0 0001h 1
Chute Open O:2 L 0 1746-OW8
Cap Proximity I:1 e 0003 e e e
Input w/Mask I:1.0 0064h 1
Output w/Mask O:2.0 0001h 1
RET Return
END
Page 259
Understanding Interrupt Routines
11-27
I/O Interrupt Overview (ISR) This function allows a specialty I/O module to interrupt the normal processor operating cycle in order to scan a specified subroutine file. Interrupt operation for a specific module is described in the user’s manual for the module.
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
•
•
•
Not all specialty I/O modules are capable of generating I/O interrupts. Refer to the user manual of the specific specialty I/O module to see if it supports this feature. For example, you cannot use a standard discrete I/O module to accomplish an I/O event-driven interrupt. This section describes: • I/O operation. • I/O interrupt parameters. • IID and IIE instructions. • RPI instruction. • INT instruction.
Basic Programming Procedure for the I/O Interrupt Function • When you are configuring the specialty I/O module slot with the programming device, make sure you program the “ISR” (interrupt subroutine) program file number (range 3 to 255) that you want the processor to execute when the module generates an interrupt. Specialty I/O modules that create interrupts should be configured in the lowest numbered I/O slots. • Create the subroutine file that you have specified as the ISR number in the I/O module slot configuration.
Operation
When you restore your program and enter the REM Run mode, the I/O interrupt begins operation as follows. 1. The specialty I/O module determines that it needs servicing and generates an interrupt request to the SLC processor. 2. The processor is interrupted from what it is doing, and the specified interrupt subroutine file (ISR) is scanned. 3. When the ISR scan is completed, the specialty I/O module is notified. This informs the specialty I/O module that it is allowed to generate a new interrupt. 4. The processor resumes normal operation from where it left off.
Publication 1747-RM001G-EN-P - November 2008
Page 260
11-28
Understanding Interrupt Routines
Interrupt Subroutine (ISR) Content The Interrupt Subroutine (INT) instruction should be the first instruction in your ISR. This identifies the subroutine file as an I/O interrupt subroutine. The ISR contains the rungs of your application logic. You can program any instruction inside an ISR except a TND, REF, or SVC instruction. IIM or IOM instructions are needed in an ISR if your application requires immediate update of input or output points. Terminate the ISR with an RET (return) instruction. JSR stack depth is limited to 3. That is, you may call other subroutines to a level 3 deep from an ISR.
Interrupt Latency and Interrupt Occurrences Interrupt latency is the interval between the I/O module’s request for service and the start of the interrupt subroutine. I/O interrupts can occur at any point in your program, but not necessarily at the same point on successive interrupts. Interrupts can only occur between instructions in your program, inside the I/O scan (between slots), or between the servicing of communication packets. The following table shows the interaction between an interrupt and the processor operating cycle.
SLC 5/02 I/O Interrupts 5/03 and Higher I/O Interrupts with Bit S:33/8 set
5/03 and Higher I/O Interrupts with Bit S:33/8 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
Processor Overhead
At start and end
Between communication packets
Between word updates Between word updates
Events in the Processor Operating Cycle
Note that ISR execution time adds directly to the overall scan time. During the latency period, the processor is performing operations that cannot be disturbed by the ISR interrupt function.
Publication 1747-RM001G-EN-P - November 2008