2016-04-13 42 views
-1

我有一個3位向上/向下計數器的vhdl代碼,但是當我模擬它不給出任何輸出結果時,出了什麼問題?VHDL 3位u/d計數器

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use ieee.std_logic_unsigned.all; 
use ieee.numeric_std.all; 
entity counter is 
    Port (rst,clk : in STD_LOGIC; 
    up: in bit; 
      z : out STD_LOGIC_vector(2 downto 0)); 
end counter; 
architecture Behavioral of Counter is 
signal zint: STD_LOGIC_vector(2 downto 0) ; 
begin 
z<= zint; 
process (clk) 
begin 
if (clk' event and clk='1') then 
if (rst ='1') then 
zint <= "000" ; 
end if; 
if (zint <= "111")then zint <= "000"; 
elsif (up='1') then zint <= zint+1; 
else zint <= zint-1; 
end if; 
end if; 
end process; 
end Behavioral; 
+0

歡迎堆棧溢出。通常最好給一個[MCVE](http://stackoverflow.com/help/mcve),讓其他人可以重現你的錯誤,但在這種情況下,我想我可以看到什麼是錯的。 –

+2

請縮進您的代碼。 – Paebbels

+0

請顯示您的測試臺。 _do沒有給出任何輸出結果_你是什麼意思? –

回答

0

您在復位時將zint設置爲「000」。然後,只要zint不等於「111」,則將其再次設置爲「000」。 zint與「000」有什麼不同?
如果完全放棄第一個條件,計數器將自動從「111」溢出到「000」,反之亦然。

0

我覺得這條線是你的問題:

if (zint <= "111")then zint <= "000"; 

沒有你的意思呢?

if (zint = "111")then zint <= "000"; 

事實上,你根本不需要上述行 - 計數器將自動包裝。 (而且,同樣是倒計時真,這種情況你有沒有代碼,反正。)

話雖如此,這裏有一些其他的建議,以提高你的代碼:

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
-- use ieee.std_logic_unsigned.all;  -- DON'T USE THIS... 
use ieee.numeric_std.all;     -- ...USE THIS INSTEAD 
entity counter is 
    Port (rst,clk : in STD_LOGIC; 
    up: in bit;        -- DID YOU REALLY WANT TYPE 'bit' HERE? 
    z : out STD_LOGIC_vector(2 downto 0)); 
end counter; 

architecture Behavioral of Counter is 
    signal zint: unsigned(2 downto 0) ; -- MAKE THIS TYPE 'unsigned'... 
begin 
    z<= std_logic_vector(zint);    -- ... AND USE A TYPE CONVERSION HERE 
    process (clk) 
    begin 
    if rising_edge(clk) then    -- '(clk' event and clk='1')' BECAME OLD-FASHIONED in 1993! 
     if rst ='1' then      -- YOU DON'T NEED THE BRACKETS 
     zint <= "000" ;     -- USE INDENTATION! 
     --end if; 
     --if zint = "111" then zint <= "000"; 
     elsif up='1' then 
     zint <= zint+1; 
     else 
     zint <= zint-1; 
     end if; 
    end if; 
    end process; 
end Behavioral;