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 use Floating Point Operator...

Status
Not open for further replies.

juansiahaan

Junior Member level 2
Joined
May 14, 2012
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,581
Hi everyone,

I have a 12 bit signal and I want to multiply this to a 32-bit floating point...in ISE there is an FP operator...but the problem is that both inputs require 32-bits....so how do I adjust my signal so that it can be multipllied by the 32-bit floating point?

Regards,

Juan
 

you need to convert the 12 bit integer to floating point in a convert block. why do you need floating point anyway? fpgas work better with fixed point.
 

you need to convert the 12 bit integer to floating point in a convert block. why do you need floating point anyway? fpgas work better with fixed point.

what's the significant difference between them?
 

Well Floating point is difficult to deal with as TrickyDicky said

I too was working on it and every time I had to change a little logic or found a little change to be made in my program, I find it hectic,
So I quit the idea and hence fixed point worked well...

Any ways you can find the difference between the two using google :) since there is lots of stuff present.

With regards to converting converting your input to 32 bit you can concatenate 20 ZEROS on the MSBs ( verilog has concatenating and replicating function, utilize it). But even then it
will not be a floating point rather a fixed point number, you have to completey change your number to floating point using fixed-to-floating pt IP
 
Well Floating point is difficult to deal with as TrickyDicky said

I too was working on it and every time I had to change a little logic or found a little change to be made in my program, I find it hectic,
So I quit the idea and hence fixed point worked well...

Any ways you can find the difference between the two using google :) since there is lots of stuff present.

With regards to converting converting your input to 32 bit you can concatenate 20 ZEROS on the MSBs ( verilog has concatenating and replicating function, utilize it). But even then it
will not be a floating point rather a fixed point number, you have to completey change your number to floating point using fixed-to-floating pt IP

Hi Shan,

I also had the idea of concatenating but again I also told myself that maybe I have to change that to a floating point-again....

So is it better to convert the floating-points to fixed points (in terms of easiness) and then from the fixed-points I take the 12-bit LSBs again?

By the way I'm using VHDL...if I'm about to concatenate 20 zeroes on the MSBs, do I write them like this:

A <= "00000000000000000000" & A; or the other way around...

and when I use that zero adding (like the example above), I receive warnings about 0 constant value...how do I remove that? I don't really like looking at those warnings though they're expected...

Regards,

Juan
 

Well I dont have much idea of VHDL since I work on verilog,

