3. Instructions
686
CS/CJ/NSJ Series Instructions Reference Manual (W474)
Subroutines
Subroutine instruction
In the CS/CJ Series, function blocks and subroutines can be used as a means of structuring programs.
The advantages and disadvantages of each are as follows:
z Differences between function blocks and subroutines
The subroutine function has two types of subroutines: regular subroutines and global subroutines.
The differences between the two types are as follows.
z Differences between regular subroutines and global subroutines
Function blocks Subroutines
Unit versions of CPU
Units that can be used
CS1-H, CJ1-H, CJ1M CPU Units: Unit version 3.0 or later
CJ2 CPU Units: All unit versions
All unit versions
Process names Instance names can be assigned. Names cannot be assigned
Clarification of input and
output
Clarification as FB input variable or output variable is possible Clarification is not possible
Variable names Names can be assigned to variables Variable names can be assigned
Internal variables Yes
When instance names are the same, the same variable is
accessed. When instance names are different, different
variables are accessed. As such, data can be stored
separately for each call (instance) in a function block.
Using timers in function blocks does not result in
duplicated use.
No
All subroutines are accessed using the same variables.
For this reason, data cannot be stored separately for
each call in a subroutine.
If timers are used in a subroutine, duplicated timer use
will result.
Program writing method Variable programming by ladder or ST language Address programming by ladder
Indication by diagram Processing content and input/output parameters are easier to
understand (visibility can be heightened)
Address programming by ladder
Protection Read protect can be set for each function block
(Supported from CX-Programmer 6.1)
No protect function
Storing Can be stored by function block Storing is not possible by subroutine.
Regular subroutines Global subroutines
Functions A subroutine within the same task can be called.
For example, a subroutine in task 0 cannot be called from task
1.
Global subroutines can be called from all tasks.
A subroutine in interrupt task 0 can be called from any task.
Combined-use
instructions
SBS (subroutine call) instruction
SBN (subroutine entry) instruction
RET (subroutine return) instruction
GSBS (global subroutine call) instruction
GSBN (global subroutine entry) instruction
GRET (global subroutine return) instruction
Entry in subroutine
program
Entered at the end of the task that uses the subroutine (before
the END instruction).
Entered at the end of interrupt task 0 (before the END
instruction).
Processing content can be clarified
Control of
heater A
Present
value read
&10
D1
(BOOL)
EN
(BOOL)
EN
Temperature control
number
Set value
(BOOL)
ENO
(BOOL)
ENO
Current
temperature
Temperature control
number
Set value
Current
temperature
D100
Input/output parameters can be clarified
Control of heater A
Present value read
&11
D2
D102
Internal variables are different
Using timers does not result in
duplicated use (different timers
are used)
Input/output parameters
cannot be clarified
Variables used internally are
the same When timers are used,
duplicate timer use results
MOV &10
Temperature control number
MOV &11
Temperature control number
MOV D1 Set value
SBS 10
MOV Current temperature D100
MOV D2 Set value
SBS 10
MOV Current temperature D102