Verilog - 像在 VHDL 中一样,一个块中有多个边缘?

Verilog - multiple edges in one block like in VHDL?

我正在使用 Quartus II 11.0 版,我正在尝试将我的 VHDL 代码移植到 Verilog(仅供练习)。

我需要检查 - 'a' 线有多长。有可用的 VHDL 代码:

process (clock, a)
begin
    -- on each rising edge of clock...
    if (rising_edge(clock))
    then -- count how long 'a' is low
        if (a = '0' and a_low_time < 3)
        then
            a_low_time <= a_low_time + 1;
        end if;
    end if;
    -- reset counter if 'a' is not low
    if a = '1' then
        a_low_time <= 0;
    end if;
end process;

非常简单,运行完美。但是我如何使用 Verilog 来实现呢? 此代码:

// on each rising edge of clock...
always @ (posedge clock)
begin
    // count how long 'a' is low
    if (!a && a_low_time < 3)
        a_low_time <= a_low_time + 1;
end

// reset counter if 'a' is high
always @ (*)
begin
    if (a)
        a_low_time <= 0;
end

抛出“сan't resolve multiple constant drivers”错误。还有这个:

always @ (posedge clock, posedge a)
begin
    if (!a && a_low_time < 3)
        a_low_time <= a_low_time + 1;
    else if (a)
        a_low_time <= 0;
end

引发 "cannot match operand(s) in the condition to the corresponding edges in the enclosing event control of the always construct" 错误。

此代码有效:

always @ (posedge clock)
begin
    if (!a && a_low_time < 3)
        a_low_time <= a_low_time + 1;
    else if (a)
        a_low_time <= 0;
end

但我需要在 'a' 变高后立即重置 a_low_time,而不是在时钟的上升沿。

我该怎么做?真不敢相信我做不到这么简单的任务。

为什么需要异步重置 a_low_time?无论如何,也许您可​​以使用 a 作为重置行:

always @(posedge clock or posedge a)
begin
    if (a)
        a_low_time <= 0;
    else if (!a && a_low_time < 3)
        a_low_time <= a_low_time + 1;

实际上,由于 a 是您的重置,因此您不需要检查它来递增:

always @(posedge clock or posedge a)
begin
    if (a)
        a_low_time <= 0;
    else if (a_low_time < 3)
        a_low_time <= a_low_time + 1;