【发布时间】: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 而不是在时钟上升沿。
我该怎么做?不敢相信我不能做这么简单的任务。
【问题讨论】:
-
已经在 EE 网站上提问和回答,阅读electronics.stackexchange.com/q/28369/1743