2011-05-13 63 views
0

在下面的代碼中沒有合成錯誤,但是當我模擬它時仍然沒有得到輸出。 cout始終保持邏輯1。請任何人幫我找出最新的錯誤?爲什麼我沒有得到輸出以下除以3時鐘vhdl代碼?

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_ARITH.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 

entity divide_by_3 is 
port (
    cout :out std_logic; -- Output clock 
    clk :in std_logic; -- Input clock 
    reset :in std_logic -- Input reset 
); 
end divide_by_3; 

architecture Behavioral of divide_by_3 is 
    signal pos_cnt :std_logic_vector (1 downto 0); 
    signal neg_cnt :std_logic_vector (1 downto 0); 
begin 

    process (clk, reset) 
    begin 
     if (reset = '1') then 
     pos_cnt <= (others=>'0'); 
     elsif (rising_edge(clk)) then 
     if (pos_cnt = "10") then 
      pos_cnt <= pos_cnt + '1'; 
     end if; 
     end if; 
    end process; 

    process (clk, reset) begin 
     if (reset = '1') then 
     neg_cnt <= (others=>'0'); 
     elsif (falling_edge(clk)) then 
     if (neg_cnt = "10") then 
      neg_cnt <= neg_cnt + '1'; 
     end if; 
     end if; 
    end process; 

    cout <= '1' when ((pos_cnt /= "10") and (neg_cnt /= "10")) else 
    '0'; 
end Behavioral; 

回答

5

你的櫃檯永遠不會算,因爲你做的事:

if (neg_cnt = "10") then 
     neg_cnt <= neg_cnt + '1'; 
    end if; 

if (pos_cnt = "10") then 
     pos_cnt <= pos_cnt + '1'; 
    end if; 

但兩者pos_cntneg_cnt重置爲"00"。我想你可能想要做類似的事情:

if (pos_cnt = "10") then 
     pos_cnt <= (others => '0'); 
    else 
     pos_cnt <= pos_cnt + '1'; 
    end if; 
+0

嘿感謝很多..它的工作:) – meghs 2011-05-13 13:05:53

相關問題