题解 | #边沿检测#

边沿检测

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 delay_a ;
	always @(posedge clk or negedge rst_n) begin
		if(!rst_n) begin
			delay_a <=1'b0 ;
		end
		else begin
			delay_a <= a ; 
		end
	end
	always @(posedge clk or negedge rst_n) begin
		if(!rst_n) begin
			rise <=1'b0 ;
		end
		else if(a & (!delay_a))begin
			rise <= 1'b1 ;
		end
		else begin
			rise <= 1'b0 ;
		end
	end
	always @(posedge clk or negedge rst_n) begin
		if(!rst_n) begin
			down <=1'b0 ;
		end
		else if((!a) & delay_a)begin
			down <= 1'b1 ;
		end
		else begin
			down <= 1'b0 ;
		end		
	end
endmodule

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 11:16
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 10:39
一个证都没&nbsp;我能填什么
程序员小白条:别人有,你为什么没有,还是这个道理,社会就是比较,竞争,淘汰,你要安逸,那么就要做好淘汰的准备
点赞 评论 收藏
分享
05-19 19:57
蚌埠学院 Python
2237:Gpa70不算高,建议只写排名,个人技能不在多而在精,缩到8条以内。项目留一个含金量高的,减少间距弄到一页,硕士简历也就一页,本科不要写很多
实习,投递多份简历没人回...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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