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

Reply

VHDL - real to signed

 
Thread Tools Search this Thread
Old 02-29-2008, 02:46 PM   #1
Default real to signed


How to convert real to signed. The range of real will be from -1 to 1,
-5 to 5, -10 to 10 and so on. I would like to convert this range to a
signed vector of bit width bw(generic). The data has to be scaled but
I have no idea on how to do it. I have searched on the internet and
did not find any valuable information.



FPGA
  Reply With Quote
Old 02-29-2008, 04:19 PM   #2
Symon
 
Posts: n/a
Default Re: real to signed
FPGA wrote:
> How to convert real to signed. The range of real will be from -1 to 1,
> -5 to 5, -10 to 10 and so on. I would like to convert this range to a
> signed vector of bit width bw(generic). The data has to be scaled but
> I have no idea on how to do it. I have searched on the internet and
> did not find any valuable information.


Google this:-

convert real signed vhdl

Click on the first link with the left button of your mouse.

HTH., Syms.






Symon
  Reply With Quote
Old 02-29-2008, 04:25 PM   #3
Mike Treseler
 
Posts: n/a
Default Re: real to signed
FPGA wrote:
> How to convert real to signed. The range of real will be from -1 to 1,
> -5 to 5, -10 to 10 and so on. I would like to convert this range to a
> signed vector of bit width bw(generic). The data has to be scaled but
> I have no idea on how to do it. I have searched on the internet and
> did not find any valuable information.
>


Start with modulo arithmetic.
http://deadsmall.com/3AE


Mike Treseler
  Reply With Quote
Old 02-29-2008, 04:29 PM   #4
Tricky
 
Posts: n/a
Default Re: real to signed
On Feb 29, 2:46 pm, FPGA <FPGA.unkn...@gmail.com> wrote:
> How to convert real to signed. The range of real will be from -1 to 1,
> -5 to 5, -10 to 10 and so on. I would like to convert this range to a
> signed vector of bit width bw(generic). The data has to be scaled but
> I have no idea on how to do it. I have searched on the internet and
> did not find any valuable information.


You will need to know magnitude width and fraction width as you will
be generating a fixed point decimal.
Magnitude width (MW) can be done by taking log2(limit) and adding 1
(to account for the sign bit).
Fraction width (FW) is then bw-MW.

Then you scale the result by 2**FW and convert it to an integer (which
then gives you your signed number).
Remember Integer(my_real) always rounds to nearest. If you dont want
to round to nearest, you have to write a function that rounds to zero,
otherwise removing the LSBs will always round down. (towards 0 for
+ve, away from 0 for -ve).


Tricky
  Reply With Quote
Old 02-29-2008, 04:32 PM   #5
Paul Uiterlinden
 
Posts: n/a
Default Re: real to signed
FPGA wrote:

> How to convert real to signed. The range of real will be from -1 to 1,
> -5 to 5, -10 to 10 and so on.


I don't understand this.

> I would like to convert this range to a
> signed vector of bit width bw(generic). The data has to be scaled but
> I have no idea on how to do it.


What do you mean by scaling?

> I have searched on the internet and did not find any valuable information.


If it is only about converting from real to signed, then first convert the
real to integer, and then to signed with the to_signed function from
ieee.numeric_std.

Something like this:

LIBRARY ieee;
USE ieee.numeric_std.ALL;
...
FUNCTION real2signed
(
r: real;
return_width: positive
) RETURN signed IS
BEGIN
RETURN to_signed(integer(r), return_width);
END FUNCTION real2signed;

--
Paul Uiterlinden
www.aimvalley.nl
e-mail addres: remove the not.


Paul Uiterlinden
  Reply With Quote
Old 02-29-2008, 04:50 PM   #6
Tricky
 
Posts: n/a
Default Re: real to signed
On Feb 29, 4:29 pm, Tricky <Trickyh...@gmail.com> wrote:
> On Feb 29, 2:46 pm, FPGA <FPGA.unkn...@gmail.com> wrote:
>
> > How to convert real to signed. The range of real will be from -1 to 1,
> > -5 to 5, -10 to 10 and so on. I would like to convert this range to a
> > signed vector of bit width bw(generic). The data has to be scaled but
> > I have no idea on how to do it. I have searched on the internet and
> > did not find any valuable information.

>
> You will need to know magnitude width and fraction width as you will
> be generating a fixed point decimal.
> Magnitude width (MW) can be done by taking log2(limit) and adding 1
> (to account for the sign bit).
> Fraction width (FW) is then bw-MW.
>
> Then you scale the result by 2**FW and convert it to an integer (which
> then gives you your signed number).
> Remember Integer(my_real) always rounds to nearest. If you dont want
> to round to nearest, you have to write a function that rounds to zero,
> otherwise removing the LSBs will always round down. (towards 0 for
> +ve, away from 0 for -ve).


PS. None of this is synthesisable, as it bases all working on reals,
which you cannot synthesise in any way. Reals are only allowed to
create constants (which then have to be of a synthesizable type).

If you are trying now to synthesize your sine wave generator, you are
going about it the wrong way.


Tricky
  Reply With Quote
Old 02-29-2008, 06:18 PM   #7
FPGA
 
Posts: n/a
Default Re: real to signed
On Feb 29, 11:50*am, Tricky <Trickyh...@gmail.com> wrote:
> On Feb 29, 4:29 pm, Tricky <Trickyh...@gmail.com> wrote:
>
>
>
>
>
> > On Feb 29, 2:46 pm, FPGA <FPGA.unkn...@gmail.com> wrote:

