VL24 边沿检测时遇到的问题
不可以使用边缘检测来判定rise和down的状态,会出现以下问题。
`timescale 1ns/1ns
module edge_detect(
input clk,
input rst_n,
input a,
output reg rise,
output reg down
);
reg rise_ray,down_ray;
always@(posedge clk or negedge rst_n)begin
if (~rst_n) begin
rise <= 0;
down <= 0;
down_ray <= 0;
rise_ray <= 0;
end
else begin
if (rise_ray) begin
rise <= 1;
rise_ray <= 0;
end
if (down_ray) begin
down <= 1;
down_ray <= 0;
end
if (down_ray==0&down==1) down <= 0;
if (rise_ray==0&rise==1) rise <= 0;
end
end
always@(posedge a)begin
rise_ray <= 1;
end
always@(negedge a)begin
down_ray <= 1;
end
endmodule
输出结果:
出现的问题:
可以发现当a信号从X态转为1或0时,边沿检测会额外检测到一次变化,使rise和down额外跳转一次。
#在线编程#