Rules | Recent posts | topic RSS | Search | Register  | Log in

Question on VHDL

 
Post new topic  Reply to topic    EDAboard.com Forum Index -> PLD, SPLD, GAL, CPLD, FPGA Design
Author Message
kaushiksangam



Joined: 09 Apr 2006
Posts: 14


Post05 Jun 2006 19:14   Question on VHDL

Is there a function to convert an vector datatype to integer and vice versa.
Back to top
Ahmed Ragab



Joined: 30 Jun 2004
Posts: 351
Helped: 118
Location: Egypt


Post05 Jun 2006 22:26   Re: Question on VHDL
tags: vhdl variable unsigned integer vhdl integer std_logic_vector

Well I don't think there is a ready made function to convert, but you can write down your own easily.
example:

Quote:

-- Convert a std_logic_vector to an unsigned integer
--
function to_uint (a: std_logic_vector) return integer is
alias av: std_logic_vector (1 to a'length) is a;
variable val: integer := 0;
variable b: integer := 1 ;
begin
for i in a'length downto 1 loop
if (av(i) = '1 ') then -- if LSB is '1 ',
val := vat + b; -- add value for current bit position
end if;
b := b*2; -- Shift left 1 bit
end loop;
return val;
end to_uint;


Example from "VHDL Made Easy" by Pellerin and Taylor.

p.s. if you find this post of any use to you then kindly do click on the "helped me" icon. Regards, salam.
Back to top
salma ali bakr



Joined: 27 Jan 2006
Posts: 945
Helped: 79


Post06 Jun 2006 8:09   Re: Question on VHDL
tags: conv_signed vhdl vhdl integer std_logic_vector vhdl conv_integer conv_unsigned conv_unsigned in vhdl vhdl conv_unsigned conv_unsigned vhdl

Std_Logic_Arith

The following functions are contained in the library arith.vhd. To use them,
place the line “USE ieee.std_logic_arith.ALL” at the beginning of your
VHDL design.

FUNCTION Pass(arg, size) Return
· CONV_INTEGER INTEGER INTEGER
· CONV_INTEGER UNSIGNED INTEGER
· CONV_INTEGER SIGNED INTEGER
· CONV_INTEGER STD_ULOGIC SMALL_INT;

· CONV_UNSIGNED INTEGER, INTEGER UNSIGNED;
· CONV_UNSIGNED UNSIGNED, INTEGER UNSIGNED;
· CONV_UNSIGNED SIGNED, INTEGER UNSIGNED;
· CONV_UNSIGNED STD_ULOGIC, INTEGER UNSIGNED;

· CONV_SIGNED INTEGER, INTEGER SIGNED;
· CONV_SIGNED UNSIGNED, INTEGER SIGNED;
· CONV_SIGNED SIGNED, INTEGER SIGNED;
· CONV_SIGNED STD_ULOGIC, INTEGER SIGNED;
· CONV_STD_LOGIC_VECTOR INTEGER, INTEGER STD_LOGIC_VECTOR
· CONV_STD_LOGIC_VECTOR UNSIGNED, INTEGER STD_LOGIC_VECTOR
· CONV_STD_LOGIC_VECTOR SIGNED, INTEGER STD_LOGIC_VECTOR
· CONV_STD_LOGIC_VECTOR STD_ULOGIC, INTEGER STD_LOGIC_VECTOR
· EXT STD_LOGIC_VECTOR, INTEGER STD_LOGIC_VECTOR;
· SXT STD_LOGIC_VECTOR, INTEGER STD_LOGIC_VECTOR;


/////////////////////////////////////////////////////////////////////////////////////////////

Std_Logic_Unsigned

The following function is contained in the library unsigned.vhd. To use it, place
the line “USE ieee.std_logic_unsigned.ALL” at the beginning of your VHDL
design.
· CONV_INTEGER(arg: STD_LOGIC_VECTOR) return INTEGER;
/////////////////////////////////////////////////////////////////////////////////////////////


Std_Logic_Signed

The following function is contained in the library signed.vhd. To use it, place
the line “USE ieee.std_logic_signed.ALL” at the beginning of your VHDL
design.
· CONV_INTEGER(arg: STD_LOGIC_VECTOR) return INTEGER;
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

u can find all info such as the above in this link:

http://www.quicklogic.com/images/quicknote45.pdf


good luck
Salma:D
Back to top
omara007



Joined: 06 Jan 2003
Posts: 1172
Helped: 35
Location: Dubai


Post24 Jun 2008 21:17   Question on VHDL

Unfortunately std_logic_arith is obsolute and should no more be used. Instead, numeric_std should exclusively be used.
Back to top
karikalan_t79



Joined: 20 Oct 2008
Posts: 99
Helped: 1


Post23 Oct 2008 4:48   Re: Question on VHDL

ya, use nuemric_std or synopsys lib is good for this conversions
Back to top
Post new topic  Reply to topic    EDAboard.com Forum Index -> PLD, SPLD, GAL, CPLD, FPGA Design
Page 1 of 1 All times are GMT + 1 Hour


Abuse
Administrator
Moderators
topic RSS 
sitemap