verilog 基础设计1 -序列检测

要求:设计一个10010 序列检测器

目录

1、按照要求画出状态转移图

2、根据状态转移图书写代码

3、书写testbench,测试功能

4、modelsim 仿真结果

5、总结


1、按照要求画出状态转移图

        

2、根据状态转移图书写代码

       端口说明:

输入端口:时钟、复位、输入的序列in

输出端口: 标志符号flag

代码如下

module seq_test(
	input wire clk,
	input wire rst_n,
	input wire in,
	output wire flag
	);

reg [5:0] current_state;
reg [5:0] next_state;

parameter IDLE = 6'b000_001,
		  A = 6'b000_010,
		  B = 6'b000_100,
		  C = 6'b001_000,
		  D = 6'b010_000,
		  E = 6'b100_000;


always @(posedge clk or negedge rst_n) begin
	if (!rst_n) 
		current_state <= IDLE;
	else
		current_state <= next_state;
end

always @(*) begin
	case(current_state)
		IDLE: if(in == 1'b1)
				next_state = A;
		A:	  if(in == 1'b0)
				next_state = B;
		B:	  if(in == 1'b0)
				next_state = C;
			  else 
			  	next_state = A;
		C:	  if(in == 1'b1)
				next_state = D;
			  else 
			  	next_state = IDLE;
		D:	 if(in == 1'b0)
				next_state = E;
			 else 
			 	next_state = A;
		E:   if(in == 1'b0)
				next_state = C;
			 else 
			 	next_state = A;
		default: next_state = IDLE;
	endcase
end


assign flag = (current_state == E)? 1'b1:1'b0;

endmodule

3、书写testbench,测试功能

module tb_seq_test();

reg clk;
reg rst_n;
reg	in;
wire flag;

reg [15:0] data;

integer i;
initial begin
	rst_n =0;
	clk =0;
	in=0;
	data = 16'b1100100100010010;
	#100;
	rst_n =1;
	for(i = 0; i <16 ;i=i+1) begin
		@(posedge clk) begin
			in = data[15-i];
		end
	end
	
end


always #10 clk =~clk;




seq_test seq_test_inst(
	.clk(clk),
	.rst_n(rst_n),
	.in(in),
	.flag(flag)
	);


endmodule





4、modelsim 仿真结果

仿真输入的序列为1100100100010010,根据仿真,正确指示出10010序列

5、总结

      10010序列检测器,是比较基础的设计之一,主要问题在于需要画出正确的状态转移图,本设计主要考虑的问题在于,如何考虑重复序列的检测,否则容易出现状态遗漏。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值