Yes. The floating point library at www.vhdl.org/fphdl has a to_slv function.
library IEEE;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
use IEEE.STD_LOGIC_1164.all;
use ieee.numeric_std.all;
package MDWT_PKG is
-- 2's complement numbers
constant h0 : sfixed(3 downto -4) := 0.483;
constant h1 : sfixed(3 downto -4) := 0.837;
constant h2 : sfixed(3 downto -4) := 0.224;
constant h3 : sfixed(3 downto -4) := -0.129;
you need to use the to_sfixed function to convert the real number to an sfixed type.
library IEEE;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
use IEEE.STD_LOGIC_1164.all;
use ieee.numeric_std.all;
package MDWT_PKG is
signal n1 : sfixed(3 downto -4);
signal n2 : sfixed(4 downto -4);
-- 2's complement numbers
constant h0 : sfixed(3 downto -4) := to_sfixed(0.483,n1);
constant h1 : sfixed(3 downto -4) := to_sfixed(0.837,n1);
constant h2 : sfixed(3 downto -4) := to_sfixed(0.224,n1);
constant h3 : sfixed(4 downto -4) := to_sfixed(-0.129,n2);
type ROM_TYPE is array (0 to (2**ROMADDR_W)-1)
of STD_LOGIC_VECTOR(13 downto 0);
constant rom : ROM_TYPE :=
( --error occur at this line
(others => '0'),
to_slv( h0 ),
to_slv( h1 ),
to_slv( h0+h1 ),
to_slv( h2 ),
to_slv( h2+h0 ),
to_slv( h2+h1),
to_slv( h2+h1+h0 ),
to_slv( h3 ),
to_slv( h3+h0),
to_slv( h3+h1),
to_slv( h3+h1+h0 ),
to_slv( h3+h2),
to_slv( h3+h2+h0 ),
to_slv( h3+h2+h1 ),
to_slv( h3+h2+h1+h0),
If you declared h0-h3 as sfixed, you need to know that h0 + h1 will produce a result that is 1 bit larger. You need to resize the result with the resize function.
type ROM_TYPE is array (0 to (2**ROMADDR_W)-1)
of STD_LOGIC_VECTOR(13 downto 0);
constant rom : ROM_TYPE :=
(
(others => '0'),
to_slv( h0 ),
to_slv( h1 ),
STD_LOGIC_VECTOR(RESIZE(RESIZE(SIGNED(to_slv( h0)),ROMDATA_W))+(RESIZE(SIGNED(to_slv(h1))),ROMDATA_W)),
to_slv( h2 ),
CONSTANT H0 : real := 0.483;
....etc
CONSTANT H0_FP : sfixed(3 downto -4) := to_sfixed(H0, 3, -4);
..etc
...in the ROM Constant
to_slv( to_sfixed( H0 + H1, H0'high, H0'low) ),
--etc
type ROM_TYPE is array (0 to (2**ROMADDR_W)-1)
of STD_LOGIC_VECTOR(13 downto 0);
constant rom : ROM_TYPE :=
(
(others => '0'),
to_slv( h0_FP ),
to_slv( h1_FP ),
to_slv(to_sfixed(h0+h1,h0'high,h0'low )),
to_slv( h2_FP ),
to_slv(to_sfixed(h2+h0,h2'high,h2'low)),
to_slv(to_sfixed(h0+h1,h0_FP'high,h0_FP'low )),
thats because 'high and 'low attributes can only be used on array types, not on real types.
Yes, you are right. Thanks TrickyDicky! :smile:
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?