FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > FPGA

FPGA comp.arch.fpga newsgroup (usenet)

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-29-2005, 07:43 PM
genlock
Guest
 
Posts: n/a
Default Dividing a 24 bit std_logic_vector by a decimal number

Hi,
Is there anywayz a 24 bit std_logic_vector can be divided by a decimal
number (eg: 1.36)using VHDL.

The quotient needs to be a 24 bit std_logic_vector as well.

I am currently using Xilinx ISE for implementing this division.

Any help is appreciated.

Thanks

Reply With Quote
  #2 (permalink)  
Old 03-29-2005, 08:08 PM
John_H
Guest
 
Posts: n/a
Default Re: Dividing a 24 bit std_logic_vector by a decimal number

First of all, is the decimal number constant?
If so, think multiplication. Embedded multipliers are quick and easy while
dividers are much more work.

Do you need a new result every 200 MHz clock or do you need to know the once
every 3 microseconds?


"genlock" <[email protected]> wrote in message
news:[email protected] oups.com...
> Hi,
> Is there anywayz a 24 bit std_logic_vector can be divided by a decimal
> number (eg: 1.36)using VHDL.
>
> The quotient needs to be a 24 bit std_logic_vector as well.
>
> I am currently using Xilinx ISE for implementing this division.
>
> Any help is appreciated.
>
> Thanks



Reply With Quote
  #3 (permalink)  
Old 03-29-2005, 09:20 PM
genlock
Guest
 
Posts: n/a
Default Re: Dividing a 24 bit std_logic_vector by a decimal number

Yes the decimal number is a constant value.

What do you mean by embedded multipliers?

Is there a VHDL code available for that or how do we go about coding
one.

I dont need a clock for this one.

Thankyou

Reply With Quote
  #4 (permalink)  
Old 03-29-2005, 09:59 PM
John_H
Guest
 
Posts: n/a
Default Re: Dividing a 24 bit std_logic_vector by a decimal number

I'm a Verilog guy and your question is for VHDL - it would be great if a
VHDL guy gould give the proper code snippets. The question is addressed in
general:

"genlock" <[email protected]> wrote in message
news:[email protected] ups.com...
> Yes the decimal number is a constant value.


For the example of division by 1.36, multiplying by (2^24/1.36) and taking
the 24 MSbits of the result, you get an "effective" division. If you
generate the "reciprical integer multiplier" from real literals and do a
type conversion to std_logic_vector, the multiply would follow as a simple
multiply. Then just shift or select the upper bits and you have your
result.

> What do you mean by embedded multipliers?


The modern FPGAs tend to have multipliers as part of the logic fabric.
You're using ISE so my expectation is you're using a
Virtex(-E)Virtex-II(Pro), Virtex-4, Spartan-II(E), or Spartan-3/3L/3E.
These should all have multipliers if memory serves me right. Check the data
sheets.

> Is there a VHDL code available for that or how do we go about coding
> one.


I'd like to see someone on this newsgroup provide you a snippet to do
(roughly) what I suggest. If you wanted Verilog, it'd be something like
result[23:0] <= In[23:0] * ((1<<24)/1.36 + 0.5) >> 24;

but I haven't used real variables in my code much if at all. I think this
would synthesize.

> I dont need a clock for this one.
>
> Thankyou



Reply With Quote
  #5 (permalink)  
Old 03-29-2005, 10:42 PM
genlock
Guest
 
Posts: n/a
Default Re: Dividing a 24 bit std_logic_vector by a decimal number

Can you explain this logic that you have mentioned in more detail?

I am using Xilinx ISE and when I try doing any division or
multiplication, it keeps showing an error as follows:

/ can not have such operands in this context.
ERROR: XST failed

a)What I am trying to do is first convert the 24 bit vector to an
integer.

b)Then figure out a method to divide this integer by 1.36 that gives
the result as an integer

c)This integer is converted back to a 24 bit vector

Any idea about how this division (b)can be performed?

Thankyou

Reply With Quote
  #6 (permalink)  
Old 03-29-2005, 11:46 PM
Thomas Womack
Guest
 
Posts: n/a
Default Re: Dividing a 24 bit std_logic_vector by a decimal number

In article <[email protected] com>,
genlock <[email protected]> wrote:
>Can you explain this logic that you have mentioned in more detail?
>
>I am using Xilinx ISE and when I try doing any division or
>multiplication, it keeps showing an error as follows:
>
> / can not have such operands in this context.


Why not just use the explicit number 12336188, with a comment that
it's the nearest integer to 2^24/1.36?

Tom

Reply With Quote
  #7 (permalink)  
Old 03-30-2005, 07:24 AM
Johan Bernspång
Guest
 
Posts: n/a
Default Re: Dividing a 24 bit std_logic_vector by a decimal number

genlock wrote:

> Can you explain this logic that you have mentioned in more detail?
>
> I am using Xilinx ISE and when I try doing any division or
> multiplication, it keeps showing an error as follows:
>
> / can not have such operands in this context.
> ERROR: XST failed
>
> a)What I am trying to do is first convert the 24 bit vector to an
> integer.
>
> b)Then figure out a method to divide this integer by 1.36 that gives
> the result as an integer
>
> c)This integer is converted back to a 24 bit vector
>
> Any idea about how this division (b)can be performed?
>
> Thankyou
>



If you're using ISE you can always have a look into the Language
Templates (the icon with the light bulb on it).

The following code will do the trick:

signal product : std_logic_vector(47 downto 0);
signal mult_in : std_logic_vector(23 downto 0);
constant const_val : std_logic_vector(23 downto 0) := X"the divisor";

