题解 | #边沿检测#

边沿检测

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		a_reg;

always@(posedge clk or negedge rst_n)
	if(~rst_n)
		a_reg <= 1'b0;
	else
		a_reg <= a;

always@(posedge clk or negedge rst_n)
	if(~rst_n)
		rise <= 1'b0;
	else if(!a_reg & a)
		rise <= 1'b1;
	else
		rise <= 1'b0;

always@(posedge clk or negedge rst_n)
	if(~rst_n)
		down <= 1'b0;
	else if(a_reg & ~a)
		down <= 1'b1;
	else
		down <= 1'b0;


endmodule

全部评论

相关推荐

阿武同学:基本信息保留前面三行,其他的可以全部删掉,邮箱最重要的你没写,主修课程精简到8个以内,实习里面2/3/4都是水内容的,非要写的话建议两到三句话,项目经历排版优化下,自我评价缩到三行
点赞 评论 收藏
分享
09-24 18:30
已编辑
长春工业大学 产品经理
小肥罗:HR就是好人的缩写哈哈哈哈
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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