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