我的VHDL代码有问题,希望有人能提供帮助。看,'q'信号应该检测状态是否已经改变,但它永远不会。好像状态永远不会从'检测'变为'空闲'。即使状态改变,q信号仍然保持在'0'值,而复位关闭且clk信号在上边缘。我希望你能看到问题所在。 附: state_reg信号用于此刻的状态,下一个用于下一个状态。 qlevel_detected是我用于调试的信号。
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity detector is
port
(
clk, reset : in std_logic;
level : in std_logic;
q : out std_logic;
qlevel_detected : out std_logic
);
end detector;
architecture behavioral of detector is
type state is (idle, detecting);
signal state_reg, state_next : state;
signal level_detected_reg, level_detected_next : std_logic;
begin
process(clk, reset)
begin
if (reset = '1') then
state_reg <= idle;
elsif (clk'event and clk = '1') then
state_reg <= state_next;
level_detected_reg <= level_detected_next;
end if;
end process;
process(state_reg)
begin
state_next <= state_reg;
level_detected_next <= level_detected_reg;
case state_reg is
when idle =>
level_detected_next <= level;
state_next <= detecting;
when detecting =>
if (level /= level_detected_reg) then
state_next <= idle;
end if;
end case;
end process;
-- Output logic
q <= '0' when state_reg = idle else
'1' when state_reg = detecting;
qlevel_detected <= level_detected_reg;
end behavioral;
答案 0 :(得分:2)
您的下一个状态流程仅对state_reg
敏感。作为一个组合过程,它需要灵敏度列表中列出的所有输入(或all
和VHDL-2008)。
process(state_reg, level, level_detected_reg)
begin
...
你也错过了对q的赋值的无条件else,这将在综合中创建一个锁存器。