Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Convert enumeration to std_logic_vector

Reply
Thread Tools

Convert enumeration to std_logic_vector

 
 
Stef
Guest
Posts: n/a
 
      05-16-2008
I have a problem converting an enum with known encoding to a
std_logic_vector. Here's some fragments of the code:

entity controller is
port (
...
ledsel : out std_logic_vector(1 downto 0);
...
);


ctrl_proc : process(clock)
type opmode_t is (OPMODE_IDENT, OPMODE_CONFIG, OPMODE_ACQ);
attribute enum_encoding : string;
attribute enum_encoding of opmode_t : type is "00 01 10";
variable opmode_v : opmode_t;


I now want to assign opmode_v to the ledsel output and thought to do it
like this:

ledsel <= std_logic_vector(opmode_v);

That didn't work: " Illegal type conversion from opmode_t to
ieee.std_logic_1164.std_logic_vector (non-numeric to array)."

Is there another way to do it? Didn't find anythmh yet wityh google.


--
Stef (remove caps, dashes and .invalid from e-mail address to reply by mail)
 
Reply With Quote
 
 
 
 
Stef
Guest
Posts: n/a
 
      05-16-2008
In comp.lang.vhdl,
Stef <(E-Mail Removed)> wrote:
> I have a problem converting an enum with known encoding to a
> std_logic_vector. Here's some fragments of the code:
>
> entity controller is
> port (
> ...
> ledsel : out std_logic_vector(1 downto 0);
> ...
> );
>
>
> ctrl_proc : process(clock)
> type opmode_t is (OPMODE_IDENT, OPMODE_CONFIG, OPMODE_ACQ);
> attribute enum_encoding : string;
> attribute enum_encoding of opmode_t : type is "00 01 10";
> variable opmode_v : opmode_t;
>
>
> I now want to assign opmode_v to the ledsel output and thought to do it
> like this:
>
> ledsel <= std_logic_vector(opmode_v);
>
> That didn't work: " Illegal type conversion from opmode_t to
> ieee.std_logic_1164.std_logic_vector (non-numeric to array)."


Just after hitting the send button, I had a thought. I don't even
need the encoding if I do it like this:

ledsel <= std_logic_vector(to_unsigned(opmode_t'pos(opmode_v ), ledsel'length));

Problem solved for now, but I would still like to know how to do it with
use of the encoding as this solution only works for straight forward
encoding.

--
Stef (remove caps, dashes and .invalid from e-mail address to reply by mail)
 
Reply With Quote
 
 
 
 
KJ
Guest
Posts: n/a
 
      05-16-2008
On May 16, 7:09*am, Stef <(E-Mail Removed)>
wrote:
> In comp.lang.vhdl,
>
>
>
>
>
> Stef <(E-Mail Removed)> wrote:
> > I have a problem converting an enum with known encoding to a
> > std_logic_vector. Here's some fragments of the code:

>
> > * entity controller is
> > * * port (
> > * * * ...
> > * * * ledsel : out std_logic_vector(1 downto 0);
> > * * * ...
> > * * );

>
> > * ctrl_proc : process(clock)
> > * * type opmode_t is (OPMODE_IDENT, OPMODE_CONFIG, OPMODE_ACQ);
> > * * attribute enum_encoding : string;
> > * * attribute enum_encoding of opmode_t : type is "00 01 10";
> > * * variable opmode_v : opmode_t;

>
> > I now want to assign opmode_v to the ledsel output and thought to do it
> > like this:

>
> > * * * ledsel <= std_logic_vector(opmode_v);

>
> > That didn't work: " Illegal type conversion from opmode_t to
> > ieee.std_logic_1164.std_logic_vector (non-numeric to array)."

>
> Just after hitting the send button, I had a thought. I don't even
> need the encoding if I do it like this:
>
> * *ledsel <= std_logic_vector(to_unsigned(opmode_t'pos(opmode_v ), ledsel'length));
>
> Problem solved for now, but I would still like to know how to do it with
> use of the encoding as this solution only works for straight forward
> encoding.
>
> --
> Stef * *(remove caps, dashes and .invalid from e-mail address to reply by mail)- Hide quoted text -
>
> - Show quoted text -


Enumerated types do not have any encoding. Say that 100 times. Now
ask yourself, since enumerated types do not have any encoding then how
would can you convert from an enumerated type to a std_logic_vector?
(Hint: The answer is you have to write your own conversion function).

The 'enum_encoding' attribute may (or may not) get used by a synthesis
tool to encode your enumerated type but that will not affect the
language syntax in any way.

