MDrive/MForce – On Error handler sample

The OE or On Error instruction is a subroutine call that is invoked whenever an error occurs during the execution of a program. The subroutine must end with either a RT (Return) if program execution is to continue or an E (End) if program execution is to end. In the following example, if a limit is activated the OE calls label j2 and in the subroutine the limit is identified, error flag set to zero, and program execution continues. If a stall or unidentified error occurs, the error number is printed and program execution is halted.

 

'CODE         	DESCRIPTION

'Parameter Setup
S1=2,0      	'set input 1 as positive limit, low true
S2=3,0      	'set input 2 as negative limit, low true
Ee=1        	'enable encoder
Sm=0       	'have motor stop on a stall detect

'===================================================
'Program
PG 1        	'enter program mode at address 1
LB su       	'reserved startup label
 OE j2      	'on any error call sub j2
LB aa       	'label aa
 Vm=30000   	'set max velocity to 30000 steps/sec
 MA 102400  	'move positive 102400 steps
            	'close switch at input 1 to
            	'stop motion in the positive direction
            	'and cause an error 83
            	'NOTE: PROGRAM CONTINUES TO EXECUTE
            	'leave switch open and program runs normal
 H          	'hold program execution until motion complete
 H 250      	'hold program execution for 250 millisecond
 MA 0       	'move to absolute 0
            	'close switch at input 2 to
            	'stop motion in the negative direction
            	'and cause an error 84
            	'NOTE: PROGRAM CONTINUES TO EXECUTE
 H          	'hold program execution until motion complete
 H 250      	'hold program execution for 250 millisecond
 BR aa      	'branch to label aa
E           	'end program
'========================================================
'On_Error Handler Subroutine
LB j2
PR "Error " Er 	'print the error
BR se, Er=86   	'if a stall jump to se
BR lp, Er=83   	'jump if limit plus to lp
BR Ln, Er=84   	'jump if limit minus to ln

LB ue          	'end program if error unknown
 PR "Undefined Error"
 PR "Ending Program!"
 E

LB Ln         	'limit minus - return to main pgm
 PR "Limit Minus"
 Er=0         	'clear the error flag
 RT

LB lp         	'limit plus - return to main pgm
 PR "Limit Plus"
 Er=0
 RT           	'clear the error flag

LB se         	'stall detected - end pgm
 PR "Stall"
 PR "Ending Program!"
 E

PG      		'exit program mode

'hit "Esc" key to stop program

Download On Error Handler .mxt file
(color-coded in IMS Terminal)

 

> Motion Control Code Index