{
    S7_Author := "ABH";
    S7_BlockNumber := "15183";
    S7_BlockTitle := "MLC_wZ";
    S7_Family := "ZeusControl";
    S7_Optimized := "TRUE";
    S7_PreferredLanguage := "LAD";
    S7_UserDefinedId := "FB15183_ZC_FERM_CORTE";
    S7_Version := "1.0"
}
FUNCTION_BLOCK "FB15183_ZC_FERM_CORTE"
    VAR_INPUT
        { S7_MLC := "MLC_xt" }
        NombreSecuencia : String := 'ADICION PRODUCTO';
        { S7_MLC := "MLC_4dm" }
        Pulso1Seg : Bool;
        { S7_MLC := "MLC_4Td" }
        Ack : Bool;
        { S7_MLC := "MLC_3sV" }
        OrdenMarcha : Bool;
        { S7_MLC := "MLC_5C2" }
        EstadoEnMarcha : Bool;
        { S7_MLC := "MLC_4UU" }
        EnEtapa : Bool;
        { S7_MLC := "MLC_3Qf" }
        OrdenPausa : Bool;
        { S7_MLC := "MLC_3GT" }
        TT_Tanque : Real;
        { S7_MLC := "MLC_545" }
        LT_Tanque : Real;
        Parametros : _.UDT_ZC_RECETA_BATCH_ETAPA := (
            { S7_MLC := "MLC_5B4" }
            TipoEtapa := (),
            { S7_MLC := "MLC_jP" }
            P_Real_1 := (),
            { S7_MLC := "MLC_3YD" }
            P_Real_2 := (),
            { S7_MLC := "MLC_3qC" }
            P_Real_3 := (),
            { S7_MLC := "MLC_3GH" }
            P_Real_4 := (),
            { S7_MLC := "MLC_4FM" }
            P_Real_5 := (),
            { S7_MLC := "MLC_42j" }
            P_Real_6 := (),
            { S7_MLC := "MLC_3BU" }
            P_Real_7 := (),
            { S7_MLC := "MLC_4Gr" }
            P_Real_8 := (),
            { S7_MLC := "MLC_3P2" }
            P_Real_9 := (),
            { S7_MLC := "MLC_4JA" }
            P_Real_10 := (),
            { S7_MLC := "MLC_cD" }
            P_Real_11 := (),
            { S7_MLC := "MLC_WG" }
            P_Real_12 := (),
            { S7_MLC := "MLC_46Y" }
            P_Real_13 := (),
            { S7_MLC := "MLC_zR" }
            P_Real_14 := (),
            { S7_MLC := "MLC_WY" }
            P_Real_15 := (),
            { S7_MLC := "MLC_4rJ" }
            P_Real_16 := (),
            { S7_MLC := "MLC_4gq" }
            P_Real_17 := (),
            { S7_MLC := "MLC_3wT" }
            P_Int_1 := (),
            { S7_MLC := "MLC_4Ve" }
            P_Int_2 := (),
            { S7_MLC := "MLC_4jB" }
            P_Int_3 := (),
            { S7_MLC := "MLC_4im" }
            P_Int_4 := (),
            { S7_MLC := "MLC_4at" }
            P_Int_5 := (),
            { S7_MLC := "MLC_39j" }
            P_Int_6 := (),
            { S7_MLC := "MLC_3aY" }
            P_Int_7 := (),
            { S7_MLC := "MLC_53F" }
            P_Int_8 := (),
            { S7_MLC := "MLC_NV" }
            P_Int_9 := (),
            { S7_MLC := "MLC_qa" }
            P_Int_10 := (),
            { S7_MLC := "MLC_3jV" }
            P_Int_11 := (),
            { S7_MLC := "MLC_4sa" }
            P_Int_12 := (),
            { S7_MLC := "MLC_4Fv" }
            P_Int_13 := (),
            { S7_MLC := "MLC_5BQ" }
            P_Int_14 := (),
            { S7_MLC := "MLC_3ed" }
            P_Int_15 := (),
            { S7_MLC := "MLC_3fn" }
            P_String_1 := (),
            { S7_MLC := "MLC_3tF" }
            P_String_2 := (),
            { S7_MLC := "MLC_4tB" }
            P_String_3 := (),
            { S7_MLC := "MLC_3u4" }
            P_String_4 := (),
            { S7_MLC := "MLC_3st" }
            P_String_5 := (),
            { S7_MLC := "MLC_4uA" }
            P_String_6 := (),
            { S7_MLC := "MLC_YA" }
            P_String_7 := (),
            { S7_MLC := "MLC_54J" }
            P_String_8 := (),
            { S7_MLC := "MLC_4LP" }
            P_String_9 := (),
            { S7_MLC := "MLC_4LN" }
            P_String_10 := ()
        );
    END_VAR
    VAR_OUTPUT
        MarchaAgitador : Bool;
        VelocidadAgitador : Real;
        { S7_MLC := "MLC_xE" }
        OrdenEnfriar : Bool;
        { S7_MLC := "MLC_4iX" }
        SP_CalEnf : Real;
        VisibilidadCalEnf : Bool;
        { S7_MLC := "MLC_4cU" }
        SecuenciaIniciada : Bool;
        { S7_MLC := "MLC_Rz" }
        FinSecuencia : Bool;
    END_VAR
    VAR RETAIN
        { S7_MLC := "MLC_58Q" }
        s_EtapaActual : Int;
        { S7_MLC := "MLC_WX" }
        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 := [
            3(()),
            { S7_MLC := "MLC_3EW" }
        (),
            { S7_MLC := "MLC_4GX" }
        (),
            { S7_MLC := "MLC_3HH" }
        (),
            4(()),
            { S7_MLC := "MLC_3WM" }
        (),
            { S7_MLC := "MLC_44e" }
        ()
        ];
    END_VAR
    VAR RETAIN
        { S7_MLC := "MLC_4Ge" }
        s_TiempoEtapa : STRUCT
            { S7_MLC := "MLC_4uP" }
            Activar : Bool;
            { S7_MLC := "MLC_4F5" }
            Reset : Bool;
            { S7_MLC := "MLC_539" }
            Actual : Int;
            { S7_MLC := "MLC_3cm" }
            SP : Int;
            { S7_MLC := "MLC_4vE" }
            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_3Hq" }
        (),
            { S7_MLC := "MLC_357" }
        ()
        ];
        s_FF : Array[1..#NUM_MAX_FF] of _.UDT_ZC_DISP_FF;
        { S7_MLC := "MLC_4c4" }
        s_NumeroCiclosAgitador : Int;
        {
            S7_Access := "ReadOnly := External";
            S7_Visibility := "Hidden := External"
        }
        s_OrdenEnfriar : 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;
    END_VAR
    VAR CONSTANT
        SiempreON : Bool := TRUE;
        SiempreOFF : Bool := FALSE;
        NUM_MAX_TON : Int := 2;
        NUM_MAX_FF : Int := 1;
    END_VAR

    {
        S7_Language := "SCL";
        S7_NetworkTitle := "MLC_4bn"
    }
    NETWORK
        (*
        ============================================================================
        ZEUS CONTROL, S.A.
        (c)Copyright (2024) All Rights Reserved
        -----------------------------------------------------------------------------
        
        Software:       TIA Portal 18
        Restricciones:  PLC serie 1200/1500
        
        
        Nombre:         FB15183_ZC_FERM_CORTE
        Descripcion:    Bloque de gestión de fase adicion de producto
        
        Dependencias:   
            FC:         -
            FB:         -
            DB:         -
            UDT:        -
                     
        
        Change log:
        
            Version     Fecha       Tecnico a cargo     Descripción
            
            01.00.00    08.07.2025  (ABH)               Primera versión
            
         ============================================================================
         *)
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3m2"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4kS"
    }
    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_5BN"
    }
    NETWORK
        RUNG wire#powerrail
            I_Contact( #EnEtapa )
            Move(
                in := 0,
                out1 => #s_EtapaActual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "SCL";
        S7_NetworkTitle := "MLC_3jE"
    }
    NETWORK
        //  ================================================================
        //  TEXTO ETAPA
        CASE #s_EtapaActual OF
            0:
                #s_TextoEtapa := CONCAT_STRING(IN1:= #NombreSecuencia,IN2:= ' - REPOSO');
                
            140:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - CORTE');
                
            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_3Wt"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3M4"
    }
    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_iK"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_ZW"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 0
            )
            Contact( #EnEtapa )
            Contact( #OrdenMarcha )
            Move(
                in := 140,
                out1 => #s_EtapaActual
            )
            wire#w1
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
        RUNG wire#w1
            Move(
                in := 0,
                out1 => #s_NumeroCiclosAgitador
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3Rb"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
            wire#w1
            P_Trig( #s_Pulsos[4] )
            Move(
                in := 1,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_NumeroCiclosAgitador,
                in2 := #Parametros.P_Int_1
            )
            Move(
                in := 999,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4Ch"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 999
            )
            wire#w1
            P_Trig( #s_Pulsos[10] )
            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_3W3"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4cX"
    }
    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_4ap"
    }
    NETWORK
        
        //  ============================================================================
        //  TON
        FOR #for_i := 1 TO #NUM_MAX_TON DO
            "FC2928_ZC_TON_INDV"(Pulso1seg:=#Pulso1Seg,
                                 TON:=#s_TON[#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_4Ke"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4KK"
    }
    NETWORK
        RUNG wire#powerrail
            Contact( #SiempreON )
            wire#w1
            Move(
                in := #Parametros.P_Int_4,
                out1 => #s_FF[1].Config_SetPointTiempoFlip
            )
            Move(
                in := #Parametros.P_Int_3,
                out1 => #s_FF[1].Config_SetPointTiempoFlop
            )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
            I_Contact( #s_Pausa_V )
            { S7_Templates := "SrcType := Real" }
            GT_Contact(
                in1 := #LT_Tanque,
                in2 := #Parametros.P_Real_2
            )
            { S7_Templates := "SrcType := Real" }
            LT_Contact(
                in1 := #LT_Tanque,
                in2 := #Parametros.P_Real_3
            )
            Coil( #s_FF[1].Orden_Activar )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4A8"
    }
    NETWORK
        RUNG wire#powerrail
            Contact( #SiempreON )
            I_Contact( #s_FF[1].Estado_Flip )
            P_Trig( #s_Pulsos[11] )
            Contact( #s_FF[1].Orden_Activar )
            { S7_Templates := "DestType := Int" }
            Inc( #s_NumeroCiclosAgitador )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_432"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_XA"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
            I_Contact( #s_Pausa_M )
            wire#w1
            Move(
                in := #Parametros.P_Real_6,
                out1 => #SP_CalEnf
            )
            wire#w2
            { S7_Templates := "SrcType := Real" }
            GE_Contact(
                in1 := #TT_Tanque,
                in2 := #SP_CalEnf
            )
            S_Coil( #s_OrdenEnfriar )
        END_RUNG
        RUNG wire#w2
            { S7_Templates := "SrcType := Real" }
            LE_Contact(
                in1 := #TT_Tanque,
                in2 := #t_TempHistInferior
            )
            R_Coil( #s_OrdenEnfriar )
        END_RUNG
        RUNG wire#w1
            Coil( #VisibilidadCalEnf )
        END_RUNG
        RUNG wire#w1
            Contact( #s_OrdenEnfriar )
            Coil( #OrdenEnfriar )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            NE_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
            { S7_Templates := "SrcType := Int" }
            NE_Contact(
                in1 := #s_EtapaActual,
                in2 := 150
            )
            R_Coil( #s_OrdenEnfriar )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3Jp"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
            I_Contact( #s_Pausa_M )
            Contact( #s_FF[1].Estado_Flip )
            Coil( #MarchaAgitador )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "SCL";
        S7_NetworkTitle := "MLC_3p4"
    }
    NETWORK
        
        IF #Parametros.P_Int_5 = 1 THEN
            // =============================================================================
            //VELOCIDAD FIJA
            #VelocidadAgitador := #Parametros.P_Real_1;
        ELSE
            // =============================================================================
            //VELOCIDAD POR NIVEL
            #t_x0 := #Parametros.P_Real_2;
            #t_x1 := #Parametros.P_Real_3;
            #t_x := #LT_Tanque;
            #t_y0 := #Parametros.P_Real_4;
            #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_3JG"
    }
    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_4zE"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 999
            )
            Coil( #FinSecuencia )
        END_RUNG
    END_NETWORK
END_FUNCTION_BLOCK
