【问题标题】:FSM in vhdl using counter as outputvhdl 中的 FSM 使用计数器作为输出
【发布时间】:2014-03-09 20:33:04
【问题描述】:

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

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

输出为 1 时:

BDA
BAA
BAD

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

因此,每次我将其输出 1 时,我都会将其发送回 B 并计数 + 1。这应该在 LED 上显示为在 18 位序列中找到的次数。

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

【问题讨论】:

  • State diagram 对某些人来说似乎有不同的含义,或者您只是没有向我们展示您的含义?没有字符文字“00”、“11”或“10”。请注意,数据是单个元素 std_logic。根据您的上下文子句和附加使用子句,没有可用的“+”运算符。您要求对非功能源代码中没有证据的执行环境(例如测试台)进行批评。您的 VHDL 设计描述没有传达足够的信息来满足您的要求。
  • @David Koontz 好的,有没有办法将 18 位转换为 9 - 2 位条目,我可以对其进行测试以使其正确?也许使用移位寄存器?另外,我该怎么做才能让它成为一个计数?

标签: logic vhdl fsm digital-logic


【解决方案1】:

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

我认为您在 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;

【讨论】:

    猜你喜欢
    • 2015-07-29
    • 1970-01-01
    • 2013-10-17
    • 2013-11-30
    • 2013-04-21
    • 2014-01-16
    • 2011-08-25
    • 2018-11-01
    • 1970-01-01
    相关资源
    最近更新 更多