The text of a manual · part 25 of 40
DL05 Micro PLC User Manual, Volume 1 of 2: Chapter 5: Standard RLL and Intelligent Box Instructions, pages 224 to 233
Pages 224 to 233 of 379, from DL05 Micro PLC User Manual, Volume 1 of 2
The original document is the PDF (5.8 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 AutomationDirect D0-05AA
Page 224
Chapter 5: Standard RLL - Program Control Instructions
Program Control Instructions For / Next (FOR) (NEXT) DS5
Used
HPP
Used
The For and Next instructions are used to execute a section of ladder logic between the For and Next instruction a specified numbers of times. When the For instruction is enabled, the program will loop the specified number of times. If the For instruction is not energized the section of ladder logic between the For and Next instructions is not executed. For / Next instructions cannot be nested. The normal I/O update and CPU housekeeping is suspended while executing the For / Next loop. The program scan can increase significantly, depending on the amount of times the logic between the For and Next instruction is executed. With the exception of immediate I/O instructions, I/O will not be updated until the program execution is completed for that scan. Depending on the length of time required to complete the program execution, it may be necessary to reset the watch dog timer inside of the For / Next loop using the RSTWT instruction. Operand Data Type ....................................A V-memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . V Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . K
A aaa FOR
NEXT
DL05 Range aaa See memory map 1-9999
DL05 Micro PLC User Manual, 6th Edition, Rev. A
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D 5–101
Page 225
Chapter 5: Standard RLL - Program Control Instructions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D 5–102
In the following example, when X1 is on, the application program inside the For / Next loop will be executed three times. If X1 is off the program inside the loop will not be executed. The immediate instructions may or may not be necessary depending on your application. Also, The RSTWT instruction is not necessary if the For / Next loop does not extend the scan time larger the Watch Dog Timer setting. For more information on the Watch Dog Timer, refer to the RSTWT instruction. DirectSOFT 5
Direct SOFT32 X1
1
K3
2
FOR
RSTWT
X20
Y5 OUT
NEXT
Handheld Programmer Keystrokes B
$ STR
1
R ORN T MLR
SHFT SHFT
R ORN
S
$
SHFT
I
STR
5
GX OUT SHFT
RST 8 F 5
N TMR
ENT
O INST#
F
E
3
SET
ENT
W ANDN
T MLR
ENT
C
A
ENT
2
0
T MLR
ENT
ENT X
4
D
DL05 Micro PLC User Manual, 6th Edition, Rev. A
3
Page 226
Chapter 5: Standard RLL - Program Control Instructions
Goto Subroutine (GTS) (SBR) DS5
Used
HPP
Used
The Goto Subroutine instruction allows a section of ladder K aaa logic to be placed outside the main body of the program GTS execute only when needed. There can be a maximum of 64 GTS instructions and 64 SBR instructions used in a program. The GTS instructions can be nested up to 8 levels. An error E412 will occur if the maximum limits are exceeded. Typically this will be used in an application where a block of program logic may be slow to execute and is not required to execute K aaa SBR every scan. The subroutine label and all associated logic is placed after the End statement in the program. When the subroutine is called from the main program, the CPU will execute the subroutine (SBR) with the same constant number (K) as the GTS instruction which called the subroutine. By placing code in a subroutine it is only scanned and executed when needed since it resides after the End instruction. Code which is not scanned does not impact the overall scan time of the program. Operand Data Type
DL05 Range
....................................A Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . K aaa 1-FFFF
Subroutine Return (RT) DS5
Used
HPP
Used
When a Subroutine Return is executed in the subroutine the CPU will return to the point in the main body of the program from which it was called. The Subroutine Return is used as termination of the subroutine which must be the last instruction in the subroutine and is a stand alone instruction (no input contact on the rung).
RT
Subroutine Return Conditional (RTC) DS5
Used
HPP
Used
The Subroutine Return Conditional instruction is a optional instruction used with a input contact to implement a conditional return from the subroutine. The Subroutine Return (RT) is still required for termination of the Subroutine.
RTC
DL05 Micro PLC User Manual, 6th Edition, Rev. A
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
5–103
Page 227
Chapter 5: Standard RLL - Program Control Instructions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D 5–104
In the following example, when X1 is on, Subroutine K3 will be called. The CPU will jump to the Subroutine Label K3 and the ladder logic in the subroutine will be executed. If X35 is on the CPU will return to the main program at the RTC instruction. If X35 is not on Y0–Y17 will be reset to off and then the CPU will return to the main body of the program. X1
Direct SOFT32 Display DirectSOFT 5
K3 GTS
C0
LD
K10
END SBR
K3
X20
Y5 OUTI
X21
Y10 OUTI
X35 RTC X35
Y0
Y17 RSTI
RT
Handheld Programmer Keystrokes $
B
STR
SHFT
G
1
ENT
6
T MLR
S RST
4
N TMR
D B
D
3
ENT
? ? SHFT
E
SHFT
S RST
SHFT
$
SHFT
I
GX OUT
SHFT
I
$
SHFT
I
SHFT
I
STR
STR
GX OUT $
F C
8
B
8
I
T MLR
SP STRN
SHFT
I
S RST
SHFT
I
SHFT
R ORN
T MLR
ENT R ORN C
8
SHFT
SHFT
1
8
R ORN
STR
3
D
8 C
2
A
8
5 2 1 3
A
0
3
ENT
ENT
ENT B A F
1 0 5
ENT ENT ENT
ENT D
8
2
D
3
F
5
0
ENT
DL05 Micro PLC User Manual, 6th Edition, Rev. A
ENT B
1
H
7
ENT
Page 228
Chapter 5: Standard RLL - Program Control Instructions In the following example, when X1 is on, Subroutine K3 will be called. The CPU will jump to the Subroutine Label K3 and the ladder logic in the subroutine will be executed. The CPU will return to the main body of the program after the RT instruction is executed. DirectSOFT Direct SOFT532 X1
K3 GTS
END
SBR
K3
X20
Y5 OUT
X21
Y10 OUT
RT
Handheld Programmer Keystrokes $
B
STR
SHFT
G
1
ENT
6
T MLR
S RST
4
N TMR
D B
D
3
ENT
SHFT
E
SHFT
S RST
SHFT
$
SHFT
I
STR
GX OUT $
STR
F SHFT
GX OUT SHFT
I B
R ORN
3 1
T MLR
2
D A
0
3
ENT
ENT
ENT C
8 1
R ORN C
8 5
ENT
A
0
2
B
1
ENT
ENT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
ENT
DL05 Micro PLC User Manual, 6th Edition, Rev. A
5–105
Page 229
Chapter 5: Standard RLL - Program Control Instructions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
Master Line Set (MLS) DS5
Used
HPP
Used
The Master Line Set instruction allows the program to control sections of ladder logic by forming a new power rail controlled by the main left power rail. The main left rail is always master line 0. When a MLS K1 instruction is used, a new power rail is created at level 1. Master Line Sets and Master Line Resets can be used to nest power rails up to seven levels deep. Operand Data Type
K aaa MLS
DL05 Range aaa
....................................A Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . K
1-7
Master Line Reset (MLR) DS5
Used
HPP
Used
The Master Line Reset instruction marks the end of control for the corresponding MLS instruction. The MLR reference is one less than the corresponding MLS.
K aaa MLR
Understanding Master Control Relays Operand Data Type
DL05 Range aaa
....................................A Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . K
0-7
The Master Line Set (MLS) and Master Line Reset (MLR) instructions allow you to quickly enable (or disable) sections of the RLL program. This provides program control flexibility. The following example shows how the MLS and MLR instructions operate by creating a sub power rail for control logic.
DirectSOFT 5
Direct SOFT32 X0
K1 MLS
X1
Y7 OUT K2
X2
MLS X3
When contact X0 and X2 are ON, logic under the second MLS will be executed.
Y10 OUT K1 MLR K0 MLR
X10
Y11 OUT
5–106
When contact X0 is ON, logic under the first MLS will be executed.
DL05 Micro PLC User Manual, 6th Edition, Rev. A
The MLR instructions note the end of the Master Control area.
Page 230
Chapter 5: Standard RLL - Program Control Instructions
MLS/MLR Example In the following MLS/MLR example logic between the first MLS K1 (A) and MLR K0 (B) will function only if input X0 is on. The logic between the MLS K2 (C) and MLR K1 (D) will function only if input X10 and X0 is on. The last rung is not controlled by either of the MLS coils. DirectSOFT 5 DirectSOFT32
Handheld Programmer Keystrokes
X0
K1
X1
X2
A
Y MLS
B
OUT
$
B STR
1
C1
GX OUT
SHFT
C
$
C
ENT
OUT K2
Y1
Y2
MLR X5
SHFT
C
$
D
ENT
X6
GX OUT
A
$
B
0
C
$
F 5
GX OUT
B
$
E
1 4
GX OUT
C
OUT
T MLR
B
Y3
$
F
K0 MLR Y4 OUT
B
B
2 1
0
ENT ENT ENT ENT ENT
GX OUT
SHFT
C
$
G
ENT
GX OUT
D
T MLR
A
$
H
3 0
STR GX OUT
7 E
C 2
2
ENT ENT ENT C
4
ENT
ENT
5
6
ENT
ENT
STR
STR
1
ENT
ENT A
2
0
2
1
Y MLS
OUT
X7
3
STR
C2
A 2
GX OUT
STR
D
ENT
2
OUT K1
ENT
STR
STR
OUT X4
1
STR C
MLS X5
0
ENT
C0
Y0
X10
A STR
OUT X3
$
MLS
2
ENT
DL05 Micro PLC User Manual, 6th Edition, Rev. A
ENT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
5–107
Page 231
Chapter 5: Standard RLL - Interrupt Instructions
1 Interrupt Instructions Interrupt (INT) 2 The Interrupt instruction allows a section of ladder logic to be placed below the main body of the program and executed only when needed. High-Speed I/O 3 Modes 10, 20, and 40 can generate an interrupt. With Mode 40, you may select an external interrupt (input 4 X0), or a time-based interrupt (5–999 mS). Typically, interrupts are used in an application when a fast response to an input is needed or a 5 program section must execute faster than the normal CPU scan. The interrupt label and all associated logic must be placed after the End statement in the program. When an interrupt occurs, the CPU will complete execution of the current instruction it is processing in ladder 6 logic, then execute the interrupt routine. After interrupt routine execution, the ladder program resumes from the point at which it was interrupted. 7 See Chapter 3, the section on Mode 40 (Interrupt) Operation for more details on interrupt configuration. In the DL05, only one hardware interrupt is available. 8 Operand Data Type DL05 Range 9 Interrupt Return (IRT) An Interrupt Return is normally executed as the last instruction in the interrupt routine. It 10 returns the CPU to the point in the main program from which it was called. The Interrupt Return is a stand-alone instruction 11 (no input contact on the rung). Return Conditional (IRTC) 12 Interrupt The Interrupt Return Conditional instruction is a optional instruction used with an input contact to implement a conditional return from the interrupt 13 routine. The Interrupt Return is required to terminate the interrupt routine. 14 Enable Interrupts (ENI) The Enable Interrupt instruction is placed in the main ladder program (before the End instruction), enabling the interrupt. The interrupt remains A enabled until the program executes a Disable Interrupt instruction. B C D DS5
Used
HPP
Used
Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . O
DS5
Used
HPP
Used
INT
O aaa
INT
1
0, 1
IRT
DS5
Used
HPP
Used
IRTC
DS5
Used
HPP
Used
ENI
5–108
DL05 Micro PLC User Manual, 6th Edition, Rev. A
Page 232
Chapter 5: Standard RLL - Interrupt Instructions
Disable Interrupts (DISI) DS5 HPP
1 2 3 External Interrupt Program Example In the following example, we do some initialization on the first scan, using the first-scan 4 contact SP0. The interrupt feature is the HSIO Mode 40. Then we configure X0 as the external interrupt by writing to its configuration register, V7634. See Chapter 3, Mode 40 5 Operation for more details. During program execution, when X2 is on the interrupt is enabled. When X2 is off the interrupt will be disabled. When an interrupt signal (X0) occurs the CPU will jump to the 6 interrupt label INT O 0. The application ladder logic in the interrupt routine will be performed. The CPU will return to the main body of the program after the IRT instruction is 7 executed. 8 9 10 11 12 13 14 A B C D A Disable Interrupt instruction in the main body of the application program (before the End instruction) will disable the interrupt (either external or timed). The interrupt remains disabled until the program executes an Enable Interrupt instruction.
Used Used
DISI
DirectSOFT
SP0
LD
OUT
LD
OUT
Load the constant value (K40) into the lower 16 bits of the accumulator
K40
Copy the value in the lower 16 bits of the accumulator to V7633
V7633
K4
Load the constant value (K4) into the lower 16 bits of the accumulator
V7634
Copy the value in the lower 16 bits of the accumulator to V7634
Handheld Programmer Keystrokes
$
SHFT
L ANDST
GX OUT
SHFT
D
SHFT
L ANDST
D
SHFT
C
ENI
SHFT
DISI
SP STRN SHFT
E
4
D
3
I
V AND
2
8
A
0
ENT
SHFT
K JMP
E
H
G
D
7
6
SHFT
K JMP
E
H
G
D
7
6
4 3
4
3
A
D
0
3
ENT ENT
ENT
E
4
ENT
ENT
2
N TMR C
V AND
3
$
STR
SP STRN
3
GX OUT
X2
X2
SHFT
STR
I
ENT
8
ENT
S RST
I
8
ENT
END
INT
O0
X1
X3
Y5 SETI Y7 SETI
IRT
SHFT
E
SHFT
I
$
SHFT
I
X SET
SHFT
I
$
STR
4
N TMR
D
8
N TMR
T MLR
I
SHFT
I
SHFT
I
R ORN
8
A
F
8
SHFT
ENT
B
8
X SET
STR
3
D
8
H
8
T MLR
1
5 3
7
0
ENT
ENT ENT ENT ENT
ENT
DL05 Micro PLC User Manual, 6th Edition, Rev. A
5–109
Page 233
Chapter 5: Standard RLL - Interrupt Instructions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
Timed Interrupt Program Example In the following example, we do some initialization on the first scan, using the first-scan contact SP0. The interrupt feature is the HSIO Mode 40. Then we configure the HSIO timer as a 10 mS interrupt by writing K104 to the configuration register for X0 (V7634). See Chapter 3, Mode 40 Operation for more details. When X4 turns on, the interrupt will be enabled. When X4 turns off, the interrupt will be disabled. Every 10 mS the CPU will jump to the interrupt label INT O 0. The application ladder logic in the interrupt routine will be performed. If X3 is not on Y0–Y7 will be reset to off and then the CPU will return to the main body of the program. DirectSOFT 5
Direct SOFT32
Handheld Programmer Keystrokes SP0
Load the constant value (K40) into the lower 16 bits of the accumulator
LD K40
$
B STR
SHFT OUT V7633
K104
D 3
Copy the value in the lower 16 bits of the accumulator to V7633
GX OUT
Load the constant value (K10) into the lower 16 bits of the accumulator
GX OUT
SHFT
V AND
$
E
ENT
SHFT LD
SHFT L ANDST
Copy the value in the lower 16 bits of the accumulator to V7634
V7634 X4 ENI
SHFT
V AND
D 3
STR OUT
ENT
1 L ANDST
4 E 4
SP STRN
N TMR E 4
SHFT
D
SHFT
E
SHFT
I
I
SHFT
K JMP
E
H
G
D
7
6
SHFT
K JMP
B
H
G
D
7
I
A 4
0 D
3
3 A
1
6
ENT E
0 E
3
ENT
4
4
ENT
ENT
ENT
8 ENT S
I
3
8
RST
N TMR
D
4 8
N TMR
T MLR
8
ENT
X4 DISI
END $ INT
SHFT SHFT
I
SHFT
I
Y5
SP STRN
SETI
X
SHFT
I
I
R ORN
STR X SET
X2
SET X3
Y7
Y0
SHFT
8
ENT A 0 C
I
O0
3
8
2 F
8
5 D
8
3 A
8
ENT ENT ENT H
0 T MLR
ENT
7
ENT
ENT
RSTI
IRT
Independent Timed Interrupt Interrupt O1 is also available as an interrupt. This interrupt is independent of the HSIO features. Interrupt O1 uses an internal timer that is configured in V-memory location V7647. The interrupt period can be adjusted from 5 to 9999 mS. Once the interrupt period is set and the interrupt is enabled in the program, the CPU will continuously call the interrupt routine based on the time setting in V7647. Input Configuration Register Function Hex Code Required –
5–110
V7647
High-Speed Timed Interrupt
DL05 Micro PLC User Manual, 5th Edition, 6/04 xxxx (xxxx = timer setting) 5 - 9999 mS (BCD)