{
    S7_Author := "ABH";
    S7_BlockNumber := "15164";
    S7_BlockTitle := "MLC_VR";
    S7_Family := "ZeusControl";
    S7_Optimized := "TRUE";
    S7_PreferredLanguage := "LAD";
    S7_Version := "1.0"
}
FUNCTION_BLOCK "FB15164_ZC_CIP_SOLO_ENJ"
    VAR_INPUT
        { S7_MLC := "MLC_gh" }
        NombreSecuencia : String := 'ENJUAGUE';
        { S7_MLC := "MLC_3h6" }
        Pulso1Seg : Bool;
        { S7_MLC := "MLC_b5" }
        Ack : Bool;
        { S7_MLC := "MLC_4Ja" }
        EstadoEnMarcha : Bool;
        { S7_MLC := "MLC_Ld" }
        OrdenPausa : Bool;
        { S7_MLC := "MLC_3w3" }
        EtapasEnjuague : Bool;
        { S7_MLC := "MLC_45w" }
        OrdenMarcha : Bool;
        { S7_MLC := "MLC_4Pm" }
        HabilitacionRecuperacion : Bool;
        { S7_MLC := "MLC_3jM" }
        EstadoBombaImpulsion : Bool;
        { S7_MLC := "MLC_4gw" }
        EstadoRetorno : Bool;
        { S7_MLC := "MLC_4SS" }
        EstadoSinRetorno : Bool;
        { S7_MLC := "MLC_4GJ" }
        DestinoVacio : Bool;
        { S7_MLC := "MLC_4R9" }
        ParoBombaImpulsion : Bool;
        { S7_MLC := "MLC_3zL" }
        ParoTiempo : Bool;
        { S7_MLC := "MLC_3ew" }
        FinLimpieza : Bool;
        { S7_MLC := "MLC_nj" }
        CT_Retorno : Real;
        { S7_MLC := "MLC_4px" }
        TT_Retorno : Real;
        { S7_MLC := "MLC_4Gu" }
        HL_TQAguaRecup : Bool;
        { S7_MLC := "MLC_33g" }
        ParametrosEnjuague : _.UDT_ZC_RECETA_CIP_SOLO_ENJ;
        { S7_MLC := "MLC_is" }
        TiempoRetardoBomInterm : Int;
        { S7_MLC := "MLC_3cm" }
        TiempoAutocBomIntermOn : Int;
        { S7_MLC := "MLC_47v" }
        TiempoAutocBomIntermOff : Int;
        { S7_MLC := "MLC_59F" }
        IntentosAutocBomInterm : Int := 3;
        { S7_MLC := "MLC_4VS" }
        EstadoDFInterm : Bool;
        { S7_MLC := "MLC_ti" }
        EstadoBombaInterm : Bool;
    END_VAR
    VAR_OUTPUT
        { S7_MLC := "MLC_53k" }
        MarchaBombaImpulsion : Bool;
        { S7_MLC := "MLC_4XM" }
        MarchaBombaIntermedia : Bool;
        { S7_MLC := "MLC_4Qw" }
        AperturaValvulaEnvioAgua : Bool;
        { S7_MLC := "MLC_3N7" }
        AperturaValvulaRetornoTqAguaRecup : Bool;
        { S7_MLC := "MLC_47M" }
        AperturaValvulaDrenajeLinea : Bool;
        { S7_MLC := "MLC_36s" }
        AperturaValvulaEnvioCip : Bool;
        { S7_MLC := "MLC_4py" }
        AperturaValvulaDQO : Bool;
        { S7_MLC := "MLC_4CH" }
        SecuenciaIniciada : Bool;
        { S7_MLC := "MLC_4ZN" }
        FalloAutocebadoBombaInterm : Bool;
        { S7_MLC := "MLC_3mt" }
        FinSecuencia : Bool;
        { S7_MLC := "MLC_35T" }
        CondicionesOk : Bool;
        { S7_MLC := "MLC_4VV" }
        EtapaActual : Int;
    END_VAR
    VAR RETAIN
        { S7_MLC := "MLC_4Ck" }
        s_EtapaActual : Int;
        { S7_MLC := "MLC_4yi" }
        s_TextoEtapa : String[100];
        s_Pausa_M : Bool;
        s_Pausa_V : Bool;
        s_Continuar : Bool;
        s_DrenajeLinea : Bool := false;
        s_AguaRecuperada : Bool;
    END_VAR
    VAR
        {
            S7_Access := "ReadOnly := External";
            S7_Visibility := "Hidden := External"
        }
        s_EnvioDQO : Bool;
        {
            S7_Access := "ReadOnly := External";
            S7_Visibility := "Hidden := External"
        }
        s_Pulsos : Array[0..15] of Bool := [
            { S7_MLC := "MLC_3vX" }
        (),
            { S7_MLC := "MLC_385" }
        (),
            { S7_MLC := "MLC_559" }
        (),
            { S7_MLC := "MLC_4hf" }
        (),
            { S7_MLC := "MLC_f3" }
        (),
            { S7_MLC := "MLC_4Ks" }
        (),
            { S7_MLC := "MLC_3cN" }
        (),
            { S7_MLC := "MLC_4NJ" }
        (),
            2(()),
            { S7_MLC := "MLC_3aj" }
        ()
        ];
    END_VAR
    VAR RETAIN
        s_TiempoEtapa : STRUCT
            Activar : Bool;
            Reset : Bool;
            Actual : Int;
            SP : Int;
            Restante : Int;
        END_STRUCT;
        { S7_MLC := "MLC_4w8" }
        s_TiempoConductividadCorrecta : Int;
        { S7_MLC := "MLC_4BQ" }
        s_NumeroIntentosAutocActuales : Int;
    END_VAR
    VAR
        { S7_Setpoint := "False" }
        s_TON : Array[1..#NUM_MAX_TON] of _.UDT_ZC_DISP_TON := [
            { S7_MLC := "MLC_4ma" }
        (),
            { S7_MLC := "MLC_4Ze" }
        (),
            { S7_MLC := "MLC_cZ" }
        (),
            { S7_MLC := "MLC_ig" }
        (),
            { S7_MLC := "MLC_4En" }
        (),
            { S7_MLC := "MLC_4Mm" }
        ()
        ];
    END_VAR
    VAR RETAIN
        { S7_Setpoint := "False" }
        s_TOF : Array[1..#NUM_MAX_TOF] of _.UDT_ZC_DISP_TOF := [
            { S7_MLC := "MLC_zr" }
        (),
            { S7_MLC := "MLC_3f4" }
        (),
            { S7_MLC := "MLC_54M" }
        (),
            { S7_MLC := "MLC_3nu" }
        (),
            { S7_MLC := "MLC_4z9" }
        (),
            { S7_MLC := "MLC_XM" }
        ()
        ];
        { S7_Setpoint := "False" }
        s_TONR : Array[1..#NUM_MAX_TONR] of _.UDT_ZC_DISP_TONR := [
            { S7_MLC := "MLC_3EW" }
        ()
        ];
        s_FF : Array[1..#NUM_MAX_FF] of _.UDT_ZC_DISP_FF := [
            { S7_MLC := "MLC_3sa" }
        ()
        ];
    END_VAR
    VAR_TEMP
        for_i : Int;
        t_CondicionesDrenaje : Bool;
        t_MarchaBombaInterm : Bool;
        t_TiempoEnvioDQO : Int;
    END_VAR
    VAR CONSTANT
        SiempreON : Bool := TRUE;
        SiempreOFF : Bool := FALSE;
        NUM_MAX_TON : Int := 6;
        NUM_MAX_TOF : Int := 6;
        NUM_MAX_TONR : Int := 1;
        NUM_MAX_FF : Int := 1;
    END_VAR

    {
        S7_Language := "SCL";
        S7_NetworkTitle := "MLC_4tV"
    }
    NETWORK
        (*
        ============================================================================
        ZEUS CONTROL, S.A.
        (c)Copyright (2024) All Rights Reserved
        -----------------------------------------------------------------------------
        
        Software:       TIA Portal 18
        Restricciones:  PLC serie 1200/1500
        
        
        Nombre:         FB15164_ZC_CIP_SOLO_ENJ
        Descripcion:    Bloque de gestión de enjuague CIP fase SOLO ENJUAGUE
        
        Dependencias:   
            FC:         -
            FB:         -
            DB:         -
            UDT:        -
                     
        
        Change log:
        
            Version     Fecha       Tecnico a cargo     Descripción
            
            01.00.00    01.03.2023  (ABH)               Primera versión
            01.00.01    16.04.2024  (ABH)               Se cambian temporizadores por tipos de datos ZC.
                                                        Se añade parametro entrada intentos autocebado bomba intermedia.
                                                        Se modifica logica de autocebado bomba intermedia.
            01.00.02    09.06.2025  (ABH)               Se cambia logica reset retardo bomba intermedia, para que se resetee en pasos que no se activa
            01.00.03    11.06.2025  (ABH)               Se añade bit pausa limpieza para reset de intentos autocebado
                                                        bomba intermedia
            01.00.04    15.06.2025  (ABH)               Se añade orden de paro bomba impulsion.
            01.00.05    08.07.2025  (ABH)               Se añade condicion de bomba impulsion para contar tiempo en limpieza/enjuague
            01.00.06    28.07.2025  (ABH)               Se añade salida etapa actual y condiciones limpieza/enjuague Ok
            01.00.07    09.09.2025  (ABH)               Se añade entradas para orden paro tiempo limpieza y orden fin limpieza (ordenes externas)
            
         ============================================================================
         *)
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3pu"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_k3"
    }
    NETWORK
        RUNG wire#powerrail
            Contact( #SiempreON )
            wire#w1
            Contact( #OrdenPausa )
            wire#w2
            S_Coil( #s_Pausa_M )
        END_RUNG
        RUNG wire#w1
            I_Contact( #EstadoEnMarcha )
        END_RUNG wire#w2
        RUNG wire#w1
            Contact( #s_Pausa_M )
            wire#w3
            Move(
                in := 3,
                out1 => #s_TON[3].SP
            )
            Coil( #s_TON[3].IN )
        END_RUNG
        RUNG wire#w3
            Contact( #s_TON[3].Q )
            I_Contact( #s_Continuar )
            S_Coil( #s_Pausa_V )
        END_RUNG
        RUNG wire#w1
            I_Contact( #OrdenPausa )
            Contact( #EstadoEnMarcha )
            wire#w4
            R_Coil( #s_Pausa_V )
        END_RUNG
        RUNG wire#w4
            S_Coil( #s_Continuar )
        END_RUNG
        RUNG wire#w1
            Contact( #s_Continuar )
            wire#w5
            Move(
                in := 3,
                out1 => #s_TON[4].SP
            )
            Coil( #s_TON[4].IN )
        END_RUNG
        RUNG wire#w5
            Contact( #s_TON[4].Q )
            wire#w6
            R_Coil( #s_Pausa_M )
        END_RUNG
        RUNG wire#w6
            R_Coil( #s_Continuar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 0
            )
            wire#w7
            R_Coil( #s_Pausa_M )
        END_RUNG
        RUNG wire#w7
            R_Coil( #s_Pausa_V )
        END_RUNG
        RUNG wire#w7
            R_Coil( #s_Continuar )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_a4"
    }
    NETWORK
        RUNG wire#powerrail
            I_Contact( #EtapasEnjuague )
            Move(
                in := 0,
                out1 => #s_EtapaActual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "SCL";
        S7_NetworkTitle := "MLC_4pB"
    }
    NETWORK
        //  ================================================================
        //  TEXTO ETAPA
        CASE #s_EtapaActual OF
            0:
                #s_TextoEtapa := CONCAT_STRING(IN1:= #NombreSecuencia,IN2:= ' - REPOSO');
            5:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - PARO BOMBA PARA APERTURA DE CAMINOS');
            10:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - ENVIO A DESTINO');
            20:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - VACIADO DE DESTINO');
            30:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - RETORNO A CIP');
            40:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - LIMPIEZA');
            50:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - VACIADO DE DESTINO');
            60:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - FIN DE ENJUAGUE');
            70:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - FIN DE SECUENCIA');
                
                
            ELSE
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - FUERA DE ETAPA');
        END_CASE;
        
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3VB"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3mw"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 0
            )
            Contact( #EtapasEnjuague )
            Contact( #OrdenMarcha )
            Move(
                in := 10,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_35m"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 5
            )
            wire#w1
            P_Trig( #s_Pulsos[0] )
            Move(
                in := 10,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            I_Contact( #EstadoBombaImpulsion )
            S_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.SP
            )
            Move(
                in := 10,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_P2"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 10
            )
            wire#w1
            P_Trig( #s_Pulsos[1] )
            Move(
                in := #ParametrosEnjuague.TiempoEmpujeADestino,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            Contact( #EstadoBombaImpulsion )
            S_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.SP
            )
            Move(
                in := 20,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3RM"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 20
            )
            wire#w1
            P_Trig( #s_Pulsos[2] )
            Move(
                in := #ParametrosEnjuague.TiempoMaxVaciadoDestino,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            S_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#w1
            Contact( #EstadoSinRetorno )
            Contact( #DestinoVacio )
            Contact( #EstadoEnMarcha )
            I_Contact( #s_Pausa_M )
            Move(
                in := 10,
                out1 => #s_TON[1].SP
            )
            Coil( #s_TON[1].IN )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.SP
            )
            wire#w2
            Move(
                in := 40,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
        RUNG wire#w1
            Contact( #s_TON[1].Q )
        END_RUNG wire#w2
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4tc"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 30
            )
            wire#w1
            P_Trig( #s_Pulsos[3] )
            Move(
                in := #ParametrosEnjuague.TiempoEmpujeDestinoACIP,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            Contact( #EstadoRetorno )
            S_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.Actual
            )
            Move(
                in := 40,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4R7"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 40
            )
            wire#w1
            P_Trig( #s_Pulsos[4] )
            Move(
                in := #ParametrosEnjuague.TiempoMaxEnjuague,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            Contact( #EstadoBombaImpulsion )
            I_Contact( #ParoTiempo )
            S_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Real" }
            LE_Contact(
                in1 := #CT_Retorno,
                in2 := #ParametrosEnjuague.ConductividadEnjuague
            )
            Contact( #EstadoRetorno )
            I_Contact( #s_Pausa_M )
            I_Contact( #ParoTiempo )
            Contact( #Pulso1Seg )
            { S7_Templates := "DestType := Int" }
            Inc( #s_TiempoConductividadCorrecta )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Real" }
            GT_Contact(
                in1 := #CT_Retorno,
                in2 := #ParametrosEnjuague.ConductividadEnjuague
            )
            Move(
                in := 0,
                out1 => #s_TiempoConductividadCorrecta
            )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.SP
            )
            I_Contact( #ParoTiempo )
            wire#w2
            Move(
                in := 50,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
        RUNG wire#w1
            Contact( #FinLimpieza )
        END_RUNG wire#w2
        RUNG wire#w1
            { S7_Templates := "SrcType := Real" }
            NE_Contact(
                in1 := #ParametrosEnjuague.ConductividadEnjuague,
                in2 := 0.0
            )
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoConductividadCorrecta,
                in2 := #ParametrosEnjuague.TiempoEnjuagueConConductividad
            )
        END_RUNG wire#w2
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            NE_Contact(
                in1 := #s_EtapaActual,
                in2 := 40
            )
            Move(
                in := 0,
                out1 => #s_TiempoConductividadCorrecta
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_34J"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 50
            )
            wire#w1
            P_Trig( #s_Pulsos[5] )
            Move(
                in := #ParametrosEnjuague.TiempoMaxVaciadoDestino,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            S_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#w1
            Contact( #EstadoSinRetorno )
            Contact( #DestinoVacio )
            Contact( #EstadoEnMarcha )
            I_Contact( #s_Pausa_M )
            Move(
                in := 10,
                out1 => #s_TON[2].SP
            )
            Coil( #s_TON[2].IN )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.SP
            )
            wire#w2
            Move(
                in := 60,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
        RUNG wire#w1
            Contact( #s_TON[2].Q )
        END_RUNG wire#w2
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3F8"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 60
            )
            wire#w1
            P_Trig( #s_Pulsos[6] )
            Move(
                in := 10,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            I_Contact( #EstadoBombaImpulsion )
            S_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.SP
            )
            Move(
                in := 70,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4Z8"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 70
            )
            wire#w1
            P_Trig( #s_Pulsos[7] )
            Move(
                in := 5,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            I_Contact( #EtapasEnjuague )
            S_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.SP
            )
            Move(
                in := 0,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_33x"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4rx"
    }
    NETWORK
        RUNG wire#powerrail
            Contact( #s_TiempoEtapa.Activar )
            wire#w1
            Contact( #EstadoEnMarcha )
            I_Contact( #s_Pausa_M )
            Contact( #Pulso1Seg )
            { S7_Templates := "SrcType := Int" }
            LT_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.SP
            )
            { S7_Templates := "DestType := Int" }
            Inc( #s_TiempoEtapa.Actual )
        END_RUNG
        RUNG wire#w1
            Contact( #s_TiempoEtapa.Reset )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
        RUNG wire#w1
            R_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#powerrail
            Sub(
                in1 := #s_TiempoEtapa.SP,
                in2 := #s_TiempoEtapa.Actual,
                out => #s_TiempoEtapa.Restante
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_TiempoEtapa.Restante,
                in2 := 0
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Restante
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "SCL";
        S7_NetworkTitle := "MLC_4Kq"
    }
    NETWORK
        
        //  ============================================================================
        //  TON
        FOR #for_i := 1 TO #NUM_MAX_TON DO
            "FC2928_ZC_TON_INDV"(Pulso1seg:=#Pulso1Seg,
                                 TON:=#s_TON[#for_i]);
        END_FOR;
        
        //  ============================================================================
        //  TOF
        FOR #for_i := 1 TO #NUM_MAX_TOF DO
            "FC2929_ZC_TOF_INDV"(Pulso1seg := #Pulso1Seg,
                                 TOF := #s_TOF[#for_i]);
        END_FOR;
        
        //  ============================================================================
        //  TONR
        FOR #for_i := 1 TO #NUM_MAX_TONR DO
            "FC2930_ZC_TONR_INDV"(Pulso1seg := #Pulso1Seg,
                                 TONR := #s_TONR[#for_i]);
        END_FOR;
        
        //  ============================================================================
        //  FLIP FLOP
        FOR #for_i := 1 TO #NUM_MAX_FF DO
            "FC2926_ZC_FF_INDV"(Pulso1Seg := #Pulso1Seg,
                                FF := #s_FF[#for_i]);
        END_FOR;
        
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_WF"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3hF"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 10
            )
            { S7_Templates := "SrcType := Int" }
            LT_Contact(
                in1 := #s_EtapaActual,
                in2 := 70
            )
            wire#w1
            { S7_Templates := "SrcType := Real" }
            GE_Contact(
                in1 := #CT_Retorno,
                in2 := #ParametrosEnjuague.ConductividadDrenaje
            )
            wire#w2
            I_Contact( #s_Pausa_M )
            Coil( #t_CondicionesDrenaje )
        END_RUNG
        RUNG wire#w1
            I_Contact( #HabilitacionRecuperacion )
        END_RUNG wire#w2
        RUNG wire#w1
            Contact( #HL_TQAguaRecup )
        END_RUNG wire#w2
        RUNG wire#powerrail
            Contact( #t_CondicionesDrenaje )
            Contact( #s_TON[6].Q )
            wire#w3
            S_SR(
                operand := #s_DrenajeLinea,
                r1 := wire#w4
            )
        END_RUNG
        RUNG wire#powerrail
            Contact( #HL_TQAguaRecup )
        END_RUNG wire#w3
        RUNG wire#powerrail
            I_Contact( #t_CondicionesDrenaje )
            Contact( #s_TON[5].Q )
        END_RUNG wire#w4
        RUNG wire#powerrail
            I_Contact( #t_CondicionesDrenaje )
            Move(
                in := 3,
                out1 => #s_TON[5].SP
            )
            Coil( #s_TON[5].IN )
        END_RUNG
        RUNG wire#powerrail
            Contact( #t_CondicionesDrenaje )
            Move(
                in := 3,
                out1 => #s_TON[6].SP
            )
            Coil( #s_TON[6].IN )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_339"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Real" }
            LT_Contact(
                in1 := #CT_Retorno,
                in2 := #ParametrosEnjuague.ConductividadDrenaje
            )
            I_Contact( #HL_TQAguaRecup )
            Coil( #s_AguaRecuperada )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_54F"
    }
    NETWORK
        RUNG wire#powerrail
            Contact( #SiempreON )
            wire#w1
            R_Coil( #s_EnvioDQO )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 40
            )
            { S7_Templates := "SrcType := Int" }
            NE_Contact(
                in1 := #ParametrosEnjuague.TiempoEnjuagueConConductividad,
                in2 := 0
            )
            { S7_Templates := "SrcType := Real" }
            NE_Contact(
                in1 := #ParametrosEnjuague.ProcentajeEnvioDQO,
                in2 := 0.0
            )
            wire#w2
            {
                S7_Expression := "IN1 * IN3 / IN2"; 
                S7_Templates := "SrcType := Int"
            }
            Calculate(
                in1 := #ParametrosEnjuague.TiempoEnjuagueConConductividad,
                in2 := 100.0,
                in3 := #ParametrosEnjuague.ProcentajeEnvioDQO,
                out => #t_TiempoEnvioDQO
            )
            Sub(
                in1 := #ParametrosEnjuague.TiempoEnjuagueConConductividad,
                in2 := #t_TiempoEnvioDQO,
                out => #t_TiempoEnvioDQO
            )
        END_RUNG
        RUNG wire#w2
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoConductividadCorrecta,
                in2 := #t_TiempoEnvioDQO
            )
            S_Coil( #s_EnvioDQO )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 50
            )
            { S7_Templates := "SrcType := Real" }
            NE_Contact(
                in1 := #ParametrosEnjuague.ProcentajeEnvioDQO,
                in2 := 0.0
            )
            S_Coil( #s_EnvioDQO )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3qE"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_Pm"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 10
            )
            wire#w1
            I_Contact( #s_Pausa_M )
            I_Contact( #ParoBombaImpulsion )
            Coil( #MarchaBombaImpulsion )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 40
            )
        END_RUNG wire#w1
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3V6"
    }
    NETWORK
        RUNG wire#powerrail
            Move(
                in := #TiempoRetardoBomInterm,
                out1 => #s_TONR[1].SP
            )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 40
            )
            I_Contact( #DestinoVacio )
            I_Contact( #s_Pausa_M )
            Coil( #s_TONR[1].IN )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            NE_Contact(
                in1 := #s_EtapaActual,
                in2 := 40
            )
            wire#w1
            Coil( #s_TONR[1].RESET )
        END_RUNG
        RUNG wire#powerrail
            Contact( #DestinoVacio )
        END_RUNG wire#w1
        RUNG wire#powerrail
            Contact( #s_TONR[1].Q )
            wire#w2
            I_Contact( #DestinoVacio )
            Coil( #t_MarchaBombaInterm )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 20
            )
            wire#w3
            I_Contact( #s_Pausa_M )
        END_RUNG wire#w2
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 50
            )
        END_RUNG wire#w3
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_XE"
    }
    NETWORK
        RUNG wire#powerrail
            Move(
                in := #TiempoAutocBomIntermOn,
                out1 => #s_FF[1].Config_SetPointTiempoFlop
            )
            Move(
                in := #TiempoAutocBomIntermOff,
                out1 => #s_FF[1].Config_SetPointTiempoFlip
            )
            Contact( #t_MarchaBombaInterm )
            I_Contact( #FalloAutocebadoBombaInterm )
            I_Contact( #EstadoDFInterm )
            Coil( #s_FF[1].Orden_Activar )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4EP"
    }
    NETWORK
        RUNG wire#powerrail
            Contact( #s_FF[1].Orden_Activar )
            Contact( #s_FF[1].Estado_Flip )
            I_Contact( #s_Pausa_M )
            P_Trig( #s_Pulsos[10] )
            { S7_Templates := "DestType := Int" }
            Inc( #s_NumeroIntentosAutocActuales )
        END_RUNG
        RUNG wire#powerrail
            Contact( #Ack )
            Contact( #FalloAutocebadoBombaInterm )
            wire#w1
            Move(
                in := 0,
                out1 => #s_NumeroIntentosAutocActuales
            )
        END_RUNG
        RUNG wire#powerrail
            I_Contact( #EtapasEnjuague )
        END_RUNG wire#w1
        RUNG wire#powerrail
            Contact( #EstadoBombaInterm )
            Contact( #EstadoDFInterm )
        END_RUNG wire#w1
        RUNG wire#powerrail
            Contact( #s_Pausa_V )
        END_RUNG wire#w1
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_z8"
    }
    NETWORK
        RUNG wire#powerrail
            Contact( #t_MarchaBombaInterm )
            wire#w1
            Contact( #s_FF[1].Estado_Flop )
            wire#w2
            I_Contact( #s_Pausa_M )
            I_Contact( #DestinoVacio )
            I_Contact( #FalloAutocebadoBombaInterm )
            Coil( #MarchaBombaIntermedia )
        END_RUNG
        RUNG wire#w1
            Contact( #EstadoDFInterm )
        END_RUNG wire#w2
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_ZL"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 10
            )
            I_Contact( #s_Pausa_V )
            Move(
                in := 5,
                out1 => #s_TOF[5].SP
            )
            Coil( #s_TOF[5].IN )
        END_RUNG
        RUNG wire#powerrail
            Contact( #s_TOF[5].Q )
            Coil( #AperturaValvulaEnvioCip )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_32h"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 10
            )
            wire#w1
            I_Contact( #s_Pausa_V )
            I_Contact( #ParoBombaImpulsion )
            Move(
                in := 1,
                out1 => #s_TOF[1].SP
            )
            Coil( #s_TOF[1].IN )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 40
            )
        END_RUNG wire#w1
        RUNG wire#powerrail
            Contact( #s_TOF[1].Q )
            Coil( #AperturaValvulaEnvioAgua )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_57X"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 10
            )
            { S7_Templates := "SrcType := Int" }
            LT_Contact(
                in1 := #s_EtapaActual,
                in2 := 70
            )
            wire#w1
            I_Contact( #s_AguaRecuperada )
            wire#w2
            Contact( #s_DrenajeLinea )
            I_Contact( #s_EnvioDQO )
            I_Contact( #s_Pausa_V )
            Move(
                in := 8,
                out1 => #s_TOF[4].SP
            )
            Coil( #s_TOF[4].IN )
        END_RUNG
        RUNG wire#w1
            I_Contact( #HabilitacionRecuperacion )
        END_RUNG wire#w2
        RUNG wire#powerrail
            Contact( #s_TOF[4].Q )
            Coil( #AperturaValvulaDrenajeLinea )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_43c"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 10
            )
            { S7_Templates := "SrcType := Int" }
            LT_Contact(
                in1 := #s_EtapaActual,
                in2 := 70
            )
            Contact( #HabilitacionRecuperacion )
            Contact( #s_AguaRecuperada )
            I_Contact( #s_Pausa_V )
            Move(
                in := 3,
                out1 => #s_TOF[3].SP
            )
            Coil( #s_TOF[3].IN )
        END_RUNG
        RUNG wire#powerrail
            Contact( #s_TOF[3].Q )
            Coil( #AperturaValvulaRetornoTqAguaRecup )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4qs"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 40
            )
            wire#w1
            I_Contact( #s_AguaRecuperada )
            wire#w2
            Contact( #s_DrenajeLinea )
            Contact( #s_EnvioDQO )
            I_Contact( #s_Pausa_V )
            Move(
                in := 3,
                out1 => #s_TOF[6].SP
            )
            Coil( #s_TOF[6].IN )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 50
            )
        END_RUNG wire#w1
        RUNG wire#w1
            I_Contact( #HabilitacionRecuperacion )
        END_RUNG wire#w2
        RUNG wire#powerrail
            Contact( #s_TOF[6].Q )
            Coil( #AperturaValvulaDQO )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_58t"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GT_Contact(
                in1 := #s_EtapaActual,
                in2 := 0
            )
            Coil( #SecuenciaIniciada )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_RW"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 70
            )
            Coil( #FinSecuencia )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4bA"
    }
    NETWORK
        RUNG wire#powerrail
            Contact( #SiempreON )
            wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 40
            )
            wire#w2
            { S7_Templates := "SrcType := Real" }
            LE_Contact(
                in1 := #CT_Retorno,
                in2 := #ParametrosEnjuague.ConductividadEnjuague
            )
            Contact( #EstadoRetorno )
            S_Coil( #CondicionesOk )
        END_RUNG
        RUNG wire#w2
            { S7_Templates := "SrcType := Real" }
            GT_Contact(
                in1 := #CT_Retorno,
                in2 := #ParametrosEnjuague.ConductividadEnjuague
            )
            wire#w3
            R_Coil( #CondicionesOk )
        END_RUNG
        RUNG wire#w2
            I_Contact( #EstadoRetorno )
        END_RUNG wire#w3
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            NE_Contact(
                in1 := #s_EtapaActual,
                in2 := 40
            )
            R_Coil( #CondicionesOk )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3yy"
    }
    NETWORK
        RUNG wire#powerrail
            Move(
                in := #s_EtapaActual,
                out1 => #EtapaActual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_pH"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4st"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_NumeroIntentosAutocActuales,
                in2 := #IntentosAutocBomInterm
            )
            Coil( #FalloAutocebadoBombaInterm )
        END_RUNG
    END_NETWORK
END_FUNCTION_BLOCK
