library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity scrolling_timer is
    port(
        clk : in std_logic;
        rst : in std_logic;
        cnt_start : in std_logic;
        cnt_done : out std_logic;
        cnt_value : in std_logic_vector(31 downto 0)
    );
end entity scrolling_timer;

architecture Behavioral of scrolling_timer is

	signal counter : std_logic_vector(31 downto 0);
    signal done : std_logic;
    signal counting : std_logic;
    signal value : std_logic_vector(31 downto 0);

begin

	process(clk)
	begin
		if clk'event and clk='1' then
			if rst = '1' then
				counter <= x"00000000";
				done <= '0';
				counting <= '0';
			else
			    value <= cnt_value;
                done <= '0';

				if counter = value and counting = '1' then
                    counter <= x"00000000";
                    done <= '1';
                    counting <= '0';
                elsif counting = '1' then
                    counter <= std_logic_vector(unsigned(counter) + 1);
                elsif counting = '0' and cnt_start = '1' then
                    counting <= '1';
                end if;
			end if;
		end if;
	end process;

    cnt_done <= done;

end Behavioral;
