----------------------------------------------------------------------------------
-- Company:   University of Connecticut
-- Engineer:  Igor Senderovich
-- 
-- Create Date:    09:40:38 11/12/2007 
-- Design Name: 
-- Module Name:    Counter12bit - Behavioral 
-- Description:    12-bit counter that measures out 2^12 cycles and reports "Done"
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Counter12bit is
    Port ( Clk : in  STD_LOGIC;
			  Rst : in STD_LOGIC;
           Go  : in  STD_LOGIC;
           Done : out  STD_LOGIC);
end Counter12bit;

architecture Behavioral of Counter12bit is

	signal count : STD_LOGIC_VECTOR (11 downto 0);
	
begin
		
	Counter12bit : process (Clk, Go,Rst)
	begin
		if (Rst='1') then
			count <= "000000000000";
		else
			if rising_edge(Clk) then
				if (count="000000000000") then
					count <= count + ("00000000000" & Go);
				else
					count <= count +  "000000000001";
				end if;
			else
				count <= count;
			end if;
		end if;
	end process;
	
	Done <= '1' when (count="111111111111") else '0';
end Behavioral;