>
> > > How to convert real to signed. The range of real will be from -1 to 1,
> > > -5 to 5, -10 to 10 and so on. I would like to convert this range to a
> > > signed vector of bit width bw(generic). The data has to be scaled but
> > > I have no idea on how to do it. I have searched on the internet and
> > > did not find any valuable information.

>
> > You will need to know magnitude width and fraction width as you will
> > be generating a fixed point decimal.
> > Magnitude width (MW) can be done by taking log2(limit) and adding 1
> > (to account for the sign bit).
> > Fraction width (FW) is then bw-MW.

>
> > Then you scale the result by 2**FW and convert it to an integer (which
> > then gives you your signed number).
> > Remember Integer(my_real) always rounds to nearest. If you dont want
> > to round to nearest, you have to write a function that rounds to zero,
> > otherwise removing the LSBs will always round down. (towards 0 for
> > +ve, away from 0 for -ve).

>
> PS. None of this is synthesisable, as it bases all working on reals,
> which you cannot synthesise in any way. Reals are only allowed to
> create constants (which then have to be of a synthesizable type).
>
> If you are trying now to synthesize your sine wave generator, you are
> going about it the wrong way.- Hide quoted text -
>
> - Show quoted text -


I dont want to synthesize this.


FPGA
  Reply With Quote
Old 02-29-2008, 06:30 PM   #8
FPGA
 
Posts: n/a
Default Re: real to signed
On Feb 29, 11:32*am, Paul Uiterlinden <puit...@notaimvalley.nl> wrote:
> FPGA wrote:
> > How to convert real to signed. The range of real will be from -1 to 1,
> > -5 to 5, -10 to 10 and so on.

>
> I don't understand this.
>
> > I would like to convert this range to a
> > signed vector of bit width bw(generic). The data has to be scaled but
> > I have no idea on how to do it.

>
> What do you mean by scaling?
>
> > I have searched on the internet and did not find any valuable information.

>
> If it is only about converting from real to signed, then first convert the
> real to integer, and then to signed with the to_signed function from
> ieee.numeric_std.

real can be of type 0.0134 .. if I convert this to integer it is going
to give a 0.
>
> Something like this:
>
> * LIBRARY ieee;
> * USE ieee.numeric_std.ALL;
> * ...
> * FUNCTION real2signed
> * (
> * * r: real;
> * * return_width: positive
> * ) RETURN signed IS
> * BEGIN
> * * RETURN to_signed(integer(r), return_width);
> * END FUNCTION real2signed;
>
> --
> Paul Uiterlindenwww.aimvalley.nl
> e-mail addres: remove the not.




FPGA
  Reply With Quote
Old 02-29-2008, 06:33 PM   #9
FPGA
 
Posts: n/a
Default Re: real to signed
On Feb 29, 11:29*am, Tricky <Trickyh...@gmail.com> wrote:
> On Feb 29, 2:46 pm, FPGA <FPGA.unkn...@gmail.com> wrote:
>
> > How to convert real to signed. The range of real will be from -1 to 1,
> > -5 to 5, -10 to 10 and so on. I would like to convert this range to a
> > signed vector of bit width bw(generic). The data has to be scaled but
> > I have no idea on how to do it. I have searched on the internet and
> > did not find any valuable information.

>
> You will need to know magnitude width and fraction width as you will
> be generating a fixed point decimal.
> Magnitude width (MW) can be done by taking log2(limit) and adding 1
> (to account for the sign bit).


MW and FW of output real changes with change in amplitude. What is
'limit'?

> Fraction width (FW) is then bw-MW.
>
> Then you scale the result by 2**FW and convert it to an integer (which
> then gives you your signed number).
> Remember Integer(my_real) always rounds to nearest. If you dont want
> to round to nearest, you have to write a function that rounds to zero,
> otherwise removing the LSBs will always round down. (towards 0 for
> +ve, away from 0 for -ve).




FPGA
  Reply With Quote
Old 03-03-2008, 06:19 AM   #10
Thomas Stanka
 
Posts: n/a
Default Re: real to signed
On 29 Feb., 15:46, FPGA <FPGA.unkn...@gmail.com> wrote:
> How to convert real to signed. The range of real will be from -1 to 1,
> -5 to 5, -10 to 10 and so on. I would like to convert this range to a
> signed vector of bit width bw(generic). The data has to be scaled but
> I have no idea on how to do it. I have searched on the internet and
> did not find any valuable information.


Start with understanding what a real is:
http://en.wikipedia.org/wiki/IEEE_754-1985
Than it is easy to write your conversion function.

bye Thomas


Thomas Stanka
  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
signed divider with fractions in vhdl sueco_ Hardware 0 07-07-2009 12:05 PM
Running signed applet without creating policy file in client side abcd Software 0 02-17-2009 06:37 AM
SAVE HD-DVD Almost 32,000 signed and counting. Robb DVD Video 15 02-01-2008 04:22 PM
Last Day! SERPENT AND THE RAINBOW dvd, Signed CHASING AMY Crit ld J Rusnak DVD Video 0 05-30-2006 10:08 PM
FA: BATMAN BEGINS Deluxe DVD w/Free Bonus! PHANTASM Signed LD w/Gold CD! Last Day:BLAZING SADDLES LD J Rusnak DVD Video 0 05-10-2006 01:14 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