--snip--
process (clk)
begin
if rising_edge(clk) then
product <= mult_in * const_val;
end if;
end process;

To make sure you're inferring hardware multipliers you have to set the
correct synthesize properties for that.

The value of the perfect constant could probably be a discussion in
itself but I would probably multiply by 47 (i.e. 2F hex) and then do a 6
bit right shift after the multiplication:

prod_out <= product(41 downto 18);

This method does not divide exactly by 1.36, but pretty close: 1.362.

Correct me if I'm totally wrong...

--
-----------------------------------------------
Johan Bernspång, [email protected]
Research engineer

Swedish Defence Research Agency - FOI
Division of Command & Control Systems
Department of Electronic Warfare Systems

www.foi.se

Please remove the x's in the email address if
replying to me personally.
-----------------------------------------------
Reply With Quote
  #8 (permalink)  
Old 03-30-2005, 02:57 PM
c d saunter
Guest
 
Posts: n/a
Default Re: Dividing a 24 bit std_logic_vector by a decimal number

Comments inline below... Basic summary is you need to think more like
hardware and less like software.

genlock ([email protected]) wrote:
: Can you explain this logic that you have mentioned in more detail?

: I am using Xilinx ISE and when I try doing any division or
: multiplication, it keeps showing an error as follows:

: / can not have such operands in this context.
: ERROR: XST failed

: a)What I am trying to do is first convert the 24 bit vector to an
: integer.

: b)Then figure out a method to divide this integer by 1.36 that gives
: the result as an integer

: c)This integer is converted back to a 24 bit vector

Synthesis tools (ISE's XST etc.) use typecodes (and hence typecode
conversions) as a queue to how to implement something (e.g. signed or
unsigned multiply.) XST doesn't implement divides (other than by powers
of 2:-) full stop, so converting to a type where it's obvious to you
won't help the syn tool produce hardware. (It might work in simulation
though.)

Remember inside the FPGA you are working with signals made of bits, and
only bits, so something like 1.36 is a bit meaningless. As others have
said just multiply by the reciprocal of the divisor. Below is an untested
code snippet to demonstrate how to do this in VHDL.

signal input : std_logic_vector(23 downto 0);
signal recip : std_logic_vector(23 downto 0);
signal mult_res: std_logic_vector(47 downto 0);
signal div_res : std_logic_vector(23 downto 0);

recip <= conv_std_logic(2^24 * 1 / 1.36) -- not sure this is the right
-- conv_blah function
-- Note that the calculation is
-- evaluated at synthesis time


mult_res <= input * recip -- assuming unsigned input
div_res <= mult_res(47 downto 24) -- there's a .5 bit rounding
-- error here for some results
Cheers,
Chris

: Any idea about how this division (b)can be performed?

: Thankyou

Reply With Quote
  #9 (permalink)  
Old 03-31-2005, 05:36 PM
genlock
Guest
 
Posts: n/a
Default Re: Dividing a 24 bit std_logic_vector by a decimal number

What do u mean by an explicit number and how did you arrive at this
value?

Reply With Quote
  #10 (permalink)  
Old 03-31-2005, 05:39 PM
genlock
Guest
 
Posts: n/a
Default Re: Dividing a 24 bit std_logic_vector by a decimal number

How did you arrive at the value 47 ( 2F hex) for the value 1.36.....

What if the number is 1.122 instead?....

Is there a technique to do that..

Thankyou

Reply With Quote
  #11 (permalink)  
Old 03-31-2005, 05:41 PM
genlock
Guest
 
Posts: n/a
Default Re: Dividing a 24 bit std_logic_vector by a decimal number

Thankyou Chris,
Instead of 2^24, we need to plug in the deicmal equivalent of the 24
bit input we have.

Is that right

And also,

recip <= conv_std_logic(2^24 * 1 / 1.36) -- not sure this is the right

I am not sure if this would work because it again uses the '/'
operator.

This cannot be synthesized in XST.

Thankyou

Reply With Quote
  #12 (permalink)  
Old 03-31-2005, 07:11 PM
Thomas Womack
Guest
 
Posts: n/a
Default Re: Dividing a 24 bit std_logic_vector by a decimal number

In article <[email protected] .com>,
genlock <[email protected]> wrote:
>How did you arrive at the value 47 ( 2F hex) for the value 1.36.....


Because 64/47 is nearly 1.36, so multiplying by 47 and dividing by 64
is about the same as dividing by 1.36

>What if the number is 1.122 instead?....


1.122 is nearly 64/57, so multiplying by 57 and dividing by 64 is
about the same as dividing by 1.122

>Is there a technique to do that..


Given X, for example 1.122, work out w = 2^k / X for k from 1 to some
conveniently big number, and use the [k,w] pair that makes w nearest
to a whole number.

eg 1.5678, you try lots of k and find that 2^18 / 1.5678 is almost
exactly 167205.

This general technique is called fixed-point arithmetic.

Tom
Reply With Quote
  #13 (permalink)  
Old 03-31-2005, 10:26 PM
genlock
Guest
 
Posts: n/a
Default Re: Dividing a 24 bit std_logic_vector by a decimal number

Tom,

Thankyou.

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
cascaded dividers for dividing down clocks anand Verilog 1 08-16-2006 09:21 PM
binary coded decimal code. miniwolf Verilog 4 05-06-2006 10:44 PM
std_logic_vector vs unsigned Chuck McManis FPGA 6 05-18-2004 03:07 PM
VHDL:Dividing a real number by two?? kwaj FPGA 4 02-10-2004 09:04 AM


All times are GMT +1. The time now is 08:40 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved