88
6250 Servo Controller User Guide
Unconditional
Branching
There are three ways to branch unconditionally:
❏
GOSUB
: The
GOSUB
command branches to the program name or label stated in the
GOSUB
command. After the subroutine is completed, control is returned to the calling program where
the branch occurred, starting with the line after the
GOSUB
.
❏
GOTO
: The
GOTO
command transfers control from the current program being processed to the
program name or label stated in the
GOTO
command. Unlike the
GOSUB
, the program or label
that the
GOTO
initiates will not return control to the calling program—instead, the program
will end. This holds true unless the subroutine in which the
GOTO
resides was called by another
program; in which case, the
END
in the
GOTO
program will initiate a return to the calling
program.
❏
JUMP
: The
JUMP
command branches to the program name or label stated in the
JUMP
command.
All nested
IF
s,
WHILE
s, and
REPEAT
s, loops, and subroutines are cleared; thus, the program or
label that the
JUMP
initiates will not return control to the line after the
JUMP
, when the
program completes operation. Instead, the program will end.
If an invalid program or label name is entered, the branch command will be ignored and
processing will continue with the next line in the program.
NOTE
Be careful about performing a
GOTO
within a loop or branch statement area (i.e., between
L
&
LN
,
between
IF
&
NIF
, between
REPEAT
&
UNTIL
, or between
WHILE
&
NWHILE
). Branching to a
different location within the same program will cause the next
L
,
IF
,
REPEAT
, or
WHILE
statement
encountered to be nested within the previous
L
,
IF
,
REPEAT
, or
WHILE
statement area, unless an
LN
,
NIF
,
UNTIL
, or
NWHILE
command has already been encountered. If you wish to avoid this
nesting situation, use the
JUMP
command instead of the
GOTO
command.
Example
Command
Description
>
DEF cut1
Begin definition of program
cut1
-
HOM11
Send axes 1 and 2 to the home position
-
WAIT(1AS=bØXXX1 AND 2AS=bØXXX1)
Wait for axes 1 and 2 to come to a halt at home
-
GOSUB prompt
Go to subroutine program called
prompt
-
MAØØ
Place axes 1 and 2 in the incremental mode
-
A1Ø,3Ø
Set acceleration: axis 1 = 10 rps
2
, axis 2 = 30 rps
2
-
AD5,12
Set deceleration: axis 1 = 5 rps
2
, axis 2 = 12 rps
2
-
V5,8
Set velocity: axis 1 = 5 rps, axis 2 = 8 rps
-
D16ØØØ,1ØØØØØ
Set distance: axis 1 = 16,000 steps,
axis 2 = 100,000 steps
-
OUT.6-1
Turn on output number 6
-
T5
Wait for 5 seconds
-
L(VAR2)
Begin loop ( the number of loops = value of VAR2)
-
GO11
Initiate moves on axes 1 and 2
-
T3
Wait for 3 seconds
-
LN
End loop
-
OUT.6-Ø
Turn off output number 6
-
END
End definition of program
cut1
>
DEF prompt
Begin definition of program
prompt
-
VARS1="Enter part count >"
Place message in string variable #1
-
VAR2=READ1
Prompt operator with string variable #1, and read
data into numeric variable #2
-
END
End definition of program
prompt
>
RUN cut1
Run the program called
cut1
After issuing the
RUN cut1
command, the program
cut1
is executed until it gets to the
command
GOSUB prompt
. From there it branches unconditionally to the subroutine (actually a
program) called
prompt
. The subroutine
prompt
queries the operator for the number of parts to
process. After the part number is entered (e.g., operator enters the
!'12
command to process
12 parts), the rest of the
prompt
subroutine is executed and control goes back to the
cut1
program and resumes program execution with the next command after the
GOSUB
, which is
MAØØ
.
Conditional Looping and Branching