我正在用VHDL编写代码,将其合成到XilinX FPGA上。我通常使用GHDL来模拟我的测试台。为了除以变量,我需要使用XilinX除法核心,但是我不知道如何做到这一点,因为在XilinX文档中似乎没有示例。我是否必须使用XilinX软件来为除法器生成VHDL组件?还是XilinX隐式地理解除法器意味着使用IP核?如果我的第二句话是真的,我将如何使用GHDL进行模拟,或者我是否需要使用XilinX模拟工具?我真的可以用一个最小的例子来使用XilinX除法器核心来通过变量来实现除法,例如:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_1164.all;
entity DividingExample is
port (
clk : in std_logic;
reset : in std_logic;
InputSignal : in std_logic_vector(15 downto 0);
OutputSignal : out std_logic_vector(15 downto 0)
);
end DividingExample;
architecture behaviour of DividingExample is
-- declarations
signal numerator : integer;
begin
-- behaviour
process(clk)
begin
if(rising_edge(clk)) then
if(reset = '1') then
-- reset values
numerator <= 1000;
else
-- calculate value to be output
OutputSignal <= numerator/to_integer(signed(InputSignal))
end if;
end if;
end process;
end behaviour;这个示例代码显然不工作,因为除法( '/‘操作符)不是为整数数据类型定义的。我该怎么做?
发布于 2017-01-18 10:33:30
最后,我编写了自己的部门代码,这比使用XilinX的IP Core要快得多,实现起来也容易得多。我使用了二进制除法算法详细的这里,并为一个签名的32位除法编写了以下VHDL代码:
function Divide(N : signed(31 downto 0); D : signed(31 downto 0)) return signed is
variable Q : signed(31 downto 0) := to_signed(0, 32);
variable R : signed(31 downto 0) := to_signed(0, 32);
variable l : line;
constant N_Abs : signed(31 downto 0) := abs(N);
constant D_Abs : signed(31 downto 0) := abs(D);
begin
-- behaviour
for i in N_Abs'high downto 0 loop
R := shift_left(R, 1);
R(0) := N_Abs(i);
if R >= D_Abs then
R := R - D;
Q(i) := '1';
end if;
end loop;
if ((N < 0 and D > 0) or (N > 0 and D < 0)) then
return -Q;
else
return Q;
end if;
end function;https://stackoverflow.com/questions/41241377
复制相似问题