Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Enumerated integer type

Reply
Thread Tools

Enumerated integer type

 
 
Colin Beighley
Guest
Posts: n/a
 
      06-24-2011
Hello,

I'd like to declare a type like this

type mytype is (-1,1);

However, it appears that enumerated types aren't allowed to be
integers.

Is there a way to create an integer subtype where the values of the
type are constrained to certain hand-picked values, rather than a
range? The workaround for this is to use std_logic and convert it to
signed when you need to, but it seems an integer subtype would work
better.

Colin
 
Reply With Quote
 
 
 
 
Colin Beighley
Guest
Posts: n/a
 
      06-26-2011
On Jun 24, 11:54*am, Alan Fitch <a...@invalid.invalid> wrote:
> On 24/06/11 17:24, Colin Beighley wrote:
>
>
>
>
>
>
>
>
>
> > Hello,

>
> > I'd like to declare a type like this

>
> > type mytype is (-1,1);

>
> > However, it appears that enumerated types aren't allowed to be
> > integers.

>
> > Is there a way to create an integer subtype where the values of the
> > type are constrained to certain hand-picked values, rather than a
> > range? The workaround for this is to use std_logic and convert it to
> > signed when you need to, but it seems an integer subtype would work
> > better.

>
> > Colin

>
> Enumerated types can be a mixture of character literals and identifiers.
>
> What you probably want is an integer subtype, e.g.
>
> subtype mytype is integer range -1 to 1;
>
> Because this is a subtype of integer, it can be assigned to and from
> integers and other integer subtypes.
>
> regards
> Alan
>
> --
> Alan Fitch


My problem is that I want this type to only be able to assume the
values of -1 and 1, not 0. However, I suppose the declaration of a new
type for this is inconvenient because if I want to do any math with
the type I have to convert to a new integer type if the result assumes
a value that is not (-1,1)?
 
Reply With Quote
 
 
 
 
backhus
Guest
Posts: n/a
 
      06-27-2011
On 24 Jun., 18:24, Colin Beighley <colinbeigh...@gmail.com> wrote:
> Hello,
>
> I'd like to declare a type like this
>
> type mytype is (-1,1);
>
> However, it appears that enumerated types aren't allowed to be
> integers.
>
> Is there a way to create an integer subtype where the values of the
> type are constrained to certain hand-picked values, rather than a
> range? The workaround for this is to use std_logic and convert it to
> signed when you need to, but it seems an integer subtype would work
> better.
>
> Colin


Hi,
Not sure what you are about to do with this kind of type declaration
You can declare some ordinary enumerated type like :
type mytype is (neg,pos);
Then you can access the integers then with some simple conversion
function:
function getint(a : mytype) return integer range -1 to 1; -- or
whatever you like to call that function

usage example:
xx <= xx * getint(neg);

Have a nice synthesis
Eilert
 
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
assignment of integer to enumerated value John Goche C Programming 7 11-24-2006 09:03 PM
define attribute as NOT a member of enumerated type davidmcb@pacbell.net XML 1 03-06-2006 05:16 AM
define attribute as NOT a member of enumerated type David XML 0 03-01-2006 01:11 PM
Redefining an enumerated attribute type Nick Bassiliades XML 1 12-12-2005 01:21 PM
Enumerated Type in assertion ? Marek Ponca VHDL 2 01-10-2005 10:32 AM



Advertisments