有限状态机(Finite-state machine, FSM)
Moore Machine
输出仅是当前状态的函数
Mealy Machine
输出是当前状态和输入的函数
有限状态机 ->状态转换
A->输入 Y->输出
我们设计一个如下图所示的有限状态机
reset=1 复位 状态=s0
状态为s0 时 输入为1 时 状态转换为s1
状态为s1 时 输入为0 时 状态转换为s2
状态为s2 时 输入为1 时 状态转换为s3
状态为s3 时 输入为0 时 状态转换为s0
other 情况不变
library ieee;
use ieee.std_logic_1164.all;
entity ztj is
port(
clk,inp,reset:in std_logic;
outp :out std_logic_vector(3 downto 0)
);
end entity;
architecture behave of ztj is
type zt is (s0,s1,s2,s3);
signal nowzt: zt;
begin
main_process: process(clk,reset)
begin
if reset ='1' then nowzt<=s0;
elsif clk'event and clk='1' then
if nowzt = s0 then
if inp = '1' then
nowzt <= s1;
end if;
elsif nowzt = s1 then
if inp = '0' then
nowzt <= s2;
end if;
elsif nowzt = s2 then
if inp = '1' then
nowzt <= s3;
end if;
elsif nowzt = s3 then
if inp = '0' then
nowzt <= s0;
end if;
end if;
end if;
end process;
out_process:process(nowzt)
begin
case nowzt is
when s0 => outp <= "0000";
when s1 => outp <= "1001";
when s2 => outp <= "1100";
when s3 => outp <= "1111";
end case;
end process;
end architecture;
vwf仿真波形图如下