题解 | #输入序列不连续的序列检测#

输入序列不连续的序列检测

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

yeah

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

reg [2:0] state;
reg [2:0] nxt_state;
parameter zero = 0, one = 1, two = 2, three = 3, four = 4;

always @(posedge clk or negedge rst_n)
begin
	if (!rst_n)
	state <= zero;
	else 
	state <= nxt_state; 
end

always @(*)(1444584)
begin
	if (!rst_n)
	nxt_state = zero;
	else 
	case(state)
	zero: nxt_state = (data_valid & ~data)? one:zero;
	one: nxt_state = (data_valid & data)? two:one;
	two: nxt_state = (data_valid & data)? three:((data_valid & ~data)? one:two);
	three: nxt_state = (data_valid & ~data)? four:((data_valid & data)? zero:three);
	four: nxt_state = (data_valid & ~data)? one:((data_valid & data)? two:zero);
	default:nxt_state = zero;
	endcase
end

always @(*)(1444584)
begin
	if (state == four)
		match = 1;
	else 
		match = 0;
end




  
endmodule

全部评论

相关推荐

过往烟沉:我说什么来着,java就业面就是广!
点赞 评论 收藏
分享
Bug压路:老哥看得出来你是想多展示一些项目,但好像一般最多两个就够了😂页数一般一页,多的也就2页;这些项目应该是比较同质化的,和评论区其他大佬一样,我也觉得应该展示一些最拿手的(质量>数量)😁😁😁专业技能部分也可以稍微精简一些
点赞 评论 收藏
分享
字节 飞书绩效团队 (n+2) * 15 + 1k * 12 + 1w
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务