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

Reply

VHDL - rounding to integer

 
Thread Tools Search this Thread
Old 02-15-2004, 03:35 PM   #1
Default rounding to integer


This line is synthesizable but result is truncated (according to
simulation):
constant DIVIDER: integer := Frequency / BaudRate / 16;

The following rounds to closest integer but works only in simulator:
constant DIVIDER: integer := integer(real(Frequency) / real(BaudRate) /
real(16)); -- not synthetable
Synplify tells "Right argument must evaluate to a constant integer power of
2".


How could I implement a synthesizable round function? Please note, the
floating-point arithmetics is required at compile time only, not at
run-time.




valentin tihomirov
  Reply With Quote
Old 02-15-2004, 07:46 PM   #2
Egbert Molenkamp
 
Posts: n/a
Default Re: rounding to integer
Interesting. I tried the following with Leonardo Spectrum.
Maybe as work around the second solution can be used?

library ieee;
use ieee.std_logic_1164.all;

entity funny is
port (d : out integer);
end entity funny is;

architecture demo of funny is
constant a : real := 10.0E2;
constant b : real := 0.50;
begin
-- d <= integer (a/b); --Leonardo Spectrum supports this

-- Work around .. multiply both operands with a (large) constant before
division?
d <= integer(1000.0*a)/integer(1000.0*b) ;

end architecture demo;

Egbert Molenkamp

"valentin tihomirov" <> schreef in
bericht news:c0o3jl$195it3$...
> This line is synthesizable but result is truncated (according to
> simulation):
> constant DIVIDER: integer := Frequency / BaudRate / 16;
>
> The following rounds to closest integer but works only in simulator:
> constant DIVIDER: integer := integer(real(Frequency) / real(BaudRate) /
> real(16)); -- not synthetable
> Synplify tells "Right argument must evaluate to a constant integer power

of
> 2".
>
>
> How could I implement a synthesizable round function? Please note, the
> floating-point arithmetics is required at compile time only, not at
> run-time.
>
>





Egbert Molenkamp
  Reply With Quote
Old 02-16-2004, 10:07 AM   #3
Jonathan Bromley
 
Posts: n/a
Default Re: rounding to integer
hi Valentin,

"valentin tihomirov" <> wrote
in message news:c0o3jl$195it3$...

> This line is synthesizable but result is truncated (according to
> simulation):
> constant DIVIDER: integer := Frequency / BaudRate / 16;
>
> The following rounds to closest integer but works only in simulator:
> constant DIVIDER: integer := integer(real(Frequency) / real(BaudRate) /
> real(16)); -- not synthetable
> Synplify tells "Right argument must evaluate to a constant integer power

of
> 2".
>
> How could I implement a synthesizable round function? Please note, the
> floating-point arithmetics is required at compile time only, not at
> run-time.


As we have regretted here on many previous occasions, most simulators
do not allow you to perform floating-point arithmetic even at
compile time.

The integer divide operator / is defined to truncate, as you
observed. But I think you can easily modify it to make a
round-to-nearest divide, using this relationship:

round(A/B) == trunc( (A+B/2) / B)

So your constant could be defined like this...

constant DIVIDER: integer :=
(Frequency + 8 * BaudRate) / (16 * BaudRate);

cheers
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.





Jonathan Bromley
  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
How to convert string contain Hex data into integer asifjavaid Software 0 09-09-2008 08:50 AM
Fast Integer Division In Vhdl Vitrion Hardware 0 11-01-2007 07:33 AM
VHDL help needed TomboT Hardware 2 11-21-2006 05:01 PM
getting integer values from electronic weigh scale through serial port dotnet_smart Software 2 09-17-2006 05:24 AM
getting integer values from electrolnic weigh scale through serial port dotnet_smart Hardware 0 07-28-2006 11:54 AM




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