Verilog 错误处理 "always" 块中的两个 posedge 信号

Verilog error handling two posedge signals in "always" block

我对 Verilog 中的“始终”块有疑问。首先让我展示代码:

module syncRX(clk, signal, detect, output clk_1khz);
    input clk, signal;
    output reg [7:0] detect = 0;

    //wire clk_1khz;
    freq_div div(.clk(clk), .clk_1khz(clk_1khz));
    
    always @(posedge signal, posedge clk_1khz)
     begin
        detect <= detect + 1;
     end

endmodule // top

module freq_div(input clk, output reg clk_1khz);
    reg [12:0] count = 0;
    always @(posedge clk)
     begin
        if(count == 6000)
            begin
                clk_1khz <= ~clk_1khz;
                count <= 0;
            end
        else
            count <= count + 1;
     end
    
endmodule

我收到此错误消息(使用 Icestorm):

2.3.7. Executing PROC_DFF pass (convert process syncs to FFs). Creating register for signal \freq_div.\clk_1khz' using process \freq_div.$proc$syncRX.v:22'. created $dff cell $procdff' with positive edge clock. Creating register for signal \freq_div.\count' using process \freq_div.$proc$syncRX.v:22'. created $dff cell $procdff' with positive edge clock. Creating register for signal \syncRX.\detect' using process \syncRX.$proc$syncRX.v:8'. ERROR: Multiple edge sensitive events found for this signal! make: *** [Makefile:44: syncRX.bin] Error 1

我可以检测到涉及的“始终”块是:

always @(posedge signal, posedge clk_1khz)
     begin
        detect <= detect + 1;
     end

因为如果将“始终@(posedge 信号,posedge clk_1khz)”更改为“始终@(posedge 信号)”有效。

也以同样的方式失败:

always @(posedge signal)
     begin
        detect <= detect + 1;
     end
    
    always @(posedge clk_1khz)
     begin
        detect <= detect + 1;
     end

当注释行“detect <= detect + 1;”时错误消失在购买的情况下。那么该错误与访问“检测”计数器寄存器有关。我不知道为什么我不能从两个不同的信号触发这个计数器,但事实上,我必须增加购买的 post 边缘信号的计数器(我可以在我的脑海中弄清楚一个非常简单的数字电路做这个),我在 Verilog 中发现了很多使用带有两个 posedges 触发器的“总是”块的例子......但是我的不工作。

拜托,如果有人能解释我为什么不工作以及我如何做。这对我来说非常有用。

我想您可以为每个 clk_1khz 和信号使用单独的计数器。然后只需添加它们:

always @(posedge signal)
     begin
        detect_sig <= detect_sig + 1;
     end
    
always @(posedge clk_1khz)
     begin
        detect_clk <= detect_clk + 1;
     end

assign detect = detect_sig + detect_clk;

虽然,@(posedge signal) 对我来说看起来很奇怪。你不应该在这里使用任何时钟。所以,检查你的算法。

并且,您还应该在综合之前模拟和验证您的模型。

由于您在另一个问题中提出过这个问题,因此您的第二个变体具有 2 个不同的 always 块,也无法合成。它导致由多个 always 块驱动的 detect 信号,并导致综合中的 multiply-driven 条件。在模拟中,它将导致 non-deterministic 结果。综合应该打破。查看消息。