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

Reply

VHDL - Binary division

 
Thread Tools Search this Thread
Old 03-28-2005, 11:18 PM   #1
Default Binary division


I am trying to divide a 24 bit binary value by 2,4,8...for which I have
used the following syntax:

sample / "000000000000000000000010"

It keeps showing an error as follows :

/ can not have such operands in this context

Any suggestions welcome.

Thanks



genlock
  Reply With Quote
Old 03-28-2005, 11:44 PM   #2
info_
 
Posts: n/a
Default Re: Binary division
Did you simply try sample / 2 ????
If sample is signed or unsigned or integer range, it should work.
If not, simply do type conversions.

The "hardware orientated" guys (like me) would probably do a shift right...


genlock wrote:

> I am trying to divide a 24 bit binary value by 2,4,8...for which I have
> used the following syntax:
>
> sample / "000000000000000000000010"
>
> It keeps showing an error as follows :
>
> / can not have such operands in this context
>
> Any suggestions welcome.
>
> Thanks
>



info_
  Reply With Quote
Old 03-29-2005, 10:17 PM   #3
genlock
 
Posts: n/a
Default Re: Binary division
I tried sample / 2 but it keeps showing the same error.....sample is a
24 bit vector.

The point is that I have to divide this bit vector value by 1.122 in
which case , I cannot use a shift right operation.

What kind of type conversions are u referring to?

I tried converting the 24 bit binary to an integer but I need to divide
this integer by the value 1.122.

It shows the same error for using the operator '/'

Any suggestions

Thankyou



genlock
  Reply With Quote
Old 03-30-2005, 06:18 PM   #4
Bert Cuzeau
 
Posts: n/a
Default Re: Binary division
If you want to divide a 24 bits by a real (floating point) just with a
/, do you want the synthesizer to work this out, or do you need it only
in a test bench ?

In a test bench, no problem. Just write legal VHDL.
Like :
to_integer(unsigned(Sample)) / 2 (returns an integer) or :
real(to_integer(unsigned(sample))) / 1.122 which returns a real
etc...
unsigned() is a type conversion, to_integer() is a conversion.

For synthesis, the efficient method is different.
For example you could :
(to_integer(unsigned(sample)) * 7301 ) / 8192
Multiplying by a constant is easy to most synthesizers and efficiently
implemented (3 add/sub ?). Dividing by a power of 2 is trivial (no
hardware necessary).
For RTL, the solution is even smaller if you can spread the calculation
over 13 clock cycles (in the case above), so you will only need an
accumulator and a shiftregister.
This problem has a lot of solutions, well documented in many books.
Choose the one best suited to your needs and constraints.

Bert



Bert Cuzeau
  Reply With Quote
Old 03-31-2005, 06:59 PM   #5
genlock
 
Posts: n/a
Default Re: Binary division
Bert,
Thankyou very much for this technique.

I want the synthesizer to work and it is working when using the '/'
operator with powers of 2.

What library do I need to add in order to use the function: to_integer?
I need to convert the resultant integer back to a bit vector.

I am using the functions conv_integer and conv_std_logic_vector. I have
added the library
ieee.std_logic_signed.vhd for these functions.

Can you explain where I would need an accumulator and shift register...
I am using Xilinx ISE and coding in VHDL....I dont understnad the RTL
part you are talking about...

I am going to try this solution and see how it works....

Thankyou



genlock
  Reply With Quote
Old 03-31-2005, 11:21 PM   #6
info_
 
Posts: n/a
Default Re: Binary division
It's just an example. It can be further optimized.
It's a parallel full speed solution...

-- Divide a 24 bits unsigned by 1.122
-- Author : Bert Cuzeau
-- not overly optimzed (under 200 LCs)

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;

-- ---------------------------------------
Entity DIVBYR is -- Divide a 24 bits by 1.122
-- ---------------------------------------
Port ( Clk : In std_logic; -- Main System Clock
Rst : In std_logic; -- Asynchronous reset, active high
D : in unsigned (23 downto 0); -- use std_logic_vector !
Q : out unsigned (23 downto 0) -- use std_logic_vector !
); --
end;

-- ---------------------------------------
Architecture RTL of DIVBYR is
-- ---------------------------------------
begin

process (Rst,Clk)
begin
if Rst='1' then
Q <= (others=>'0');
elsif rising_edge (Clk) then
Q <= to_unsigned( (to_integer(D) * 7301 / 8192 ),24);
end if;
end process;

end RTL;


genlock wrote:

> Bert,
> Thankyou very much for this technique.
>
> I want the synthesizer to work and it is working when using the '/'
> operator with powers of 2.
>
> What library do I need to add in order to use the function: to_integer?
> I need to convert the resultant integer back to a bit vector.
>
> I am using the functions conv_integer and conv_std_logic_vector. I have
> added the library
> ieee.std_logic_signed.vhd for these functions.
>
> Can you explain where I would need an accumulator and shift register...
> I am using Xilinx ISE and coding in VHDL....I dont understnad the RTL
> part you are talking about...
>
> I am going to try this solution and see how it works....
>
> Thankyou
>



info_
  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
image (jpg,bmp,gif, etc.) convert to equivalent binary representation using vb.net? archieSupremo Software 0 09-06-2009 12:20 PM
Gi Hold Retail Division cafemingle@yahoo.se DVD Video 0 01-08-2008 01:21 AM
Fast Integer Division In Vhdl Vitrion Hardware 0 11-01-2007 07:33 AM
dvd in binary newsgroups gord1234@yahoo.com DVD Video 1 11-06-2005 09:46 AM
Counting In Binary Raymond A+ Certification 13 03-07-2004 07:28 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