'NEW VERSION FOR FLASH  BOILER DESIGN

 
        'Issue F4s now iss F5
        'Addition to stop pump running during cut-out period
        
      'T1 (MP1) senses temp of water return to hot well coil (infomation only)
      'T2 (MP2)senses temp of exhaust from steam engine or feed water from economiser (infomation only)
      'T3 (MP3) senses temp of steam/water from main coil                 
      'T4 (MP4) senses temp of steam from separator (infomation only)
      'T5 (MP5) senses temp of steam output from superheater
      'P senses  pressure of steam at outlet from separator
                                         
     Include "PROTON_G20X.INT"                        
        
                                       'Version based on SERVO_ADINBOLDav

    GLCD_EXTERNAL_PRINT = PPRINT                     ' Point to PPRINT.INC file
     ADIN_RES = 10                           ' Set number of bits in result
             ADIN_TAD = FRC                          ' Set clock source (3=rc)
             ADIN_STIME = 100             ' Set sampling time in uS
     
        Dim x           As Word                                 
        Dim Raw0        As Word 
        Dim Raw0a               As Word
         Dim Raw0b              As Word                 
         Dim Raw1               As Word
         Dim Raw1a              As Word
         Dim Raw1b              As Word
         Dim Raw2               As Word
         Dim Raw2a              As Word
         Dim Raw2b              As Word
         Dim Raw3               As Word
         Dim Raw4               As Word
         Dim Raw5               As Word         
                Dim Value0              As Word
                Dim Value1              As Word
                Dim Value2              As Word
                Dim Value3              As Word
                Dim Value4              As Word
                Dim Value5              As Word
        Dim Scale0      As Word
        Dim Scale1      As Word
        Dim Scale2      As Word
        Dim Temp0          As Word      
        Dim Temp1          As Word
        Dim Temp2          As Word
        Dim Temp3          As Word
        Dim Temp4          As Word
        Dim Presure        As Word
        Dim Shut        As Bit
        Dim Shut2       As Bit
        
        Dim w          As Word
                Dim G          As Word
        Dim z          As Word
        Dim o          As Word
        Dim F          As Word
        Dim b          As Word  
        
        
                Symbol Pin0 = PORTB.0              ' Alias servo pin 
             Symbol Pin1 = PORTB.4
                Symbol Pin2 = PORTB.5
                Symbol Level = PORTB.7      'Alias float level switch (used only to operate pump' manually)
        Symbol Pump = PORTB.6      'Alias Feed pump "Pump"
        
       'Position the servo

             Input TRISA                                        ' Set PORTA to all input
             TRISB = %11110000                  ' Set PORTB.0-3 to output
             PORTB = 0                                  ' Set PORTB.0-3 low
        ADCON1 = %10000010                   ' Set PORTA analog and right justify result
        TRISE = %00000001           ' Set PORTE.0 To Output
        PORTE = 0                   ' Set PORTE.0 low
        TRISB.6 = 0                 ' Set PORTB.6 output
           Shut = 0
          Shut2 = 0
          z = 0
          G = 0
          F = 0
          b = 0
                          
