关于VHDL中Loop State error...loop must terminate within 10,000 iterations错误解决方法

关于VHDL中Loop State error...loop must terminate within 10,000 iterations错误解决方法

首先比较下面两段代码:(使用while循环描述偶校验位产生电路)

代码一

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity parity_check is
port(
  	datain: in std_logic_vector(7 downto 0);
    y: out std_logic
	);
end parity_check;

architecture rtl of parity_check is
begin
    process(datain)
    	variable tmp: std_logic:='0';		;不同点
		variable i: integer:= 0;			;不同点
    begin
        while i<8 loop
        	tmp:=tmp xor datain(i);
			i:= i + 1;
        end loop
        y <= tmp;
    end datain;
end rtl;

代码二

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity parity_check is
port(
  	datain: in std_logic_vector(7 downto 0);
    y: out std_logic
	);
end parity_check;
    
architecture rtl of parity_check is
begin
    process(datain)
    	variable tmp: std_logic;		;不同点
		variable i: integer;			;不同点
    begin
        tmp:='0';						;不同点
		i:=0;							;不同点
        while i<8 loop
        	tmp:=tmp xor datain(i);
			i:= i + 1;
        end loop
        y <= tmp;
    end datain;
end rtl;

代码二在编码过程中没有报错,而代码一却在编译过程中报错,出现题目所述错误。同样是赋值,原因到底在哪里呢?

在进程中,说明语句只执行一次,即变量的声明部分只执行一次,由于代码二中进程的主体部分开头每次都对变量i进行赋值操作,相当于每次都会对其进行清零操作,显然循环过程不会发生错误;而代码一中,当进程被触发的次数不止一次时,loop循环就会发生错误。所以平时应该养成代码二的编程习惯。

posted @ 2024-05-11 22:00  讯号  阅读(53)  评论(0编辑  收藏  举报