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

Reply

VHDL - Adding a NATURAL and a STD_LOGIC_VECTOR

 
Thread Tools Search this Thread
Old 06-08-2007, 01:31 PM   #1
Default Adding a NATURAL and a STD_LOGIC_VECTOR


Hi,

I'd like to compute the arithmetic sum of a NATURAL signal and a
STD_LOGIC_VECTOR signal, and store the value into a NATURAL signal,
ie. a <= b + c, with a NATURAL, b NATURAL and c STD_LOGIC_VECTOR.
How should I do ? Here the compiler complains about not finding a
suitable definition of the + operator. I tried various combinations of
TO_INTEGER(), TO_BIT_VECTOR(), UNSIGNED(), ... but no luck.
The sum works when all operands are NATURAL.

I'm using Quartus II from Altera.

Regards,

Sebastien



Sebastien Bourdeauducq
  Reply With Quote
Old 06-08-2007, 01:55 PM   #2
Andy
 
Posts: n/a
Default Re: Adding a NATURAL and a STD_LOGIC_VECTOR
On Jun 8, 7:31 am, Sebastien Bourdeauducq
<sebastien.bourdeaud...@gmail.com> wrote:
> Hi,
>
> I'd like to compute the arithmetic sum of a NATURAL signal and a
> STD_LOGIC_VECTOR signal, and store the value into a NATURAL signal,
> ie. a <= b + c, with a NATURAL, b NATURAL and c STD_LOGIC_VECTOR.
> How should I do ? Here the compiler complains about not finding a
> suitable definition of the + operator. I tried various combinations of
> TO_INTEGER(), TO_BIT_VECTOR(), UNSIGNED(), ... but no luck.
> The sum works when all operands are NATURAL.
>
> I'm using Quartus II from Altera.
>
> Regards,
>
> Sebastien


use ieee.numeric_std.all;

....

a <= to_integer(b + unsigned(c));

or:

a <= b + to_integer(unsigned(c));


Andy



Andy
  Reply With Quote
Old 06-08-2007, 02:02 PM   #3
Tim McBrayer
 
Posts: n/a
Default Re: Adding a NATURAL and a STD_LOGIC_VECTOR
"Sebastien Bourdeauducq" <> wrote in message
news: ups.com...
> Hi,
>
> I'd like to compute the arithmetic sum of a NATURAL signal and a
> STD_LOGIC_VECTOR signal, and store the value into a NATURAL signal,
> ie. a <= b + c, with a NATURAL, b NATURAL and c STD_LOGIC_VECTOR.
> How should I do ? Here the compiler complains about not finding a
> suitable definition of the + operator. I tried various combinations of
> TO_INTEGER(), TO_BIT_VECTOR(), UNSIGNED(), ... but no luck.
> The sum works when all operands are NATURAL.


The base VHDL language (through VHDL-2002) does not define arithmetic on
std_logic_vectors. You have to use an external package (or write the
addition operator yourself) to get the desired functionality. Following the
IEEE standard approach, you will need to use package IEEE.numeric_std from
1076.3-1997. If IN1 and OUT1 are std_logic_vectors of the same length, and
IN2 is of type NATURAL, the following assignment works:

out1 <= std_logic_vector( unsigned(in1) + in2 );

This a) converts IN1 from SLV to UNSIGNED, b) performs the addition
creating an UNSIGNED result, and c) converts the result back to SLV.

Some alternative approaches:
Using Synopsys' package IEEE.std_logic_arith: out1 <= unsigned(in1) + in2;
Using Synopsys' package IEEE.std_logic_unsigned: out1 <= in1 + in2;




Tim McBrayer
  Reply With Quote
Old 06-08-2007, 03:05 PM   #4
Sebastien Bourdeauducq
 
Posts: n/a
Default Re: Adding a NATURAL and a STD_LOGIC_VECTOR
a <= b + to_integer(unsigned(c)); with ieee.numeric_std.all works.
Thanks !



Sebastien Bourdeauducq
  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
DVD Verdict reviews: NATURAL CITY, UNO BIANCA, GODZILLA: MONSTER EDITION, and more! DVD Verdict DVD Video 0 04-27-2006 09:21 AM
FS: Lot of 10 DVDs - City of God , Natural Born Killers , $60.00.............dvd#CGW253 campu2 DVD Video 0 05-31-2005 06:38 AM
Natural Born Killers in a triple-pack? Pepper DVD Video 0 06-28-2004 01:58 AM
Natural Born Killers music question PW DVD Video 7 09-04-2003 03:19 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