VHDL——含异步清零的4状态同步有限状态机

1.VHDL语言

package mtype is                                --定义一个包,包中包含的通用定义可以在整个VHDL或多个设计中共享使用。 
type state_t is (s1,s2,s3,s0);
end mtype;

library ieee;
use ieee.std_logic_1164.all;
use work.mtype.all;

entity s4_machine is
    port(clk,inc,al,bl : in std_logic;
	      rst : in boolean;
			out1 : out std_logic);
end s4_machine;

architecture behave of s4_machine is              --在结构体中定义了两个同步运行的进程
signal current_state,next_state : state_t;        --声明两个信号,类型对应包中的类型
begin 
    sync : process(clk,rst)                       --进程sync:监测复位信号rst,一旦测得复位信号,
	 begin                                         --当前状态立即返回到初始态s0
	     if(rst) then  
		      current_state <= s0;
				elsif(clk'event and clk = '1') then   --没有复位信号,就监测时钟信号clk,当clk为上升沿
		  current_state <= next_state;              --当前状态值立即赋给信号current_state,并由他传给第二个进程
		  end if;                                   --在同一时间,第二个进程根据current_state的值,确定下一状态的值
	 end process sync;

    fsm : process(inc,current_state,al,bl)
	 begin
	     out1 <= al;
		  next_state <= s0;
		  if (inc = '1') then
		  case current_state is
		    when s0 => next_state <= s1;
			 when s1 => next_state <= s2;
		  out1 <= bl;
		    when s2 => next_state <= s3;
			 when s3 => null;
		  end case;
		  end if;
	 end process fsm;
end behave;
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

364.99°

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值