Forum Discussion
Altera_Forum
Honored Contributor
11 years agoyou haven't constrained your counters.
I will do it as nested ifs starting from count0 towards count7:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity stop_watch is
Port (
clk : in STD_LOGIC;
start : in STD_LOGIC;
reset : in STD_LOGIC;
hex0 : out STD_LOGIC_VECTOR (3 downto 0);
hex1 : out STD_LOGIC_VECTOR (3 downto 0);
hex2 : out STD_LOGIC_VECTOR (3 downto 0);
hex3 : out STD_LOGIC_VECTOR (3 downto 0);
hex4 : out STD_LOGIC_VECTOR (3 downto 0);
hex5 : out STD_LOGIC_VECTOR (3 downto 0);
hex6 : out STD_LOGIC_VECTOR (3 downto 0);
hex7 : out STD_LOGIC_VECTOR (3 downto 0)
);
end stop_watch;
architecture Behavioral of stop_watch is
signal count0:std_logic_vector(3 downto 0):=(others=>'0');
signal count1:std_logic_vector(3 downto 0):=(others=>'0');
signal count2:std_logic_vector(3 downto 0):=(others=>'0');
signal count3:std_logic_vector(3 downto 0):=(others=>'0');
signal count4:std_logic_vector(3 downto 0):=(others=>'0');
signal count5:std_logic_vector(3 downto 0):=(others=>'0');
signal count6:std_logic_vector(3 downto 0):=(others=>'0');
signal count7:std_logic_vector(3 downto 0):=(others=>'0');
begin
process(clk,reset)
begin
if reset = '1' then
count0 <= (others=>'0');
count1 <= (others=>'0');
count2 <= (others=>'0');
count3 <= (others=>'0');
count4 <= (others=>'0');
count5 <= (others=>'0');
count6 <= (others=>'0');
count7 <= (others=>'0');
elsif rising_edge(clk) then
if start='1' then
if count0 /= x"9" then
count0 <= count0 + 1;
else
count0 <= x"0";
if count1 /= x"9" then
count1 <= count1 + 1;
else
count1 <= x"0";
if count2 /= x"9" then
count2 <= count2 + 1;
else
count2 <= x"0";
if count3 /= x"5" then
count3 <= count3 + 1;
else
count3 <= x"0";
if count4 /= x"9" then
count4 <= count4 + 1;
else
count4 <= x"0";
if count5 /= x"5" then
count5 <= count5 + 1;
else
count5 <= x"0";
if count6 /= x"9" then
count6 <= count6 + 1;
else
count6 <= x"0";
if count7 /= x"9" then
count7 <= count7 + 1;
else
count7 <= x"0";
end if;
end if;
end if;
end if;
end if;
end if;
end if;
end if;
end if;
end if;
end process;
hex0 <= count0;
hex1 <= count1;
hex2 <= count2;
hex3 <= count3;
hex4 <= count4;
hex5 <= count5;
hex6 <= count6;
hex7 <= count7;
end Behavioral;