有限状态机之1001序列检测器

有限状态机之 1001 序列检测器

设计一个“1001”串行数据检测器。
其输入、输出如下所示:
输入 x:000 101 010 010 011 101 001 110 101
输出 z:000 000 000 010 010 000 001 000 000

Verilog源码
//1001序列检测器

module fsm_seq1001(clk,clr,x,z);

input clk,clr,x;
output reg z;

reg [4:0] state;

parameter S0=5'b00001,S1=4'b00010,S2=4'b00100,S3=4'b01000,S4=4'b10000;

always @(posedge clk,posedge clr)
begin 
 if(clr) state<=S0;
 else case(state)
  S0: begin 
    if(x) begin state<=S1; z=1'b0; end
    else begin state<=S0; z=1'b0; end
    end
  S1: begin 
    if(x) begin state<=S1; z=1'b0; end
    else begin state<=S2; z=1'b0; end
    end
  S2: begin 
    if(x) begin state<=S1; z=1'b0; end
    else begin state<=S3; z=1'b0; end
    end
  S3: begin 
    if(x) begin state<=S1; z=1'b1; end
    else begin state<=S0; z=1'b0; end
    end
  default: begin state<=S0; z=1'b0; end 
  endcase
end

endmodule
testbench
initial                                                
begin                                                  
clk=0;clr=1;x=0;
#15 clr=0;
//序列x: 000 101 010 010 011 101 001 110 101
#10 x=0;
#10 x=0;
#10 x=0;
#10 x=1;
#10 x=0;
#10 x=1;
#10 x=0;
#10 x=1;
#10 x=0;
#10 x=0;
#10 x=1;
#10 x=0;
#10 x=0;
#10 x=1;
#10 x=1;
#10 x=1;
#10 x=0;
#10 x=1;
#10 x=0;
#10 x=0;
#10 x=1;
#10 x=1;
#10 x=1;
#10 x=0;
#10 x=1;
#10 x=0;
#10 x=1;
#100 $stop;                           
$display("Running testbench");                       
end                                                    
always                                                               
begin                                                  
#5 clk=~clk;                                     
end                                                    
endmodule
RTL

RTL

状态转移图

状态转移图

modelsim仿真波形1001序列检测
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值