文档详情

11第4章 状态机的设计1.doc

发布:2017-03-30约5.35千字共6页下载文档
文本预览下载声明
第四章 状态机的设计 第一节 概述 前面我们探讨了VHDL的基本语句及构造方式,本章阐述它们在有限状态机(finite state machine,FSM)设计中的应用。 moore型状态机:输出为现态的函数; mealy型状态机:输出为现态和现输入的函数。 在VHDL描述中,描述两种状态机的方法无本质的差异。 传统的设计方法:绘制状态图,列写状态表,合并等价状态,状态分配,列写次态方程和输出方程。 状态机逻辑通常非常适用于可编程逻辑器件来实现。 第二节 基本的状态机设计 —双进程描述风格 设计一:设计一个控制器,根据微处理器的读写周期,分别对存储器输出写使能we和读使能oe信号。该控制器的输入为微处理器的ready和read_write信号。 (状态图) 下面简要写出用VHDL描述该控制器的步骤: 1)画出状态图; 2)定义一个可枚举类型,它包含所有可能用到的状态; type state is(idle,decision,write,read); 3) 定义两个信号ps (present state)和ns(next state)次态; signal ps,ns:state; 4) 建立第一个进程,用于描述次态逻辑和输出逻辑; a、敏感表中包含ps和输入信号ready, read_write。 b、在进程中定义按输入信号决定的状态转移和输出。其中,使用case when语句来判断状态,使用if elsif end if语句决定状态的转移。 5)建立第二个进程,使次态同步于时钟的变化变为现态。 library ieee; use ieee.std_logic_1164.all; entity wr_control is port (clk,ready,read_write:in std_logic; we,oe:out std_logic); end entity wr_control; architecture biprocess of wr_control is type state is (idle,decision,write,read); signal ps,ns:state; begin --进程state_comb描述次态逻辑和输出逻辑,是设计的组合逻辑部分。 state_comb:process(ps,ready,read_write) --现态和所有影响状态转移的输入信号必须列写在敏感表 begin case ps is when idle = oe=0; we=0; if ready=1 then ns=decision; else ns=idle; end if; when decision=oe=0; we=0; if read_write=1 then ns=read; else ns=write; end if; when read = oe=1; we=0; if ready=1 then ns=idle; else ns=read; end if; when write = oe=0; we=1; if ready=1 then ns=idle; else ns=write; end if; end case; end process state_comb; state_clocked:process(clk) --进程state_clocked描述状态转移同步于时钟的上升沿,是设计的时序逻辑部分。 begin if rising_edge(clk) then ps=ns; end if; end process state_clocked; end architecture biprocess; (1)在综合的时候,将状态自动解释为最小宽度的矢量。本例有四个状态idle,decision,write,read,编码依次为00、01、10、11。大多数综合工具采用顺序编码方式,有的工具采用“步进”编码,每次只改变一位,00、01、11、10。 (2)采用行为描述方式设计状态机可以简化编码,降低产生错误的几率。 设计二:双进程状态机描述中的同步复位,需要修改第一个进程。 state_comb:process(ps,ready,read_write,reset)
显示全部
相似文档