在quartus中编译,报错:在时钟沿之外不能保持cnt的值,所以不能infer register.(以前也碰到这种问题,没有解决)
请各位帮忙说说错在那?为什么?
代码如下:
counter:process(rst,clk.ena,sop)
begin
if(ena='0' or sop='1')then --清零 //这个if语句报上述的错误,请高手出来说说是怎么回事?
cnt<=(others=>'0');
end if;
if(clk'event and clk='1')then --计数
if(ena='1')then
if(cnt=b"1111_1111")then
cnt<=(others=>'0');
else
cnt<=cnt+1;
end if;
end if;
end if;
end process counter;
代码改成如下,就编译通过,不报错。
counter:process(rst,clk,ena,sop)
begin
if(clk'event and clk='1')then
if(ena='0' or sop='1')then --清零
cnt<=(others=>'0');
end if;
if(ena='1')then --计数
if(cnt=b"1111_1111")then
cnt<=(others=>'0');
else
cnt<=cnt+1;
end if;
end if;
end if;
end process counter;
-----------------------
高手能解释一下原因吗
谢谢!