题解 | #边沿检测#

边沿检测

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=0;
always@(posedge clk or negedge rst_n)
begin
   if(rst_n==1'b0)  begin  a0<=0; end
   else a0<=a;
end 

always@(posedge clk or negedge rst_n)
begin
	if(rst_n==1'b0)  begin  rise<=1'b0; down<=1'b0; end
    else if(!a0&&a&& !rise) begin rise<=1;  down<=0; end
	else if(a0&&!a&& !down) begin down<=1; rise <=0; end
   else begin down<=0; rise <=0; end

end 


endmodule

之前写过这个功能的代码,但没想到可以用打拍的方式解决。当时调试了好久,还定义了好几个变量。现在还是不太理解“边沿”在实际编程中是什么样的

全部评论

相关推荐

昨天 14:14
门头沟学院 Java
7.10投递7.15感谢信
投递地平线等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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