Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to convert real value to logic vector in VHDL?

Status
Not open for further replies.

surisingh

Member level 1
Joined
Jun 14, 2007
Messages
32
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,499
Hi,

Can anyone tell me how to convert a real value (b/w +1.0 and -1.0) in VHDL into std_logic_vector(13 downto 0) and again revert back this std_logic_vector into real value.

I tried to write a function to convert these things,but it didn't work out for me.
Take an example of -0.000136114. I want to convert this real value into 14 bit vector and again convert this vector into real so that i have to get the final real value which should be equal to -0.000136114.

Suresh
 

real in vhdl

It can be done in simulation and as compile time operation for synthesis.

Code:
slv_val <= STD_LOGIC_VECTOR(CONV_SIGNED(INTEGER(r_val*8192.0),14));

r_val <= REAL(CONV_INTEGER(SIGNED(slv_val)))/8192.0;
 

vhdl real

Thanks.. But I tried with functions in VHDL. I got the same result in both my functions as well as the one you suggested. That is if i give -0.000136114 to real_to_vec then i am getting 14'h3FFF and if I give this value to vec_to_real, i am not getting -0.000136114, instead I am getting -0.00012207. Is it the expected one?
 

real vhdl

0,00012207 is 1/8192, the finest precision you can represent in 13 bit. As you first multiply by 8192, then round to the nearest integer, and then divide again, you get a roundoff error of 1 least significan bit, or 1/8192.

In other words: the result is as precise as it can get. Your starting value is -0.000136114, which is -1.115/8192. You round to -1/8192 by going from real to the fixed point integer representation. What else could one expect?
 

conv real vhdl

Thank you guys. I understand..

Regards,
CSuresh
 

Re: vhdl real

Thanks.. But I tried with functions in VHDL. I got the same result in both my functions as well as the one you suggested. That is if i give -0.000136114 to real_to_vec then i am getting 14'h3FFF and if I give this value to vec_to_real, i am not getting -0.000136114, instead I am getting -0.00012207. Is it the expected one?
is there any particluar library that needs to be included for doing this?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top