----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date: 02.03.2026 13:52:15
-- Design Name: 
-- Module Name: divider - Behavioral
-- Project Name: 
-- Target Devices: 
-- Tool Versions: 
-- Description: 
-- 
-- Dependencies: 
-- 
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
-- 
----------------------------------------------------------------------------------


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;


entity counter is
    Port ( CLK : in STD_LOGIC;
           RST : in STD_LOGIC;
           CE : in std_logic;
           COUNT_OUT : out STD_LOGIC_VECTOR (3 downto 0));
end counter;

architecture Behavioral of counter is

signal div_cnt : STD_LOGIC_VECTOR (3 downto 0);

begin

DIV: process (CLK, CE, RST, div_cnt)
begin
    if (RST = '1') then
        div_cnt <= (others => '0');
    elsif ((CLK = '1') and (CLK'event)) then
        if (CE = '1') then
            if (div_cnt < "1111") then
                div_cnt <= div_cnt +1;
            else
                div_cnt <= (others => '0');
            end if;
        end if;
    end if;
end process;

COUNT_OUT <= div_cnt;
   
end Behavioral;
