-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathncounter.vhd.bak
More file actions
43 lines (36 loc) · 935 Bytes
/
ncounter.vhd.bak
File metadata and controls
43 lines (36 loc) · 935 Bytes
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
----------------------------------------
-- N-Bit Counter
----------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_unsigned.all;
----------------------------------------
entity counter is
generic(N : integer := 4);
port(
en: in STD_LOGIC;
clr : in STD_LOGIC;
clk : in STD_LOGIC;
q : out STD_LOGIC_VECTOR(N-1 downto 0)
);
end counter;
----------------------------------------
architecture counter of counter is
signal count: STD_LOGIC_VECTOR(N-1 downto 0);
begin
process(clk, clr)
begin
if clr = '1'then
count <= (others => '0');
end if;
if en = '1' then
if count (3 downto 0) ="1000" and rising_edge(clk)then
count <= (others => '0');
elsif rising_edge(clk) then
count <= count + 1;
end if;
end if;
end process;
q <= count;
end counter;
----------------------------------------