-
Notifications
You must be signed in to change notification settings - Fork 2
/
BCD.vhd
47 lines (43 loc) · 1.42 KB
/
BCD.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
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.numeric_std.all;
entity BCD is
port(Clk, Direction, Init, Enable: in std_logic;
Q_Out: out std_logic_vector(3 downto 0));
end entity BCD;
architecture behaviour of BCD is
signal counter: std_logic_vector(3 downto 0);--integer := 0;
begin
--Originally hae counter set as integer.
process(Clk)
--variable counter: integer := 0;
begin
if (clk'event and clk = '1') then
if Init = '1' then --Original was using cases. All cases was changed to If statements
if (Direction = '1') then
counter <= "0000";--0;
else
counter <= "1001";--9;
end if;
elsif (Enable = '1') then
if (Direction = '1') then
--counter <= (counter + 1) mod 10;
if (counter = "1001") then
counter <= "0000";
else
counter <= counter + 1;
end if;
else
if counter = "0000" then
counter <= "1001";
else
counter <= counter - 1;
end if;
end if;
end if;
--Q_out <= std_logic_vector(to_unsigned(counter, Q_out'length));
end if;
end process;
Q_out <= counter; --std_logic_vector(to_unsigned(counter, Q_out'length));
end architecture;