【问题标题】:How to use the Xilinx Division IP Core如何使用 Xilinx Division IP 核
【发布时间】:2016-12-20 11:33:24
【问题描述】:

我正在用 VHDL 编写代码以合成到 XilinX FPGA 上。我通常使用 GHDL 来模拟我的测试平台。我需要使用 XilinX 除法核心来除以变量,但是我不确定如何执行此操作,因为 XilinX 文档中似乎没有示例。我是否必须使用 XilinX 软件为分频器生成 VHDL 组件?或者赛灵思是否隐含地理解分频器意味着使用 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;

这个示例代码显然不起作用,因为除法('/' 运算符)没有为整数数据类型定义。我该怎么办?

【问题讨论】:

标签: vhdl fpga xilinx divider


【解决方案1】:

我最终编写了自己的除法代码,与使用 XilinX 的 IP 核相比,它的实施速度明显更快、更容易。我使用了详细的二进制除法算法here 并为带符号的 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;

【讨论】:

    猜你喜欢
    • 2023-04-08
    • 1970-01-01
    • 2021-04-11
    • 2022-10-05
    • 1970-01-01
    • 1970-01-01
    • 2010-12-21
    • 2021-08-24
    • 1970-01-01
    相关资源
    最近更新 更多