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

含有无关项的序列检测

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

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input a,
	output reg match
	);
parameter S0=0,S1=1,S2=2,S3=3,S4=4,S5=5,S6=6,S7=7,S8=8,S9=9,S10=10;
	reg [3:0] state,state_next;

always @(*) begin

case(state)
S0:begin if(a)  state_next=S0; else state_next=S1; end
S1:begin  if(a)  state_next=S2; else state_next=S1; end
S2:begin  if(a)  state_next=S3; else state_next=S1; end
S3:   state_next=S4; 
S4: state_next=S5; 
S5:state_next=S6;
S6:begin  if(a)  state_next=S7; else state_next=S1; end
S7:begin  if(a) state_next=S8; else  state_next=S1;end
S8:begin  if(a) state_next=S0; else  state_next=S9;end
S9:begin  if(a) state_next=S0; else  state_next=S1;end
default:begin if(a) state_next=S0; else  state_next=S1;end
endcase
end
  
  always @(posedge clk or negedge rst_n) begin
if(rst_n==0)
state<=S0;
else state<=state_next;
  end
   always @(posedge clk or negedge rst_n) begin
if(rst_n==0)
match<=0;
else match<=(state==S9)?1:0;
  end
endmodule

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 10:56
点赞 评论 收藏
分享
鬼迹人途:你去投一投尚游游戏,服务器一面,第一个图算法,做完了给你一个策略题,你给出方案他就提出低概率问题,答不上当场给你挂
点赞 评论 收藏
分享
榕城小榕树:1200单休,我去干点啥别的不好
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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