ステートマシン / ミーリー型 / "abc"の順に文字が入力されたらフラグを立てる

pp.407-409
今度は、ステートマシン / ムーア型 / "abc"の順に文字が入力されたらフラグを立てる -のミーリー型を試す。

ミーリー型のFSM(有限ステートマシン)とは、その入力が出力を直接左右する可能性のあるFSMのことである。言い換えると、出力はマシンのステートのみに依存するのではなく入力にも依存するということである。出力はクロックと無関係に変化する可能性があるため、生成される回路はもはや完全な同期回路とはいえない。(p.68)

library ieee;
use ieee.std_logic_1164.all;

entity string_detector is
    port(
        clk, rst: in  std_logic;
        x       : in  character;
        y       : out std_logic
    );
end entity;

architecture rtl of string_detector is
    type state_type is (idle, char1, char2, char3);
    signal state: state_type;
begin
    
    process(clk, rst)
    begin
        if rst then
            state <= idle;
        elsif rising_edge(clk) then
            case state is
                when idle =>
                    if    x='a'  then state <= char1; y <= '0';
                    else              state <= idle;  y <= '0';
                    end if;
                when char1 =>
                    if    x ='b' then state <= char2; y <= '0';
                    elsif x/='a' then state <= idle ; y <= '0';
                    else              state <= char1; y <= '0';
                    end if;
                when char2 =>
                    if    x='c'  then state <= char3; y <= '1';
                    elsif x='a'  then state <= char1; y <= '0';
                    else              state <= idle ; y <= '0';
                    end if;
                when char3 =>
                    if     x='a' then state <= char1; y <= '0';
                    else              state <= idle ; y <= '0';
                    end if;
                end case;
            end if;
        end process;

end architecture;

f:id:ti-nspire:20210510085003j:plain