Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (16.5 MB, 964 trang )
FX3S/FX3G/FX3GC/FX3U/FX3UC Series
8 Program Flow – FNC 00 to FNC 09
Programming Manual - Basic & Applied Instruction Edition
8.2 FNC 01 – CALL / Call Subroutine
1
Introduction
Caution
1. Using a label (P) number two or more times
In CALL instructions, the same number can be used two or more times in operands (P).
However, do not use a label (P) and number used in another instruction (CJ instruction).
FNC 00
CJ
X030
FNC 01
CALLP
P9
2
P9
Overview
X020
Bad
3
User program
Instruction
List
Label
P9
1. Example of fundamental use (no nesting)
4
Program examples
FNC 01
CALL
Devices
in Detail
X000
P 10
Main program
While X000 is ON, the program execution jumps to a
step with the label P10.
FNC 06
FEND
5
Specified the
Device &
Constant
Label
P 10
Subroutine program
When SRET instruction is executed after the subroutine
program has executed, the program execution returns to
the original step +1.
FNC 02
SRET
6
Before
Programming
END
2. Example of multiple CALL instructions in subroutines (multiple nesting)
CALL instruction can be used up to 4 times in subroutine programs. Nesting of up to five layers is allowed.
FNC 01
CALLP
P 11
FNC 06
FEND
Label
P 11
Label
P 12
FNC 01
CALL
FNC 02
SRET
P 12
Main program
When X001 turns from OFF to ON, the program execution
jumps to the label P11 only once.
8
Subroutine program 1
When SRET instruction is executed, the program
execution returns to the main program.
If X002 is ON while the subroutine program 1 is
executed, the program execution jumps to a step with the
label P12.
FNC00-FNC09
Program Flow
X002
Basic
Instruction
X001
7
X003
FNC10-FNC19
Move & Compare
FNC 02
SRET
9
Subroutine program 2
The subroutine program with P12 is executed, and then
the program execution returns to the subroutine program
with P11 by SRET instruction.
END
10
FNC20-FNC29
Arith. & Logic
Operation
229
FX3S/FX3G/FX3GC/FX3U/FX3UC Series
8 Program Flow – FNC 00 to FNC 09
Programming Manual - Basic & Applied Instruction Edition
8.2 FNC 01 – CALL / Call Subroutine
8.2.1
Cautions on subroutines and interrupt routines
This section explains cautions on creating programs in subroutines and interrupt routines.
The explanation below is given for subroutines, but the situation also applies to interrupt routines.
1. When using timers in subroutines (or interrupt routines)
Use retentive type timers T192 to T199 in subroutines.
These timers execute counting when the coil instruction or END instruction is executed.
After a timer reaches the set value, the output contact is activated when the coil instruction or END instruction is
executed.
Because general timers execute counting only when the coil instruction is executed, they do not execute counting if
they are used in subroutines in which the coil instruction is executed only under some conditions.
2. When using retentive type 1 ms timers in subroutines (or interrupt routines)
If a retentive type 1 ms timer is used in a subroutine, note that the output contact is activated when the first coil
instruction (or subroutine) is executed after the timer reaches its set value.
3. Countermeasures against latches of devices used in subroutines (or interrupt routines)
Devices which were set to ON in a subroutine are latched in the ON status even after the subroutine is finished. (Refer
to the program example shown below.)
When RST instruction for a timer or counter is executed, the reset status of the timer or counter is latched also.
For turning OFF such a device latched in the ON status or for canceling such a timer or counter latched in the reset
status, reset such a device in the main program after the subroutine is finished, or program a sequence for resetting
such a device or for deactivating RST instruction in the subroutine.
(Refer to the program example shown on the next page.)
Example in which outputs are latched
In the following program example, the counter C0 is provided to count X001. When X000 is input, the subroutine P0 is
executed only in one scan, and then the counter is reset and Y007 is output.
1)
Program example
X000
FNC 01
CALLP
X001
C0
P0
K10
FNC 06
FEND
P0
X000
RST
C0
Y007
FNC 02
SRET
2)
Timing chart
Execution of
subroutine P0
triggered by X000
Subroutine is executed.
X001
Current
value of C0
1
2
3
Counter
is reset.
Because the reset instruction
for C0 is valid, the current value
of C0 remains unchanged even
if pulses are input.
RST
C0
Remains reset.
Y007
Y007 is being output.
Outputs are held.
230
FX3S/FX3G/FX3GC/FX3U/FX3UC Series
8 Program Flow – FNC 00 to FNC 09
Programming Manual - Basic & Applied Instruction Edition
8.2 FNC 01 – CALL / Call Subroutine
1
1)
Introduction
Example for resetting held outputs (countermeasures)
Program example
X000
FNC 01
CALLP
X001
X002
2
K10
RST
Y007
Overview
C0
P0
Y007 is reset at an arbitrary timing.
FNC 06
FEND
X000
RST
C0
RST
C0
Instruction
List
P0
3
A
B
M8001
4
The preceding RST C0 instruction is
deactivated in the subroutine.
Devices
in Detail
RUN monitor
(normally OFF)
Y007
FNC 02
SRET
5
Timing chart
Specified the
Device &
Constant
2)
Subroutine is
executed.
Execution of P0 is
triggered by X000
6
X001
RST
C0
1
3
2
1
Counter is reset (part
A in above program).
2
3
Before
Programming
Current
value of C0
4
Counter reset instruction is deactivated
(part B in above program).
7
Basic
Instruction
Y007
X002
Y007 is reset.
8
FNC00-FNC09
Program Flow
9
FNC10-FNC19
Move & Compare
10
FNC20-FNC29
Arith. & Logic
Operation
231
FX3S/FX3G/FX3GC/FX3U/FX3UC Series
8 Program Flow – FNC 00 to FNC 09
Programming Manual - Basic & Applied Instruction Edition
8.3
8.3 FNC 02 – SRET / Subroutine Return
FNC 02 – SRET / Subroutine Return
Outline
This instruction returns the program execution from a subroutine to the main program.
1. Instruction format
FNC 02
SRET
Independent Inst. Mnemonic
1 step SRET
Operation Condition
Continuous
Operation
This instruction is the independent type, and
does not require drive contact.
2. Set data
Operand type
–
Description
Data type
There is no set data.
–
3. Applicable devices
Operand
Type
Bit Devices
System User
Word Devices
Digit Specification
System User
X Y M T C S D .b KnX KnY KnM KnS T
–
Others
Special
Unit
C D R U \G
Index
V
Constant
Z Modify K
H
Real
CharacPointer
Number ter String
E
" "
P
There are no applicable devices.
Explanation of function and operation
When CALL instruction in the main program is executed, the program execution jumps to a subroutine.
SRET instruction returns the program execution to the main routine.
→ Refer to Section 8.2.
232
FX3S/FX3G/FX3GC/FX3U/FX3UC Series
8 Program Flow – FNC 00 to FNC 09
Programming Manual - Basic & Applied Instruction Edition
1
FNC 03 – IRET / Interrupt Return
Introduction
8.4
8.4 FNC 03 – IRET / Interrupt Return
2
Outline
Overview
This instruction returns the program execution from an interrupt routine to the main program.
1. Instruction format
FNC 03
IRET
Independent Inst. Mnemonic
1 step IRET
Operation Condition
3
This instruction is the independent type, and
does not require drive contact.
Continuous
Operation
Instruction
List
2. Set data
Operand type
–
Description
Data type
There is no set data.
–
4
Operand
Type
Bit Devices
Word Devices
System User
Digit Specification
System User
X Y M T C S D .b KnX KnY KnM KnS T
–
Others
Special
Unit
C D R U \G
Index
V
Constant
Z Modify K
H
Real
CharacPointer
Number ter String
E
" "
P
There are no applicable devices.
When an interrupt (input, timer or counter) is generated while the main program is executed, the program execution
jumps to an interrupt (I) routine.
IRET instruction returns the program execution to the main routine.
The table below shows three types of jump to an interrupt routine.
Function
Interrupt No.
Description
Reference
I00* to I50*
Timer interrupt
I6** to I8**
Executes the interrupt processing at a specified time interval (constant
cycle).
Section 36.5
Counter interrupt*1
I010 to I060
Executes the interrupt processing when a high-speed counter reaches
it’s set value.
Section 36.6
*1.
This function is supported only in FX3U/FX3UC PLCs.
7
Basic
Instruction
Input interrupt
Executes the interrupt processing when an input (X) signal turns ON or Section 36.3 and
OFF.
Section 36.4
6
Before
Programming
1. Types of interrupt function
5
Specified the
Device &
Constant
Explanation of function and operation
Devices
in Detail
3. Applicable devices
→ For the interrupt function, refer to Chapter 36.
8
FNC00-FNC09
Program Flow
9
FNC10-FNC19
Move & Compare
10
FNC20-FNC29
Arith. & Logic
Operation
233