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.

[SOLVED] How to use real numbers in VHDL?

Status
Not open for further replies.

marcelos

Newbie level 4
Joined
Nov 4, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,355
Hi.

I'm working on a digital video evaluation project and trying to implement the evaluation process on a FPGA using VHDL.

The problem is: the equations that our project uses to rate the videos are a bit complex, with a lot of multiplications (of positive and negative numbers with decimal units) and also a exponential.

I try to simulate the code but the Quartus II compiler doesn't accept to compile a variable of the REAL type. And of course I can't work with just INTEGERs.

So the question (for now) is: how to use real/float/double numbers in a VHDL code and synthetize it? I've done some research and found some stuff about a library called ieee_proposed, but I have not been able to use it.

Thanks for any help.
 

Dear marcelos,

numbers of type REAL are not synthesizable on real hardware. You have to use floating-point numbers instead. The IEEE 754 standard defines floating points numbers as sign-extended bit vectors with a mantissa (23 bits) and an exponent (8 bits) for the 32-bits case. You have to use these if you want a synthesizable design.

Cheers
 

Dear marcelos,

numbers of type REAL are not synthesizable on real hardware. You have to use floating-point numbers instead. The IEEE 754 standard defines floating points numbers as sign-extended bit vectors with a mantissa (23 bits) and an exponent (8 bits) for the 32-bits case. You have to use these if you want a synthesizable design.

Cheers

I see. But how do I implement this on the VHDL code? Is there a library with the IEEE 754 standard pre-defined, that creates a FLOAT type?

I thought that it would be really easy to work with numbers like these on VHDL, but the more I search about the more I get lost.
 

You should first check if floating-point is required, or fixed-point is enough for your purposes. There are some real efforts in making VHDL and packages for synthesizable floating-point and fixed-point operations: take a look at the following link, it should contain appropriate information:

**broken link removed**

Cheers
 
If you really have to use floating point, you will need to use the floating point cores provided by Altera or Xilinx. They have a long latency (the divider and square root are the of the order of 25+ clock cycles) but they are pipelined so can be clocked quick.

But do you really need floating point? fixed point is usually more than anyone needs. Fixed point is really just integer arithmatic.
 
You should first check if floating-point is required, or fixed-point is enough for your purposes. There are some real efforts in making VHDL and packages for synthesizable floating-point and fixed-point operations: take a look at the following link, it should contain appropriate information:

**broken link removed**

Cheers

I have seen this link before. I had some issues on compiling the library, but I will try harder.

If you really have to use floating point, you will need to use the floating point cores provided by Altera or Xilinx. They have a long latency (the divider and square root are the of the order of 25+ clock cycles) but they are pipelined so can be clocked quick.

But do you really need floating point? fixed point is usually more than anyone needs. Fixed point is really just integer arithmatic.

Didn't really thought about that. I've said floating-point because of the common FLOAT type in C and other languages. More a matter of common use.
But I think that fixed point is enough. I have to do calculations like this one:

x = 1 + (-0.6345/(1+exp((0.3193*2.3666) + (-106.8397*0.0545) + (1.6123*2.5190) + (-0.2291*11.8461) + (0.8980*3.6648) + (-18.7552*0.3128+5.2098))))

So I think that fixed-point is enough for me. Is it easier to implement than floating?
 

fixed point is WAY easier to implement, because its just integer arithmatic with a 2^n offset. have a read of the fixfloatlib in the link that kingslayer posted
 
So I think that fixed-point is enough for me. Is it easier to implement than floating?
A lot easier. Fixed point arithmetic can be implemented with ieee.fixed_pkg_c. In contrast to the ieee float package it's well synthesizable. The float package is more in an experimental state, demonstrating the concept. But it doesn't synthesize to pipelined logic, which is absolutely required for reasonable speed.
 
Thanks for all the answers. I'm still having some issues.

I have added the files of the fixed-point arithmetic to the project, like **broken link removed** says (I'm using the same version of Quartus) and added the lines
use ieee.fixed_float_types.all;
use ieee.fixed_pkg.all;
like the user guide **broken link removed** says, but it seems to not recognize the type, as the error message states:

Error (10482): VHDL error at Project.vhd(79): object "sfixed" is used but not declared

Any ideas of what I'm not catching?
 

The package sources must be either added to the project or the Quartus library folder.
 
Thanks to everyone who helped. I've managed to use the fixed-point package from **broken link removed** which also has a math pack with a exponential function, what will also be very useful.

The problem is that you can't see clearly the numbers you are working with, because the package works with binary set (6.5 = 0011010000, for example). But well, I guess I will have to live with that, at least for now.
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top