EDAboard.com | EDAboard.eu | EDAboard.de | EDAboard.co.uk | RTV forum PL | NewsGroups PL

converting a subtype to unsigned?

elektroda.net NewsGroups Forum Index - VHDL Language - converting a subtype to unsigned?

laserbeak43
Guest

Thu Jun 03, 2010 7:44 am   



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

Jonathan Bromley
Guest

Thu Jun 03, 2010 10:13 am   



On Jun 3, 5:44 am, laserbeak43 <laserbea...@gmail.com> wrote:

Quote:
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 Smile
--
Jonathan Bromley

Jonathan Bromley
Guest

Thu Jun 03, 2010 10:21 am   



On Jun 3, 8:13 am, Jonathan Bromley wrote:
Quote:
  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 Smile

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

laserbeak43
Guest

Fri Jun 04, 2010 6:17 am   



On Jun 3, 3:21 am, Jonathan Bromley <s...@oxfordbromley.plus.com>
wrote:
Quote:
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. Smile
Malik

elektroda.net NewsGroups Forum Index - VHDL Language - converting a subtype to unsigned?

Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
RTV map EDAboard.com map News map EDAboard.eu map EDAboard.de map EDAboard.co.uk map Opony