
In this example, this statement will cause the program to jump to the label #TEST if v1 is less than v2 and v3 is less
than v4. To illustrate this further, consider this same example with an additional condition:
JP #TEST, ((v1<v2) & (v3<v4)) | (v5<v6)
This statement will cause the program to jump to the label #TEST under two conditions; 1. If v1 is less than v2 and
v3 is less than v4. OR 2. If v5 is less than v6.
Using the JP Command:
If the condition for the JP command is satisfied, the controller branches to the specified label or line number and
continues executing commands from this point. If the condition is not satisfied, the controller continues to execute
the next commands in sequence.
Conditional
Meaning
JP #Loop,count<10
Jump to #Loop if the variable, count, is less than 10
JS #MOVE2,@IN[1]=1
Jump to subroutine #MOVE2 if input 1 is logic level high. After the subroutine MOVE2 is executed,
the program sequencer returns to the main program location where the subroutine was called.
JP #BLUE,@ABS[v2]>2
Jump to #BLUE if the absolute value of variable, v2, is greater than 2
JP #C,v1*v7<=v8*v2
Jump to #C if the value of v1 times v7 is less than or equal to the value of v8*v2
JP#A
Jump to #A
Example Using JP command:
Move the X motor to absolute position 1000 counts and back to zero ten times. Wait 100 msec between moves.
#BEGIN
Begin Program
count=10
Initialize loop counter
#LOOP
Begin loop
PA 1000
Position absolute 1000
BGX
Begin move
AMX
Wait for motion complete
WT 100
Wait 100 msec
PA 0
Position absolute 0
BGX
Begin move
AMX
Wait for motion complete
WT 100
Wait 100 msec
count=count-1
Decrement loop counter
JP #LOOP,count>0
Test for 10 times thru loop
EN
End Program
Using If, Else, and Endif Commands
The DMC-40x0 provides a structured approach to conditional statements using IF, ELSE and ENDIF commands.
Using the IF and ENDIF Commands
An IF conditional statement is formed by the combination of an IF and ENDIF command. The IF command has as
it’s arguments one or more conditional statements. If the conditional statement(s) evaluates true, the command
interpreter will continue executing commands which follow the IF command. If the conditional statement
evaluates false, the controller will ignore commands until the associated ENDIF command is executed OR an ELSE
command occurs in the program (see discussion of ELSE command below).
Note
: An ENDIF command must always be executed for every IF command that has been executed. It is
recommended that the user not include jump commands inside IF conditional statements since this causes re-
direction of command execution. In this case, the command interpreter may not execute an ENDIF command.
Using the ELSE Command
The ELSE command is an optional part of an IF conditional statement and allows for the execution of command
only when the argument of the IF command evaluates False. The ELSE command must occur after an IF command
Chapter 7 Application Programming ▫ 126
DMC-40x0 User Manual