以下代码中没有合成错误,但在模拟时仍未获得输出。 cout
始终保持逻辑1。请有人帮我解决什么错误吗?
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;
答案 0 :(得分: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_cnt
和neg_cnt
都重置为"00"
。我想你可能想做类似的事情:
if (pos_cnt = "10") then
pos_cnt <= (others => '0');
else
pos_cnt <= pos_cnt + '1';
end if;