-
Notifications
You must be signed in to change notification settings - Fork 1
/
Counter.vhd
executable file
·57 lines (51 loc) · 1.29 KB
/
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
48
49
50
51
52
53
54
55
56
57
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 16:27:59 11/24/2016
-- Design Name:
-- Module Name: Counter - 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_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Counter is
Port ( rst : in STD_LOGIC;
clk : in STD_LOGIC;
carry_in : in STD_LOGIC;
carry_out : out STD_LOGIC;
count_out : out STD_LOGIC_VECTOR(3 DOWNTO 0));
end Counter;
architecture Behavioral of Counter is
SIGNAL count : STD_LOGIC_VECTOR(3 DOWNTO 0) := "0000";
begin
process(rst, clk)
begin
IF rst = '1' then
count <= "0000";
elsif clk'event and clk = '1' then
if carry_in = '1' then
if count < "1001" then
count <= count + 1;
else
count <= "0000";
end if;
else null;
end if;
end if;
end process;
count_out <= count;
carry_out <= '1' when carry_in = '1' and count = "1001" else '0';
end Behavioral;