Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Convert Real number to Std_logic_vector

Reply
Thread Tools

Convert Real number to Std_logic_vector

 
 
Sudhir
Guest
Posts: n/a
 
      02-03-2007
Hi

I Have 2 constant values nu= 3.131764231e-3
and v = 0.993736471

Later on in my VHDL code I have to multiply these with two values
which are std_logic_vectors of 20bits. So I would like to convert
these constants to vectors of 20 bits without losing precision.How
could I do so in VHDL

tried to do conv_std_logic_vector(nu,20); unfortunately it didnt work!

Please if anyone could help me I would be grateful

Thanks

Sudsy

 
Reply With Quote
 
 
 
 
KJ
Guest
Posts: n/a
 
      02-03-2007

"Sudhir" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi
>
> I Have 2 constant values nu= 3.131764231e-3
> and v = 0.993736471
>
> Later on in my VHDL code I have to multiply these with two values
> which are std_logic_vectors of 20bits. So I would like to convert
> these constants to vectors of 20 bits without losing precision.How
> could I do so in VHDL

You can't. The real numbers are represented with more than 20 bits of
precision so converting them to 20 std_logic_vectors will result in lost
precision.

>
> tried to do conv_std_logic_vector(nu,20); unfortunately it didnt work!

Because you can't convert a real to a std_logic_vector using this function.

>
> Please if anyone could help me I would be grateful
>

Convert the std_logic_vectors into real numbers and keep the full precision
of your calculation.

Also since your attempt used the 'conv_std_logic_vector' this implies that
you're using the 'ieee.std_logic_arith' package. This package is not a
standard and really should not be used. Use the ieee.numeric_std package
instead and you'll save yourself some headaches down the road.

Kevin Jennings


 
Reply With Quote
 
 
 
 
David Bishop
Guest
Posts: n/a
 
      03-10-2007
Sudhir wrote:
> Hi
>
> I Have 2 constant values nu= 3.131764231e-3
> and v = 0.993736471
>
> Later on in my VHDL code I have to multiply these with two values
> which are std_logic_vectors of 20bits. So I would like to convert
> these constants to vectors of 20 bits without losing precision.How
> could I do so in VHDL
>
> tried to do conv_std_logic_vector(nu,20); unfortunately it didnt work!
>
> Please if anyone could help me I would be grateful


First off, these are real numbers. Real numbers don't synthesize.
Internally they are represented as 64 bit floating point numbers.

I would recommend using fixed point. Then you can convert the numbers
into something synthesizable.

http://www.vhdl.org/vhdl-200x/vhdl-2...ges/files.html
For the documentation.

For code to synthesize, look at:
http://www.vhdl.org/fphdl/vhdl.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to handle a real number in order to transport it to output in std_logic_vector thaosb VHDL 0 04-10-2009 06:59 AM
convert string number to real number - ValueError: invalid literal davidj411 Python 11 05-29-2008 12:02 AM
inout std_logic_vector to array of std_logic_vector of generic length conversion... Thomas Rouam VHDL 6 11-09-2007 11:49 AM
how to convert real type to std_logic_vector ? jing VHDL 1 05-17-2006 05:41 PM
Convert from std_logic_vector to real eNo VHDL 2 08-09-2005 06:02 PM



Advertisments