Verilog 中信号边缘检测的正确方法
我想检测信号的上升沿从触发器AA
到BB
+----+
A ----------------| |----- OUT
+----+ | BB |
B ----| |------|> |
| AA | +----+
clk ----|> |
+----+
Verilog代码:
module edge_detect (
input A,
input B,
input clk,
output OUT
);
reg AA;
reg BB;
always @(posedge clk) begin
AA <= B;
end
always @(posedge AA)begin
BB <= A;
end
assign OUT = BB;
endmodule
AA<的输出/code> 用作
BB
的时钟,表示 AA
已完成其工作,然后 BB
现在可以继续其操作。
我很少看到这段代码。这是一个好的做法吗?
如果没有,是否还有其他正确的方法来检测信号边缘?
I want to detect a rising edge of a signal from a flip-flop AA
to BB
+----+
A ----------------| |----- OUT
+----+ | BB |
B ----| |------|> |
| AA | +----+
clk ----|> |
+----+
Verilog code:
module edge_detect (
input A,
input B,
input clk,
output OUT
);
reg AA;
reg BB;
always @(posedge clk) begin
AA <= B;
end
always @(posedge AA)begin
BB <= A;
end
assign OUT = BB;
endmodule
The output of AA
is used as a clock to BB
saying that AA
has done its job and then BB
can now continue its operation.
I rarely see this code. Is this a good practice?
If not, are there any other proper way to detect an edge of a signal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想在 Verilog 中检测上升沿或下降沿,只需将信号流水线或延迟 1 个时钟脉冲即可。在数字环境中,边缘可以被视为 0 到 1 的转换或 1 到 0 的转换。
因此,您可以检查信号是否转换到任一状态,然后仅在该情况下将输出断言为高电平。
例如 :
If you wanna detect a rising or a falling edge in Verilog, simply pipeline or delay the signal by 1 clock pulse. In a digital environment, an edge can be thought of as a 0 to 1 transition or 1 to 0 transition.
So you can check if the signal made a transition to either state and then assert your output high only for that condition.
For example :
由于各种原因,人们往往不赞成使用数据作为时钟。
就我个人而言,如果我写这篇文章,我会同意:
不过行为有点不同。
People tend to frown on using data as clocks for various reason.
Personally if I was writing this I'd go with:
The behaviour is a little different though.