HDLBits DFF 和门

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

我试图从电路/顺序逻辑/锁存器和触发器中解决HDLBits的问题:DFF和门(https://hdlbits.01xz.net/wiki/Exams/ece241_2014_q4)。 我在网上找到了解决方案(https://github.com/y-C-x/HDLBits_Solution/blob/master/3%20Circuit/3.2%20Sequential%20Logic/3.2.1%20Latches%20and%20Flip-Flops/3.2.1.13% 20DFFs%20and%20Gates.v)但我想了解为什么我的(更顽固的)解决方案不起作用:

module top_module (
    input clk,
    input x,
    output z
); 
    wire d_xor, d_and, d_or;
    wire z1, z2, z3;
    wire fb_xor, fb_and, fb_or;
    
    assign d_xor = x ^ fb_xor;
    assign d_and = x && fb_and;
    assign d_or = x || fb_or;
    
    d_ff(.d(d_xor), .clk(clk), .q(fb_xor));
    d_ff(.d(d_and), .clk(clk), .q(z2), .nq(fb_and));
    d_ff(.d(d_or), .clk(clk), .q(z3), .nq(fb_or));
    
    assign z = ~|{fb_xor, z2, z3};
endmodule

module d_ff (
    input wire d, 
    input wire clk,
    output reg q = 1'b0, 
    output reg nq = 1'b1
);
    always @(posedge clk) begin
        
        q = d;
        nq = ~d;
        
    end
    
endmodule

当我使用

q = d;
q <= d;
时没有区别,并且输出使我的输出看起来比正确信号延迟了 1 个周期。

verilog
1个回答
0
投票

问题出在 HDLBits 网站上,而不是您的代码上。

该网站的一大缺点是他们不向您展示所使用的 Verilog 测试平台代码。您无法看到测试平台如何驱动输入信号或采样输出信号以进行比较。测试台代码中可能存在细微的错误。

还有一个缺点就是不知道用的是什么模拟软件。该网站说使用了

iverilog
,但你不知道该软件的版本或它有什么错误。

我在EDA Playground上创建了一个简单的测试平台,它显示了预期的输出波形。

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