为什么我没有得到输出以下除以3时钟vhdl代码?

问题描述:

在下面的代码中没有合成错误,但是当我模拟它时仍然没有得到输出。 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; 

你的柜台永远不会算,因为你做的事:

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