Program flow commands break the normal sequential order of program flow by forcing an out of sequence location of the next command. Commands then execute sequentially again starting at the new location. The main program flow commands are unconditional jumps and loops (GOTO), calls and returns from subroutines (CALL), If-Then-Else conditional jumps (IF) and wait loops (PAUSE).
_______________________________________________________________________________________________________________
GOTO PROGRAM FLOW COMMAND
Syntax: GOTO k, LOOP n TIMES <ENTER>
Operands: k = <LABEL>
0 <= n <= 255
Operation: Go to label name location in the user program.
Dependence: None
Type: The command value is local.
Description:
This command jumps to the label name location and resumes executing the program from there. Additionally, the command can jump to a label location a set number of times before the command is ignored (LOOP n TIMES).
Example:
GOTO abcd <ENTER>
GOTO is the GOTO command
abcd means jump to program a location named 'abcd:'
<ENTER> indicates the command entry is done
Example:
GOTO abcd, LOOP 8 TIMES <ENTER>
GOTO is the GOTO command
abcd means jump to program a location named 'abcd:'
, indicates looping is required
8 means LOOP 8 TIMES through this command before going to the next program line after this command
<ENTER> indicates the command entry is done
In the below example, SOME COMMAND executes at line 01007 and then the GOTO command at line 01008. The GOTO loop count decrements and if it's not zero, the program jumps to 'abcd:'. This repeats 5 times until the LOOP count is zero. On the zero count the LOOP counter is set to 5 again, the GOTO jump is ignored and the program advances to NEXT COMMAND on line 01009.
01006 abcd:
01007 SOME COMMAND
01008 GOTO abcd, LOOP 5 TIMES
01009 NEXT COMMAND
Nested loops:
Nested loops are loops within loops. An example would be some process that has to be repeated for 'y' rows and 'x' columns. In the example below, there are 5 rows and 10 columns. The program loops through line 01004 to line 01010 ten times. Lines 01006 and 01008 are repeated five times for every pass through the first loop. Lines 01007 and 01008 get repeated 50 times.
Note: Up to 4 nested loops are allowed.
01004 outer_loop:
01005 SOME OTHER COMMAND
01006 inner_loop:
01007 SOME COMMAND
01008 GOTO inner_loop, LOOP 5 TIMES
01009 NEXT COMMAND
01010 GOTO outer_loop, LOOP 10 TIMES
01011 ANOTHER COMMAND
_______________________________________________________________________________________________________________
CALL PROGRAM FLOW COMMAND
Syntax: CALL k <ENTER>
Operands: k = <LABEL>
Operation: Calls a function. Returns to the program line after this one when finished.
Dependence: None
Type: The command value is local.
Description:
This command jumps from the current command line to a command line specified by the value n. The program continues from that line until the function is finished. The last command line in the function must be CALL which causes a return to the command line immediately after the one which called the function.
Note: Up to 4 nested function calls are allowed.
Example:
CALL function_name <ENTER>
CALL is the CALL command
function_name means the CALL function begins at a program location labeled as 'function_name:'
<ENTER> indicates the command entry is done
The following example shows how nested CALLs are used:
00198 COMMAND
00199 CALL func_1 Call a subroutine beginning at line 758.
00200 COMMAND ←Return from func_1 here.
00201 COMMAND
------- -------
00311 func_2:
00312 COMMAND ← CALL func_2 from line 00760 from inside func_1 calls another function starting on this command line.
00313 COMMAND
00314 RETURN Return. Subroutine func_2 is finished.
-------- -------
00757 func_1:
00758 COMMAND ← CALL func_1 from line 00199 calls a subroutine starting on this command line.
00759 COMMAND
00760 CALL func_2 Call another subroutine beginning at line 312. This call is from inside the CALL 758 function.
00761 COMMAND ←Return from func_2 here.
00762 RETURN Return. Subroutine func_1 is finished
_______________________________________________________________________________________________________________
RETURN PROGRAM FLOW COMMAND
Syntax: RETURN <ENTER>
Operands: None
Operation: Returns to the program line after the CALL command line.
Dependence: None
Type: The command value is local.
Description:
This command is used to end a CALL function. The program counter jumps to the next program line after the CALL command line.
Example:
RETURN <ENTER>
RETURN means this a RETURN command.
<ENTER> indicates the command entry is completed
_______________________________________________________________________________________________________________
WAIT PROGRAM FLOW COMMAND
Syntax: WAIT nn.nnn SECONDS <ENTER>
Operands: 0 <= nn.nnn <= 65.535
Operation: Pauses program execution for a period of time
Dependence: None
Type: The command value is local.
Description:
This command inserts a time delay on n milliseconds to pause the user program.
Example:
WAIT 2.500 SECONDS <ENTER>
WAIT means this is a PAUSE command.
2500 means wait for 2,500 milliseconds (2.5 seconds)
<ENTER> indicates the command entry is done
_______________________________________________________________________________________________________________
IF-THEN-ELSE PROGRAM FLOW COMMAND
Syntax: IF a t IS c GOTO k <ENTER>
Operands: a = X or Y or Z or W axis name
t = IN1 or IN2 or IN3 or RDY or ERR single-bit variable test or VEL or POS or VIN multiple-bit variable test
c = ON or OFF single-bit test or > or = or < multiple-bit variable test against COMPARE
k = <LABEL>
Operation: IF a test is true, THEN go to the label name program location, ELSE go to the next program line.
Dependence: None
Type: The command value is local.
Description:
This command is a conditional jump. A single bit variable i is tested for ON or OFF. If true, then the next command line location is at the labeled name. Else the next command line is executed. Multiple-bit variables VELOCITY, POSITION and VIN are compared against the COMPARE value (see COMPARE command). VIN is a 1-byte analog to digital conversion of a 0V to 5V input to the GM215. VEL is a 2-byte value of the axis's current velocity and POS is a 3-byte value of the axis' current position.
Examples:
IF X IN 3 IS ON GOTO someplace <ENTER>
IF means this is an IF-THEN-ELSE command.
X means test an X axis input or variable.
IN3 means test general purpose input number 3.
ON means the test is for an ON state.
someplace is the GOTO label if the test is true.
IF Z VEL IS > GOTO vel_is_bigger <ENTER>
IF means this is an IF-THEN-ELSE command.
Z means test an Z axis input or variable.
VEL means the axis current velocity.
> means test if velocity is greater than the COMPARE value.
vel_is_bigger is the GOTO label if the test is true.
IF W VIN IS < GOTO low_voltage <ENTER>
IF means this is an IF-THEN-ELSE command.
W means test an W axis input or variable.
VIN means test the axis analog input voltage VIN.
< means test VIN to determine if it is less than the COMPARE value.
low_voltage is the GOTO label if the test is true.
An input can be continuously polled (tested) for an input state. If the input test is false, the input test is repeated until the result is true. When true, the user program advances to the next program line.
A HOME command is required when a switch connected to the X axis IN1 turns ON and the program waits until this is true. Assume the code to do this starts at command line 00123.
PGM LINE COMMAND COMMENT
00122 wait_for_switch: Label name
00123 IF X IN1 IS OFF GOTO wait_for_switch While the X axis IN1 is OFF the command THEN keeps retesting IN1
00124 HOME X ← ELSE if you are here, IN1 was ON. Home the axis.
00125 NEXT COMMAND Do something after the axis has homed
If it's undesirable to stall the program while waiting for IN1 to be ON and it can be tested later, the IF command can be written as:
PGM LINE COMMAND COMMENT
00122 IF X IN1 IS OFF GOTO switch_is_off Test the X axis for IN1 is OFF
00123 HOME X ← ELSE if you are here, IN1 was ON. Home the axis.
00124 switch_is_off: Label name
00125 NEXT COMMAND Continue with the program but have it loop through PGM LINE 00122 again.
Assume X axis output 3 must be turned 'on' if the Z axis voltage on VIN is between 2.5V and 3.0V.
PGM LINE COMMAND COMMENT
00455 Z COMPARE VALUE154 256 times 3.0V divided by 5.0V
00456 IF Z VIN > GOTO out3_off GOTO label out3_off if VIN is greater than 3V.
00457 Z COMPARE VALUE 128 256 times 2.5V divided by 5.0V
00458 IF Z VIN > GOTO out3_on GOTO label out3_on if VIN is greater than 2.5V.
00459 out3_off: Label name
00460 X OUT 3 OFF Turn X axis output 3 off.
00461 X GOTO skip_line GOTO label skip_line
00462 out3_on: Label name
00463 X OUT 3 ON Turn X axis output 3 on.
00464 skip_line: Label name
00465 NEXT COMMAND Continue with the program
The following is a partial list of Boolean operations on 2 and 3 inputs using the IF command. They are offered as a template to the user from which other, not listed logical operations can be formed:
AND2 AND3 XOR2
IF X IN1 IS OFF GOTO false IF X IN1 IS OFF GOTO false IF X IN1 IS ON GOTO next
IF X IN2 IS OFF GOTO false IF X IN2 IS OFF GOTO false IF X IN2 IS ON GOTO true
SOME COMMAND (true) IF X IN3 IS OFF GOTO false false:
false: SOME COMMAND (true) SOME COMMAND
SOME OTHER COMMAND false: next:
SOME OTHER COMMAND IF X IN2 IS ON GOTO false
true:
SOME OTHER COMMAND
OR2 OR3 AND-OR
IF X IN1 IS ON GOTO true IF X IN1 IS ON GOTO true IF X IN 1 IS OFF GOTO +3
IF X IN2 IS ON GOTO true IF X IN2 IS ON GOTO true IF X IN 2 IS OFF GOTO +2
false: IF X IN3 IS ON GOTO true → (IN1 & IN2) | IN3 is true
SOME COMMAND false: IF X IN3 IS ON GOTO -1
true: SOME COMMAND → (IN1 & IN2) | IN3 is false
SOME OTHER COMMAND true: → (IN1 & IN2) | IN3 is false
SOME OTHER COMMAND
NAND2 OR-AND
IF X IN1 IS ON GOTO false IF X IN1 IS ON GOTO false
IF X IN2 IS ON GOTO false IF X IN2 IS OFF GOTO false
→ NAND2 is true IF X IN3 IS OFF GOTO false
→ NAND2 is false → IN1 | (IN2 & IN3) is true
→ IN1 | (IN2 & IN3) is false
NOR2
IF X IN1 IS OFF GOTO false
IF X IN2 IS OFF GOTO false
→ NOR2 is false
→ NOR2 is true
MUX (2 INPUT / 1 OUTPUT MULTIPLEXER)
IF XIN3:+2; (MUX A/B SELECT IS IN3)
IF XIN1:+2; (MUX A IN IS IN1)
→ MUX OUT IS TRUE
IF /XIN2:-1; (MUX B IN IS IN2)
→ MUX OUT IS FALSE