;*************************************************************************
;
;This program processes input A4 as software controlled Enable/Disable input
;When A4 activates program starts moves. If during the move 
;A4 becomes deactivated,  program disables drive immedietly
;and waits for A4 again to be activated.
;If fault occurs OUT1 gets activated and A4 needs to be deactivated 
;and activated again to resume operation
;Set up note: Parameter "Enable switch function" MUST be set to "Inhibit"
;And input A3 (hardware enable) has to be activated. If A3 gets disable 
;at any time when drive is enabled drive disables and goto fault state.
;See programmer's manual for details on operation of the A3 input.
;
;*************************************************************************
;
;
;
;
;This event gets fired up when A3 deactivated
EVENT  Disabled INPUT IN_A4 FALL
	 JUMP StopSystem
ENDEVENT	
;
;
;
;-------------------------------------------------------------------------

	VAR_REFERENCE = 1	 ;select trajectory generator as positioning source
	VAR_DRIVEMODE = 2	 ;position mode
	VAR_ENABLE_SWITCH_TYPE=0 ;enable switch function set to "Enable only"
;-------------------------------------------------------------------------


	UNITS =1		;set user units to revolutions
	ACCEL=50		;acceleration = 50 Rps*s
	DECEL=50		;deceleration = 50 Rps*s
	MAXV = 5		;Top velocity = 5 Rps = 5*60 = 300 Rpm 
	QDECEL=50000	;quick deceleration = 50000 Rps*s*s
;*************************************************************************
;


WAITENABLE:
	WAIT   UNTIL IN_A3 	;wait until A3 - hardware "enable" closed
	WAIT   UNTIL IN_A4 	;wait until input IN_A4 becomes active (our ENABLE) 	
				;if A3 deactivates event will disable drive
				;and goto WAITENABLE label
	EVENT Disabled ON	;arm EVENT to catch if A3 gets disabled

	ENABLE			;enable drive
		
	V0=0
	OUT1 = 0;                    ;clear "fault" output
Again:	
	MOVED 10		;move 10 revolutions forward
	WAIT TIME 2000		;wait for 2000mS ( 2 Seconds)
	MOVED -10		;move 10 revolutions reverse
	WAIT TIME 2000		;wait
	GOTO Again		;execute motions in the loop 	
;
	END			;shouldn't get here anyway

;---------------------------------------------------------------------------
;In case if fult happens... it gets here!
;---------------------------------------------------------------------------
PROCESSFAULT:
;Do your fault processing here
	
	V0=1;			;do this so you can see that it was a fault
	OUT1 =1;		;indicate fault on output too
	WAIT UNTIL IN_A4        ;Use A4 as fault reset acknowledge from user
	GOTO WAITENABLE		;continue program
				
;**************************************************************************
;Event Disabled handler
;**************************************************************************

StopSystem:
	EVENT Disabled OFF    ;to prevent nesting
	DISABLE
	GOTO WAITENABLE


;***************************************************************************
;
ON FAULT

	RESUME PROCESSFAULT
ENDFAULT

 
