Altera_Forum
Honored Contributor
12 years agodividing to 32bit signed integers with ieee_fixed_pkg -> error
Hello everyone,
I am trying to divide two 32 bit signed integer signals (see code below). I am using the fixed point package from bishop, which invokes the lpm_divide megafunction. When compiling the following error occurs: Error (272006): In lpm_divide megafunction, LPM_WIDTHN must be less than or equals to 64 This tells me that the width of the numerator exceeded 64 bits, however the width of signal as is 32 bits. Could someone please tell me what I am doing wrong? Would you recommend to divide signals like this or are there better ways of doing this? I am grateful for your advices.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
-- ----------------------------------------------------------------
entity fixed_pkg_example is
port (
rstN : in std_logic;
clk : in std_logic;
a : in std_logic_vector(31 downto 0);
b : in std_logic_vector(31 downto 0);
div_out : out std_logic_vector(31 downto 0)
);
end entity;
-- ----------------------------------------------------------------
architecture behave of fixed_pkg_example is
signal as : sfixed(31 downto 0);
signal bs : sfixed(31 downto 0);
signal divs : sfixed(sfixed_high(as,'/',bs) downto sfixed_low(as,'/',bs));
begin
-- Type conversions
as <= to_sfixed(a,as'high,as'low);
bs <= to_sfixed(b,bs'high,bs'low);
-- calculation
divs <= as / bs;
-- resize to meet output signal width
div_out <= to_slv(resize(divs,31,0));
end architecture;