题解 | #状态机-非重叠的序列检测#

注意:判断输出flag需要用nstata来判断。

always@(posedge clk or negedge rst)
		if(~rst)
			flag <= 0;
		else
			flag <= nstata==S_10111? 1:0;


`timescale 1ns/1ns

module sequence_test1(
	input wire clk  ,
	input wire rst  ,
	input wire data ,
	output reg flag
);
//*************code***********//
	parameter IDLE=0, S_1=1, S_10=2, S_101=3, S_1011=4, S_10111=5;
	reg [4:0] stata, nstata;

	always@(posedge clk or negedge rst)
		if(~rst)
			stata <= IDLE;
		else
			stata <= nstata;

	always@(*)begin
		case(stata)
			IDLE: nstata <= data==1? S_1: IDLE;
			S_1: nstata <= data==1? S_1: S_10;
			S_10: nstata <= data==1? S_101: IDLE;
			S_101: nstata <= data==1? S_1011: S_10;
			S_1011: nstata <= data==1? S_10111: S_10;
			S_10111: nstata <= data==1? S_1: IDLE;
			default: nstata <= IDLE;
		endcase
	end
	always@(posedge clk or negedge rst)
		if(~rst)
			flag <= 0;
		else
			flag <= nstata==S_10111? 1:0;

//*************code***********//
endmodule


全部评论

相关推荐

码农索隆:1.照片换成证件照。 2.专业技能写的太少了,太单薄了。 3.项目经历描写的太冗余,分成几点。 4.无实习经历,看看能不能包一个。
点赞 评论 收藏
分享
亲切的00后在笔试:我也遇到了,所以我早他一步查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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