【问题标题】:FSM in VHDL is Moore or Mealy?VHDL 中的 FSM 是 Moore 还是 Mealy?
【发布时间】:2018-12-12 17:42:36
【问题描述】:

我正在用 VHDL 编写 FSM。具体来说,它是一个同步序列检测器,它在输入中输入一个 8 位数字和一个“第一个”,该“第一个”必须仅在序列的第一个数字期间为“1”。输出由解锁和警告组成:如果序列 (36, ...) 正确,则解锁 = '1',或者如果序列错误,则警告 = '1' 或 first = '1' 不在第一个数字期间顺序。

在 VHDL 中,我使用两个进程,一个同步的,一个不同步。第二个的简化版是:

state_register_p : process(clk)
    begin 
        if (clk'EVENT and clk = '1') then
            if(rst = '0') then
                current_state <= S0;

                errors_num <= "00";
                five_cycles <= "000";
                first_error <= '1';
            else
                current_state <= next_state;

                if correct = '0' then
                    errors_num <= errors_num + "01";
                else
                    errors_num <= "00";
                end if;

            end if;

        end if;

end process state_register_p;

combinatorial_logic_p : process(current_state, num_in, first)

    begin       
        unlock <= '0';
        warning <= '0';

        case (current_state) is             
            when S0 =>
                if (to_integer(unsigned(num_in)) = 36) and (first = '1') then
                    next_state <= S1;
                else
                    next_state <= S0;
           when S1 =>
                correct <= '0';
                if (to_integer(unsigned(num_in)) = 19) and (first = '0') and errors_num /= "11" then
                    next_state <= S2;
                elsif first = '1' or errors_num = "11" then
                    next_state <= S6;
                else
                    next_state <= S0;
                end if;

            when S2 =>
                correct <= '0';
                if (to_integer(unsigned(num_in)) = 56)  and (first = '0') then
                    next_state <= S3;
                elsif first = '1' then
                    next_state <= S6;
                else
                    next_state <= S0;
                end if;

            when S3 =>
                correct <= '0';
                if (to_integer(unsigned(num_in)) = 101) and (first = '0') then
                    next_state <= S4;
                elsif first = '1' then
                    next_state <= S6;
                else
                    next_state <= S0;
                end if;

            when S4 =>
                correct <= '0';
                if (to_integer(unsigned(num_in)) = 73) and (first = '0') and (to_integer(unsigned(five_cycles)) = 5) then
                    next_state <= S5;
                    correct <= '1';
                elsif first = '1' then
                    next_state <= S6;
                else
                    next_state <= S0;
                end if;

            when S5 =>
                correct <= '1';
                if to_integer(unsigned(num_in)) = 36 and (first = '1') then
                    next_state <= S1;
                else
                    next_state <= S0;
                end if;

                unlock <= '1';

            when S6 =>
                correct <= '0';
                next_state <= S6; -- default, hold in current state
                warning <= '1';

        end case;               
end process combinatorial_logic_p;

通过在线阅读,我知道在摩尔机器中,下一个状态仅取决于当前状态,因此输出仅在时钟沿发生变化,而在 Mealy 中,它也取决于输入,因此当输入发生变化时其输出可能会发生变化(即,不一定在时钟沿)。 .

在我的敏感度列表中,我使用 current_state 和 2 个输入(num_in 和 first),所以可以说我在描述 Mealy 机器还是它仍然是 Moore 机器,因为我正在等待下一个上升沿来更新输出?

我仍然认为是摩尔,但我不确定。谢谢

【问题讨论】:

  • 这是一个 Mealy 状态机,如果输出 unlockwarning 取决于任何输入 num_infirst,并且输出的摩尔状态机仅取决于 @ 987654327@。这个figure 有一个很好的介绍。但是,您的代码没有显示输出是如何驱动的,假设它们不是微不足道的 0,所以请更新代码...但是您现在可能可以自己确定答案 ;-)
  • 谢谢@MortenZilmer。我的怀疑与许多书说在 Mealy 机器中输出可能不会在上升沿发生变化有关,但我的情况并非如此,因为输出更新是由此处未显示的过程完成的,即同步的。但是在你的图中说输出是异步的......编辑:添加了其余的代码

标签: vhdl automata


【解决方案1】:

这是一个摩尔状态机,因为unlockwarning 的输出仅依赖于combinatorial_logic_p 进程中的current_state

请注意,errors_numfive_cycles 信号在 combinatorial_logic_p 进程中使用,但在敏感度列表中被遗忘。所以添加它们,或者如果使用 VHDL-2008,则更改为 (all)

【讨论】:

  • 你说得对,我把旧版本的代码放了,实际上 Vivado 出现了一个错误,因为它们在敏感度列表中的缺失。所以它是摩尔,这是有道理的,因为输出仅在时钟的上升沿发生变化,即使我的输入是通过同步测试台给出的。所以主要思想是组合过程设置状态,但它仍然是摩尔,因为它只有在同步过程将其分配给current_state时才生效。谢谢,你解决了我的疑惑。
  • 如果该属性对设计至关重要,您可以考虑在单独的流程或连续分配中驱动输出,以明确它们不依赖于输入。
  • 如果这是最好的解决方案,请记住接受答案,如此处所述What should I do when someone answers my question?
  • 我做了一个包含三个进程的解决方案,我正在比较它们,看看哪个更好,更容易调试。
猜你喜欢
  • 2019-04-23
  • 1970-01-01
  • 1970-01-01
  • 2013-01-19
  • 2014-01-16
  • 2011-08-25
  • 2013-11-30
  • 2018-11-01
  • 1970-01-01
相关资源
最近更新 更多