Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > converting a subtype to unsigned?

Reply
Thread Tools

converting a subtype to unsigned?

 
 
laserbeak43
Guest
Posts: n/a
 
      06-03-2010
Hello,
I've created a subtype:

subtype digit is integer range 0 to 9;

and then used this type to make a signal. Is it possible to convert
this type to unsigned? when i do it, i get errors.

signal h1 : digit;
signal hv1 : unsigned(3 downto 0);
hv1 <= unsigned(h1); --Error (10305): VHDL Type Conversion error at
part1.vhd(75): cannot convert type "digit" to type "UNSIGNED"

thanks,
Malik
 
Reply With Quote
 
 
 
 
Jonathan Bromley
Guest
Posts: n/a
 
      06-03-2010
On Jun 3, 5:44*am, laserbeak43 <laserbea...@gmail.com> wrote:

> subtype digit is integer range 0 to 9;
> Is it possible to convert
> this type to unsigned? when i do it, i get errors.
>
> signal h1 * * * : digit;
> signal hv1 * * *: unsigned(3 downto 0);
> hv1 <= unsigned(h1); *--Error


You're just using the name of the new type (unsigned)
as if it were a function. That's not really a function;
it's a "type conversion", which works only between
closely related types. For example:

- REAL and any INTEGER subtype are closely related,
because they are simple numeric types
- STD_LOGIC_VECTOR and UNSIGNED are closely related,
because they are both arrays of STD_LOGIC indexed
by INTEGER

But INTEGER and UNSIGNED are not closely related, so
you need a conversion function:

hvl = to_unsigned(hl, hvl'length);

If you get an error for this line, it's because you
are a Very Bad Person and are using std_logic_arith.
Switch to numeric_std before we get angry with you
--
Jonathan Bromley
 
Reply With Quote
 
 
 
 
Jonathan Bromley
Guest
Posts: n/a
 
      06-03-2010
On Jun 3, 8:13*am, Jonathan Bromley wrote:
> * hvl = to_unsigned(hl, hvl'length);
>
> If you get an error for this line, it's because you
> are a Very Bad Person and are using std_logic_arith.
> Switch to numeric_std before we get angry with you


Alternatively, of course, it might be because I am a
Very Bad Person who forgot the < in a VHDL signal
assignment. Far too much Verilog recently...
--
Jonathan Bromley

 
Reply With Quote
 
laserbeak43
Guest
Posts: n/a
 
      06-04-2010
On Jun 3, 3:21*am, Jonathan Bromley <s...@oxfordbromley.plus.com>
wrote:
> On Jun 3, 8:13*am, Jonathan Bromley wrote:
>
> > * hvl = to_unsigned(hl, hvl'length);

>
> > If you get an error for this line, it's because you
> > are a Very Bad Person and are using std_logic_arith.
> > Switch to numeric_std before we get angry with you

>
> Alternatively, of course, it might be because I am a
> Very Bad Person who forgot the < in a VHDL signal
> assignment. *Far too much Verilog recently...
> --
> Jonathan Bromley


Well if you're a bad person, I'm sure we'd all like to see you on a
good day.
Thanks a lot for your help.
Malik
 
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
incompatible types for ?: neither is a subtype of the other John Goche Java 1 02-09-2006 01:06 PM
Variable Subtype Problem Takuon Soho VHDL 6 03-02-2005 04:08 AM
Error:Case expression must be of a locally static subtype. Mohammed A khader VHDL 1 01-28-2005 11:02 AM
subtype for integers Hari VHDL 5 01-12-2004 04:14 PM
NetFlow & ICMP type/subtype Slava Astashonok Cisco 1 12-09-2003 02:50 PM



Advertisments
 



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 47 48 49 50 51 52 53 54 55 56 57