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

注意:判断输出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


全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 18:05
哈哈哈哈哈感觉朋友找工作的已经疯掉了,直接上图
码农索隆:真老板娘:“我嘞个去,这不我当年的套路吗
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 13:05
点赞 评论 收藏
分享
牛客84809583...:举报了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 11:16
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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