FSM Mealy机器序列检测器。如何使用多个人字拖?

时间:2017-10-25 05:03:40

标签: vhdl fsm flip-flop

目前我正在开发一个名为Valyado的小型项目,一个Mealy FSM。程序必须检测6位序列001011,并输出" 1"当检测到序列时。

关于序列检测的代码做得很好,但除此之外,它还必须使用三个触发器:JK,D和T.

有关如何添加它们的任何建议或建议?

感谢您的时间。

这是FSM代码:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;


entity sequence is
port(
    clk : in std_logic;
    reset : in std_logic;
    x: in std_logic;
    z : out std_logic;
    a : out std_logic;
    b : out std_logic;
    c : out std_logic;
    d : out std_logic;
    e : out std_logic;
    f : out std_logic);
end sequence;

architecture behavioral of sequence is


type state_type is (Q0, Q1, Q2, Q3, Q4, Q5);


signal state, next_state : state_type;

begin


state_register: process (clk, reset)
  begin
    if (reset = '1') then   --if reset is high, goto state Q0
       state <= Q0;
    elsif (clk'event and clk = '1') then    --if not, and rising 
       state <= next_state;                 --edge, go to next state
    end if;
end process;  


next_state_func: process (x, state)
begin 
  case state is 
      when Q0 =>
          if x = '0' then
             next_state <= Q1;
          else 
             next_state <= Q0;
          end if;
      when Q1 =>
           if x = '0' then
             next_state <= Q2;
           else
             next_state <= Q0;
           end if;
      when Q2 =>
           if x = '1' then
              next_state <= Q3;
           else 
              next_state <= Q2;
           end if;
      when Q3 =>
           if x ='0' then
              next_state <= Q4;
           else
              next_state <= Q0;
           end if;
      when Q4 =>
           if x = '1' then
              next_state <= Q5;
           else
              next_state <= Q2;
           end if;
      when Q5 =>
           if x = '1' then
              next_state <= Q0;
           else
              next_state <= Q1;                       
           end if;
      end case;
end process;

-- This process controls the output of the sequence detector.
-- Each state has it's own output along with 'z' which indicates
-- the entire sequence 001011 has been detected.
output_func:  process (x, state)
  begin
  case state is 
      when Q0 => z <= '0';
           a <= '1';
           b <= '0';
           c <= '0';
           d <= '0';
           e <= '0';
           f <= '0';
      when Q1 => z <= '0';
           a <= '0';
           b <= '1';
           c <= '0';
           d <= '0';
           e <= '0';
           f <= '0';
      when Q2 => z <= '0';
           a <= '0';
           b <= '0';
           c <= '1';
           d <= '0';
           e <= '0';
           f <= '0';
      when Q3 => z <= '0';
           a <= '0';
           b <= '0';
           c <= '0';
           d <= '1';
           e <= '0';
           f <= '0';
      when Q4 => z <= '0';
           a <= '0';
           b <= '0';
           c <= '0';
           d <= '0';
           e <= '1';
           f <= '0';
      when Q5 => z <= '1';
           a <= '0';
           b <= '0';
           c <= '0';
           d <= '0';
           e <= '0';
           f <= '1';
    end case;
  end process;

end behavioral;

[1]:https://i.stack.imgur.com/pVwxL.jpg - 这是包含FSM状态图表的表。

1 个答案:

答案 0 :(得分:0)

你的代码错了。看看output_func过程;这是组合,只是解码当前状态,没有查看xaf输出是不必要的,只是对当前状态的6位解码 - 为什么?当前状态为z时设置Q5输出,这不是您想要的 - 整个过程是多余的。您需要在主FSM中设置z,当前状态为Q5 x为1 - 即。在next_state <= Q0转换。

关于你的实际问题 - 你不能用这个代码强制选择任何特定的F / F类型 - 合成器会做任何你想做的事情,这意味着它将在D类型中实现整个事物,因为JKs在过去的20年里已经过时了。 T类型可能也是如此。您需要重新开始,并假装您拥有T,D和JK的技术和库。将这些作为单独的实体编写,并重新编写代码以实例化这些组件,而不是让合成器推断它们。重新编写FSM以使用JK - 您给出的图表将向您展示如何使用JK。换句话说,导出每个F / F的J和K输入。 z输出可以是D类型。你应该能够在某个地方适应T - 我已经把它作为锻炼给你了。