题解 | #含有无关项的序列检测#

含有无关项的序列检测

https://www.nowcoder.com/practice/cba67d06d6834a5d9b93e1087b56c8d8

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input a,
	output reg match
	);

	reg	[8:0]	data;
	reg	[3:0]	bit_cnt;
	reg	flag;

always@(posedge clk  or negedge rst_n)
	if(!rst_n)
		bit_cnt	<=	4'd0;
	else	if(bit_cnt== 4'd10)
		bit_cnt	<=	4'd0;
	else
		bit_cnt	<=	bit_cnt	+ 1'b1;

always@(posedge clk  or negedge rst_n)
	if(!rst_n)
		flag	<=	1'b0;
	else	if(bit_cnt == 4'd8)
		flag	<=	1'b1;
	else
		flag	<=	1'b0;

always@(posedge clk or negedge rst_n)
	if(!rst_n)
		data	<=	8'd0;
	else	if(bit_cnt <= 4'd8)
		data[8-bit_cnt] <=	a;
	
always@(posedge clk or negedge rst_n)
	if(!rst_n)
		match	<=	1'b0;
	else	if(flag && data[8:6]==3'b011 && data[2:0]==3'b110)
		match	<=	1'b1;
	else
		match	<=	1'b0;
endmodule

全部评论

相关推荐

10-25 00:32
香梨想要offer:感觉考研以后好好学 后面能乱杀,目前这简历有点难
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务