【问题标题】:Verilog - multiple edges in one block like in VHDL?Verilog - 一个块中有多个边缘,如VHDL?
【发布时间】:2015-02-24 22:20:56
【问题描述】:

我正在使用 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

引发“无法解析多个常量驱动程序”错误。还有这个:

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

抛出“无法将条件中的操作数与始终构造的封闭事件控件中的相应边匹配”错误。

这段代码工作

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 而不是在时钟上升沿。

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

【问题讨论】:

标签: verilog quartus


【解决方案1】:

为什么需要异步重置 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;

【讨论】:

  • 我需要它用于基于 A12 行的 MMC3 IRQ:wiki.nesdev.com/w/index.php/MMC3 此行由 PPU 使用,它与主 CPU 异步工作。
  • @Cluster 我一直认为 always 块区分时钟线和复位线的方式有点……奇怪(也许不直观)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多