Enumerated integer type

Discussion in 'VHDL' started by Colin Beighley, Jun 24, 2011.

  1. 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
     
    Colin Beighley, Jun 24, 2011
    #1
    1. Advertising

  2. On Jun 24, 11:54 am, Alan Fitch <> 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)?
     
    Colin Beighley, Jun 26, 2011
    #2
    1. Advertising

  3. Colin Beighley

    backhus Guest

    On 24 Jun., 18: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


    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
     
    backhus, Jun 27, 2011
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marek Ponca

    Enumerated Type in assertion ?

    Marek Ponca, Jan 10, 2005, in forum: VHDL
    Replies:
    2
    Views:
    3,336
    Jonathan Bromley
    Jan 10, 2005
  2. Nick Bassiliades

    Redefining an enumerated attribute type

    Nick Bassiliades, Dec 9, 2005, in forum: XML
    Replies:
    1
    Views:
    458
    Henry S. Thompson
    Dec 12, 2005
  3. Replies:
    1
    Views:
    392
    Henry S. Thompson
    Mar 6, 2006
  4. David
    Replies:
    0
    Views:
    378
    David
    Mar 1, 2006
  5. John Goche

    assignment of integer to enumerated value

    John Goche, Nov 24, 2006, in forum: C Programming
    Replies:
    7
    Views:
    363
    Ian Collins
    Nov 24, 2006
Loading...

Share This Page