gpt4 book ai didi

VHDL:Mealy FSM 不在时钟边沿产生状态变化?

转载 作者:行者123 更新时间:2023-12-05 01:22:24 28 4
gpt4 key购买 nike

我是 VHDL 的新手,正在关注 this tutorial实现以下 Mealy 有限状态机:

enter image description here

并用VHDL编写了以下代码:

library ieee;
use ieee.std_logic_1164.all;

entity fsm is
port(clk, rst, in1 : in std_logic; o1 : out std_logic);
end fsm;

architecture mealy of fsm is
type state is (state1, state2);
signal current_state, next_state : state;
begin

comb: process(current_state, in1) begin
next_state <= current_state; -- default case
case current_state is
when state1 =>
o1 <= '0';
if in1 = '1' then
o1 <= '1';
next_state <= state2;
end if;

when state2 =>
o1 <= '1';
if in1 = '0' then
o1 <= '0';
next_state <= state1;
end if;
end case;
end process;

mem: process(clk, rst) begin
if rst = '1' then
current_state <= state1;
else
current_state <= next_state;
end if;
end process;

end mealy;

但是在应用以下测试平台时:

library ieee;
use ieee.std_logic_1164.all;

entity fsm_tb is
end fsm_tb;

architecture sim of fsm_tb is
constant clockperiod : time := 10 ns; -- 100 Mhz clock
signal clk : std_logic := '0';
signal rst : std_logic;
signal in1, o_mealy : std_logic;
begin
uut_mealy : entity work.fsm(mealy) port map( clk => clk, rst => rst, in1 => in1, o1 => o_mealy);
clk <= not clk after clockperiod/2;
process begin
-- initial reset
in1 <= '0';
rst <= '1';
wait until rising_edge(clk);
-- take device out of reset
rst <= '0';
-- apply same inputs to both the devices
in1 <= '0'; wait for 23 ns;
in1 <= '1'; wait for 32 ns;
in1 <= '0'; wait for 7 ns;
in1 <= '1'; wait for 15 ns;
wait;
end process;
end sim;

我得到的波形对我来说没有意义:

enter image description here

如您所见,即使没有时钟边沿,输出 o_mealy 也会发生变化。它似乎只是在遵循输入。相比之下,我已经实现了等效的 Moore 机器,它似乎工作得很好:

enter image description here

如果有人能指出我做错了什么,将不胜感激。同样,我使用了 this video以供引用。我将 GHDL 与 GTKWave 结合使用。

最佳答案

看看你的并发逻辑:

        case current_state is
when state1 =>
o1 <= '0';
if in1 = '1' then
o1 <= '1';
next_state <= state2;
end if;

when state2 =>
o1 <= '1';
if in1 = '0' then
o1 <= '0';
next_state <= state1;
end if;
end case;

在这两种状态中的任何一种状态下,如果 in1 = '1',则输出为 1,如果 in1 = '0',则输出为 0。所以 FSM 工作正常,但从外面看你就是看不到两种状态的区别。

关于你做错了什么:我认为这是正确的,实际上,看着你的画。在粉状机器中,输出取决于当前状态和当前输入,这正是这里发生的情况。

关于VHDL:Mealy FSM 不在时钟边沿产生状态变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74209174/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com