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

Reply

VHDL - basic question about data types

 
Thread Tools Search this Thread
Old 12-01-2008, 07:29 AM   #1
Default basic question about data types


Hi,

I have some basic question about data types in vhdl. I hope you can give
me an answer. Which library should I use in new designs (numeric_std or
std_logic_unsigned)? The unsigned type is a vector type?

Thank your for your answer.

bye

martin sauer


Martin Sauer
  Reply With Quote
Old 12-01-2008, 08:00 AM   #2
Martin Sauer
 
Posts: n/a
Default Re: basic question about data types
Hi,

I have an example:

In my VHDL code I have two unsigned signals

signal sDataR : unsigned (9 downto 0);
signal sR : unsigned (1 downto 0);

I want to add bit 1 of sR to sDataR. sDataR + sR(1) doesn't work. I will
get the following error:

ERROR: cannot convert type std_ulogic to type unsigned

How can I add one bit of an unsigned signal to another unsigned signal?

Thank you for your answer.

bye

martin sauer

Martin Sauer schrieb:
> Hi,
>
> I have some basic question about data types in vhdl. I hope you can give
> me an answer. Which library should I use in new designs (numeric_std or
> std_logic_unsigned)? The unsigned type is a vector type?
>
> Thank your for your answer.
>
> bye
>
> martin sauer



Martin Sauer
  Reply With Quote
Old 12-01-2008, 09:30 AM   #3
Tricky
 
Posts: n/a
Default Re: basic question about data types
On 1 Dec, 08:00, Martin Sauer <m...@displaign.de> wrote:
> Hi,
>
> I have an example:
>
> In my VHDL code I have two unsigned signals
>
> signal sDataR : unsigned (9 downto 0);
> signal sR : unsigned (1 downto 0);
>
> I want to add bit 1 of sR to sDataR. sDataR + sR(1) doesn't work. I will
> get the following error:
>
> ERROR: cannot convert type std_ulogic to type unsigned
>
> How can I add one bit of an unsigned signal to another unsigned signal?
>
> Thank you for your answer.
>
> bye
>
> martin sauer
>
> Martin Sauer schrieb:
>
> > Hi,

>
> > I have some basic question about data types in vhdl. I hope you can give
> > me an answer. Which library should I use in new designs (numeric_std or
> > std_logic_unsigned)? The unsigned type is a vector type?

>
> > Thank your for your answer.

>
> > bye

>
> > martin sauer

>
>


Definatly use numeric_std, because it is an actual IEEE standard,
std_logic_unsigned is not - it was origionally defined by Synopsys and
compiled (wrongly) in to the IEEE library. Different vendors implement
std_logic_unsigned differently, whereas the IEEE defined numeric_std.

As for your error, sR(1) is just a single bit, which is why you're
getting the problem. Addition has to be done on 2 unsigned numbers
that have the same length that match the result length. So, the best
way around your problem:

signal output : unsigned(10 downto 0); --addition output will be 1
bit bigger than largest input if you dont want overflow
...
output <= ('0' & sDataR) + resize(sR, output'length);
--'0' is concatenated the make sDataR 11 bits.

if you really wanted to add a single bit from sR then you have to use
a range to keep it as an unsigned type. Indexing just 1 returns a
std_ulogic, as you found.:

output <= ('0' & sDataR) + resize(sR(1 downto 1), output'length);


Tricky
  Reply With Quote
Old 12-01-2008, 09:38 AM   #4
olekk
 
Posts: n/a
Default Re: basic question about data types


Martin Sauer wrote:
> Hi,
>
> I have an example:
>
> In my VHDL code I have two unsigned signals
>
> signal sDataR : unsigned (9 downto 0);
> signal sR : unsigned (1 downto 0);
>
> I want to add bit 1 of sR to sDataR. sDataR + sR(1) doesn't work. I will
> get the following error:
>
> ERROR: cannot convert type std_ulogic to type unsigned
>
> How can I add one bit of an unsigned signal to another unsigned signal?
>
> Thank you for your answer.
>
> bye
>
> martin sauer
>
> Martin Sauer schrieb:
> > Hi,
> >
> > I have some basic question about data types in vhdl. I hope you can give
> > me an answer. Which library should I use in new designs (numeric_std or
> > std_logic_unsigned)? The unsigned type is a vector type?
> >


operator '+' is defined in std_logic_unsigned for logic vectors. So
you can do it like

use ieee.std_logic_unsigned;
.....
srout <= sDataR + sR(1 downto 1);

It will certainly compile

Regards


olekk
  Reply With Quote
Old 12-01-2008, 09:42 AM   #5
Tricky
 
Posts: n/a
Default Re: basic question about data types

> operator '+' is defined in std_logic_unsigned for logic vectors. So
> you can do it like
>



See above 2 posts


Tricky
  Reply With Quote
Old 12-01-2008, 09:45 AM   #6
Martin Sauer
 
Posts: n/a
Default Re: basic question about data types
Hi all,

thank you for your fast answer.

Now it works fine.

bye

martin sauer

olekk schrieb:
>
> Martin Sauer wrote:
>> Hi,
>>
>> I have an example:
>>
>> In my VHDL code I have two unsigned signals
>>
>> signal sDataR : unsigned (9 downto 0);
>> signal sR : unsigned (1 downto 0);
>>
>> I want to add bit 1 of sR to sDataR. sDataR + sR(1) doesn't work. I will
>> get the following error:
>>
>> ERROR: cannot convert type std_ulogic to type unsigned
>>
>> How can I add one bit of an unsigned signal to another unsigned signal?
>>
>> Thank you for your answer.
>>
>> bye
>>
>> martin sauer
>>
>> Martin Sauer schrieb:
>>> Hi,
>>>
>>> I have some basic question about data types in vhdl. I hope you can give
>>> me an answer. Which library should I use in new designs (numeric_std or
>>> std_logic_unsigned)? The unsigned type is a vector type?
>>>

>
> operator '+' is defined in std_logic_unsigned for logic vectors. So
> you can do it like
>
> use ieee.std_logic_unsigned;
> ....
> srout <= sDataR + sR(1 downto 1);
>
> It will certainly compile
>
> Regards



Martin Sauer
  Reply With Quote
Old 12-01-2008, 09:03 PM   #7
Nicolas Matringe
 
Posts: n/a
Default Re: basic question about data types
Martin Sauer a écrit :
> Hi all,
>
> thank you for your fast answer.
>
> Now it works fine.


The quick and ugly way. Read the other answers please. Please. I
*really* mean it.

Nicolas


Nicolas Matringe
  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
VERY basic Perl question geoffh Software 0 08-23-2009 01:00 PM
70-542 - MOSS App Dev Basic Question Eric Kraus MCTS 1 08-09-2007 02:32 AM
A+ Cert exam question types Christopher Range A+ Certification 4 04-19-2006 02:01 PM
Re: A+ - question types Remo A+ Certification 0 01-07-2005 11:09 AM
Re: Throwaway DVD Question Scot Gardner DVD Video 64 09-12-2003 06:20 PM




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