AHDL

Implementing State Machines



You can create a state machine by declaring the name of the state machine, its states, and, optionally, the state machine bits in a State Machine Declaration in the Variable Section.

The simple.tdf file shown below has the same functionality as a D flipflop (DFF).

SUBDESIGN simple
(
   clk, reset, d : INPUT;
   q             : OUTPUT;
)
VARIABLE
   ss: MACHINE WITH STATES (s0, s1);
BEGIN
   ss.clk = clk;
   ss.reset = reset;

   CASE ss IS
      WHEN s0 =>
         q = GND;

         IF d THEN
            ss = s1;
         END IF;
      WHEN s1 =>
         q = VCC;

         IF !d THEN
            ss = s0;
         END IF;
   END CASE;

END;

In simple.tdf, a state machine with the name ss is declared in a State Machine Declaration in the Variable Section. The states of the machine are defined as s0 and s1, and no state bits are declared.

State machine transitions define the conditions under which the state machine changes to a new state. You must conditionally assign the states within a single behavioral construct to specify state machine transitions. Case or Truth Table Statements are recommended for this purpose. For example, in simple.tdf, the transitions out of each state are defined in the WHEN clauses of the Case Statement.

You can also define an output value for a state with an If Then or Case Statement. In Case Statements, these assignments are made in WHEN clauses. For example, in simple.tdf, output q is assigned to GND when state machine ss is in state s0, and to VCC when the machine is in state s1.

Output values can also be defined in truth tables, as described in Assigning State Machine Bits & Values.


Back to Top

- Altera -

 

Created by chm2web html help conversion utility.