Verilog - 等待组合逻辑完成

时间:2015-05-28 22:47:48

标签: verilog

我有一些组合逻辑f依赖于这样的寄存器r

reg r;
assign output = f(r); // f is a complicated function of r

现在,我想更改r并使用output。我想要这样的东西:

always begin
    r = r + 1;
    if(output) begin
        // do something
    end
end

在模拟中,我可以在#100r = r + 1之间添加if(output)来实现我想要的效果。但是,#100不可合成。硬件是否会自动插入某种延迟?如果没有,我该如何等待组合逻辑完成?

1 个答案:

答案 0 :(得分:1)

在一般情况下,您可以将逻辑设置为相对于routput异步行为,它们之间有一个组合循环(即outputrr的组合函数的输出是output的组合函数的输出,形成循环)。然而,由于许多原因,这种设计很难处理,并且需要非常详细和具体的时序和其他属性(诸如稳定状态和防止毛刺之类的事情)。如果您想了解更多关于它如何工作的信息,请对异步设计进行一些研究。

但是,根据您似乎希望此电路的行为,您真的想要进行同步设计。在这种情况下,您可能希望注册r并关闭时钟来运行系统。这样的设计可能如下所示:

input      clk; // We need an input clock to run the design
output reg out; // Lets not call it output as thats a keyword in verilog
reg [3:0]  r; // I assume you want r to do more than just flip between 1 and 0, so you need to give it a few more bits of width

assign out = f(r); // figure out the output

// Heres your combinational function of out which does more stuff, not sure if it belongs here or in the parent module, but you'd need to give more info on what you do with out
always @* begin
  if (out) begin
    // Do your thing
  end
end

// The register for r (which acts as a counter in your design)
always @(posedge clk) begin
  r <= r + 4'd1;
end

如果没有关于你的设计的更多细节,我真的无法确定你是否需要做更多的工作,但这种基于时钟信号的同步设计是你可能应该使用的。

相关问题