*-----------------------------------------------------------------------------
*  Spindle reference - special mode (X30)
*-----------------------------------------------------------------------------
*  Module Description
*    special function if no ROD on spindle
*      MP3143: 1 or
*      MP3143: 2
*
*    M18 - traverse reference again for spindle with special mode (X30)
*
*-----------------------------------------------------------------------------

#define /s    KL_direction_positive                    K +1

#define /s    BL_Case_reference                        B

#include Mac_Lib.inc

GLOBAL Spindle_reference

;----------------------------
LBL Spindle_reference
;----------------------------

  CASE   BL_Case_reference
    CM     Reference_active            ;00
    CM     G_coupling_ok               ;01
    CM     Drive_on                    ;02
    CM     Reference_start             ;03
    CM     Reference_ok                ;04
    CM     Reference_quit              ;05
    CM     Reference_end               ;06
  ENDC

  PLL
  IFT
    INC    BL_Case_reference
  ENDI

  LN     MG_control_operational
  CMT    Spindle_reset

EM

;----------------------------
LBL Reference_active                   ;00

  L      MG_M18_spindle_reference
  S      MG_spindle_reference_active

  L      MG_spindle_reference_active
  A      MG_spindle_stand_still
  AN     MG_guard_open
  PSL

EM

;----------------------------
LBL G_coupling_ok                      ;01

  LN     PN_M4134_strobe_G_range_S_speed
  PSL

EM

;----------------------------
LBL Drive_on                           ;02

  L      MG_spindle_digital
  IFT
    L      DG_servo_drives_ready
    BT     KG_spindle
    PSL
  ELSE
    LN     TR_servo_drive_release_S
    PSL
  ENDI

EM

;----------------------------
LBL Reference_start                    ;03

  PS     KG_spindle
  PS     DG_S1_reference_rpm[BG_number_active_spindle]
  PS     KL_direction_positive
  CM     9220
  PLW
  ==     K+0
  PSL
    M_display_module_error

EM

;----------------------------
LBL Reference_ok                       ;04

  LN     NP_M4018_S_no_reference
  PSL

EM

;----------------------------
LBL Reference_quit                     ;05

  L      NP_M4072_strobe_M_function
  S      PN_M4092_quit_M_function

  LN     NP_M4072_strobe_M_function
  PSL

EM

;----------------------------
LBL Reference_end                      ;06

  PS     MG_marker_zero

LBL Spindle_reset

  L      MG_marker_one
  R      MG_spindle_reference_active

  L      K+0
  =      BL_Case_reference

EM
