FUNCTION_BLOCK FB 1
TITLE =
VERSION : 0.0


VAR_INPUT
  Start : BOOL ;	
  Stop : BOOL ;	
  Response : BOOL ;	
  Reset_Maint : BOOL ;	
  Timer_No : TIMER ;	
  Response_Time : S5TIME ;	
END_VAR
VAR_OUTPUT
  Fault : BOOL ;	
  Start_Dsp : BOOL ;	
  Stop_Dsp : BOOL ;	
  Maint : BOOL ;	
END_VAR
VAR_IN_OUT
  Motor : BOOL ;	
END_VAR
VAR
  Time_bin : WORD ;	
  Time_BCD : WORD ;	
  Starts : INT ;	
  Start_Edge : BOOL ;	
END_VAR
BEGIN
NETWORK
TITLE =Start/Stop and Latching

      A(    ; 
      O     #Start; 
      O     #Motor; 
      )     ; 
      AN    #Stop; 
      =     #Motor; 
NETWORK
TITLE =Startup Monitoring

      A     #Motor; 
      L     #Response_Time; 
      SD    #Timer_No; 
      AN    #Motor; 
      R     #Timer_No; 
      L     #Timer_No; 
      T     #Time_bin; 
      LC    #Timer_No; 
      T     #Time_BCD; 
      A     #Timer_No; 
      AN    #Response; 
      S     #Fault; 
      R     #Motor; 
NETWORK
TITLE =Start Lamp / Fault Reset

      A     #Response; 
      =     #Start_Dsp; 
      R     #Fault; 
NETWORK
TITLE =Stop Lamp

      AN    #Response; 
      =     #Stop_Dsp; 
NETWORK
TITLE =Count Starts

      A     #Motor; 
      FP    #Start_Edge; 
      JCN   lab1; 
      L     #Starts; 
      +     1; 
      T     #Starts; 
lab1: NOP   0; 
NETWORK
TITLE =Maintenance

      L     #Starts; 
      L     50; 
      >=I   ; 
      =     #Maint; 
NETWORK
TITLE =Reset Maintenance

      A     #Reset_Maint; 
      A     #Maint; 
      JCN   END; 
      L     0; 
      T     #Starts; 
END:  NOP   0; 
END_FUNCTION_BLOCK

DATA_BLOCK DB 1
TITLE =
VERSION : 0.0

 FB 1
BEGIN
   Start := FALSE; 
   Stop := FALSE; 
   Response := FALSE; 
   Reset_Maint := FALSE; 
   Timer_No := T 0; 
   Response_Time := S5T#0MS; 
   Fault := FALSE; 
   Start_Dsp := FALSE; 
   Stop_Dsp := FALSE; 
   Maint := FALSE; 
   Motor := FALSE; 
   Time_bin := W#16#0; 
   Time_BCD := W#16#0; 
   Starts := 0; 
   Start_Edge := FALSE; 
END_DATA_BLOCK

DATA_BLOCK DB 2
TITLE =
VERSION : 0.0

 FB 1
BEGIN
   Start := FALSE; 
   Stop := FALSE; 
   Response := FALSE; 
   Reset_Maint := FALSE; 
   Timer_No := T 0; 
   Response_Time := S5T#0MS; 
   Fault := FALSE; 
   Start_Dsp := FALSE; 
   Stop_Dsp := FALSE; 
   Maint := FALSE; 
   Motor := FALSE; 
   Time_bin := W#16#0; 
   Time_BCD := W#16#0; 
   Starts := 0; 
   Start_Edge := FALSE; 
END_DATA_BLOCK

DATA_BLOCK DB 3
TITLE =
VERSION : 0.0

 FB 1
BEGIN
   Start := FALSE; 
   Stop := FALSE; 
   Response := FALSE; 
   Reset_Maint := FALSE; 
   Timer_No := T 0; 
   Response_Time := S5T#0MS; 
   Fault := FALSE; 
   Start_Dsp := FALSE; 
   Stop_Dsp := FALSE; 
   Maint := FALSE; 
   Motor := FALSE; 
   Time_bin := W#16#0; 
   Time_BCD := W#16#0; 
   Starts := 0; 
   Start_Edge := FALSE; 
END_DATA_BLOCK

FUNCTION FC 1 : VOID
TITLE =
VERSION : 0.0


VAR_INPUT
  Open : BOOL ;	
  Close : BOOL ;	
END_VAR
VAR_OUTPUT
  Dsp_Open : BOOL ;	
  Dsp_Closed : BOOL ;	
