0

我目前正在编写我的第一个 FSM,但不确定我的逻辑是否正确。我的任务是为以下逻辑创建状态图:

A = 00
B = 01
C = 10
D = 11

输出为 1 时:

BDA
BAA
BAD

因此,我创建了以下 vhdl 代码来完成此操作:

所以每次我让它输出 1 时,我将它发送回 B 并计数 + 1。这应该在 LED 上显示为在 18 位序列中找到的次数。

我是否以正确的方式处理这个问题?我对如何通过 18 位序列移动它感到困惑。我应该将板上的开关作为我的 18 位,表示为 SW。我会用 替换 data_inSW(17 downto 0)吗?

4

1 回答 1

0

这是评论而不是答案,因为我还没有资格发表评论,所以我将其作为答案。

我认为您在 FSM 概念中存在一些问题。同样如评论中所说, data_in 是 std_logic 而不是向量。您一次输入一位串行输入,因此请相应地编写流程。您可以编写代码来检测序列 BDA、BAA、BAD,即序列“011100”、“010000”和“010011”。我会写一个简单的 FSM 代码,这样你就可以清除你的概念,然后你可以尝试。

library ieee;
use IEEE.std_logic_1164.all;

entity mealy is
port (clk : in std_logic;
      reset : in std_logic;
      input : in std_logic;
      output : out std_logic
  );
end mealy;

architecture behavioral of mealy is

type state_type is (s0,s1,s2,s3);  --type of state machine.
signal current_s,next_s: state_type;  --current and next state declaration.

begin

process (clk,reset)
begin
 if (reset='1') then
  current_s <= s0;  --default state on reset.
elsif (rising_edge(clk)) then
  current_s <= next_s;   --state change.
end if;
end process;

--state machine process.
process (current_s,input)
begin
  case current_s is
     when s0 =>        --when current state is "s0"
     if(input ='0') then
      output <= '0';
      next_s <= s1;
    else
      output <= '1';
      next_s <= s2;
     end if;   

     when s1 =>;        --when current state is "s1"
    if(input ='0') then
      output <= '0';
      next_s <= s3;
    else
      output <= '0';
      next_s <= s1;
    end if;

    when s2 =>       --when current state is "s2"
    if(input ='0') then
      output <= '1';
      next_s <= s2;
    else
      output <= '0';
      next_s <= s3;
    end if;


  when s3 =>         --when current state is "s3"
    if(input ='0') then
      output <= '1';
      next_s <= s3;
    else
      output <= '1';
      next_s <= s0;
    end if;
  end case;
end process;

end behavioral;
于 2014-03-19T04:29:34.577 回答