unsigned(), unsigned'(), to_unsigned()

S

Shannon

Ok, I struggle with this each and every time. Can someone help
clarify for me when each version of these is valid to use? They all
look so similar to me but I have to randomly guess each time I want to
use one type of signal with a different type of signal.

TIA,
Shannon
 
T

Tim McBrayer

Shannon said:
Ok, I struggle with this each and every time. Can someone help
clarify for me when each version of these is valid to use? They all
look so similar to me but I have to randomly guess each time I want to
use one type of signal with a different type of signal.

I'll give it a shot. I am assuming here that you are using either IEEE.NUMERIC_BIT or
IEEE.NUMERIC_STD for the definition of signed/unsigned.

unsigned(<expr>) is a type conversion, and part of the base language. A type conversion
provides for explicit conversion between closely related types. Without considering
user-defined types, <expr> will be one of: std_logic_vector, std_ulogic_vector, or signed.

unsigned'(<expr>) is a qualified expression, and also part of the base language. It is
used to explicitly provide the type and/or subtype of an expression. This is common when
the type of <expr> is not known from the context, as perhaps with a bit string literal.
This is less commonly needed than a type conversion, as VHDL is usually pretty good at
figuring out from the context what e.g. the type of "00001111" needs to be.

to_unsigned(<expr>, <size>) is a function in IEEE.NUMERIC_[STD|BIT] that accepts an <expr>
of type NATURAL (a non-negative integer) and converts it to a unsigned vector of length
<size>.

Regards,
 
M

Mike Treseler

Tim said:
Shannon wrote: Re: unsigned(), unsigned'(), to_unsigned()


If I declare my numeric registers as unsigned, signed or integer range,
I don't need any of them.

-- Mike Treseler
 
M

Mike Treseler

Jim said:
Mike

Do you make your external data bus unsigned?

Not for device pins.
For everything else it's up to the designer.
I have been in the habit of making all top level signals
as std_logic_vector - hopefully just a historical thing that
was due to older ASIC synthesis tools strongly preferred
std_logic_vector over any other type at the top level).
As a result, I use type conversions when loading the
std_logic_vector data bus into my unsigned programmable timers.

If I use one of your modules,
I guess I will have to use conversions as well ;)

-- Mike Treseler
 
S

Shannon

Mike



Do you make your external data bus unsigned?  It may carry
some untyped stuff and some unsigned as well.

I have been in the habit of making all top level signals
as std_logic_vector - hopefully just a historical thing that
was due to older ASIC synthesis tools strongly preferred
std_logic_vector over any other type at the top level).

As a result, I use type conversions when loading the
std_logic_vector data bus into my unsigned programmable timers.

Jim
--

Exactly my situation as well. Thank you for the help. I know I will
still run into confusion on this problem. I've posted here many times
when the synthesis tool can't figure out what type to choose for
something ambiguous.

Shannon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top