Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Division of an integer by a real number using VHDL

 
Thread Tools Search this Thread
Old 03-29-2005, 10:24 PM   #1
Default Division of an integer by a real number using VHDL


Hi,

Is there a way to divide an integer by a real number(decimal number).

Can we simply use the operator '/' as follows:
eg: a <= 1234/ 1.36;
where we define 'a' as an integer.

Are there any specific libraries to be included for such a VHDL design
file.

If so, should these libraries be included in a particular order?

Thankyou



genlock
  Reply With Quote
Old 03-29-2005, 11:06 PM   #2
Brad Smallridge
 
Posts: n/a
Default Re: Division of an integer by a real number using VHDL
Can you give us a hint? If this is for a testbench then you
can easily do the division using varaibles. If this is hardware
then we need to know how fast and how big the vectors are.
Lookup tables are fast if the numbers are small.





Brad Smallridge
  Reply With Quote
Old 03-29-2005, 11:33 PM   #3
genlock
 
Posts: n/a
Default Re: Division of an integer by a real number using VHDL
This is not for a testbench.

Its for hardware which has to be implemented on a FPGA.

This division is a part of another code

I am basically trying to divide a 24 bit vector by 1.36.(output result
eventually being a bit vector)

I am first converting this 24 bit vector to an integer.

Was wondering if we can simply use the operator '/' for then dividing
the integer by 1.36.

Does the '/' operator need specific IEEE libraries to be included in
the design file.

If so, is there any particular order?

Thankyou.



genlock
  Reply With Quote
Old 03-30-2005, 12:34 AM   #4
dutchgoldtony
 
Posts: n/a
Default Re: Division of an integer by a real number using VHDL
Are you assuming the imput vector is going to be a multiple of 1.36?



dutchgoldtony
  Reply With Quote
Old 03-30-2005, 03:17 AM   #5
Brad Smallridge
 
Posts: n/a
Default Re: Division of an integer by a real number using VHDL
That's tough. More like microprocessor work than FPGA.
Can't help you but I do know that there is no / operator in
VHDL that will do it on "real" signals. I suggest you do a
Google search on Xilinx (or whatever you are using) and
division and see what pops up. Perhaps other people in this
comp.fpga group can be more help.

b r a d @ a i v i s i o n . c o m





Brad Smallridge
  Reply With Quote
Old 03-30-2005, 04:28 AM   #6
Hal Murray
 
Posts: n/a
Default Re: Division of an integer by a real number using VHDL
>I am basically trying to divide a 24 bit vector by 1.36.(output result
>eventually being a bit vector)


One trick is to multiply by the inverse.

--
The suespammers.org mail server is located in California. So are all my
other mailboxes. Please do not send unsolicited bulk e-mail or unsolicited
commercial e-mail to my suespammers.org address or any of my other addresses.
These are my opinions, not necessarily my employer's. I hate spam.



Hal Murray
  Reply With Quote
Old 03-30-2005, 07:53 AM   #7
Ralf Hildebrandt
 
Posts: n/a
Default Re: Division of an integer by a real number using VHDL
genlock wrote:


> I am basically trying to divide a 24 bit vector by 1.36.(output result
> eventually being a bit vector)


Don't divide by 1.36, but multiply by 1/1.36. Multiplication is much easier.

Am I right, that you have a constant factor? Then multiplication is very
easy. It becomes only a series of additions (and shifts).

The fractional number should not be used in floating point format but in
fixed point format with the accuracy you need. Remember that within some
bounds of accuracy a number can be given with:
2^n + ... + 2^1 + 2^0 + 2^(-1) + 2^(-2) + ... + 2^(-m)

Then your problem is nothing more than normal integer multiplication by
a constant value, which can be greatly optimized using even the normal
"*" Operator.


> I am first converting this 24 bit vector to an integer.


No. A vector is much better (signed or unsigned is suitable). Extend
this vector by some zeros to the left to have a fractional part.
Use a constant with the same bitwidth (also signed or unsigned),
representing 1/1.36 with your desired accuracy using the above mentioned
fixed point scheme.



Addition: This multiplication will be represented by several additions.
Pipelining is possible, if needed for speed or lower area.

Ralf


Ralf Hildebrandt
  Reply With Quote
Old 03-30-2005, 10:19 AM   #8
Mohammed A khader
 
Posts: n/a
Default Re: Division of an integer by a real number using VHDL
HI Ralf,

> Extend this vector by some zeros to the left to have a fractional

part.

Suppose y is the integer variable which can be represented in 8 bit
as <8.0> format, and 1/1.36 = 0.73529 is represented in 16 bits as
<1.15> format. Then under such conditions multiplication can be done
between unsymmetrical formats i.e. format of <8.0> * <1.15> gives
<9.15>. I think there is no need to pad the integer to represent
fractional part. Correct me if I am going wrong.

Thanks a lot.

-- Mohammed A Khader.



Mohammed A khader
  Reply With Quote
Old 03-30-2005, 11:46 AM   #9
Ralf Hildebrandt
 
Posts: n/a
Default Re: Division of an integer by a real number using VHDL
Mohammed A khader wrote:


>>Extend this vector by some zeros to the left to have a fractional
>> part.

>
> Suppose y is the integer variable which can be represented in 8 bit
> as <8.0> format, and 1/1.36 = 0.73529 is represented in 16 bits as
> <1.15> format. Then under such conditions multiplication can be done
> between unsymmetrical formats i.e. format of <8.0> * <1.15> gives
> <9.15>. I think there is no need to pad the integer to represent
> fractional part. Correct me if I am going wrong.


Do you mean

result <= integer_signal * unsigned_constant;

while unsigned_constant is in <9.15> format? Well - seems to be a good
option (I have no simulator at hand to check ist). I was thinking of
something like

result <= unsigned_signal * unsigned_constant;

and there adding a (zero) fractional part is nessecary. But your
solution seems to be more elegant.

Ralf


Ralf Hildebrandt
  Reply With Quote
Old 03-30-2005, 12:14 PM   #10
Mohammed A khader
 
Posts: n/a
Default Re: Division of an integer by a real number using VHDL
Hi Ralf,

I mean result <= unsigned_signal * unsigned_constant;

but no need to adjust the fixed point as it is needed in addition.
'unsigned_signal' should'nt be of same format as 'unsigned_constant'.

Even in ieee.numeric_std standard, ' * ' fucntion is defined to
handle
unsymetrical input vectors.

For result <= integer_signal * unsigned_constant;

if ' integer_signal' is defined with appropriate range limits then it
is equivalent to the other.

-- Mohammed A Khader.



Mohammed A khader
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
VHDL differential equations, multiplication division by powers of 10 boer Hardware 0 04-24-2009 12:28 PM
Division by repeated multiplication VHDL stevebarly Software 0 05-21-2008 11:11 AM
ARRAY(n DOWNTO 0) OF STD_LOGIC_VECTOR(m DOWNTO 0) - VHDL freitass Hardware 0 11-01-2007 03:44 PM
Fast Integer Division In Vhdl Vitrion Hardware 0 11-01-2007 07:33 AM
New Releases: Troy, Ultimate Matrix & status changes: Updated complete downloadable R1 DVD DB & info lists Doug MacLean DVD Video 1 08-31-2004 01:02 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46