5.4.10 Standalone Example Program 10 – Multi-thread with subroutine
Download this program:
Summary of operation
Program 1 will home X and Y axes, then will continuously move the X and Y axes and control a laser pointer to draw a circle, line, then an arc. Simultaneously, program 3 will control the status of general-purpose digital outputs to control LEDs. Subroutine 1 turns off a laser pointer, Subroutine 2 turns on the laser pointer, Subroutine 7 enables and homes the X and Y axes, and Subroutine 31 handles errors.
Program code
PRG 1 ;Start program 1
GOSUB 1 ;Go to subroutine 1, Turn off laser pointer
GOSUB 7 ;Go to subroutine 7, Enable and Home X/Y
WHILE 1=1 ;Forever loop
; Draw Circle
X85610Y562530 ;Move to start point for Circle
WAITX ;Wait for X-axis move to complete
GOSUB 2 ;Go to subroutine 2, Turn on laser pointer
CIRXYP487659:562431 ;Moves XY in a CW circle around points X487659 Y562431
WAITX ;Wait for X-axis move to complete
GOSUB 1 ;Go to subroutine 1, Turn off laser pointer
; Draw Line
X100000Y100000 ;Move to start point of Line
WAITX ;Wait for X-axis move to complete
GOSUB 2 ;Go to subroutine 2, Turn on laser pointer
X909000Y642390 ;Linear XY move from X100000 Y100000 to X909000 Y642390
WAITX ;Wait for X-axis move to complete
GOSUB 1 ;Go to subroutine 1, Turn off laser pointer
; Draw Arc
X430589Y20623 ;Move to start point for Arc
WAITX ;Wait for X-axis move to complete
GOSUB 2 ;Go to subroutine 2, Turn on laser pointer
ARCXYN288899:267403:95000 ;270deg arc of XY CCW around points X288899 Y267403
WAITY ;Wait for Y-axis move to complete
GOSUB 1 ;Go to subroutine 1, Turn off laser pointer
ENDWHILE ;Go back to WHILE statement
END ;End program 1
PRG 3 ;Start program 3
WHILE 1 = 1 ;Forever loop
IO=64 ;General-purpose output 7 on.
DELAY=700 ;Delay 0.7 seconds
IO=80 ;General-purpose output 5 and 7 on.
DELAY=700 ;Delay 0.7 seconds
IO=84 ;General-purpose output 3, 5, and 7 on.
DELAY=700 ;Delay 0.7 seconds
IO=85 ;General-purpose output 1, 3, 5, and 7 on.
DELAY=700 ;Delay 0.7 seconds
V30=0 ; Set variable 30 to 0.
WHILE V30 < 10 ;Loop while variable 30 is less than 10
IO = 85 ;General-purpose output 1, 3, 5, and 7 on.
DELAY=50 ;Delay 0.05 seconds
IO = 0 ;All general-purpose outputs off.
DELAY=50 ;Delay 0.05 seconds
V30=V30+1 ;Increment variable 30 by 1
ENDWHILE ;Go back to WHILE statement
ENDWHILE ;Go back to WHILE statement
END ;End Program 3
SUB 1 ;Subroutine start line, subroutine 1
DO2=0 ;DO 2 off to turn off Laser pointer
DELAY=10 ;Delay 0.01 seconds to stabilize laser
ENDSUB ;End of subroutine 1
SUB 2 ;Subroutine start line, subroutine 2
DO2=1 ;DO 2 on to turn on Laser pointer
DELAY=10 ;Delay 0.01 seconds to stabilize laser
ENDSUB ;End of subroutine 2
SUB 7 ;Subroutine start line, subroutine 7
; Enable motors
HSPD=15000 ;Set high speed to 15,000 pulses/sec
LSPD=500 ;Set low speed to 500 pulses/sec
ACC=100 ;Set acceleration to 100 msec
EO=3 ;Enable X and Y axis
; Home axis
HOMEX-6 ;Home X-axis with mode 6 in the negative direction
WAITX ;Wait for X-axis move to complete
HOMEY-6 ;Home Y-axis with mode 6 in the negative direction
WAITY ;Wait for Y-axis move to complete
; Move X/Y to Start Position
HSPD=35000 ;Set high speed to 15,000 pulses/sec
X500000Y500000 ;Move X and Y-axis to X500,000 Y500,000
WAITX ;Wait for X-axis move to complete
ENDSUB ;End of subroutine 7
SUB 31 ;Subroutine start line, subroutine 31 (error handling)
SR1=0 ;Stop program 1
SR3=0 ;Stop program 3
ABORT ;Abort motion of all axes
ECLEARX ;Clear the current error in X-axis
ECLEARY ;Clear the current error in Y-axis
IO=0 ;All general-purpose outputs off.
DO2=0 ;DO 2 off to turn off Laser pointer
ENDSUB ;End of subroutine 31
< Previous Chapter | Topic Home | Home | Next Topic >