function  [hCount,vCount,ctrlOut] = pixelCount(ctrlIn)
%pixelCount 
% Returns the current active pixel count per line, hCount, and the active
% line count, vCount, based on the pixel-stream control signals.
% ctrlIn and ctrlOut are structures that contain control signals associated
% with the pixel.
% The object implements counters that accommodate the next power-of-two above
% each property value. This configuration can count frames up to (512 
% pixels)-by-(256 lines).
% You can generate HDL code from this function.

  persistent hvcount;
  if isempty(hvcount)
    hvcount = visionhdl.HVCounter(...
      'ActivePixelsPerLine',320,...
      'ActiveVideoLines',240);    
  end
  
 [hCount,vCount,ctrlOut] = hvcount(ctrlIn);
end