Verilog错误处理“ always”块中的两个posege信号

问题描述

我在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。执行PROC_DFF传递(将进程同步转换为FF)。为信号\freq_div.\clk_1khz' using process \ freq_div。$ proc $ syncRX.v:22 $ 4'创建寄存器。使用进程$procdff$15' with positive edge clock. Creating register for signal $ procdff $ 16'和上升沿时钟创建$ dff单元\freq_div.$proc$syncRX.v:22$4'. created $dff cell \ freq_div。\ count'。创造 注册信号\syncRX.\detect' using process \ syncRX。$ proc $ syncRX.v:8 $ 1'。错误:多个边缘敏感事件 找到这个信号! make:*** [Makefile:44:syncRX.bin]错误1

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

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

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

也以相同的方式失败:

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

注释行“ detect

请,如果有人能解释我为什么不工作以及我该怎么做。对我来说将非常有用。

解决方法

我想您可以为每个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块的第二个变量也无法合成。它导致detect信号由多个Always模块驱动,并在合成中引起乘法驱动条件。在仿真中,它将导致不确定的结果。合成应该中断。检查邮件。