AKD Basic Sample Program to Change Index Distance with Modbus
'-------------- Device Params -----------------------
Params
End Params
'-------------- Define (dim) Global Variables --------
Dim indexdistance as integer
Dim homefound as integer
MBInfo
$MBMap32(5000, indexdistance) 'Modbus registers 5000 and 5001 for index distance from HMI
End
'-------------- Main Program -------------------------
'Homing starts on Input 3
'Home switch on Input 2
'Start index move on Input 1
'Jog positive on Input 4 (interrupt)
'Jog negative on Input 5 (interrupt)
Main
DRV.SWENABLE = 0
homefound = 0
'Enable Interrupts
INTR.HWLS.POSSTATE = 1
INTR.HWLS.NEGSTATE = 1
Intr.DRV.FAULTS = 1
INTR.DISABLE = 1
INTR.DRV.HWENABLE = 1
Intr.DIN4Hi = 1 'jog positive on input 4
Intr.DIN5Hi = 1 'jog positive on input 5
indexdistance = 50 'default distance, in integer user units
Move.Acc = 1000 ' Acceleration (drive units)
Move.Dec = 1000 ' Deceleration (drive units)
While DRV.ACTIVE = 0 : Wend 'wait for hardware and software enable
While 1 = 1 'start continuous loop
'Homing uses Input 3 to start homing move and Input 2 for the position capture
If homefound = 0 Then 'If axis has not been homed, then wait for starthome button
While DIN3.STATE = 0 : Wend 'Use input 3 to start homing
CAP0.MODE = 0 'standard position capture
CAP0.TRIGGER = 1 'Use input 2 for position capture
CAP0.EDGE = 1 'positive edge
CAP0.EVENT = 0 'no pre-conditions must be met
CAP0.EN = 1 'Start looking for the capture trigger
MOVE.RUNSPEED = 254 'mm/s
MOVE.DIR = 1 'negative direction
MOVE.GOVEL 'start moving
While CAP0.STATE = 0 : Wend 'wait for the capture to trigger
Print "cap"
MOVE.RUNSPEED = 0
MOVE.GOVEL 'stop moving, zero speed
While MOVE.MOVING = 1 : Wend 'wait for motion to stop
MOVE.POSCOMMAND = (PL.FB -CAP0.PLFB ) 'set position to the difference between the actual position and captured position
Pause (.2)
MOVE.RUNSPEED = 50 'mm/s
MOVE.TARGETPOS = 0
MOVE.GOABS 'move back to the captured position
Pause (1) 'this is the end of the homing routine
homefound = 1 'set homefound tag
End If
While DRV.HWENABLE = 0 : Wend
'Indexing Move
While DIN1.STATE = 0 : Wend 'start indexing move on input 1
Move.RunSpeed = 100 'index speed in integer position units per sec
MOVE.RELATIVEDIST = indexdistance 'index distance in integer position units (from HMI)
Move.GoRel
While MOVE.MOVING = 1 : Wend
While DIN1.STATE = 1 : Wend 'wait for input 1 to turn off
Wend 'return to "While 1 = 1" loop
End Main
'-------------- Subroutines and Functions ------------
'-------------- Interrupt Routines -------------------
Interrupt HWLS.NEGSTATE
If homefound = 0 Then 'look for home in the other direction
While MOVE.MOVING = 1 : Wend
MOVE.DIR = 0 'positive direction
MOVE.RUNSPEED = 50 'mm/s
MOVE.GOVEL 'start moving
While DIN2.STATE = 0 : Wend 'wait for home switch to turn on
While DIN2.STATE = 1 : Wend 'wait for home switch to turn off (pass the home switch)
Pause (0.5)
MOVE.RUNSPEED = 0
MOVE.GOVEL 'stop moving, zero speed
While MOVE.MOVING = 1 : Wend
CAP0.EN = 1 'Start looking for the capture trigger
MOVE.DIR = 1 'negative direction
MOVE.RUNSPEED = 50 'mm/s
MOVE.GOVEL 'start moving
ElseIf homefound = 1 Then
Restart
End If
INTR.HWLS.NEGSTATE = 1
End Interrupt
Interrupt HWLS.POSSTATE
Restart
End Interrupt
Interrupt DRV.HWENABLE
Restart
End Interrupt
Interrupt disable
Restart
End Interrupt
Interrupt DRV.FAULTS
Restart
End Interrupt
Interrupt DIN4Hi 'jog positive on input 4
MOVE.RUNSPEED = 100
MOVE.GOVEL
While DIN4.STATE = 1 : Wend
MOVE.RUNSPEED = 0
MOVE.GOVEL 'stop jog move
Intr.DIN4Hi = 1
End Interrupt
Interrupt DIN5Hi 'jog negative on input 5
MOVE.RUNSPEED = -100
MOVE.GOVEL
While DIN5.STATE = 1 : Wend
MOVE.RUNSPEED = 0
MOVE.GOVEL 'stop jog move
Intr.DIN5Hi = 1
End Interrupt
Note: This program has been modified since the original post. The GoTo statements have been removed from the interrupts, since the firmware will no longer support that.