VHDL语言状态机汇总课件.ppt
《VHDL语言状态机汇总课件.ppt》由会员分享,可在线阅读,更多相关《VHDL语言状态机汇总课件.ppt(72页珍藏版)》请在三一办公上搜索。
1、第八章有限状态机FSM的设计 哈尔滨工业大学(威海) 信息工程学院电子工程系,第八章 有限状态机FSM的设计,1.状态机概念2.一般状态机3.摩尔状态机4.米利状态机5.状态机实例,一 .有限状态机的基本概念,有限状态机:指那些输出取决于过去输入部分和当前输入部分的时序逻辑电路。有限状态机一般有三部分:输入部分、输出部分和状态寄存器。Moore型有限状态机:输出信号仅与当前状态有关Mealy型有限状态机:输出信号不仅与当前状态有关,而且还与所有的输入信号有关。,状态机的特点,克服了纯硬件数字系统顺序方式控制不灵活的缺点。VHDL综合器易于优化易构成性能良好的时序逻辑模块结构模式简单、层次分明、
2、易读易懂、易排错利用同步时序和全局时钟线可实现高速FSM运行模式类似于CPU,易于进行顺序控制高可靠性,非法状态易控制,时序电路的结构与特点,1 状态机分类,根据输出函数的形式,可以分为moore机和mealy机两类。,一般状态机MOORE状态机MEALY状态机,1 状态机分类,FSM的表达形式,通常采用状态转换图表达电路信号的变化:,Moore: y = f(s) Mealy: y = f(s0,x),1 状态机分类,Moore型有限状态机的结构图,Mealy型有限状态机的结构图,FSM的设计要点,定义枚举类型表达不同的状态特点;设置信号表达现有状态和转换的状态;对每一个现态,利用选择语句,
3、根据控制条件x决定转换次态; 根据现态和x决定输出y。,1 状态机分类,状态机的基本操作,状态机内部状态转换。状态机的下一个状态由译码器根据当前状态和输入条件决定。产生输出信号序列。输出信号由输出译码器根据当前状态和输入条件决定。,1 状态机分类,为了能获得可综合的,高效的vhdl状态描述,建议使用枚举数据类型来定义状态机的状态,并使用多进程方式来描述状态机的内部逻辑。,一般情况下,一个进程描述时序逻辑,包括状态寄存器的工作和寄存器状态的输出。另一个进程描述组合逻辑,包括进程间状态值的传递逻辑以及状态以及状态转换值的输出。必要时还可以引入第三个进程完成其他的逻辑功能。,2.一般状态机,状态机的
4、编码方式,Binary、gray-code编码使用最少的触发器,较多的组合逻辑资源,而one-hot编码反之。 另一方面,对于小型设计使用Binary、gray-code更有效,而大型状态机使用one-hot编码更高效。,使用两段式状态机设计方法 设计状态机的方法多种多样,但总结起来有两大类:第一种,将状态转移和状态的操作、判断等写在一起;另一种是将状态转移单独写成一个部分,将状态的操作和判断写到另一个部分中。 第二种设计方法较好,将同步时序和组合逻辑分别放到不同的程序块中实现不仅仅便于阅读、理解、维护,更有利于综合器优化代码,利于用户添加合适的时序约束条件,利于布局布线器实现设计。,一般状态
5、机实例,library IEEE;use IEEE.STD_LOGIC_1164.all;entity s_machine is port( clk : in STD_LOGIC; rst : in STD_LOGIC; state_input : in STD_LOGIC_VECTOR(1 downto 0); comb_output : out STD_LOGIC_VECTOR(1 downto 0) );end s_machine;architecture s_machine of s_machine istype states is (st0,st1,st2,st3);signal c
6、ur_state,next_state : states;,2.一般状态机,beginprocess(clk,rst)begin if rst=1 then cur_statecomb_outputcomb_output=01; if state_input=00 then,next_statecomb_outputcomb_output=11; if state_input=11 then next_state=st3; else next_state=st0; end if; end case; end process;end s_machine;,111序列检测器,例:111序列检测器的
7、功能是连续输入三个或三个以上的1时,电路输出为1,其余情况下输出为0。,s0:初始状态,电路还未收到一个有效1 s1:收到一个1后的状态S2:连续收到两个1后的状态 s3:连续收到三个1个后的状态,111序列检测器程序,library IEEE;use IEEE.STD_LOGIC_1164.all;entity s_machine is port( clk : in STD_LOGIC; rst : in STD_LOGIC; din : in STD_LOGIC; comb_output : out STD_LOGIC );end s_machine;architecture s_mach
8、ine of s_machine istype states is (st0,st1,st2,st3);signal cur_state,next_state : states;,beginprocess(clk,rst)begin if rst=1 then cur_statecomb_outputcomb_output=0; if din=1 then,next_state if din=1 then next_state if state_input=1 then next_state=st3; comb_output=1; else next_state=st0; comb_outpu
9、t=0; end if; end case; end process;end s_machine;,3.摩尔状态机,Moore状态机的输出只与有限状态自动机的当前状态有关,与输入信号的当前值无关。 Moore有限状态机在时钟CLOCK脉冲的有效边沿后的有限个门延后,输出达到稳定值。即使在一个时钟周期内输入信号发生变化,输出也会在一个完整的时钟周期内保持稳定值而不变。输入对输出的影响要到下一个时钟周期才能反映出来。,Moore有限状态机最重要的特点就是将输入与输出信号隔离开来。,Moore机设计:例1,例1 简单的Moore状态机设计状态转换图如下所示,要求设置reset控制,能直接使状态处于s
10、0。,3.摩尔状态机,library ieee; use ieee.std_logic_1164.all;entity statmach is port(clk,input,reset: in std_logic; output: out std_logic);end statmach;,Moore机设计:例1,3.摩尔状态机,architecture beh of statmach is type state_type is (s0,s1); -采用枚举法设置状态 signal st: state_type; -表达当前的状态begin process(clk) -设置时钟控制模块 begi
11、n if reset=1 then st=s0;-异步复位 elsif clkevent and clk=1 then -边沿检测,Moore机设计:例1,3.摩尔状态机,case st is -根据现态决定下一状态 when s0 = st if input=1 then st=s0; end if; end case; end if; end process; output=1 when st=s1 else0; -根据状态决定输出end beh;,Moore机设计:例1,3.摩尔状态机,例2 Moore状态机的设计该状态机有5个状态,转换图如下所示:其中输入控制ID为4位二进制数,在图中
12、表达为16进制数;,Moore机设计:例2,3.摩尔状态机,library ieee;use ieee.std_logic_1164.all;entity moore2 is port(clk,rst: in std_logic;id: in std_logic_vector(3 downto 0);y: out std_logic_vector(1 downto 0);end moore2;,Moore机设计:例2,3.摩尔状态机,architecture beh of moore2 is signal st: std_logic_vector(2 downto 0);-状态表达 -各状态命
13、名并根据输出的特点进行赋值 constant s0:std_logic_vector(2 downto 0):=000; constant s1:std_logic_vector(2 downto 0):=010; constant s2:std_logic_vector(2 downto 0):=011; constant s3:std_logic_vector(2 downto 0):=110; constant s4:std_logic_vector(2 downto 0):=111;begin,Moore机设计:例2,rocess(clk,rst) -状态转移关系begin if rs
14、t=1 then st if id=x3 then st st if id=x7 then st=s3; end if;,Moore机设计:例2,3.摩尔状态机,when s3= if id=x7 then st if id=xb then stst=s0; end case; end if; end process;y=st(1 downto 0); -输出方程end beh;,Moore机设计:例2,3.摩尔状态机,例3 简单状态机设计,初始态:z=0连续2个触发沿A=1,则z=1;若z=1且b=1, 则z保持1。,Moore机设计:例3,3.摩尔状态机,例3 简单状态机设计,Moore机
15、设计:例3,3.摩尔状态机,architecture beh of smexamp is type sreg_type is (init,a0,a1,ok0,ok1); signal sreg:sreg_type;begin process(clk) begin if clkevent and clk=1 then case sreg is when init = if a=0 then sreg=a0; elsif a=1 then sreg=a1; end if;,Moore机设计:例3,when a0 = if a=0 then sreg if a=0 then sreg if a=0
16、then sreg=ok0; elsif a=1 and b=0 then sreg=a1; elsif a=1 and b=1 then sreg=ok1; end if;,Moore机设计:例3,when ok1 = if a=0 and b=0 then sregsreg=init; end case; end if; end process;,Moore机设计:例3,with sreg select -根据状态决定输出 z= 0 when init|a0|a1, 1 when ok0|ok1, 0 when others;end beh;,综合结果如下:,Moore机设计:例3,通过对
17、状态图的分析,可以简化:,使用1个寄存器专门存放触发时的输入a;则状态可以减少到3个;结构也简化了。,Moore机设计:例4,architecture beh of smexamp istype sreg_type is (init,looking,ok);signal sreg:sreg_type;signal lasta:std_logic;begin process(clk) begin if clkevent and clk=1 then lasta=a;,Moore机设计:例4,case sreg is when init = sreg if a=lasta then sreg if
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VHDL 语言 状态机 汇总 课件

链接地址:https://www.31ppt.com/p-1566407.html