Yes to me it is the good idea of converting floating point to fixed point. Well in fix-point if you should know how many bits you have for integer and how many for fraction in your design.
This way you should decide your operation. e.g. if you have no fraction point than no need to worry at all just multiply like normal operation else you have to manipulate little things
either before or after operation ( can't think of now...:) all mention in the link I have given )

You have better understanding reading **broken link removed**

Cheers
Shan
 
Last edited:

Well I dont have much idea of VHDL since I work on verilog,

Yes to me it is the good idea of converting floating point to fixed point. Well in fix-point if you should know how many bits you have for integer and how many for fraction in your design.
This way you should decide your operation. e.g. if you have no fraction point than no need to worry at all just multiply like normal operation else you have to manipulate little things
either before or after operation ( can't think of now...:) all mention in the link I have given )

You have better understanding reading **broken link removed**

Cheers
Shan


Currently I have to use the numbers like 0.1, 6.51E-5 and such as my multplier/comparator therefore I have to do fixed to float and then float to fixed as the output...but I was wondering, can I directly convert my 12-bit signal into a floating-point since it's possible to customize the integer width and fraction width...for example I assign 12 for the integer width and 0 for fraction width...

---------- Post added at 13:01 ---------- Previous post was at 12:56 ----------

not really..but unfortunately now I have to deal with fractions and stuffs..

---------- Post added at 13:04 ---------- Previous post was at 13:01 ----------

not really..but unfortunately now I have to deal with fractions and stuffs..
 
Last edited:

Currently I have to use the numbers like 0.1, 6.51E-5 and such as my multplier/comparator therefore I have to do fixed to float and then float to fixed as the output...but I was wondering, can I directly convert my 12-bit signal into a floating-point since it's possible to customize the integer width and fraction width...for example I assign 12 for the integer width and 0 for fraction width...


Floating point is not simple. You HAVE to use the floating point IP blocks for conversion and arithmatic, because they have a high latency and large resource usage. Fixed point on the other hand is the same as integer maths, so has very low latency and uses very little resources.

0.1 and 0.000065 can easily be done in fixed point. You just need to make sure you chose enough bits to cover the smallest fractions.
 
Yes TrickDicky,

When I'm operating with floating points it is taking large resources of the FPGA I'm using....well, fixed-points it is...

---------- Post added at 13:37 ---------- Previous post was at 13:34 ----------

Yes TrickDicky,

When I'm operating with floating points it is taking large resources of the FPGA I'm using....well, fixed-points it is...

---------- Post added at 14:49 ---------- Previous post was at 13:37 ----------

Floating point is not simple. You HAVE to use the floating point IP blocks for conversion and arithmatic, because they have a high latency and large resource usage. Fixed point on the other hand is the same as integer maths, so has very low latency and uses very little resources.

0.1 and 0.000065 can easily be done in fixed point. You just need to make sure you chose enough bits to cover the smallest fractions.

So if I convert those small numbers to a fixed-point, is it enough? Do I have to do any conversion whatsoever to my 12 bit signal?

---------- Post added at 14:50 ---------- Previous post was at 14:49 ----------

Floating point is not simple. You HAVE to use the floating point IP blocks for conversion and arithmatic, because they have a high latency and large resource usage. Fixed point on the other hand is the same as integer maths, so has very low latency and uses very little resources.

0.1 and 0.000065 can easily be done in fixed point. You just need to make sure you chose enough bits to cover the smallest fractions.

So if I convert those small numbers to a fixed-point, is it enough? Do I have to do any conversion whatsoever to my 12 bit signal?
 

No conversion necessary. You just need to keep track of the integer and fraction parts and make sure you have the bits aligned properly.
 
No conversion necessary. You just need to keep track of the integer and fraction parts and make sure you have the bits aligned properly.

TrickDicky,

How do I know if my bits are aligned properly?
 

well you have to make sure you always zero pad the right direction.
If you know you have a 2.2 unsigned number
"11.01" = 3.25 (13 in integer)

and 3.1 number:
"110.1" = 6.5 (13 in integer)

If you simply add, without tracking the separation, you get

"11010" = 26

Which is incorrect. You need to zero pad the numbers

"01101" + "11010" = "1001.11" = 39 integer = 9.75

There is a VHDL package which takes care of all this for you. www.vhdl.org/fphdl
Otherwise you have to track this zero padding and integer/fraction separation manually in your code.
 

well you have to make sure you always zero pad the right direction.
If you know you have a 2.2 unsigned number
"11.01" = 3.25 (13 in integer)

and 3.1 number:
"110.1" = 6.5 (13 in integer)

If you simply add, without tracking the separation, you get

"11010" = 26

Which is incorrect. You need to zero pad the numbers

"01101" + "11010" = "1001.11" = 39 integer = 9.75

There is a VHDL package which takes care of all this for you. www.vhdl.org/fphdl
Otherwise you have to track this zero padding and integer/fraction separation manually in your code.

I have downloaded the source codes for the Xilinx 11.1 (though I'm using 13.2) and followed the instructions within the documentation....however I still couldn't use the proposed library and now in my project hierarchy there's a folder icon named "Unassigned User Library Module"...how can I use the new library? And does that mean the use.IEEE.STD_LOGIC_1164.ALL; etc. are still necessary? Sorry but this is my first time of using user library...
 

yes, you still need std_logic_1164. That is the base type all the fixed point types are based on.
You need to include the source code in your project.

---------- Post added at 13:53 ---------- Previous post was at 13:52 ----------

Im not a Xilinx person so cant really help with ISE much - sorry.
 

yes, you still need std_logic_1164. That is the base type all the fixed point types are based on.
You need to include the source code in your project.

---------- Post added at 13:53 ---------- Previous post was at 13:52 ----------

Im not a Xilinx person so cant really help with ISE much - sorry.

That's OK...

But which source code do you mean that I should include in my project? is it the one that has only these lines?

Code:
-- --------------------------------------------------------------------
-- "fixed_float_types" package contains types used in the fixed and floating
-- point packages..
-- Please see the documentation for the floating point package.
-- This package should be compiled into "ieee_proposed" and used as follows:
--
--  This verison is designed to work with the VHDL-93 compilers.  Please
--  note the "%%%" comments.  These are where we diverge from the
--  VHDL-200X LRM.
--
-- --------------------------------------------------------------------
-- Version    : $Revision: 1.21 $
-- Date       : $Date: 2007-09-11 14:52:13-04 $
-- --------------------------------------------------------------------

package fixed_float_types is

  -- Types used for generics of fixed_generic_pkg
  
  type fixed_round_style_type is (fixed_round, fixed_truncate);
  
  type fixed_overflow_style_type is (fixed_saturate, fixed_wrap);

  -- Type used for generics of float_generic_pkg

  -- These are the same as the C FE_TONEAREST, FE_UPWARD, FE_DOWNWARD,
  -- and FE_TOWARDZERO floating point rounding macros.

  type round_type is (round_nearest,    -- Default, nearest LSB '0'
                      round_inf,        -- Round toward positive infinity
                      round_neginf,     -- Round toward negative infinity
                      round_zero);      -- Round toward zero (truncate)

end package fixed_float_types;


And where should I put them? in my entity or Architecture or after the begin?

OK so I put the above code in my library declaration and I synthesized my project and it gave me error telling me "<std_logic> is not declared"...there are several more errors telling the same thing...why is that?? am I missing something?
 
Last edited:

dont simply copy/paste the code. add the files on their own
The error you get is because you didnt include std_logic_1164 package
 

dont simply copy/paste the code. add the files on their own
The error you get is because you didnt include std_logic_1164 package

Actually I have included the std_logic_1164 library...so in my library declaration I put this

Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

library IEEE_PROPOSED;
use IEEE_PROPOSED.fixed_float_types.ALL;

package fixed_float_types is

  -- Types used for generics of fixed_generic_pkg
  
  type fixed_round_style_type is (fixed_round, fixed_truncate);
  
  type fixed_overflow_style_type is (fixed_saturate, fixed_wrap);

  -- Type used for generics of float_generic_pkg

  -- These are the same as the C FE_TONEAREST, FE_UPWARD, FE_DOWNWARD,
  -- and FE_TOWARDZERO floating point rounding macros.

  type round_type is (round_nearest,    -- Default, nearest LSB '0'
                      round_inf,        -- Round toward positive infinity
                      round_neginf,     -- Round toward negative infinity
                      round_zero);      -- Round toward zero (truncate)

end package fixed_float_types;

And below them is my code...

What do you mean by putting the files 1 by 1? It seemed that the files were added automatically...

Or am I doing it wrongly??
 
Last edited:

you didnt actually say where the error pointed to. but it sounds like you've copied and pasted this code into your file. don't.
 

you didnt actually say where the error pointed to. but it sounds like you've copied and pasted this code into your file. don't.

So how can I use the library (putting the code into my file is wrong, right?)? The errors are pointed to my main file, saying that the std_logic is not declared. However, those warnings are gone if I remove the new library code. Are the libraries are automatically used?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top