END_VAR
VAR_IN_OUT
  Valve : BOOL ;	
END_VAR
BEGIN
NETWORK
TITLE =Open/Close and Latching

      A(    ; 
      O     #Open; 
      O     #Valve; 
      )     ; 
      AN    #Close; 
      =     #Valve; 
NETWORK
TITLE =Display "Valve open"

      A     #Valve; 
      =     #Dsp_Open; 
NETWORK
TITLE =Display "Valve closed"

      AN    #Valve; 
      =     #Dsp_Closed; 
END_FUNCTION

ORGANIZATION_BLOCK OB 1
TITLE =
VERSION : 0.0


VAR_TEMP
  OB1_EV_CLASS : BYTE ;	//Bits 0-3 = 1 (Coming event), Bits 4-7 = 1 (Event class 1)
  OB1_SCAN_1 : BYTE ;	//1 (Cold restart scan 1 of OB1), 3 (Scan 2-n of OB1)
  OB1_PRIORITY : BYTE ;	//1 (Priority of 1 is lowest)
  OB1_OB_NUMBR : BYTE ;	//1 (Organization block 1, OB1)
  OB1_RESERVED_1 : BYTE ;	//Reserved for system
  OB1_RESERVED_2 : BYTE ;	//Reserved for system
  OB1_PREV_CYCLE : INT ;	//Cycle time of previous OB1 scan (milliseconds)
  OB1_MIN_CYCLE : INT ;	//Minimum cycle time of OB1 (milliseconds)
  OB1_MAX_CYCLE : INT ;	//Maximum cycle time of OB1 (milliseconds)
  OB1_DATE_TIME : DATE_AND_TIME ;	//Date and time OB1 started
  Enable_Motor : BOOL ;	
  Enable_Valve : BOOL ;	
  Start_Fulfilled : BOOL ;	
  Stop_Fulfilled : BOOL ;	
  Inlet_Valve_A_Open : BOOL ;	
  Inlet_Valve_A_Closed : BOOL ;	
  Feed_Valve_A_Open : BOOL ;	
  Feed_Valve_A_Closed : BOOL ;	
  Inlet_Valve_B_Open : BOOL ;	
  Inlet_Valve_B_Closed : BOOL ;	
  Feed_Valve_B_Open : BOOL ;	
  Feed_Valve_B_Closed : BOOL ;	
  Open_Drain : BOOL ;	
  Close_Drain : BOOL ;	
  Close_Valve_Fulfilled : BOOL ;	
END_VAR
BEGIN
NETWORK
TITLE =Interlock for Feed Pump A

      A     I      1.6; 
      A     I      1.3; 
      AN    Q      9.5; 
      =     #Enable_Motor; 
NETWORK
TITLE =Call FB Motor for Ingredient A

      A     I      0.0; 
      A     #Enable_Motor; 
      =     #Start_Fulfilled; 
      A(    ; 
      O     I      0.1; 
      ON    #Enable_Motor; 
      )     ; 
      =     #Stop_Fulfilled; 
      CALL FB     1 , DB     1 (
           Start                    := #Start_Fulfilled,
           Stop                     := #Stop_Fulfilled,
           Response                 := I      0.2,
           Reset_Maint              := I      1.7,
           Timer_No                 := T     12,
           Response_Time            := S5T#7S,
           Fault                    := Q      4.5,
           Start_Dsp                := Q      4.2,
           Stop_Dsp                 := Q      4.3,
           Maint                    := Q      4.6,
           Motor                    := Q      4.4);
NETWORK
TITLE =Delay Valve Enable Ingredient A

      A     Q      4.4; 
      L     S5T#1S; 
      SD    T     13; 
      AN    Q      4.4; 
      R     T     13; 
      A     T     13; 
      =     #Enable_Valve; 
NETWORK
TITLE =Inlet Valve Control for Ingredient A

      AN    I      0.2; 
      AN    Q      4.4; 
      =     #Close_Valve_Fulfilled; 
      CALL FC     1 (
           Open                     := #Enable_Valve,
           Close                    := #Close_Valve_Fulfilled,
           Dsp_Open                 := #Inlet_Valve_A_Open,
           Dsp_Closed               := #Inlet_Valve_A_Closed,
           Valve                    := Q      4.0);
