*-----------------------------------------------------------------------------
*  Hirth coupling X,Y,Z,4,5,6,7,8,9
*-----------------------------------------------------------------------------
*  Module Description
*
*-----------------------------------------------------------------------------

#define /s    KL_absolute_with_soft_limit_no_DCM       K %1010
#define /s    KL_absolute_with_software_limit_switch   K %010
#define /s    KL_inactive                              K +0

#define /s    ML_PLC_posit_necessery                   M[32]
#define /c    ML_X_PLC_posit_necessery                 M &ML_PLC_posit_necessery + 0
#define /c    ML_Y_PLC_posit_necessery                 M &ML_PLC_posit_necessery + 1
#define /c    ML_Z_PLC_posit_necessery                 M &ML_PLC_posit_necessery + 2
#define /c    ML_4_PLC_posit_necessery                 M &ML_PLC_posit_necessery + 3
#define /c    ML_5_PLC_posit_necessery                 M &ML_PLC_posit_necessery + 4
#define /c    ML_6_PLC_posit_necessery                 M &ML_PLC_posit_necessery + 5
#define /c    ML_7_PLC_posit_necessery                 M &ML_PLC_posit_necessery + 6
#define /c    ML_8_PLC_posit_necessery                 M &ML_PLC_posit_necessery + 7
#define /c    ML_9_PLC_posit_necessery                 M &ML_PLC_posit_necessery + 8

#define /s    ML_plus_active                           M[32]
#define /c    ML_X_posit_plus_active                   M &ML_plus_active + 0
#define /c    ML_Y_posit_plus_active                   M &ML_plus_active + 1
#define /c    ML_Z_posit_plus_active                   M &ML_plus_active + 2
#define /c    ML_4_posit_plus_active                   M &ML_plus_active + 3
#define /c    ML_5_posit_plus_active                   M &ML_plus_active + 4
#define /c    ML_6_posit_plus_active                   M &ML_plus_active + 5
#define /c    ML_7_posit_plus_active                   M &ML_plus_active + 6
#define /c    ML_8_posit_plus_active                   M &ML_plus_active + 7
#define /c    ML_9_posit_plus_active                   M &ML_plus_active + 8

#define /s    ML_minus_active                          M[32]
#define /c    ML_X_posit_minus_active                  M &ML_minus_active + 0
#define /c    ML_Y_posit_minus_active                  M &ML_minus_active + 1
#define /c    ML_Z_posit_minus_active                  M &ML_minus_active + 2
#define /c    ML_4_posit_minus_active                  M &ML_minus_active + 3
#define /c    ML_5_posit_minus_active                  M &ML_minus_active + 4
#define /c    ML_6_posit_minus_active                  M &ML_minus_active + 5
#define /c    ML_7_posit_minus_active                  M &ML_minus_active + 6
#define /c    ML_8_posit_minus_active                  M &ML_minus_active + 7
#define /c    ML_9_posit_minus_active                  M &ML_minus_active + 8

#define /s    BL_error_code                            B

#include Mac_Lib.inc

EXTERN Absolute

GLOBAL Hirth

;----------------------------
LBL Hirth
;----------------------------

  L      K+0
  =X

  L      MG_marker_one
  R      PN_error_hirth_position

  REPEAT
    L      DG_hirth_axes
    AN     NP_D1116_reference_nesessary
    BTX
    A      MG_machine_parameter_are_read
    CMT    Hirth_axis

    INCX

    LX
    >=     KG_max_number_axes
  UNTILT

  LD     ML_X_PLC_posit_necessery
  =      DG_PLC_posit_hirth_necessary

EM

;----------------------------
LBL Hirth_axis

  CM     Hirth_position

  L      PN_D1144_manual_motion_plus
  A      NP_D1104_axes_in_position
  BTX
  S      ML_X_posit_plus_active[X]

  L      PN_D1148_manual_motion_minus
  A      NP_D1104_axes_in_position
  BTX
  S      ML_X_posit_minus_active[X]

  LN     NP_D1104_axes_in_position
  BTX
  A      MG_manual_mode
  AN     MG_PLC_posit_active_X[X]
  A[
    LN     NP_M4155_mode_pass_over_reference
    O      MG_reference_auto_NC_start_blocked
  ]
  A[
    L      WG_number_active_NC_macro
    <=     KL_inactive
  ]
  S      ML_X_PLC_posit_necessery[X]

  L      NP_D1104_axes_in_position
  BTX
  A      ML_X_PLC_posit_necessery[X]
  AN     NP_M4176_control_in_operation_on_or_flashes
  CMT    Posit_increment

EM

;----------------------------
LBL Hirth_position

  L      DG_position_axis_X_ref[X]
  MOD    DG_MP430_hirth_increm_X[X]
  PSW
  CM     Absolute
  PLW

  PSW
  >[
    L      DG_MP430_hirth_increm_X[X]
    /      K+2
  ]
  IFT
    PLW
    -      DG_MP430_hirth_increm_X[X]
    X      K-1
    PSW
  ENDI

  PLW
  <      DG_MP1030_pos_window_X[X]
  A[
    LN     NP_D1116_reference_nesessary
    BTX
  ]
  =      MG_X_in_hirth_position[X]

  L      NP_D1104_axes_in_position
  AN     DG_keys_inhibit
  BTX
  AN     MG_start_blocked_reference
  AN     MG_PLC_posit_active_X[X]
  AN     ML_X_PLC_posit_necessery[X]
  AN     MG_X_in_hirth_position[X]
  AN     MG_3D_head_active
  AN     MG_3D_head_display
  AN     MG_3D_head_enter
  S      PN_error_hirth_position
  M_error_hirth_position

EM

;----------------------------
LBL Posit_increment

  PSX

  L      ML_X_posit_minus_active[X]
  O      ML_X_posit_plus_active[X]
  A[
    LN     PN_D1144_manual_motion_plus
    AN     PN_D1148_manual_motion_minus
    BTX
  ]
  CMT    Same_direction
  CMF    Shortest_direction

  PS     DG_feed_PLC_X[X]

  L      MG_DCM_active
  IFT
    PS     KL_absolute_with_soft_limit_no_DCM
  ELSE
    PS     KL_absolute_with_software_limit_switch
  ENDI

  CM     9221
  PL     BL_error_code
  M_display_module_error

  L      MG_marker_one
  R      ML_X_posit_minus_active[X]
  R      ML_X_posit_plus_active[X]
  R      ML_X_PLC_posit_necessery[X]

EM

;----------------------------
LBL Same_direction

  L      DG_position_axis_X_ref[X]
  /      DG_MP430_hirth_increm_X[X]
  X      DG_MP430_hirth_increm_X[X]
  PSW                                  ;increment left

  L      DG_position_axis_X_ref[X]
  <      K+0
  IFT
    PLW
    -      DG_MP430_hirth_increm_X[X]
    PSW                                ;increment left
  ENDI

  L      ML_X_posit_plus_active[X]
  IFT
    PLW
    +      DG_MP430_hirth_increm_X[X]
    PSW                                ;increment right
  ENDI

EM

;----------------------------
LBL Shortest_direction

  L      DG_MP430_hirth_increm_X[X]
  /      K+2
  +      DG_position_axis_X_ref[X]
  /      DG_MP430_hirth_increm_X[X]
  X      DG_MP430_hirth_increm_X[X]
  PSW                                  ;increment left

  L      DG_MP430_hirth_increm_X[X]
  /      K+2
  +      DG_position_axis_X_ref[X]
  <      K+0
  IFT
    PLW
    -      DG_MP430_hirth_increm_X[X]
    PSW                                ;increment left
  ENDI

EM
