Galil Motion Control DMC-21 5 Series User Manual page 94

Table of Contents

Advertisement

Subroutines
A subroutine is a group of instructions beginning with a label and ending with an
called from the main program with the jump subroutine instruction JS, followed by a label or line number, and
conditional statement. After the subroutine is executed, the program sequencer returns to the program location
where the subroutine was called unless the subroutine stack is manipulated as described in the following section.
An example of a subroutine to draw a square 500 counts per side is given below. The square is drawn at vector
position 1000,1000.
#main;
CB
1;
SH
AB;
VM
AB;
VP
1000,1000;
LE;
BG
S;
AM
S;
SB
1;
JS
#square;
CB
1;
EN;
#square;
v1=500;
JS
#l;
v1=-v1;
JS
#l;
EN;
#l;
PR
v1,v1;
BG
A;
AM
A;
BG
B;
AM
B;
EN;
Stack Manipulation
It is possible to manipulate the subroutine stack by using the
or automatic routine (such as
Normally the stack is restored with an
line where the subroutine or interrupt was called. The
program sequencer to continue to the next line. The
example, if a limit occurs and the
sequence instead of returning to the location where the limit occurred. To do this, give a
of the
routine.
#LIMSWI
Auto-Start Routine
The DMC-21x5 has a special label for automatic program execution. A program which has been saved into the
controller's non-volatile memory can be automatically executed upon power up or reset by beginning the program
with the label #AUTO. The program must be saved into non-volatile memory using the command BP.
Chapter 7 Application Programming ▫ 89
'begin main program
'clear Output 1, pick up pen
'enable A and B axes
'define S vector plane as A and B axes
'define vector position, move pen
'finish vector sequence
'begin motion
'wait for motion to finish
'set Output 1, put down pen
'jump to square subroutine
'clear Out#put 1, pick up pen
'end main program
'square subroutine
'define length of side
'jump to #l subroutine
'switch direction
'jump to #l subroutine
'end subroutine
'start of #l subroutine
'define move for length of side
'begin motion on A axis only
'wait for motion to finish on A axis only
'begin motion on B axis only
'wait for motion to finish on B axis only
'end subroutine
#POSERR
or #LIMSWI) is executed, the subroutine stack is incremented by 1.
EN
instruction. Occasionally it is desirable not to return back to the program
ZS1
ZS0
#LIMSWI
routine is executed, it is often desirable to restart the program
EN
ZS
command. Every time a
command clears 1 level of the stack. This allows the
command resets the stack to its initial value. For
command. Subroutines are
JS
instruction, interrupt
command at the end
ZS
DMC-21x5 User Manual 1.0a1

Advertisement

Table of Contents
loading

Table of Contents