Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Adding a NATURAL and a STD_LOGIC_VECTOR

Reply
Thread Tools

Adding a NATURAL and a STD_LOGIC_VECTOR

 
 
Sebastien Bourdeauducq
Guest
Posts: n/a
 
      06-08-2007
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

 
Reply With Quote
 
 
 
 
Andy
Guest
Posts: n/a
 
      06-08-2007
On Jun 8, 7:31 am, Sebastien Bourdeauducq
<(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
Tim McBrayer
Guest
Posts: n/a
 
      06-08-2007
"Sebastien Bourdeauducq" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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;


 
Reply With Quote
 
Sebastien Bourdeauducq
Guest
Posts: n/a
 
      06-08-2007
a <= b + to_integer(unsigned(c)); with ieee.numeric_std.all works.
Thanks !

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
STD_LOGIC_VECTOR >> NATURAL ? aleksa VHDL 9 01-22-2009 09:41 PM
inout std_logic_vector to array of std_logic_vector of generic length conversion... Thomas Rouam VHDL 6 11-09-2007 11:49 AM
Cast natural to std_logic_vector (and the other way) badwolf500 VHDL 0 08-14-2006 09:33 PM
Constant conversion (natural to std_logic_vector) a1_nocrap_exh@hotmail.com VHDL 10 04-13-2006 10:29 PM
Belkin kvm and Microsoft natural keyboard. raptorman Computer Support 0 09-18-2003 07:51 PM



Advertisments