HDLBits Edgedetect 关于如何更新边缘状态的问题

问题描述 投票:0回答:1

我正在 HDLBits 上尝试关于边缘检测的 verilog 练习。
但很困惑,无法理解使用

if ({d_last, in} == 2'b01)
pedge <= in & ~d_last
之间的差异行为?
它们不是只是比较之前和当前信号的相同行为吗?

我的回答:

module top_module (
    input clk,
    input [7:0] in,
    output [7:0] pedge
);
    
    reg [7:0] d_last;   
            
    always @(posedge clk) begin
        d_last <= in;           
        if ({d_last, in} == 2'b01)
            pedge <= 1;
        else
            pedge <= 0;
    end

endmodule

警告信息: 警告 (13024):输出引脚卡在 VCC 或 GND

此警告表示输出引脚永远不会改变(“卡住”)。如果输出引脚不应该是常量,这有时可能表明存在错误。如果该引脚不应保持不变,请检查是否存在导致分配的值永远不会改变的错误(例如,分配 a = x & ~x;)

HDLBits 解决方案:

module top_module(
    input clk,
    input [7:0] in,
    output reg [7:0] pedge);
    
    reg [7:0] d_last;   
            
    always @(posedge clk) begin
        d_last <= in;           // Remember the state of the previous cycle
        pedge <= in & ~d_last;  // A positive edge occurred if input was 0 and is now 1.
    end
    
endmodule
verilog system-verilog
1个回答
0
投票

您的答案与 HDLBits 解决方案非常不同。更详细的

if/else
写法是:

    if ({d_last, in} == 2'b01)
        pedge[7:0] <= 8'b0000_0001;
    else
        pedge[7:0] <= 8'b0000_0000;

如您所见,7 位向量

pedge[7:1]
始终为
7'b0000_000
pedge
的 7 位始终为 0。这就是警告消息的原因。

© www.soinside.com 2019 - 2024. All rights reserved.