There is nothing built into the language or any of the standard
packages that will convert an enumerated type that you create into a
std_logic_vector. (If at this point you feel yourself ready to say
"But I told it what the encoding was with the enum_encoding
attribute..." then go back to the first sentence of this post and
start over.

So now go about writing your conversion function (Hint: A good name
to use might be 'to_sdd_logic_vector'...conversions the other way
might well be called 'from_std_logic_vector). For your particular
case, this can be the one liner that you posted with the 'pos
attribute, but it doesn't have to be.

Kevin Jennings
 
Reply With Quote
 
Stef
Guest
Posts: n/a
 
      05-16-2008
In comp.lang.vhdl,
KJ <(E-Mail Removed)> wrote:
> On May 16, 7:09*am, Stef <(E-Mail Removed)>
> wrote:
>> In comp.lang.vhdl,
>> Stef <(E-Mail Removed)> wrote:


>> > * * type opmode_t is (OPMODE_IDENT, OPMODE_CONFIG, OPMODE_ACQ);
>> > * * attribute enum_encoding : string;
>> > * * attribute enum_encoding of opmode_t : type is "00 01 10";
>> > * * variable opmode_v : opmode_t;

>>
>> > I now want to assign opmode_v to the ledsel output and thought to do it
>> > like this:

>>
>> > * * * ledsel <= std_logic_vector(opmode_v);

>>
>> > That didn't work: " Illegal type conversion from opmode_t to
>> > ieee.std_logic_1164.std_logic_vector (non-numeric to array)."

>>
>> Just after hitting the send button, I had a thought. I don't even
>> need the encoding if I do it like this:
>>
>> * *ledsel <= std_logic_vector(to_unsigned(opmode_t'pos(opmode_v ), ledsel'length));
>>
>> Problem solved for now, but I would still like to know how to do it with
>> use of the encoding as this solution only works for straight forward
>> encoding.
>>

>
> Enumerated types do not have any encoding. Say that 100 times. Now


My understanding has always been that there will be some sort of
encoding and that that encoding can be 'forced' by the encoding
attribute. So that is wrong from when talking about the language
alone? Ok, then I say that 0x4 times.


> ask yourself, since enumerated types do not have any encoding then how
> would can you convert from an enumerated type to a std_logic_vector?
> (Hint: The answer is you have to write your own conversion function).


That is clear as soon as you know there's no encoding.

> The 'enum_encoding' attribute may (or may not) get used by a synthesis
> tool to encode your enumerated type but that will not affect the
> language syntax in any way.


Are you aware of any tools that do not use the enum_encoding
attribute? I once wrote a state machine and encoded the states so
that each transition would only be a single-bit change. I would
gave been upset if the tool just ignored my carefull state layout,
but fortunately it didn't

> There is nothing built into the language or any of the standard
> packages that will convert an enumerated type that you create into a
> std_logic_vector. (If at this point you feel yourself ready to say
> "But I told it what the encoding was with the enum_encoding
> attribute..." then go back to the first sentence of this post and
> start over.


But..., okay, I'll try to surpress it. But there would still be
dissapointment if the synthesis tool had just ignored my suggested
encoding.

> So now go about writing your conversion function (Hint: A good name
> to use might be 'to_sdd_logic_vector'...conversions the other way
> might well be called 'from_std_logic_vector). For your particular
> case, this can be the one liner that you posted with the 'pos
> attribute, but it doesn't have to be.


Ok, I'll keep it in mind for the next time I need a less than straight
forward conversion.

Thanks for clearing the matter up.

--
Stef (remove caps, dashes and .invalid from e-mail address to reply by mail)
 
Reply With Quote
 
Stef
Guest
Posts: n/a
 
      05-16-2008
In comp.lang.vhdl,
Brian Drummond <(E-Mail Removed)> wrote:

> -- You can separate the encoding from the enumeration
> type encoding_array is array(opmode_t) of std_logic_vector(1 downto 0);
> -- constant encode : encoding_array := ("00", "01", "10");
> -- or for easier maintenance
> constant encode : encoding_array :=
> ( OPMODE_IDENT => "00",
> OPMODE_CONFIG => "01",
> OPMODE_ACQ => "10");
>


> ledsel <= encode(opmode_v);


Nice solution, thanks. And usable to implement that conversion function
as well.

--
Stef (remove caps, dashes and .invalid from e-mail address to reply by mail)
 
Reply With Quote
 
KJ
Guest
Posts: n/a
 
      05-17-2008

"Stef" <(E-Mail Removed)> wrote in message
news:e37a4$482d7ee4$54f63171$(E-Mail Removed)-service.com...
> In comp.lang.vhdl,
> KJ <(E-Mail Removed)> wrote:
>> On May 16, 7:09 am, Stef <(E-Mail Removed)>
>> wrote:
>>> In comp.lang.vhdl,
>>> Stef <(E-Mail Removed)> wrote:

>
>
>> The 'enum_encoding' attribute may (or may not) get used by a synthesis
>> tool to encode your enumerated type but that will not affect the
>> language syntax in any way.

>
> Are you aware of any tools that do not use the enum_encoding
> attribute? I once wrote a state machine and encoded the states so
> that each transition would only be a single-bit change. I would
> gave been upset if the tool just ignored my carefull state layout,
> but fortunately it didn't
>


I'm not aware of any but that's also because I don't use enum_encoding
because there are no guarantees that
- It will work
- It is portable

>> There is nothing built into the language or any of the standard
>> packages that will convert an enumerated type that you create into a
>> std_logic_vector. (If at this point you feel yourself ready to say
>> "But I told it what the encoding was with the enum_encoding
>> attribute..." then go back to the first sentence of this post and
>> start over.

>
> But..., okay, I'll try to surpress it. But there would still be
> dissapointment if the synthesis tool had just ignored my suggested
> encoding.
>


But now that you know the proper way to avoid possible future
disappointments with that approach.

KJ


 
Reply With Quote
 
Thomas Rouam
Guest
Posts: n/a
 
      05-18-2008
Hi Guys,

I wanted to give a little comment on Kevin's statement :
> I'm not aware of any but that's also because I don't use enum_encoding
> because there are no guarantees that
> - It will work
> - It is portable


A synthesis tool that does not handle the enum_encoding attribute, is
then not compliant with the IEEE Standard for VHDL Register Tranfer
Level (RTL) Synthesis (IEEE Std 1076.6). It is said in there :

An attribute named ENUM_ENCODING shall provide a means of encoding
enumeration type values. The attribute specification for this
attribute shall specify the encoding of the enumeration type literals
in the form of a string. This string shall be made up of tokens
separated by one or more spaces. There shall be as many tokens as
there are literals in the enumeration type, with the first token
corresponding to the first enumeration literal, the second token
corresponding to the second enumeration literal, and so on.

The word shall here is equivalent to required to.

Hope this helps as well.

Thomas.
 
Reply With Quote
 
rickman
Guest
Posts: n/a
 
      05-18-2008
On May 18, 4:09 am, Thomas Rouam <(E-Mail Removed)> wrote:
> Hi Guys,
>
> I wanted to give a little comment on Kevin's statement :
>
> > I'm not aware of any but that's also because I don't use enum_encoding
> > because there are no guarantees that
> > - It will work
> > - It is portable

>
> A synthesis tool that does not handle the enum_encoding attribute, is
> then not compliant with the IEEE Standard for VHDL Register Tranfer
> Level (RTL) Synthesis (IEEE Std 1076.6). It is said in there :
>
> An attribute named ENUM_ENCODING shall provide a means of encoding
> enumeration type values. The attribute specification for this
> attribute shall specify the encoding of the enumeration type literals
> in the form of a string. This string shall be made up of tokens
> separated by one or more spaces. There shall be as many tokens as
> there are literals in the enumeration type, with the first token
> corresponding to the first enumeration literal, the second token
> corresponding to the second enumeration literal, and so on.
>
> The word shall here is equivalent to required to.
>
> Hope this helps as well.
>
> Thomas.


Maybe I am missing something, but I don't see where your information
contradicts Kevin's statements. I don't see where the nature of the
"token" is specified. That means that the tokens are not standardized
(Kevin's second point) and therefor may not work (Kevin's second
point).

Unless the IEEE standard specifies the *method* of describing the
enumeration encoding it has not done a lot of good regardless of
whether it is "required" or not.

Rick
 
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
How convert Iterator into Enumeration Jan Burse Java 11 12-01-2012 04:49 PM
Re-using a simple type definition; with enumeration constraint andwithout enumeration constraint puvit82 XML 4 02-01-2008 03:46 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
Convert Between Enumeration and Integer Values Olaf Petzold VHDL 4 11-28-2005 11:31 PM
Record, Enumeration & std_logic_vector Jan Kindt VHDL 5 09-12-2003 10:25 AM



Advertisments