-
Notifications
You must be signed in to change notification settings - Fork 0
/
counter.vhd
47 lines (35 loc) · 970 Bytes
/
counter.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity counter is
generic (
N : integer
);
port (
enable : in std_logic;
reset : in std_logic;
clk : in std_logic;
out_count : out std_logic_vector(N - 1 downto 0)
);
end entity counter;
architecture counter_behavior of counter is
constant overflow : std_logic_vector(N - 1 downto 0) := (others => '1');
begin
count : process (clk, reset) is
variable count : std_logic_vector(N - 1 downto 0) := (others => '0');
begin
if (reset = '0') then
count := (others => '0');
elsif (clk'event and clk = '1') then
if (enable = '1') then
if (count = overflow) then
count := (others => '0');
else
count := count + '1';
end if;
end if;
end if;
out_count <= count;
end process count;
end architecture counter_behavior;