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

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

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

全部评论

相关推荐

点赞 评论 收藏
分享
11-13 20:32
门头沟学院 Java
面向未来编程code:我没看到他咋急,他不就问你个问题。。。
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务