我对VHDL非常陌生,我想得到一些帮助。您看,我们的教练告诉我们编码二进制的除法(首先将二进制转换成整数),如果除数为零,那么输出误差波形将在仿真中显示。这是我的代码:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity division_in is
Port ( A : in STD_LOGIC_VECTOR (7 downto 0);
B : in STD_LOGIC_VECTOR (7 downto 0);
clk : in STD_LOGIC;
Y : out STD_LOGIC_VECTOR (7 downto 0);
err : out STD_LOGIC);
end division_in;
architecture Behavioral of division_in is
begin
process(clk)
begin
if clk='1' and clk'event then -- error here
Y <= conv_std_logic_vector(conv_integer(A)/conv_integer(B),8);
err <= '0';
elsif B = 0 then
err <= '1';
end if;
end process;
end Behavioral;当我尝试在XilinxISE9.1i(这是大学使用的)中使用的"check语法“时,没有显示在抄本上的语法错误。我甚至可以使用testbench波形来毫无问题地模拟它。但是,当我将此代码导入Quartus II时,我在消息中发现了5个错误,特别是在这个消息中:
错误(10818):无法在division_in.vhd(45)处推断"err“的寄存器,因为它不将其值保存在时钟边缘之外
我不知道我在将确切的代码从Xilinx复制到Quartus时做错了什么,但是对于我为什么在Quartus II上出现这个错误,而在XilinxISE9.1i上没有得到这个错误,我们非常感激。由于Xilinx已经不兼容我的笔记本电脑了,所以我只使用Quartus II,因为它还有一个模拟功能,即“向量波形文件”模拟。
发布于 2017-08-18 07:55:48
好的,第一件事是第一件事,不要use IEEE.STD_LOGIC_ARITH.ALL;或use IEEE.STD_LOGIC_UNSIGNED.ALL。您应该使用use ieee.numeric_std.all,它为您提供使用signed和unsigned类型的算术,以及std_logic_vector和integer的强制转换和转换函数。
现在让我们看看您的代码:
if clk='1' and clk'event then -- error here
Y <= conv_std_logic_vector(conv_integer(A)/conv_integer(B),8);
err <= '0';
elsif B = 0 then
err <= '1';
end if;只看err信号,这意味着在上升的时钟边缘,将err设置为'0',否则,如果B = 0,则将err设置为'1'。您提到了这在仿真中有效,但是为了综合,您需要考虑这在实际硬件中意味着什么。你怎么想象没有时钟边缘被检测到的情况?答案是它不能。
目前还不清楚您到底想要实现什么,但是有两种可行的选择,即对上面的包进行了更改:
if rising_edge(clk) then -- Use rising_edge() function
Y <= std_logic_vector(signed(A)/signed(B));
err <= '0'; -- Synchronous clear of `err`
end if;
if signed(B) = 0 then -- Asynchronous set of `err`
err <= '1';
end if;或
if rising_edge(clk) then
Y <= std_logic_vector(signed(A)/signed(B));
if signed(B) = 0 then
err <= '1'; -- Synchronous control of `err`
else
err <= '0';
end if;
end if;如果您将端口的实际类型(即signed )提供给这些端口,那么代码将需要较少的类型转换。然后,您的流程的核心如下所示:
if rising_edge(clk) then
Y <= A / B;
if B = 0 then
err <= '1'; -- Synchronous control of `err`
else
err <= '0';
end if;
end if;我希望你能看到这是多么容易阅读。
https://stackoverflow.com/questions/45748035
复制相似问题