シンプルなステートマシンの例 / ムーアタイプ

pp.311-334

仕様:
2クロック続けて入力wが1のとき出力zが1になる。それ以外はzは0。

ステートマシン:
初期状態はA。
w=1が1回検出されると状態Bへ遷移。次のクロックでw=0なら状態Aへ戻る。
状態Bにいるときにw=1が検出されると(すなわち2回連続してw=1が検出されると)、状態Cへ遷移して出力zが1になる。次のクロックでw=1なら状態Cに留まって出力z=1を保つが、w=0なら状態Aに戻って出力z=0になる。

入力wをセンシティビティリストに入れていない理由は、clock信号の変化するまでwの値がstateに影響しないため。

library ieee;
use ieee.std_logic_1164.all;

entity sute_vhdl is
    port (
        clock : in std_logic;
        aclr_n: in std_logic;
        w     : in std_logic;
        
        z     : out std_logic
    );
end entity;

architecture behavior of sute_vhdl is
    type state_t is (A, B, C);
    signal state: state_t;
begin
    process (aclr_n, clock)
    begin
        if aclr_n = '0' then
            state <= A;
        elsif rising_edge(clock) then
            case state is
                when A =>
                    if w = '0' then state <= A;
                    else            state <= B;
                    end if;
                when B =>
                    if w = '0' then state <= A;
                    else            state <= C;
                    end if;
                when C =>
                    if w = '0' then state <= A;
                    else            state <= C;
                    end if;
            end case;
        end if;
    end process;
    z <= '1' when state = C else '0';
end architecture;