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

不重叠序列检测

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
	);
reg[3:0] state,state_next;
parameter S0=0,S1=1,S2=2,S3=3,S4=4,S5=5,S6=6,S7=7,S8=8,S9=9,S10=10,S11=11,S12=12;
always@(*)begin

case(state)
S0:begin match=0;not_match=0; if(data)  state_next<=S7;else state_next<=S1; end
S1:begin match=0;not_match=0; if(data)  state_next<=S2;else state_next<=S8; end
S2:begin match=0;not_match=0; if(data)  state_next<=S3;else state_next<=S9; end
S3:begin match=0;not_match=0; if(data)  state_next<=S4;else state_next<=S10; end
S4:begin match=0;not_match=0; if(data)  state_next<=S11;else state_next<=S5; end
S5:begin match=0;not_match=0; if(data)  state_next<=S12;else state_next<=S6; end
S6:begin match=1;not_match=0; if(data)  state_next<=S7;else state_next<=S1; end
S7: begin match=0;not_match=0;  state_next<=S8;end
S8:begin match=0;not_match=0;  state_next<=S9;end
S9: begin match=0;not_match=0; state_next<=S10;end
S10: begin match=0;not_match=0; state_next<=S11;end
S11:begin match=0;not_match=0;  state_next<=S12;end
S12: begin match=0;not_match=1; state_next<=S0;end
default:begin match=0;not_match=0; state_next<=S0;end
endcase
end

always @(posedge clk or negedge rst_n)begin
	if( rst_n==0) begin
	state<=S0;
	match<=0;
	 not_match<=0;
	 end
	else 
state<=state_next;
end



endmodule

全部评论

相关推荐

05-30 12:03
山西大学 C++
offer来了我跪着...:不是骗子,等到测评那一步就知道为啥这么高工资了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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