【发布时间】:2019-03-11 20:53:50
【问题描述】:
我在 eda playground 上针对我遇到的问题做了一个基本示例。 假设我有两个时钟 1x 和 2x。 2x 使用 flop 分频器从 1x 分频。
我有两个寄存器 a 和 b。 a 以 1x 计时,b 以 2x 计时。
b是a的采样值。
当我们有 1x 和 2x 时钟的上升沿时,b 没有取 a 的预期值,而是取下一个周期值。
这是因为这种时钟分频器方案,如果我们使用 icgs 进行分频,则它可以正常工作。 但是有没有办法让它使用这种带有触发器的时钟分频器方案?
EDA 操场链接:https://www.edaplayground.com/x/map#
module race_test;
logic clk1x = 0;
logic clk2x = 0;
always
#5ns clk1x = !clk1x;
int a, b;
always @(posedge clk1x) begin
a <= a+1;
clk2x <= !clk2x;
end
// Problem here is that b will sample postpone value of a
// clk2x is not triggering at the same time than clk1x but a bit later
// This can be workaround by putting blocking assignment for clock divider
always @(posedge clk2x) begin
b <= a;
end
initial begin
$dumpfile("test.vcd");
$dumpvars;
#1us
$stop;
end
endmodule
【问题讨论】:
-
见here
-
感谢您的链接,这正是我所期待的。它使用时钟分频器的阻塞分配按预期工作。但是,如果我的时钟分频器不是模型而是将在我的芯片中的真正触发器,这是否正确?在书中他们说合成器会很好(希望)
-
一般来说,经验法则是,您从不使用 NBA 作为时钟以避免比赛。
标签: verilog system-verilog clock race-condition edaplayground