You have to remember that a std_logic_vector is not a number, or integer, or signed, or real or any other type of number. It is just a collection of bits. So actually you are not assigning it with a binary number, or hex, it is a string ("00101001", x"FFAA", o"1745" etc..).
If you want to assign integers, you need to convert an integer from the integer type to a std_logic_vector. but there is one main problem with treating a std_logic_vector as an integer: Is it signed or unsigned?
To get round this, there is the package called numeric_std (an IEEE standard) that defines a signed and unsigned type that are very similarly to std_logic_vector but there are functions to treat them as integers.
Before you get started - I really really really recommend you stop using std_logic_unsigned, std_logic_signed or std_logic_arith. They are non-standard libraries. Numeric_std is the real standard, and if you start using more advanced libraries (like the fixed point libraries) they are incompatible. So stick with numeric_std. because conv_std_logic_vector is part of this non-standard library, you should NOT use it.
Because numeric_std defines signed and unsigned types, there is no need to use a std_logic_vector if what you want is an unsigned. There is also nothing wrong with using an integer. If you want an integer, use an integer.
signal a : integer range 0 to 1023 --limit to 10 bits
a <= 10;
then, if you really really have to convert it to a std_logic_vector
slv <= std_logic_vector( to_unsigned( a, 10) );
but like I said, there is nothing wrong with using integers, unsigned, boolean or any other type on a port definition, just make sure you stick with array types (including signed and unsigned) at the top level.
Here is an example that will work and synthesise perfectly fine:
Code:
entity port_ex is
port (
a : in std_logic;
b : in boolean;
c : in integer range 4 to 77;
d : out signed(7 downto 0);
e : out std_logic_vector(33 downto 23);
--and for fixed types:
f : out sfixed(7 downto -7)
);
end entity port_ex;
---------- Post added at 11:37 ---------- Previous post was at 11:36 ----------
well in define of
constant constant8: std_logic_vector(15 downto 0) := 20000;
the vhdl take error.:sad:
what should i do????
constant constant8: std_logic_vector(15 downto 0) := std_logic_vector( to_unsigned(20000, 16) );