VHDL

Manually Specifying State Assignments



You can override the Quartus® II Compiler's automatic state assignments and specify your own state assignments with the ENUM_ENCODING attribute. The ENUM_ENCODING attribute must follow the associated Type Declaration and precede any associated Signal Declarations. To use the ENUM_ENCODING attribute during compilation, set the State Machine Processing logic option to User-Encoded in the Default Logic Option Settings page of the Settings dialog box (Assignments menu).

NOTE
  1. The ENUM_ENCODING attribute is Quartus II-specific, and may not be available with other VHDL tools.

  2. If you use the ENUM_ENCODING attribute to manually specify state assignments, the Compiler will use these assignments and not attempt to recognize a state machine in a project. As a result, the Compiler will process any state machine as "regular" logic, and a state machine will not be listed as a state machine in the Compilation Report for the project. For information on the characteristics that cause a design to be recognized as a state machine, go to Implementing State Machines.

  3. Because the Compiler usually produces the best results, Altera® recommends that you do not use the ENUM_ENCODING attribute, but instead allow the Compiler to recognize and encode the state machine.

In the following example, the ENUM_ENCODING attribute is defined and declared:

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY enumsmch IS
   PORT 
   (
      updown    : IN STD_LOGIC;
      clock     : IN STD_LOGIC;
      lsb       : OUT STD_LOGIC;
      msb       : OUT STD_LOGIC
   );
END enumsmch;

ARCHITECTURE firstenumsmch OF enumsmch IS
   TYPE count_state is (zero, one, two, three);
   ATTRIBUTE ENUM_ENCODING                : STRING;
   ATTRIBUTE ENUM_ENCODING OF count_state : TYPE IS "11 01 10 00";
   SIGNAL present_state, next_state       : count_state;
BEGIN

   PROCESS (present_state, updown)
   BEGIN
      CASE present_state IS
         WHEN zero =>
            IF (updown = '0') THEN
               next_state <= one;
               lsb <= '0';
               msb <= '0';
            ELSE
               next_state <= three;
               lsb <= '1';
               msb <= '1';
            END IF;
         WHEN one =>
            IF (updown = '0') THEN
               next_state <= two;
               lsb <= '1';
               msb <= '0';
            ELSE
               next_state <= zero;
               lsb <= '0';
               msb <= '0';
            END IF;
         WHEN two =>
            IF (updown = '0') THEN
               next_state <= three;
               lsb <= '0';
               msb <= '1';
            ELSE
               next_state <= one;
               lsb <= '1';
               msb <= '0';
            END IF;
         WHEN three =>
            IF (updown = '0') THEN
               next_state <= zero;
               lsb <= '1';
               msb <= '1';
            ELSE
               next_state <= two;
               lsb <= '0';
               msb <= '1';
            END IF;
      END CASE;
   END PROCESS;
   
   PROCESS
   BEGIN
      WAIT UNTIL clock'EVENT and clock = '1';
      present_state <= next_state;
   END PROCESS;
   
END firstenumsmch;

The ENUM_ENCODING attribute must be a STRING literal that contains a series of state assignments. These state assignments are the constant values that correspond to the state names in the Enumerated Type Declaration. In this example, the states are encoded with the following values:

zero    = "11"
one     = "01"
two     = "10"
three   = "00"

Back to Top

- PLDWorld -

 

Created by chm2web html help conversion utility.