FPGA Center



ENUMERATION

Sorted values (type_elements) are  specified by listing in enumaration. The elements in an enumaration type must be different from each other. However the same named elements can be used in different types of enumarations. This is called overloading.

type type_name is (type_element, type_element, ...);

NOTE:

EXAMPLE 1

type NotGood is (X, '0', '1', X); -- Wrong (X is used twice in the same place)
type MyBit is (L, H);--True
type Test is ('0', '1', L, H); -- True (Same  L and H elements are used in previous bir önceki enumeration type)
type  Door is (Exit, Entrance); -- Wrong (Vhdl reserved word is used as type element)
type Business is (12_h, 9_h); -- Wrong (It must be start with a letter)
type XYZ is (_tyr, _abc);-- Wrong (It must be start with a letter)
type WTG is (Red, hgt_3, ogrenci_4); -- True

EXAMPLE  2


type Color is (blue, red, yellow, green);
type MY_LOGIC is (’0’, ’1’, ’U’, ’Z’);
variable TEMP: Color;
signal SIG: MY_LOGIC;
. . .
TEMP:= blue;
SIG <= ’Z’;

Enumeration Overloading


In Vhdl programs, if a type_element  used in more than one enumeration type, Enumeration Overloading (overload) occurs.

In order not to cause any mistake or absurdity, you have to specify the enumeration type that you will use in the program. In the example below:

type Color is (blue, red, yellow, green,white);
type primary_color is (blue, red, yellow);
...
A <= Color’(red);
While assigning red to A variable, we have to specify which data type to be used by using Color’ expression.


Enumeration Encoding


After enumeration declaration, the VHDL compiler automatically assigns, 0 to the first value 1 to the second value Therefore it assigns numbers to each type_elements, then converts them to bit_vector format.

In the example below:

type Color is (blue, red, yellow, green,white);

The values below are assigned to type_elements:

blue =”000”
red =”001”
yellow =”010”
green =”011”
white =”100”

In conclusion, the sorting becomes:

blue < red < yellow < green < white

You can assign values instead of VHDL compiler.

EXAMPLE 3:


type Color is (blue, red, yellow, green,white);

attribute enumeration_encoding of Color: type is ”010 000 011 100 001”;
type Color is (blue, red, yellow, green,white);

The values below are assigned to type_elements:

blue =”010”
red =”000”
yellow =”011”
green =”100”
white =”001”

In conclusion, the sorting becomes:

red < white < blue < yellow < green

EXAMPLE 4:


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity ENUMERATION_TY is
      Port ( CLK   : in  STD_LOGIC;
                OUT1 : out  STD_LOGIC);
end ENUMERATION_TY;

architecture Behavioral of ENUMERATION_TY is
type Color is (blue, red, yellow, green,white);
signal my_color: Color:= yellow;
signal temp: Color;
begin
    process(CLK)
         variable counter:integer:=0;
         begin
              if CLK='1' and CLK'event then
                  counter:= counter +1;
                   if counter =6 then
                        counter:=1;
                   end if;
                   case counter is
                             when 1  => temp<= blue;
                             when 2 => temp<= red;
                             when 3 => temp<= yellow;
                             when 4 => temp<= green;
                             when others => temp<= white;
                  end case;
                  if temp<my_color then
                      OUT1<='1';
                  else
                      OUT1<='0';
                 end if;
            end if;
    end process;
end Behavioral;

The simulation plot with Modelsim:

1

                                                                                                          

    

                                                                                                                                    

 

                                                                                                                                                                                                                                                                   

Home | Fpga | VHDL | VHDL Dictionary | Digital Design | Simulation | PCB | Examples | Contact Us
Copyright © 2010 - 2013 FPGAcenter. All Rights Reserved.