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

Enumerated integer type

Ask a question - edaboard.com

elektroda.net NewsGroups Forum Index - VHDL Language - Enumerated integer type

Colin Beighley
Guest

Fri Jun 24, 2011 6:24 pm   



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

Alan Fitch
Guest

Fri Jun 24, 2011 6:54 pm   



On 24/06/11 17:24, Colin Beighley wrote:
Quote:
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

Colin Beighley
Guest

Sun Jun 26, 2011 7:18 pm   



On Jun 24, 11:54 am, Alan Fitch <a...@invalid.invalid> wrote:
Quote:
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)?

Alan Fitch
Guest

Sun Jun 26, 2011 7:37 pm   



On 26/06/11 18:18, Colin Beighley wrote:
Quote:
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.


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)?

I guess you could go the whole hog and declared an enumerated type
representing -1 and 1, e.g.

type mytype is (minusone, plusone);

then overload operators on that type. You'd also have to write
conversion functions to and from integer. It's all quite feasible, you
just need the time and inclination :-)

regards
Alan


--
Alan Fitch

backhus
Guest

Mon Jun 27, 2011 7:59 am   



On 24 Jun., 18:24, Colin Beighley <colinbeigh...@gmail.com> wrote:
Quote:
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

elektroda.net NewsGroups Forum Index - VHDL Language - Enumerated integer type

Ask a question - edaboard.com

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