|
|
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).
|
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"
|
- PLDWorld - |
|
|
| Created by chm2web html help conversion utility. |