' Main program loop 
          
       Again:
       
          
 
       
        For x = 1 To 5            'go round  servos loop 5 times for each display loop                            
         
                                             'SUPERHEATER GAS VALVE CONTROL
                                      
                                                                     
                                                                     'SELECT  TEMPERATURE AND GAIN
          Raw0a = (Value4 / 16) + 390                    'Set S/H temp. ( = Open at aboutC150, Closed at about 195C)                                                           
          'Raw0a = (Value4 / 8) + 110                    'Set S/H temp. ( = Open at about170C, Closed at about 195C)                                                                                                                                
          'Raw0a = (Value4 / 8) + 90                     'Set S/H temp. ( = Open at about175C, Closed at about 206C)                              
         If Raw0a > 650 Then GoTo jumpover8                                                           
         If Raw0a > Raw0b + 5  Then Raw0b = Raw0b + 1 Else Raw0b = Raw0a    'dead band & slow up responce (small changes)
         If Raw0a < Raw0b - 5  Then Raw0b = Raw0b - 1 Else Raw0b = Raw0a
         If Raw0b < 600 Then GoTo jumpover0
         If Raw0a > Raw0b + 50  Then Raw0b = Raw0b + 3   'dead band & slow up responce (large changes)
         If Raw0a < Raw0b - 50  Then Raw0b = Raw0b - 3 
         jumpover0:
         If Raw0b < 600 Then Raw0b = 600                'Limit servo travel (600 = max, 640 = 60%)
         If Raw0b > 700 Then Raw0b = 700 
         If Raw0a < 650 Then Shut = 0: GoTo jumpover5
         
          jumpover8:
         If Shut = 1 Then GoTo jumpover6         
         If Raw0a > 670 Then Raw0b = 700 : Shut = 1 : GoTo jumpover5             'Snap open/closed secondary burner to 25% for ignition or shut-off 
 
         jumpover6:
         If Raw0a < 660 Then Raw0b = 650 : Shut = 0      
         jumpover5:        
       
         
      
          
          
         DelayMS 10      
            Scale0 = Raw0b -600              
             If Scale0 < 1 Then Scale0 = 0
             If Scale0 > 100 Then Scale0 = 100                                                       
             Scale0 = Scale0 * 14
             If Presure < 60 Then Scale0 = 1400                'Disable s/h outside pressure range 60-85           
             If Presure > 85 Then Scale0 = 1400
            
        If b > 450 Then b = 450                           'Disable s/h for frist 3 mins
             If b < 450 Then Scale0 = 1400     
        Servo Pin0 , 1000 + Scale0
        
        
        DelayMS 10
                                            
         
                                       ' MAIN GAS VALVE CONTROL
                                       
                                       
           If Value5 < 1000 Then Value5 = 1000 'NEW                             
                                                                   'SELECT PRESSURE AND GAIN
          'Raw1a = (Value5 / 30) + 480             'Gas valve porpotinal to pressure, ( = open at 60PSI shut at 80PSI, )
          Raw1a = (Value5 / 20) + 380             'Gas valve porpotinal to pressure, ( = open at 65PSI shut at 80PSI, )
           'Raw1a = Value5 / 9                      'Gas valve porpotinal to pressure, ( = open at 70PSI shut at 78PSI, ) 
          'Raw1a = (Value5 / 10) - 30              'Gas valve porpotinal to pressure, ( = open at 83PSI shut at 90PSI, )
          'Raw1a = Value5 / 10                     'Gas valve porpotinal to pressure, ( = open at 78PSI shut at 87PSI, )  
          'Raw1a = (Value5 / 8)  - 100             'Gas valve porpotinal to pressure, ( = open at 74PSI shut at 80PSI, )
          'Raw1a = (Value5 / 11)                   'Gas valve porpotinal to pressure, ( = open at 88PSI shut at 95PSI, )
          'Raw1a = (Value5 / 12)  + 30             'Gas valve porpotinal to pressure, ( = open at 90PSI shut at 99PSI, )
         If Raw1a > 680 Then GoTo jumpover18                                  
         If Raw1a > Raw1b + 5  Then Raw1b = Raw1b + 1  Else Raw1b = Raw1a      ' dead band & slow up responce (small changes)
         If Raw1a < Raw1b - 5  Then Raw1b = Raw1b - 1  Else Raw1b = Raw1a
         If Raw1b < 600 Then GoTo jumpover1
         If Raw1a > Raw1b + 50  Then Raw1b = Raw1b + 3   'dead band & slow up responce (large changes)
         If Raw1a < Raw1b - 50  Then Raw1b = Raw1b - 3 
         jumpover1:      
         If Raw1b < 640 Then Raw1b = 640             'Limit servo travel (600 = max, 640 = 60%)
         If Raw1b > 700 Then Raw1b = 700 
         If Raw1a < 680 Then Shut2 = 0: GoTo jumpover15
         
          jumpover18:
         If Shut2 = 1 Then GoTo jumpover16         
         If Raw1a > 699 Then Raw1b = 700 : Shut2 = 1 : GoTo jumpover15             'Snap open/closed burner to 25% for ignition or shut-off 
 
         jumpover16:
         If Raw1a < 681 Then Raw1b = 680 : Shut2 = 0      
         jumpover15:          
         DelayMS 10
     
            Scale1 = Raw1b -600              
             If Scale1 < 1 Then Scale1 = 0
             If Scale1 > 100 Then Scale1 = 100                                                           
             Scale1 = Scale1 * 14
            
        Servo Pin1 , 1000 + Scale1
             DelayMS 10
             Next x
             
              b = b + 1
             
             
                       'FEED WATER MOS-FET CONTROL 
                       
              z = z + 1
              If z = 2 Then z = 0:GoTo jumpover20        ' set pump on period - 2
                         
              Pump = 0                                    
              G = G + 1
              If G > 100 Then G = 100                     'Enable pump at 8:2 for 90 secs after start or reset 
              If G < 100 Then Pump = 1
              If G > 101 Then Pump = 0
               
            
              F = F + 1
              If F < 24 Then Pump = 0:GoTo jumpover20        'set pump off  period (2 to 19) (5 = 5:1)                                                     
              If F > 24 Then F = 24:Pump = 1
              
              If G < 100 Then Pump = 1:F = 16:GoTo jumpover20       'pump 8:2  for first 2 mins
              If Temp2 > 178 Then Pump = 1:F = 21:GoTo jumpover20   'pump 3:2  T3 > 178
              If Temp2 > 170 Then Pump = 1:F = 18:GoTo jumpover20   'pump 6:2  T3 > 170
              If Temp2 > 160 Then Pump = 1:F = 11:GoTo jumpover20   'pump 13:2  T3 > 160
              If Temp2 > 150 Then Pump = 1:F = 9:GoTo jumpover20   'pump 15:2  T3 > 150
              Pump = 1:F = 0                                       'pump 24:2  T3 < 150
              jumpover20:  
              If Level = 1 Then Pump = 0: F = 0: G = 100   ' Pump can be turned off manually during first 3 minutes
              If Level = 1 Then Pump = 1                   'Pump can be turned on/off manually after  1st 3 minutes
                   
                                      'DISPLAY
              Raw0 = ADIn 0
              Raw1 = ADIn 1
              Raw2 = ADIn 2
              Raw3 = ADIn 3
              Raw4 = ADIn 4                                                  
              Raw5 = ADIn 5             
          
          Cls                                    ' Clear the LCD
                                     ' Quantasize the result
        Value3 = Raw0 *10                     'Raw0 is T4 Temp3  Separator steam out, For information only
        Value4 = Raw1 *10            'Raw1 is T5 Temp4 for controlling superheater burner
        Value5 = Raw2 *10            'Raw2 is P5 Pressure For controllimg Main Burner
        Value0 = Raw3 *10            'Raw3 is T1 Temp0   Heat exchanger to hot well.For information only
        Value1 = Raw4 *10            'Raw4 is T2 Temp1  Feed water to main heater coil For information only
             Value2 = Raw5 *10            'Raw5 is T3 Temp2  Output from main coil. For controlling feed pump              
             
                Temp0 = Value0/46           '0-220 Deg C
             Temp1 = Value1/46           '0-220 Deg C
             Temp2 = Value2/46           '0-220 Deg C
             Temp3 = Value3/46           '0-220 Deg C
             Temp4 = Value4/23           '0-440 Deg C
             Presure = Value5/80         '0-120 PSI
    Cls

    Print Font TIMES_BOLD14                                             ' Choose the font
    
        Print At 0,0, "T1 = ", DEC3 Temp0,"  C" ' Display the result
             Print At 10,0, "T2 = ", DEC3 Temp1,"  C"
         Print At 20,0, "T3 = ", DEC3 Temp2,"  C"   
         Print At 30,0, "T4 = ", DEC3 Temp3,"  C"   
         Print At 40,0, "T5 = ", DEC3 Temp4,"  C"
         Print At 50,0, "P5 = ", DEC3 Presure," PSI" 
                  
        
        'Print At 10,90, DEC3 b          'Use this section to display diagnostic information
        'Print At 20,90, DEC3 G 
        'Print At 30,90, DEC4 Raw0a
        'Print At 40,90, DEC4 Value4 
        
        If b < 450 Then Print At 0,65, "Warm-up"        
        If b < 450 Then Print At 10,90, "2"
        If G < 100 Then Print At 10,90, "1"       
        If Pump = 1 Then Print At 40,90,"Pump"            
            If Temp2 > 173 Then Print At 20,70, "HI"
        If Temp3 > 170 Then Print At 30,70, "HI"
         If Temp4 > 205 Then Print At 40,70, "HI"
         If Presure > 100 Then Print At 50,75, "HI"
         Print At 50,104, "F5"                         'Show software issue number
             
        SerOut PORTC.6,T9600,[DEC3 Temp0,44,DEC3 Temp1,44,DEC3 Temp2,44,DEC3 Temp3,44,DEC3 Temp4,44,DEC3 Presure,44,DEC4 Scale0,44,DEC4 Scale1,44,DEC1 Pump,44,10]   ' Output serial data comma delimited(44), CR/LF(10). 
                                                                                                                                                                          ' 5 temps, pressure, 3 servo positions
                                                  'OVER TEMPERATURE/PRESSURE SHUT DOWN                                                                                       ' Use Baud 9600; no parity; Byte size 8; 1 stop bit
                                                                                                                                                                             ' Will only work properly on Lap-top
             If Presure > 100 Then GoTo closevalves         ' Close primary & secondary valve if temp exceads limits 
             If Temp2 > 185 Then GoTo closevalves                 
                If Temp3 > 175 Then GoTo closevalves 
                If Temp4 > 220 Then GoTo closevalves
        
   GoTo Again    
        closevalves:
        Print At 10,65, "Over Temp"      
        Print At 20,65, "Cut-Out" 
        Print At 30,65, "Wait"
        Print At 40,65, "1 min"
       
        For w = 0 To 50                 'Set S/H gas valve closed 
        Servo Pin0 , 2400
        DelayMS 10
             
        Servo Pin1 , 2400                 'Set  gas valve closed 
        DelayMS 10
        
        Pump = 0                          ' Stop pump during cut-out
        
        Next w     
             
        For o = 1 To 60                    'Reset cut-out after 1 mins
        DelayMS 1000
        Next o
        G = 100
        b = 300
        GoTo Again
        End
' Load the fonts used

    Include "TIMES_BOLD_14.FNT"