{
    S7_Author := "ABH";
    S7_BlockNumber := "15178";
    S7_BlockTitle := "MLC_4CY";
    S7_Family := "ZeusControl";
    S7_Optimized := "TRUE";
    S7_PreferredLanguage := "LAD";
    S7_Version := "1.0"
}
FUNCTION_BLOCK "FB15178_ZC_COCINA_HOMO"
    VAR_INPUT
        { S7_MLC := "MLC_3xx" }
        NombreSecuencia : String := 'HOMOGENIZAR';
        { S7_MLC := "MLC_3Me" }
        Pulso1Seg : Bool;
        { S7_MLC := "MLC_4kN" }
        Ack : Bool;
        { S7_MLC := "MLC_3RM" }
        OrdenMarcha : Bool;
        { S7_MLC := "MLC_3Gr" }
        EstadoEnMarcha : Bool;
        { S7_MLC := "MLC_5Bm" }
        EnEtapa : Bool;
        { S7_MLC := "MLC_m8" }
        OrdenPausa : Bool;
        { S7_MLC := "MLC_4Ux" }
        EstadoBomba : Bool;
        { S7_MLC := "MLC_4ii" }
        TipoValvulaDrenaje : Bool;
        EstadoBocaHombre : Bool;
        { S7_MLC := "MLC_3T3" }
        TT_Linea : Real;
        { S7_MLC := "MLC_3Cj" }
        TT_Tanque : Real;
        { S7_MLC := "MLC_WX" }
        LT_Tanque : Real;
        Parametros : _.UDT_ZC_RECETA_BATCH_ETAPA := (
            { S7_MLC := "MLC_5B5" }
            P_Real_1 := (),
            { S7_MLC := "MLC_3EZ" }
            P_Real_2 := (),
            { S7_MLC := "MLC_56C" }
            P_Real_3 := (),
            { S7_MLC := "MLC_3jC" }
            P_Real_4 := (),
            { S7_MLC := "MLC_464" }
            P_Real_5 := (),
            { S7_MLC := "MLC_4m9" }
            P_Real_6 := (),
            { S7_MLC := "MLC_3Jb" }
            P_Real_7 := (),
            { S7_MLC := "MLC_4TB" }
            P_Real_8 := (),
            { S7_MLC := "MLC_4nG" }
            P_Real_9 := (),
            { S7_MLC := "MLC_LX" }
            P_Real_10 := (),
            { S7_MLC := "MLC_3wP" }
            P_Real_11 := (),
            { S7_MLC := "MLC_qV" }
            P_Real_12 := (),
            { S7_MLC := "MLC_ut" }
            P_Real_13 := (),
            { S7_MLC := "MLC_33F" }
            P_Real_14 := (),
            { S7_MLC := "MLC_an" }
            P_Real_15 := (),
            { S7_MLC := "MLC_3Q4" }
            P_Real_16 := (),
            { S7_MLC := "MLC_nu" }
            P_Real_17 := (),
            { S7_MLC := "MLC_yg" }
            P_Int_1 := (),
            { S7_MLC := "MLC_4tc" }
            P_Int_2 := (),
            { S7_MLC := "MLC_ag" }
            P_Int_3 := (),
            { S7_MLC := "MLC_wJ" }
            P_Int_4 := (),
            { S7_MLC := "MLC_48p" }
            P_Int_5 := (),
            { S7_MLC := "MLC_bA" }
            P_Int_6 := (),
            { S7_MLC := "MLC_3ti" }
            P_Int_7 := (),
            { S7_MLC := "MLC_4mX" }
            P_Int_8 := (),
            { S7_MLC := "MLC_3e4" }
            P_Int_9 := (),
            { S7_MLC := "MLC_3UC" }
            P_Int_10 := (),
            { S7_MLC := "MLC_4rC" }
            P_Int_11 := (),
            { S7_MLC := "MLC_nR" }
            P_Int_12 := (),
            { S7_MLC := "MLC_3np" }
            P_Int_13 := (),
            { S7_MLC := "MLC_3PJ" }
            P_Int_14 := (),
            { S7_MLC := "MLC_4Eg" }
            P_Int_15 := (),
            { S7_MLC := "MLC_4pY" }
            P_String_1 := (),
            { S7_MLC := "MLC_3sB" }
            P_String_2 := (),
            { S7_MLC := "MLC_54z" }
            P_String_3 := (),
            { S7_MLC := "MLC_3Uk" }
            P_String_4 := (),
            { S7_MLC := "MLC_3uC" }
            P_String_5 := (),
            { S7_MLC := "MLC_3h2" }
            P_String_6 := (),
            { S7_MLC := "MLC_4M4" }
            P_String_7 := (),
            { S7_MLC := "MLC_4Qi" }
            P_String_8 := (),
            { S7_MLC := "MLC_3VC" }
            P_String_9 := (),
            { S7_MLC := "MLC_3VU" }
            P_String_10 := ()
        );
        { S7_MLC := "MLC_u2" }
        LitrosDrenajeInicial : Real := 150.0;
        { S7_MLC := "MLC_5CE" }
        LitrosEmpujeFinal : Real := 150.0;
        { S7_MLC := "MLC_35G" }
        TotalizadorDrenaje : Real := 0.0;
        { S7_MLC := "MLC_3vC" }
        TotalizadorEmpuje : Real := 0.0;
        { S7_MLC := "MLC_4PN" }
        TiempoAclarado : Int := 60;
        { S7_MLC := "MLC_3ae" }
        TiempoMaximoDrenaje : Int := 80;
        { S7_MLC := "MLC_TP" }
        TiempoMaximoEmpuje : Int := 80;
    END_VAR
    VAR_OUTPUT
        { S7_MLC := "MLC_4PT" }
        HomoEnTanque : Bool;
        { S7_MLC := "MLC_b2" }
        MarchaBombaBlender : Bool;
        { S7_MLC := "MLC_53W" }
        VelocidadBombaBlender : Real;
        { S7_MLC := "MLC_me" }
        MarchaBombaIntermedia : Bool;
        { S7_MLC := "MLC_3NT" }
        AperturaValvulaSalidaTanque : Bool;
        { S7_MLC := "MLC_3GW" }
        AperturaValvulaDrenaje : Bool;
        { S7_MLC := "MLC_3ir" }
        AperturaValvulaEntradaTanque : Bool;
        { S7_MLC := "MLC_4Yt" }
        AperturaValvulaEmpuje : Bool;
        MarchaAgitador : Bool;
        VelocidadAgitador : Real;
        { S7_MLC := "MLC_54t" }
        OrdenCalentar : Bool;
        { S7_MLC := "MLC_4Zg" }
        OrdenEnfriar : Bool;
        { S7_MLC := "MLC_3gB" }
        SP_CalEnf : Real;
        { S7_MLC := "MLC_4Cr" }
        OrdenTotalizadorDrenaje : Bool;
        { S7_MLC := "MLC_iZ" }
        OrdenTotalizadorEmpuje : Bool;
        { S7_MLC := "MLC_3Am" }
        ResetTotalizadorDrenaje : Bool;
        { S7_MLC := "MLC_43T" }
        ResetTotalizadorEmpuje : Bool;
        VisibilidadLitrosDrenaje : Bool;
        VisibilidadLitrosEmpuje : Bool;
        VisibilidadCalEnf : Bool;
        { S7_MLC := "MLC_Q3" }
        SecuenciaIniciada : Bool;
        { S7_MLC := "MLC_zF" }
        FinSecuencia : Bool;
    END_VAR
    VAR RETAIN
        { S7_MLC := "MLC_4FQ" }
        s_EtapaActual : Int;
        { S7_MLC := "MLC_3th" }
        s_TextoEtapa : String[100];
        s_Pausa_M : Bool;
        s_Pausa_V : Bool;
        s_Continuar : Bool;
    END_VAR
    VAR
        {
            S7_Access := "ReadOnly := External";
            S7_Visibility := "Hidden := External"
        }
        s_Pulsos : Array[0..15] of Bool := [
            { S7_MLC := "MLC_58L" }
        (),
            { S7_MLC := "MLC_3EY" }
        (),
            { S7_MLC := "MLC_3zJ" }
        (),
            { S7_MLC := "MLC_4Tw" }
        (),
            { S7_MLC := "MLC_k6" }
        (),
            { S7_MLC := "MLC_4yw" }
        (),
            { S7_MLC := "MLC_4ik" }
        (),
            { S7_MLC := "MLC_3NW" }
        (),
            { S7_MLC := "MLC_mx" }
        (),
            6(()),
            { S7_MLC := "MLC_3mq" }
        ()
        ];
    END_VAR
    VAR RETAIN
        { S7_MLC := "MLC_sC" }
        s_TiempoEtapa : STRUCT
            { S7_MLC := "MLC_4eP" }
            Activar : Bool;
            { S7_MLC := "MLC_4s3" }
            Reset : Bool;
            { S7_MLC := "MLC_if" }
            Actual : Int;
            { S7_MLC := "MLC_3tN" }
            SP : Int;
            { S7_MLC := "MLC_3gN" }
            Restante : Int;
        END_STRUCT;
    END_VAR
    VAR
        {
            S7_Access := "ReadOnly := External";
            S7_Setpoint := "False";
            S7_Visibility := "Hidden := External"
        }
        s_TON : Array[1..#NUM_MAX_TON] of _.UDT_ZC_DISP_TON := [
            { S7_MLC := "MLC_wM" }
        (),
            { S7_MLC := "MLC_362" }
        ()
        ];
    END_VAR
    VAR RETAIN
        {
            S7_Access := "ReadOnly := External";
            S7_Setpoint := "False";
            S7_Visibility := "Hidden := External"
        }
        s_TOF : Array[1..#NUM_MAX_TOF] of _.UDT_ZC_DISP_TOF := [
            { S7_MLC := "MLC_VQ" }
        (),
            { S7_MLC := "MLC_4Aj" }
        (),
            { S7_MLC := "MLC_3f9" }
        (),
            { S7_MLC := "MLC_kS" }
        (),
            { S7_MLC := "MLC_4j5" }
        ()
        ];
        {
            S7_Access := "ReadOnly := External";
            S7_Setpoint := "False";
            S7_Visibility := "Hidden := External"
        }
        s_TONR : Array[1..#NUM_MAX_TONR] of _.UDT_ZC_DISP_TONR;
    END_VAR
    VAR
        s_FF : Array[1..#NUM_MAX_FF] of _.UDT_ZC_DISP_FF;
        s_ControlTanque : STRUCT
            Aux_MemOrdenAgitador : Bool;
        END_STRUCT;
    END_VAR
    VAR RETAIN
        { S7_MLC := "MLC_3uE" }
        s_CalentarEnfriar : Bool;
    END_VAR
    VAR_TEMP
        for_i : Int;
        t_TempHistSuperior : Real;
        t_TempHistInferior : Real;
        t_x0 : Real;
        t_x1 : Real;
        t_x : Real;
        t_y0 : Real;
        t_y1 : Real;
        t_OrdenCalentar : Bool;
        t_OrdenEnfriar : Bool;
    END_VAR
    VAR CONSTANT
        SiempreON : Bool := TRUE;
        SiempreOFF : Bool := FALSE;
        NUM_MAX_TON : Int := 2;
        NUM_MAX_TOF : Int := 5;
        NUM_MAX_TONR : Int := 1;
        NUM_MAX_FF : Int := 1;
    END_VAR

    {
        S7_Language := "SCL";
        S7_NetworkTitle := "MLC_mH"
    }
    NETWORK
        (*
        ============================================================================
        ZEUS CONTROL, S.A.
        (c)Copyright (2024) All Rights Reserved
        -----------------------------------------------------------------------------
        
        Software:       TIA Portal 18
        Restricciones:  PLC serie 1200/1500
        
        
        Nombre:         FB15178_ZC_COCINA_HOMO
        Descripcion:    Bloque de gestión de fase homogenizar
        
        Dependencias:   
            FC:         -
            FB:         -
            DB:         -
            UDT:        -
                     
        
        Change log:
        
            Version     Fecha       Tecnico a cargo     Descripción
            
            01.00.00    09.07.2024  (ABH)               Primera versión
            01.00.01    17.09.2025  (ABH)               Se añade habilitacion para el tratamiento termico.
                                                        Se elimina condicion de temperatura Ok para contar tiempo de homogeneizacion.
            
         ============================================================================
         *)
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_aK"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_56c"
    }
    NETWORK
        RUNG wire#powerrail
            Add(
                in1 := #Parametros.P_Real_6,
                in2 := #Parametros.P_Real_7,
                out => #t_TempHistSuperior
            )
            Sub(
                in1 := #Parametros.P_Real_6,
                in2 := #Parametros.P_Real_7,
                out => #t_TempHistInferior
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_Zj"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Real" }
            GT_Contact(
                in1 := #TT_Tanque,
                in2 := #t_TempHistSuperior
            )
            S_Coil( #s_CalentarEnfriar )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Real" }
            LT_Contact(
                in1 := #TT_Tanque,
                in2 := #t_TempHistInferior
            )
            R_Coil( #s_CalentarEnfriar )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Real" }
            GT_Contact(
                in1 := #TT_Tanque,
                in2 := #t_TempHistSuperior
            )
            { S7_Templates := "SrcType := Real" }
            LT_Contact(
                in1 := #TT_Tanque,
                in2 := #t_TempHistSuperior
            )
            S_Coil( #s_CalentarEnfriar )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3L6"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4Tn"
    }
    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[1].SP
            )
            Coil( #s_TON[1].IN )
        END_RUNG
        RUNG wire#w3
            Contact( #s_TON[1].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[2].SP
            )
            Coil( #s_TON[2].IN )
        END_RUNG
        RUNG wire#w5
            Contact( #s_TON[2].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_bz"
    }
    NETWORK
        RUNG wire#powerrail
            I_Contact( #EnEtapa )
            Move(
                in := 0,
                out1 => #s_EtapaActual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "SCL";
        S7_NetworkTitle := "MLC_4Zq"
    }
    NETWORK
        //  ================================================================
        //  TEXTO ETAPA
        CASE #s_EtapaActual OF
            0:
                #s_TextoEtapa := CONCAT_STRING(IN1:= #NombreSecuencia,IN2:= ' - REPOSO');
                
                //  =========================================================================================
                //  Homogenizacion en linea
            100:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - APERTURA DE CAMINO');
            110:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - ENCENDIDO DE BOMBA');
            120:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - DRENAJE PREVIO');
            140:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - HOMOGENIZACION EN TANQUE');
            150:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - HOMOGENIZACION EN LINEA');
            160:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - EMPUJE');
            170:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - ACLARADO');
            180:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - APAGADO DE BOMBA');
            190:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - CIERRE CAMINO');
                
                //  =========================================================================================
                //  Homogenizacion en tanque
        
                
            999:
                #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_3us"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4DA"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 0
            )
            Contact( #EnEtapa )
            Contact( #OrdenMarcha )
            wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_2,
                in2 := 0
            )
            Move(
                in := 140,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_2,
                in2 := 1
            )
            Move(
                in := 100,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3CC"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 100
            )
            wire#w1
            P_Trig( #s_Pulsos[0] )
            Move(
                in := 3,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            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 := 110,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3N8"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 110
            )
            wire#w1
            P_Trig( #s_Pulsos[1] )
            Move(
                in := 1,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            Contact( #EstadoBomba )
            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 := 120,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_xG"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 120
            )
            wire#w1
            P_Trig( #s_Pulsos[2] )
            Move(
                in := #TiempoMaximoDrenaje,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            S_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Real" }
            GE_Contact(
                in1 := #TotalizadorDrenaje,
                in2 := #LitrosDrenajeInicial
            )
            wire#w2
            Move(
                in := 150,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.SP
            )
        END_RUNG wire#w2
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3WL"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
            wire#w1
            P_Trig( #s_Pulsos[3] )
            Move(
                in := #Parametros.P_Int_1,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            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 := 999,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4AD"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 150
            )
            wire#w1
            P_Trig( #s_Pulsos[4] )
            Move(
                in := #Parametros.P_Int_1,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            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 := 160,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_js"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 160
            )
            wire#w1
            P_Trig( #s_Pulsos[5] )
            Move(
                in := #TiempoMaximoEmpuje,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            S_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Real" }
            GE_Contact(
                in1 := #TotalizadorEmpuje,
                in2 := #LitrosEmpujeFinal
            )
            wire#w2
            Move(
                in := 170,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.SP
            )
        END_RUNG wire#w2
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3cn"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 170
            )
            wire#w1
            P_Trig( #s_Pulsos[6] )
            Move(
                in := #TiempoAclarado,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            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 := 180,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3dx"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 180
            )
            wire#w1
            P_Trig( #s_Pulsos[7] )
            Move(
                in := 1,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            I_Contact( #EstadoBomba )
            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 := 190,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3yb"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 190
            )
            wire#w1
            P_Trig( #s_Pulsos[8] )
            Move(
                in := 3,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            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 := 999,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3KK"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 999
            )
            wire#w1
            P_Trig( #s_Pulsos[15] )
            Move(
                in := 3,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            I_Contact( #EnEtapa )
            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_49m"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4uG"
    }
    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_3DW"
    }
    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;
        
        //  ============================================================================
        //  FF
        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_4FH"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3An"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_15,
                in2 := 1
            )
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_EtapaActual,
                in2 := 150
            )
            I_Contact( #s_Pausa_V )
            wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_2,
                in2 := 1
            )
            wire#w2
            I_Contact( #s_CalentarEnfriar )
            Move(
                in := #t_TempHistSuperior,
                out1 => #SP_CalEnf
            )
            S_Coil( #t_OrdenCalentar )
        END_RUNG
        RUNG wire#w2
            Contact( #s_CalentarEnfriar )
            Move(
                in := #t_TempHistInferior,
                out1 => #SP_CalEnf
            )
            S_Coil( #t_OrdenEnfriar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_2,
                in2 := 0
            )
            wire#w3
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_7,
                in2 := 0
            )
            Move(
                in := #Parametros.P_Real_6,
                out1 => #SP_CalEnf
            )
            wire#w4
            { S7_Templates := "SrcType := Real" }
            LE_Contact(
                in1 := #TT_Tanque,
                in2 := #SP_CalEnf
            )
            S_Coil( #t_OrdenCalentar )
        END_RUNG
        RUNG wire#w4
            { S7_Templates := "SrcType := Real" }
            GE_Contact(
                in1 := #TT_Tanque,
                in2 := #t_TempHistSuperior
            )
            R_Coil( #t_OrdenCalentar )
        END_RUNG
        RUNG wire#w3
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_7,
                in2 := 1
            )
            Move(
                in := #Parametros.P_Real_6,
                out1 => #SP_CalEnf
            )
            wire#w5
            { S7_Templates := "SrcType := Real" }
            GE_Contact(
                in1 := #TT_Tanque,
                in2 := #SP_CalEnf
            )
            S_Coil( #t_OrdenEnfriar )
        END_RUNG
        RUNG wire#w5
            { S7_Templates := "SrcType := Real" }
            LE_Contact(
                in1 := #TT_Tanque,
                in2 := #t_TempHistInferior
            )
            R_Coil( #t_OrdenEnfriar )
        END_RUNG
        RUNG wire#w1
            Coil( #VisibilidadCalEnf )
        END_RUNG
        RUNG wire#w1
            Contact( #t_OrdenCalentar )
            Coil( #OrdenCalentar )
        END_RUNG
        RUNG wire#w1
            Contact( #t_OrdenEnfriar )
            Coil( #OrdenEnfriar )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4Jb"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 100
            )
            Coil( #ResetTotalizadorDrenaje )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 120
            )
            Coil( #OrdenTotalizadorDrenaje )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4gQ"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 100
            )
            Coil( #ResetTotalizadorEmpuje )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 160
            )
            Coil( #OrdenTotalizadorEmpuje )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4JT"
    }
    NETWORK
        RUNG wire#powerrail
            Contact( #OrdenTotalizadorDrenaje )
            Coil( #VisibilidadLitrosDrenaje )
        END_RUNG
        RUNG wire#powerrail
            Contact( #OrdenTotalizadorEmpuje )
            Coil( #VisibilidadLitrosEmpuje )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3qC"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
            Coil( #HomoEnTanque )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_nk"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 20
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_EtapaActual,
                in2 := 40
            )
            wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_2,
                in2 := 1
            )
            I_Contact( #s_Pausa_M )
            wire#w2
            Coil( #MarchaBombaBlender )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 110
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_EtapaActual,
                in2 := 170
            )
        END_RUNG wire#w1
        RUNG wire#w2
            Move(
                in := #Parametros.P_Real_1,
                out1 => #VelocidadBombaBlender
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4J4"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 20
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_EtapaActual,
                in2 := 40
            )
            wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_2,
                in2 := 1
            )
            I_Contact( #s_Pausa_M )
            Coil( #MarchaBombaIntermedia )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 110
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_EtapaActual,
                in2 := 170
            )
        END_RUNG wire#w1
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4dN"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 10
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_EtapaActual,
                in2 := 50
            )
            wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_2,
                in2 := 1
            )
            I_Contact( #s_Pausa_V )
            Move(
                in := 2,
                out1 => #s_TOF[1].SP
            )
            Coil( #s_TOF[1].IN )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 100
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_EtapaActual,
                in2 := 150
            )
        END_RUNG wire#w1
        RUNG wire#powerrail
            Contact( #s_TOF[1].Q )
            Coil( #AperturaValvulaSalidaTanque )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3w9"
    }
    NETWORK
        RUNG wire#powerrail
            I_Contact( #TipoValvulaDrenaje )
            wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 100
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_EtapaActual,
                in2 := 120
            )
            wire#w2
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_2,
                in2 := 1
            )
            I_Contact( #s_Pausa_V )
            Move(
                in := 2,
                out1 => #s_TOF[3].SP
            )
            Coil( #s_TOF[3].IN )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 170
            )
        END_RUNG wire#w2
        RUNG wire#powerrail
            Contact( #TipoValvulaDrenaje )
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 130
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_EtapaActual,
                in2 := 160
            )
        END_RUNG wire#w2
        RUNG wire#powerrail
            Contact( #s_TOF[3].Q )
            Coil( #AperturaValvulaDrenaje )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_52R"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 150
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_EtapaActual,
                in2 := 160
            )
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_2,
                in2 := 1
            )
            I_Contact( #s_Pausa_V )
            Move(
                in := 2,
                out1 => #s_TOF[4].SP
            )
            Coil( #s_TOF[4].IN )
        END_RUNG
        RUNG wire#powerrail
            Contact( #s_TOF[4].Q )
            Coil( #AperturaValvulaEntradaTanque )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3dG"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 160
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_EtapaActual,
                in2 := 170
            )
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_2,
                in2 := 1
            )
            I_Contact( #s_Pausa_V )
            Move(
                in := 2,
                out1 => #s_TOF[5].SP
            )
            Coil( #s_TOF[5].IN )
        END_RUNG
        RUNG wire#powerrail
            Contact( #s_TOF[5].Q )
            Coil( #AperturaValvulaEmpuje )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4tU"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_2,
                in2 := 0
            )
            I_Contact( #s_Pausa_M )
            Contact( #EstadoBocaHombre )
            { S7_Templates := "SrcType := Real" }
            GT_Contact(
                in1 := #LT_Tanque,
                in2 := #Parametros.P_Real_8
            )
            { S7_Templates := "SrcType := Real" }
            LT_Contact(
                in1 := #LT_Tanque,
                in2 := #Parametros.P_Real_9
            )
            wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_6,
                in2 := 0
            )
            Move(
                in := #Parametros.P_Int_3,
                out1 => #s_FF[1].Config_SetPointTiempoFlip
            )
            Move(
                in := #Parametros.P_Int_4,
                out1 => #s_FF[1].Config_SetPointTiempoFlop
            )
            Coil( #s_FF[1].Orden_Activar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #Parametros.P_Int_6,
                in2 := 1
            )
            wire#w2
            Coil( #MarchaAgitador )
        END_RUNG
        RUNG wire#w1
            Contact( #s_FF[1].Estado_Flip )
        END_RUNG wire#w2
    END_NETWORK
    {
        S7_Language := "SCL";
        S7_NetworkTitle := "MLC_3QA"
    }
    NETWORK
        
        IF #Parametros.P_Int_5 = 1 THEN
            // =============================================================================
            //VELOCIDAD FIJA
            #VelocidadAgitador := #Parametros.P_Real_2;
        ELSE
            // =============================================================================
            //VELOCIDAD POR NIVEL
            #t_x0 := #Parametros.P_Real_8;
            #t_x1 := #Parametros.P_Real_9;
            #t_x := #LT_Tanque;
            #t_y0 := #Parametros.P_Real_10;
            #t_y1 := #Parametros.P_Real_11;
            #VelocidadAgitador := #t_y0 + (#t_y1 - #t_y0) * ((#t_x - #t_x0) / (#t_x1 - #t_x0));
            IF #VelocidadAgitador > #t_y1 THEN
                #VelocidadAgitador := #t_y1;
            END_IF;
            IF #VelocidadAgitador < #t_y0 THEN
                #VelocidadAgitador := #t_y0;
            END_IF;
        END_IF;
                                        
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_Ty"
    }
    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_hG"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 999
            )
            Coil( #FinSecuencia )
        END_RUNG
    END_NETWORK
END_FUNCTION_BLOCK
