-
Notifications
You must be signed in to change notification settings - Fork 0
/
cntr_4bit.vhd
101 lines (75 loc) · 2.05 KB
/
cntr_4bit.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
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
100
101
library ieee;
use ieee.std_logic_1164.all;
-- updated to 4 bit but didn't change name
entity cntr_4bit is
port (
cnt_dec : in std_logic;
reset_bar : in std_logic;
cnt_set : in std_logic;
cnt_val : out std_logic_vector(3 downto 0);
zero : out std_logic
);
end entity;
architecture rtl of cntr_4bit is
signal i_q : std_logic_vector(3 downto 0);
signal i_q_bar : std_logic_vector(3 downto 0);
signal i_cnt_set_bar : std_logic;
signal i_zero : std_logic;
signal i_reset : std_logic;
signal i_zero_d : std_logic;
--signal i_cnt_set_bar_d : std_logic;
component dflipflop
port(i_d, i_clk, i_set, i_rst: in STD_LOGIC;
o_q, o_qbar : inout STD_LOGIC);
end component;
begin
q0 : dflipflop port map (
i_d => i_q_bar(0),
i_clk => cnt_dec,
i_set => i_cnt_set_bar,
i_rst => '1',
o_q => i_q(0),
o_qbar => i_q_bar(0)
);
q1 : dflipflop port map (
i_d => i_q_bar(1),
i_clk => i_q(0),
i_set => i_cnt_set_bar,
i_rst => '1',
o_q => i_q(1),
o_qbar => i_q_bar(1)
);
q2 : dflipflop port map (
i_d => i_q_bar(2),
i_clk => i_q(1),
i_set => i_cnt_set_bar,
i_rst => '1',
o_q => i_q(2),
o_qbar => i_q_bar(2)
);
q3 : dflipflop port map (
i_d => i_q_bar(3),
i_clk => i_q(2),
i_set => '1',
i_rst => i_cnt_set_bar,
o_q => i_q(3),
o_qbar => i_q_bar(3)
);
z : dflipflop port map (
i_d => i_zero,
i_clk => i_q(3),
i_set => '1',
i_rst => i_cnt_set_bar,
o_q => i_zero_d,
o_qbar => open
);
i_reset <= cnt_set or i_zero_d;
--i_reset <= cnt_set or i_zero;
--i_cnt_set_bar <= not i_zero and (reset_bar and not cnt_set);
i_cnt_set_bar <= (reset_bar and not i_reset);
--i_zero <= (not i_q_bar(3) and not i_q_bar(2)) and (not i_q_bar(1) and not i_q_bar(0));
i_zero <= (not i_q(3) and not i_q(2)) and (not i_q(1) and not i_q(0));
--i_zero <= (i_q(3) and not i_q(2)) and (not i_q(1) and not i_q(0));
zero <= i_zero;
cnt_val <= i_q;
end architecture;