シンプルなステートマシンの例 / ミーリータイプ

pp.341-343

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

シンプルなステートマシンの例 / ムーアタイプ / 別の記述法 -の続き。今度はミーリータイプに書き換える。これだとステートが2つで済む。

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);
    signal state: state_t;
begin

    process (clock, aclr_n)
    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 <= B;
                    end if;    
            end case;
        end if;
    end process;
    
    process (state, w)
    begin
        case state is
            when A => z <= '0';
            when B => z <=  w;
        end case;
    end process;
    
end architecture;