Can anyone help,
How can I convert from Type Integer to Std_Logic_Vector ?
Thanks
Sent via Deja.com http://www.deja.com/
Before you buy.
<Std_Logic_Vector> <= CONV_STD_LOGIC_VECTOR(<interger_value>,n)
where n ist the number of bits your vector should have.....
cheers
davor
-- ---------------------------------------------- Davor Lukacic ASIC Design Engineer ---------------------------------------------- Robert Bosch GmbH Reutlingen, Dep. K8/EIC2 Development of Integrated Bipolar/MOS Asics P.O. Box 1342, D-72703 Reutlingen Tel: ++49-7121-35-4100 Fax: ++49-7121-35-2880 mailto:Davor....@bosch.com ----------------------------------------------
For example I use Cadence, and in their STD_LOGIC_ARITH package, I see
-- CONVERSION TO STD_LOGIC_VECTOR FROM INTEGER
function To_StdLogicVector (oper: INTEGER; length: NATURAL) return
STD_LOGIC_VECTOR;
You check with your library/package.
I would really suggest you NOT TO DO THE ABOVE as this is not portable
among tools. Better start using "numeric_std" package which is
"STANDARD"! In this case you must declare the "vector" to be either
"SIGNED" or "UNSIGNED" and use
"TO_INTEGER" conversion function.
Hope this helps.
Regards,
Srini
In article <86hqp1$h5t$1...@nnrp1.deja.com>, mwthw...@my-deja.com wrote:
> Can anyone help,
> How can I convert from Type Integer to Std_Logic_Vector ?
> Thanks
> Sent via Deja.com http://www.deja.com/
> Before you buy.
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
library IEEE;
use IEEE.STD_LOGIC_1164.all;
------------------------------------------------------------------------
-------------
package Conversion is
constant ZVec: std_logic_vector( 0 to 1 ) := (others => '0');
function INTEGER_TOSLV (ARG, SIZE: NATURAL) return std_logic_vector;
end Conversion;
------------------------------------------------------------------------
---------------
package body Conversion is
function INTEGER_TOSLV (ARG, SIZE: NATURAL) return std_logic_vector is
variable RESULT: std_logic_vector( SIZE - 1 downto 0 );
variable I_VAL: NATURAL := ARG;
begin
if ( SIZE < 1 ) then return ZVec;
end if;
for I in 0 to RESULT'LEFT loop
if ( I_VAL mod 2 ) = 0 then
RESULT(I) := '0';
else RESULT( I ) := '1';
end if;
I_VAL := I_VAL/2;
end loop;
if not( I_VAL =0 ) then
assert false
report "INTEGER_TOSLV: vector truncated"
severity WARNING;
end if;
return RESULT;
end INTEGER_TOSLV;
end Conversion;
Charles
> There is no *standard* conversion function for this (as far as I
> know), but every vendor provides a "std_logic_arith" package in >
> "their" IEEE library. This package normally contains the function
> that > you are looking for:
Use numeric_std. It is standard, and portable, and contains the
desired conversion function.
"Std_logic_arith" is non-standard and so can vary from vendor to
vendor....
Paul
--
Paul Menchini | me...@mench.com |"Outside of a dog, a book is
Cadence Design Systems | www.orcad.com | probably man's best friend, and
P.O. Box 71767 | 919-479-1670[v] | inside of a dog, it's too dark
Durham, NC 27722-1767 | 919-479-1671[f] | to read." --Groucho Marx
there are some pcakges in numeric or arith where there are
some functions to convert integer to std_logic _vector . he can use
for example
std_logic_vector < = CONV_STD_LOGIC_VECTOR( integer
range);
you can check this some vhdl book
hope this helps
kamal
Srinivasan Venkataramanan wrote:
> Hi,
> There is no *standard* conversion function for this (as far as
> I know), but every vendor provides a "std_logic_arith" package in
> "their" IEEE library. This package normally contains the function that
> you are looking for:
>
I completely agree with you. I would not use STD_LOGIC_ARITH. But I
thought numeric_std provides functions only to convert from UNSIGNED,
SIGNED to INTEGER (related to this context) and not directly from or to
STD_LOGIC_VECTOR. Of-course we could use an explicit type conversion
etc. That's why I wrote "there is no *standard* conversion function",
please correct me if I am wrong.
The solution is to use the fact that std_logic_vector is similar to both
signed and unsigned and so the built-in type-conversions between array
types can be used. Thus:
slv <= std_logic_vector(to_unsigned(i, slv'length));
In this case I've converted the integer i using an unsigned
representation, then converted it to the std_logic_vector type. I could
just as easily do a signed representaition:
slv <= std_logic_vector(to_signed(i, slv'length));
I would say that the original poster is probably doing something wrong
using std_logic_vectors anyway. Generally, all numeric values are best
represented as signed or unsigned where the sign convention is then
quite obvious and the possibility of error much less. This avoids all
these problems which create questions starting "how do I..." or "why
does...".
Andy