-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounter.vhd
More file actions
99 lines (81 loc) · 2.42 KB
/
Counter.vhd
File metadata and controls
99 lines (81 loc) · 2.42 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 03/06/2024 12:53:49 PM
-- 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;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity Counter is
Port ( Dir : in STD_LOGIC;
Res : in STD_LOGIC;
Clk : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR (2 downto 0));
end Counter;
architecture Behavioral of Counter is
component D_FF
port (
D : in STD_LOGIC;
Res: in STD_LOGIC;
Clk : in STD_LOGIC;
Q : out STD_LOGIC;
Qbar : out STD_LOGIC);
end component;
component Slow_Clk
port (
Clk_in : in STD_LOGIC;
Clk_out: out STD_LOGIC);
end component;
signal D0, D1, D2 : std_logic; -- Internal signals
signal Q0, Q1, Q2 : std_logic; -- Internal signals
signal Clk_slow : std_logic; -- Internal clock
begin
Slow_Clk0 : Slow_Clk
port map (
Clk_in => Clk,
Clk_out => Clk_slow);
D0 <= ((not Q2) and (not Dir)) or (Q1 and Dir);
D1 <= (Q0 and (not Dir)) or (Q2 and Dir);
D2 <= ((not Q0) and Dir) or (Q1 and (not Dir));
D_FF0 : D_FF
port map (
D => D0,
Res => Res,
Clk => Clk_slow,
Q => Q0);
D_FF1 : D_FF
port map (
D => D1,
Res => Res,
Clk => Clk_slow,
Q => Q1);
D_FF2 : D_FF
port map (
D => D2,
Res => Res,
Clk => Clk_slow,
Q => Q2);
Q(0) <= Q0;
Q(1) <= Q1;
Q(2) <= Q2;
end Behavioral;