简单有限状态机的VHDL

2019-06-18  本文已影响0人  莞工米兔

按状态机输出来分,可分为moore型和mealy型,moore型输入仅与当前的状态有关,mealy型输出不仅与当前的状态有关还与输入信号有关。换言之,有限状态机的输出(input)必定与现状(cs)有关,图中明显一个状态对应两种输出,明显输出与输入信号有关,所以是mealy型。

VHDL部分

library IEEE;

use ieee.std_logic_1164.all;

entity FSM is

port( clk,rst,input : in std_logic;

        y : out integer range 0 to 4)

end entity;

architecture bhv of fsm is

type fsm_st is (s0,s1,s2,s3);   --定义新的数据类型

signal cs :fsm_st;  --说明部分(两句话),一般放在结构体的architecture和begin之间

begin

p1:process(clk,rst)  --clk,rst信号敏感进程(时序进程)

begin

    if rst='0' then cs<=s0; --异步复位信号

    elsif clk'event and clk='1' then  --FSM是以同步时序方式工作的

        case cs is

        when s0 => if input='0' then cs<=s0;  else cs<=s1; end if;

        when s1 => if input='0' then cs<=s1; else cs<=s2;end if;

        when s2 => if input='0' then cs<=s2; else cs<=s3; end if;

        when s3 => if input='0' then cs<=s3;else cs<=s0;end if;

        end case;

end process;

p2:process(input,cs) --组合进程

begin

case cs  is

        when s0=>if input='0' then y<=4; else y<='1';end if;

        when s1=>if input='0' then y<=4; else y<='1'; end if;

        when s2=>if input='0' then y<=4; else y<='1'; end if;

        when s3=>if input='0' then y<=4; else y<='1'; end if;

end case;

end process;

end bhv;

上一篇 下一篇

猜你喜欢

热点阅读