题解 | #边沿检测#

边沿检测

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

`timescale 1ns/1ns
module edge_detect(
	input clk,
	input rst_n,
	input a,
	
	output reg rise,
	output reg down
);

reg a0;
//寄存一次
always @(posedge clk or negedge rst_n) begin
	if(!rst_n) begin
		a0 <= 0;
	end
	else begin
		a0 <= a;
	end
end
//判断上升沿和下降沿
always @(posedge clk or negedge rst_n) begin
	if(!rst_n) begin
		rise <= 0;
		down <= 0;
	end
	else begin
		if(a & ~a0) begin
			rise <= 1;
			down <= 0;
		end
		else if(~a & a0) begin
			rise <= 0;
			down <= 1;
		end
		else begin
			rise <= 0;
			down <= 0;
		end
	end
end
	
endmodule

全部评论

相关推荐

10-27 02:29
已编辑
门头沟学院 嵌入式工程师
牛客72783561...:简历不是这么写的,你这两个项目只说了用到了什么技术,却没说取得了什么成果,在我看来这就是你自己做的一个demo,没有价值。你为什么不写你电赛国二的那个项目?
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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