状态机

状态机

偏基础:berkeley: Finite State Machines in Verilog

好文:数字集成电路设计-12-状态机

在FPGA的电路实现当中FSM的应用是非常广泛的。根据状态机的输出得出的方式状态机可以分成两个大类,第一个是Moore型状态机,Moore型状态机的输出只与当前状态有关,一种状态就对应着一种输出。Mealy型状态机不仅与当前的FSM的状态有关,还与当前状态机的输入有关。相对来说,Moore机的状态更加稳定可靠,设计起来更容易理解。

使用verilog语言创建一个FSM模型,一般要经过以下几步:

  • 首先是对FSM当中出现的状态进行编码;
  • 对FSM的当前状态进行跟踪;
  • 执行状态转换;
  • 执行新旧状态的转换;
  • 基于当前状态对输出进行赋值;

Xilinx官网给了一个FSM的实现例子,可以参见这个网页。代码如下

// State Machine with single sequential block
// 
//  This example shows the use of the Vivado "fsm_encoding" attribute
//
//  Acceptable values for this are: one_hot sequential johnson gray and auto.

module fsm_test(clk,reset,flag,sm_out);
input clk,reset,flag;
output reg sm_out;
//Gray code format
parameter s1 = 3'b000;
parameter s2 = 3'b001;
parameter s3 = 3'b010;
parameter s4 = 3'b011;
parameter s5 = 3'b111;

// Adding fsm_encoding value designates to Vivado Synthesis which encoding is to be used.
    //星号部分的代码只有告知Vivado编译器编码格式的功能
    (* fsm_encoding = "gray" *)reg [2:0] state;

always@(posedge clk)
  begin
    if(reset)
      begin
        state <= s1;
        sm_out  <= 1'b1;
      end
  else
    begin
     case(state)
       s1: if(flag) 
        begin 
        state <= s2; 
        sm_out <= 1'b1; 
        end
           else
                begin
        state <= s3;
        sm_out <= 1'b0;
        end

       s2: begin state <= s4; sm_out <= 1'b0; end
       s3: begin state <= s4; sm_out <= 1'b0; end
       s4: begin state <= s5; sm_out <= 1'b1; end
       s5: begin state <= s1; sm_out <= 1'b1; end
     endcase
    end
 end
endmodule
posted on 2019-08-09 19:43  luckfyzh 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lafiizh/p/11329249.html

一、实验目的: 1、深入了解与掌握同步时序逻辑电路的设计过程; 2、了解74LS74、74LS08、74LS32及74LS04芯片的功能; 3、能够根据电路图连接好实物图,并实现其功能。学会设计过程中的检验与完善。 二、实验内容描述: 题目:“1 1 1”序列检测器。 原始条件:使用D触发器( 74 LS 74 )、“与”门 ( 74 LS 08 )、“或”门( 74 LS 32 )、非门 ( 74 LS 04 ),设计“1 1 1”序列检测器。 集成电路引脚图: D触发器( 74 LS 74 ) “与”门 ( 74 LS 08 ) “或........ 三、实验设计过程: 第1步,画出原始状态图和状态表。 根据任务书要求,设计的序列检测器有一个外部输入x和一个外部输出Z。输入和输出的逻辑关系为:当外部输入x第一个为“1”,外部输出Z为“0”;当外部输入x第二个为“1”,外部输出Z为“0”;当外部输入x第三个为“1”,外部输出Z才为“1”。假定有一个外部输入x序列以及外部输出Z为: 输入x: 0 1 0 1 1 1 0 1 1 1 1 0 1 输出Z: 0 0 0 0 0 1 0 0 0 1 1 0 0 要判别序列检测器是否连续接收了“111”,电路必须用不同的状态记载外部输入x的值。假设电路的初始状态为A,x输入第一个“1”,检测器状态由A装换到B,用状态B记载检测器接受了111序列的第一个“1”,这时外部输出Z=0;x输入第二个“1”,检测器状态由B装换到C,用状态C记载检测器接受了111序列的第二个“1”,外部输出Z=0;x输入第三个“1”,检测器状态由C装换到D,外部输出Z=1。然后再根据外部输入及其他情况时的状态转移,写出相应的输出。以上分析了序列检测器工作,由此可画出图7-1所示的原始状态图。根据原始状态图可列出原始状态表,如表7-2所示。 现态 次态/输出 x = 0 x = 1 A A / 0 B / 0 B A / 0 C / 0 C A / 0 D / 1 D A / 0 D / 1 (表 7-2 原始状态表) (图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值