- Code: Select all
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity COUNTER is
port(
clk : in std_logic;
button : in std_logic;
display3: out std_logic_vector(6 downto 0);
display2: out std_logic_vector(6 downto 0);
display1: out std_logic_vector(6 downto 0));
end COUNTER;
architecture U_D_COUNTER of COUNTER is
component clockdivider is
port(
CLKin : in std_logic;
CLKout : out std_logic);
end component;
signal clk: std_logic;
signal teller: std_logic_vector(3 downto 0);
begin
CLK DIVIDER: clockdivider
port map (CLKin => clk, CLKout => clk);
process(clk)
begin
if clk'event and (clk = '1') then
if (button = '1' ) then
teller <= teller + "0001";
else
teller <= teller - "0001";
end if;
end if;
end process;
process(teller)
begin
case teller is
when "0000" => display3 <= "1000000"; -- 0 when "0001" => display3 <= "1111001"; -- 1
when "0010" => display3 <= "0100100"; -- 2
when "0011" => display3 <= "0110000"; -- 3
when "0100" => display3 <= "0011001"; -- 4
when "0101" => display3 <= "0010010"; -- 5
when "0110" => display3 <= "0000010"; -- 6
when "0111" => display3 <= "1111000"; -- 7
when "1000" => display3 <= "0000000"; -- 8
when "1001" => display3 <= "0010000"; -- 9
end case;
case teller is
when "0000" => display2 <= "1000000"; -- 0 when "0001" => display2 <= "1111001"; -- 1
when "0010" => display2 <= "0100100"; -- 2
when "0011" => display2 <= "0110000"; -- 3
when "0100" => display2 <= "0011001"; -- 4
when "0101" => display2 <= "0010010"; -- 5
when "0110" => display2 <= "0000010"; -- 6
when "0111" => display2 <= "1111000"; -- 7
when "1000" => display2 <= "0000000"; -- 8
when "1001" => display2 <= "0010000"; -- 9
end case;
case teller is
when "0000" => display1 <= "1000000"; -- 0 when "0001" => display1 <= "1111001"; -- 1
when "0010" => display1 <= "0100100"; -- 2
when "0011" => display1 <= "0110000"; -- 3
when "0100" => display1 <= "0011001"; -- 4
when "0101" => display1 <= "0010010"; -- 5
when "0110" => display1 <= "0000010"; -- 6
when "0111" => display1 <= "1111000"; -- 7
when "1000" => display1 <= "0000000"; -- 8
when "1001" => display1 <= "0010000"; -- 9
end case;
end process;
end U_D_COUNTER;
Can I do it like this? Divide the 12 bits in three and have 4 bits in each of them? And is my counter (called "teller" in the code) ok?
Or should I in line 24 define: "signal teller: std_logic_vector(11 downto 0);" and then make 999 cases for the display?
Any tips is greatly appreaciated since I really want to get this right!