题解 | #不重叠序列检测#

不重叠序列检测

https://www.nowcoder.com/practice/9f91a38c74164f8dbdc5f953edcc49cc

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

	parameter S_0		=3'd0;
	parameter S_01		=3'd1;
	parameter S_011		=3'd2;
	parameter S_0111	=3'd3;
	parameter S_01110	=3'd4;
	parameter S_011100	=3'd5;
	parameter handle	=3'd6;

	reg [2:0] cs, ns;
	reg [5:0] stop;
	reg data_temp;

	always@(posedge clk or negedge rst_n) begin
		if (~rst_n) begin
			match <= 0;
			not_match <= 0;
			ns <= 3'd0;
			stop <= 6'b0;
		end
		else begin
			cs <= ns;
			data_temp <= data;
		end
	end


	always@(*) begin
		case(cs)
			S_0: 		{ns, stop[5]} = {S_01, 		data_temp};
			S_01: 		{ns, stop[4]} = {S_011, 	~data_temp};
			S_011: 		{ns, stop[3]} = {S_0111, 	~data_temp};
			S_0111: 	{ns, stop[2]} = {S_01110, 	~data_temp};
			S_01110: 	{ns, stop[1]} = {S_011100, 	data_temp};
			S_011100: 	{ns, stop[0]} = {S_0, 	data_temp};
		endcase
	end

	always@(*) begin
		if(cs==S_011100)	begin
			if (|stop) begin
			{match, not_match} = 2'b0_1;
			end
			else if (~&stop) begin
			{match, not_match} = 2'b1_0;
			end
			else begin
			{match, not_match} <= 2'b0_0;
			end
		end
		else begin
			{match, not_match} <= 2'b0_0;
		end
		end

	
endmodule

全部评论

相关推荐

迟缓的斜杠青年巴比Q...:简历被投过的公司卖出去了,我前两天遇到过更离谱的,打电话来问我有没有意向报班学Java学习,服了,还拿我学校一个学长在他们那报班学了之后干了华为OD当招牌
点赞 评论 收藏
分享
05-26 16:13
门头沟学院 C++
牢大肘击Java:海投就完事了bro,就当刷视频了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务