'***************************************************************************
'Galil Motion Control Sample DMC Code
'***************************************************************************
'Description:
'Example of Multitasking
'***************************************************************************
#main                  ;'main program-task 0
  AI 1                 ;'after input 1 high
  XQ #plc1, 1          ;'execute task 1
  XQ #plc2, 2          ;'execute task 2
  XQ #move, 3          ;'execute task 3
  AI -1                ;'after input 1 low
  HX                   ;'halt all tasks
EN                     ;'end program


#plc1                  ;'task 1
  OB 2, @IN[2] & @IN[3] ;'set output 2 if input 2 and 3 high
  JP #plc1             ;'loop
EN                     ;'end task 1


#plc2                  ;'task2
  AT 0                 ;'set reference time

  #loop                ;'loop label
    SB 1                ;'set output 1
    AT 10              ;'wait 10 msec
    CB 1               ;'clear output 1
    AT -50             ;'at 50 msec reset timer
  JP #loop             ;'repeat
EN


#move                  ;'task 3
  PR 100               ;'move 100 counts
  BG A                  ;'begin motion
  AM A                  ;'wait until motion complete
  WT 20                ;'wait 20 msec
JP #move               ;'repeat
EN                     ;'end task 3