三段式状态机设计序列检测器

此次实验为使用三段式状态机设计一款5位序列检测器

本次实验以设计“10010”检测器为例

quartus II输出的状态转移图

70ffe415800840e486252133aae5304e.png

modelsim的仿真波形

eaa12f0546274e018b21fd31fa611908.png

module schk(input clk,din,rst,output sout);
parameter s0=6'b000001,s1=6'b000010,s2=6'b000100,s3=6'b001000,s4=6'b010000,s5=6'b100000;//独热码
reg [5:0] current_state,next_state;
always@(posedge clk or negedge rst)
if(rst==0)
current_state<=s0;
else
current_state<=next_state;
always@(current_state or din)
begin
    case(current_state)
        s0:if(din==1'b1) next_state<=s1;else next_state<=s0;//进位是1,进入s1,反之则回到s0
        s1:if(din==1'b0) next_state<=s2;else next_state<=s1;//进位是0,进入s2,反之则回到s1
        s2:if(din==1'b0) next_state<=s3;else next_state<=s1;//进位是0,进入s3,反之则回到s1
        s3:if(din==1'b1) next_state<=s4;else next_state<=s0;//进位是1,进入s4,反之则回到s0
        s4:if(din==1'b0) next_state<=s5;else next_state<=s1;//进位是0,进入s5,反之则回到s1
        default:next_state<=s1;//if语句内条件以外的情况回到s1
    endcase
end
assign sout=(current_state==s5); //输出现态s5
endmodule

 

//搭建testbench并用modelsim进行仿真验证状态机序列检测器是否正确实现

`timescale 1ns/1ns
module schk_tb;
reg clk;
reg rst;
reg din;
wire sout;
schk u_schk(
.clk (clk),
.rst (rst),
.din (din),
.sout (sout)
);
initial begin
    clk=0;
    forever begin
        #10;clk=~clk;
    end
end
initial begin
    rst=0;
    #20;rst=1;
end
initial begin
    din=0;
    forever begin
     din=1;#20;
     din=0;#20;
     din=0;#20;
     din=1;#20;
     din=0;#20;
  end
end
endmodule

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值