NETWORK
TITLE =Feed Valve Control for Ingredient A

      AN    I      0.2; 
      AN    Q      4.4; 
      =     #Close_Valve_Fulfilled; 
      CALL FC     1 (
           Open                     := #Enable_Valve,
           Close                    := #Close_Valve_Fulfilled,
           Dsp_Open                 := #Feed_Valve_A_Open,
           Dsp_Closed               := #Feed_Valve_A_Closed,
           Valve                    := Q      4.1);
NETWORK
TITLE =Interlock for Feed Pump B

      A     I      1.6; 
      A     I      1.3; 
      AN    Q      9.5; 
      =     #Enable_Motor; 
NETWORK
TITLE =Call FB Motor for Ingredient B

      A     I      0.3; 
      A     #Enable_Motor; 
      =     #Start_Fulfilled; 
      A(    ; 
      O     I      0.4; 
      ON    #Enable_Motor; 
      )     ; 
      =     #Stop_Fulfilled; 
      CALL FB     1 , DB     2 (
           Start                    := #Start_Fulfilled,
           Stop                     := #Stop_Fulfilled,
           Response                 := I      0.5,
           Reset_Maint              := I      1.7,
           Timer_No                 := T     14,
           Response_Time            := S5T#7S,
           Fault                    := Q      5.5,
           Start_Dsp                := Q      5.2,
           Stop_Dsp                 := Q      5.3,
           Maint                    := Q      5.6,
           Motor                    := Q      5.4);
NETWORK
TITLE =Delay Valve Enable Ingredient B

      A     Q      5.4; 
      L     S5T#1S; 
      SD    T     15; 
      AN    Q      5.4; 
      R     T     15; 
      A     T     15; 
      =     #Enable_Valve; 
NETWORK
TITLE =Inlet Valve Control for Ingredient B

      AN    I      0.5; 
      AN    Q      5.4; 
      =     #Close_Valve_Fulfilled; 
      CALL FC     1 (
           Open                     := #Enable_Valve,
           Close                    := #Close_Valve_Fulfilled,
           Dsp_Open                 := #Inlet_Valve_B_Open,
           Dsp_Closed               := #Inlet_Valve_B_Closed,
           Valve                    := Q      5.0);
NETWORK
TITLE =Feed Valve Control for Ingredient B

      AN    I      0.5; 
      AN    Q      5.4; 
      =     #Close_Valve_Fulfilled; 
      CALL FC     1 (
           Open                     := #Enable_Valve,
           Close                    := #Close_Valve_Fulfilled,
           Dsp_Open                 := #Feed_Valve_B_Open,
           Dsp_Closed               := #Feed_Valve_B_Closed,
           Valve                    := Q      5.1);
NETWORK
TITLE =Interlock for Agitator

      A     I      1.6; 
      A     I      1.4; 
      AN    Q      9.5; 
      =     #Enable_Motor; 
NETWORK
TITLE =Call FB Motor for Agitator

      A     I      1.1; 
      A     #Enable_Motor; 
      =     #Start_Fulfilled; 
      A(    ; 
      O     I      1.2; 
      ON    #Enable_Motor; 
      )     ; 
      =     #Stop_Fulfilled; 
      CALL FB     1 , DB     3 (
           Start                    := #Start_Fulfilled,
           Stop                     := #Stop_Fulfilled,
           Response                 := I      1.0,
           Reset_Maint              := I      1.7,
           Timer_No                 := T     16,
           Response_Time            := S5T#10S,
           Fault                    := Q      8.3,
           Start_Dsp                := Q      8.1,
           Stop_Dsp                 := Q      8.2,
           Maint                    := Q      8.4,
           Motor                    := Q      8.0);
NETWORK
TITLE =Interlock for Drain Valve

      A     I      1.6; 
      A     I      1.5; 
      AN    Q      8.0; 
      =     #Enable_Valve; 
NETWORK
TITLE =Drain Valve Control

      A     I      0.6; 
      A     #Enable_Valve; 
      =     #Open_Drain; 
      A(    ; 
      O     I      0.7; 
      ON    #Enable_Valve; 
      )     ; 
      =     #Close_Drain; 
      CALL FC     1 (
           Open                     := #Open_Drain,
           Close                    := #Close_Drain,
           Dsp_Open                 := Q      9.6,
           Dsp_Closed               := Q      9.7,
           Valve                    := Q      9.5);
NETWORK
TITLE =Container Level Display

      AN    I      1.3; 
      =     Q      9.0; 
      AN    I      1.4; 
      =     Q      9.1; 
      AN    I      1.5; 
      =     Q      9.2; 
END_ORGANIZATION_BLOCK

