-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore_counter.vhd
More file actions
80 lines (75 loc) · 2.4 KB
/
Copy pathscore_counter.vhd
File metadata and controls
80 lines (75 loc) · 2.4 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
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity score_counter is
port (
reset : in std_ulogic;
score_increase : in std_ulogic;
score_reset : in std_ulogic;
score_highscore : out std_ulogic;
-- 6 seven segment codes
score_display : out std_ulogic_vector(41 downto 0)
);
end entity;
architecture implementation of score_counter is
component ss_decoder is
generic (
digits : natural := 6
);
port (
bcd : in std_ulogic_vector((digits * 4) - 1 downto 0);
blank : in std_ulogic_vector((digits) - 1 downto 0);
ss_codes : out std_ulogic_vector((digits * 7) - 1 downto 0)
);
end component;
signal score : unsigned(15 downto 0) := (others => '0');
signal highscore : unsigned(15 downto 0) := (others => '0');
signal score_bcd : std_ulogic_vector(23 downto 0) := (others => '0');
signal score_blank : std_ulogic_vector(5 downto 0) := (others => '1');
begin
--score_display <= score_bcd;
decoder: ss_decoder
port map (
bcd => score_bcd,
blank => score_blank,
ss_codes => score_display
);
process (score_reset, reset, score_increase)
begin
if reset = '1' then
score_blank <= "111111";
highscore <= (others => '0');
score <= (others => '0');
score_bcd <= (others => '0');
-- score_display <= (others => '0');
score_highscore <= '0';
elsif score_reset = '1' then
score_blank <= "111111";
score <= (others => '0');
score_bcd <= (others => '0');
-- score_display <= (others => '0');
score_highscore <= '0';
elsif rising_edge(score_increase) then
if score >= highscore then
highscore <= highscore + 1;
score_highscore <= '1';
end if;
score <= score + 1;
-- Instead of converting binary score to BCD score, do BCD counting directly
-- This loop iterates over 6 nibbles
for i in 0 to 5 loop
-- If nibble reaches 1001 (decimal 9), set bits to zero
-- Loop will apply the carry onto the next nibble
if score_bcd(i * 4 + 3 downto i * 4) = "1001" then
score_bcd(i * 4 + 3 downto i * 4) <= (others => '0');
else
-- Nibble is bellow 9 so no overflow occurs, add 1
score_bcd(i * 4 + 3 downto i * 4) <= std_ulogic_vector(unsigned(score_bcd(i * 4 + 3 downto i * 4)) + 1);
-- This nibble is now active on the display
score_blank(i) <= '0';
exit;
end if;
end loop;
end if;
end process;
end architecture;