Protocol to find mechanical zero with one reference switch connected to ref sw and GPIO.0 for linear translation stages

'init stepper: set acceleration and maximum steptime
print #4, "B70008001"
input #4, x$

'move to well definded position
do
   print #4, "B50000000"
   input #4, x$
   input #4, x$
   y=int(val("&h0"+right$(x$,2)))
   if bit(y,0)=0 then exit loop
   CALL Move(1, 3)
loop

do
   print #4, "B50000000"
   input #4, x$
   input #4, x$
   y=int(val("&h0"+right$(x$,2)))
   if bit(y,0) then exit loop
   CALL Move(1, 2)
loop

'activate snap shot of steps register
print #4, "B60000000"
input #4, x$

'move over reference switch
CALL MoveNP(2, 3)
input #4, x$
z=val("&h0"+right$(x$,4))/%hightscale+refswoffset
CALL Move(z, 2)
end

'Move with polling
sub Move(hight as ext, mode as integer)
   print #4, "B0"+right$("0"+ltrim$(str$(mode)),1)+right$("0000"+ltrim$(str$(hight*%hightscale)),4)+right$("00"+ltrim$(str$(%steppspeed)),2)
   input #4, x$
   do
      delay .2
      print #4, "B80000000"
      input #4, x$
      input #4, x$
   loop until x$="B0"
   delay .2
   end if
end sub

'Move without polling
sub MoveNP(hight as ext, mode as integer)
   print #4, "B0"+right$("0"+ltrim$(str$(mode)),1)+right$("0000"+ltrim$(str$(hight*%hightscale)),4)+right$("00"+ltrim$(str$(%steppspeed)),2)
   input #4, x$
   delay hight*%hightscale*%steppspeed/5000
   delay 1
end if
end sub

Disclaimer: No warranty at all!
Copyright by Martin Clausen, Germany.
Contact the author: mc AT rotgradpsi DOT de
Impressum