下面的代碼是我正在編寫的一個更簡單的例子。Verilog定時控制(模塊之間的同步)
模塊bar
將根據operation
做a
。問題是,我無法正確分配result
(應該在輸出b
之後指定foo1
)。
我找到了解決辦法,只需在result = r1
之前加上#1
即可。我想知道在模塊之間進行同步的正確方法是什麼?
module foo1(
input a,
output reg b
);
[email protected](a)
b = a;
endmodule
module foo2(
input a,
output reg b
);
[email protected](a)
b = ~a;
endmodule
module bar(
input a,
input operation,
output b
);
reg result;
assign b = result;
wire r1, r2;
foo1 submod1(a, r1);
foo2 submod2(a, r2);
[email protected](a or operation) begin
case (operation)
1'b0:
result = r1;
1'b1:
result = r2;
endcase
end
initial begin
$dumpfile("foobar.vcd");
$dumpvars(0, r1);
$dumpvars(0, r2);
$dumpvars(0, result);
$dumpvars(0, operation);
end
endmodule
module test;
reg a, op;
wire r;
bar mod(a,op,r);
integer i;
initial begin
a = 0;
op = 0;
for (i=0; i<8; i=i+1)
#10 a = ~a;
end
endmodule