hello
I solved this way.
the axis moves at high speed until you find the first signal of the limit switch
when found reverses slowing the feed
Now launch the home and tries zero encoder.
works fine.
pulse time 2 ms
mach sees it and I'm doing the tests using a simple interface card with parallel pc.
   
   Sub Main ()
   
'Dichiaro le variabili per i contatori dei cicli "For...Next"
   Dim z,y,x
   
'Dichiaro le due velocità di spostamento    
   
   FeedVeloce = 1000   'Speed approaching ... research first switch.
   FeedHoming = 20      'Search speed switches Home
   
'Imposed on the parameter of the speed of Homing for X, Y, Z
   
   SetParam ("ZRefPer", FeedHoming)
   SetParam ("YRefPer", FeedHoming)
   SetParam ("XRefPer", FeedHoming)
'Call the subprogram for the Home Z
   
   GoTo HomeZ
   HomeZ:
'Z I lift fast for a distance definitely superior to its stroke
   
      Code "G0 Z999999 F" & FeedVeloce
   
'Start of cycle for the search of the first switch
   
      For z = 1 To 600
      
'If the first switch is activated ...
      
      If IsActive(INPUT1) Then
      
'Without approaching fast, wait half a second and I start homing
      
      DoOEMButton(1003)
      Sleep 500
      DoButton(24)
      
'I look forward to concluding the homing of Z and call the subroutine for the homing of Y ...
      
      While IsMoving()                      
      Wend
      GoTo HomeY
      
'... Or, if the first switch is off, repeat the cycle "For ... Next"
      
      Else
      Sleep 100
      End If
      Next z
'ripeto per gli assi Y e X
      HomeY:
      Code "G0 Y-999999 F" & FeedVeloce
      For y = 1 To 600
      If IsActive(INPUT2) Then
      DoOEMButton(1003)
      Sleep 500
      DoButton(23)
      While IsMoving()                       
      Wend
      GoTo HomeX
      Else
      Sleep 500
      End If
      Next y
      HomeX:
      Code "G0 X-999999 F" & FeedVeloce
      For x = 1 To 600
      If IsActive(INPUT3) Then
      DoOEMButton(1003)
      Sleep 500
      DoButton(22)
      While IsMoving()                       
      Wend
      GoTo Fine
      Else
      Sleep 100
      End If
      Next x
      Fine:
      Code "(Homing eseguito)"
   
   
   End Sub