*-----------------------------------------------------------------------------
*  Lubrication Axes
*-----------------------------------------------------------------------------
*  Module Description
*
*-----------------------------------------------------------------------------

#define /s    KL_axes                                  K %011111

#define /s    ML_pressure                              M

#define /s    BL_step_lubrication                      B

#define /s    WL_next_lubrication                      W

GLOBAL Lubrication

;----------------------------
LBL Lubrication
;----------------------------

#if CFG_Lubrication_axes = "Lub_axes_01"
  L      I_lubricant_alarm
  S      PN_error_lubrication_axes
#endif

#if CFG_Lubrication_axes = "Lub_axes_02"
  L      NP_M4172_1st_PLC_run_after_power_on
  ON     MG_control_operational
  CMT    Lubrication_reset

  L      MG_marker_one
  S      TS_lubrication
  S      TS_lubricant_pressure

  CASE   BL_step_lubrication
    CM     Lubrication_start           ;00
    CM     Test_pressure_0             ;01
    CM     Lubrication_on              ;02
    CM     Lubrication_time            ;03
    CM     Lubrication_off             ;04
    CM     Lubrication_time            ;05
    CM     Test_pressure_0             ;06
    CM     Lubrication_end             ;07
  ENDC

  PLL
  IFT
    INC    BL_step_lubrication
  ENDI

  L      PN_error_lubrication_axes
  S      MG_start_blocked_lubrication

  L      MG_key_NC_start
  A      MG_start_blocked_lubrication
  A      MG_automatic_mode
  S      PN_error_lubrication_axes

;  LN     I_lubricant_level_ok          ;20120925
  L      I_lubricant_level_ok          ;CHIBA
  =      PN_error_lubricant_level_low

  L      O_lubrication_on
  O      MG_test_lamps
  =      O_lamp_lubrication_on

EM

;----------------------------
LBL Lubrication_start                  ;00

  L      WL_next_lubrication
  <=     K+0
  O[
    L      NP_D1164_lubrication_pulse
    A      KL_axes
    >      K+0
  ]
  O      MG_key_lubrication_axes
  O      MG_SK_lubrication
  R      PN_error_lubrication_axes
  PSL
  IFT
    S      MG_SK_lubrication

    L      KL_axes
    =      PN_D1168_lubrication_distance_reset
  ENDI

  LN     MG_pulse_1_min
  ON     MG_axes_in_motion
  ON     MG_control_operational
  EMT

  DEC    WL_next_lubrication

EM

;----------------------------
LBL Test_pressure_0                    ;01 ;06

  L      I_lubricant_pressure_ok
  S      PN_error_lubrication_axes

  LN     I_lubricant_pressure_ok
  A      MG_power_delayed_on
  PSL

EM

;----------------------------
LBL Lubrication_on                     ;02

  L      MG_SK_lubrication
  A      PN_error_lubrication_axes
  O      MG_key_NC_start
  O      MG_key_lubrication_axes
  O      MG_pulse_CE_key
  R      PN_error_lubrication_axes
  =      TS_lubricant_pressure

  L      TR_lubricant_pressure
  =      MG_SK_lubrication
  =      O_lubrication_on

  L      O_lubrication_on
  A      I_lubricant_pressure_ok
  PSL

  LN     TS_lubricant_pressure
  AN     TR_lubricant_pressure
  S      PN_error_lubrication_axes

EM

;----------------------------
LBL Lubrication_time                   ;03 ;05

  LN     TR_lubrication
  =      TS_lubrication
  PSL

EM

;----------------------------
LBL Lubrication_off                    ;04

  L      MG_marker_one
  R      MG_SK_lubrication
  R      O_lubrication_on
  PSL

EM

;----------------------------
LBL Lubrication_end                    ;07

  PS     MG_marker_zero

  L      MG_marker_one
  R      MG_start_blocked_lubrication
  R      PN_error_lubrication_axes
  R      MG_SK_lubrication

  L      K+0
  =      PN_D1168_lubrication_distance_reset

  L      DG_lubrication_min_time_break
  >      NP_W988_lubrication_time
  IFT
    L      DG_lubrication_min_time_break
    =      WL_next_lubrication
  ELSE
    L      DG_lubrication_max_time_break
    <      NP_W988_lubrication_time
    IFT
      L      DG_lubrication_max_time_break
      =      WL_next_lubrication
    ELSE
      L      NP_W988_lubrication_time
      =      WL_next_lubrication
    ENDI
  ENDI

LBL Lubrication_reset

  L      MG_marker_one
  R      O_lubrication_on

  L      K+0
  =      BL_step_lubrication
#endif

EM
