  function [hStartOut, hEndOut, vStartOut, vEndOut, validOut, EnableReadCompute, EnableBetweenLines, ColumnCountEnable, ColumnCountReset] =...
      ControlSignalGeneration(ReadFSMState, BlankingInterval,ColumnCountIn)
                  
  %

  % Copyright 2017-2020 The MathWorks, Inc.
  
  persistent BlankingCounter;
  persistent RowCounter;
%   persistent ColumnCounter;
  persistent EnableBetweenLinesREG;
  
  if isempty(BlankingCounter)
  BlankingCounter = uint16(0);
  RowCounter = uint16(0);
%   ColumnCounter = uint16(0);
  EnableBetweenLinesREG = false;
  end
  
  
  
  
  
  if ReadFSMState == 2 
            
                  EnableReadCompute = true;
           if (EnableBetweenLinesREG==1) && (BlankingCounter <=BlankingInterval-2)
              BlankingCounter(:) = BlankingCounter +1;
              ColumnCountReset = true;
           
              if BlankingCounter ==BlankingInterval-2
                 BlankingCounter(:) = 0;   
                 EnableBetweenLinesREG = false;
              end
           else
               ColumnCountReset = false;
           
           end
           
           if (EnableBetweenLinesREG==0) && (ColumnCountIn<BIRDSEYE_ACTIVEPIXELS+1)   
                 ColumnCountEnable = true;
                 
                 if ColumnCountIn>=2
                 validOut = true;
                 else
                 validOut = false;
                 end
                 
              if ColumnCountIn ==2
                     hStartOut = true;
                     hEndOut = false;
                    EnableReadCompute = true;

                      
              elseif ColumnCountIn == (BIRDSEYE_ACTIVEPIXELS)
                     hEndOut = true;
                     hStartOut = false;
                     RowCounter(:) = RowCounter + 1;  
                     EnableBetweenLinesREG = true;
              ColumnCountReset = true;
                     BlankingCounter(:) = 0; 
              else
                     hStartOut = false;
                     hEndOut = false;         
              end
           

           else
                 validOut = false;    
                 hStartOut = false;
                 hEndOut = false;
              ColumnCountEnable = false;

           end
              
             
           if (RowCounter == BIRDSEYE_ACTIVELINES) && hEndOut
               vEndOut = true;
               vStartOut = false;
              ColumnCountReset = true;
               BlankingCounter(:) = 0; 
               EnableBetweenLinesREG = true;
               RowCounter(:) = 0;
               
           elseif (RowCounter == 0) && hStartOut
               vStartOut = true;
               vEndOut = false;
           else
              vEndOut = false;
              vStartOut = false;
              
                       
           end
           else
          validOut = false;
          hStartOut = false;
          hEndOut = false;
          vStartOut = false;
          vEndOut = false;
          EnableReadCompute = true;
         EnableBetweenLinesREG = false;
                     ColumnCountEnable = false;
              ColumnCountReset = false;

    
  end 
%             ColumnCountOut = ColumnCounter;
            EnableBetweenLines = EnableBetweenLinesREG;
        
