Файл: Digital design with CPLD applications and VHDL (R. Dueck, 2000).pdf

ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 13.06.2025

Просмотров: 8172

Скачиваний: 6

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

466 C H A P T E R 1 0 • State Machine Design

state <= s0;

q <= “000”;

END CASE;

END IF;

END PROCESS;

END a;

The above VHDL code is identical to that of the previous example, except for the way the outputs are assigned.

SECTION 10.2 REVIEW PROBLEM

10.2Write the Boolean equations for the J and K inputs of the flip-flops in a 3-bit Gray code counter based on JK flip-flops.

10.3State Machines with Control Inputs

K E Y T E R M S

Control input A state machine input that directs the machine from state to state.

Conditional transition A transition between states of a state machine that occurs only under specific conditions of one or more control inputs.

Unconditional transition A transition between states of a state machine that occurs regardless of the status of any control inputs.

As an extension of the techniques used in the previous section, we will examine the design of state machines that use control inputs, as well as the clock, to direct their operation. Outputs of these state machines will not necessarily be the same as the states of the machine’s flip-flops. As a result, this type of state machine requires a more detailed state diagram notation, such as that shown in Figure 10.8.

The state machine represented by the diagram in Figure 10.8 has two states, and thus

FIGURE 10.8

in1/out1, out2

State Diagram Notation

1/00

State name

Legend

start

State variable

0

X /01

Input value

Output value

0/10

Unconditional

continue

Conditional

1

transition

transition

requires only one state variable. Each state is represented by a bubble (circle) containing the state name and the value of the state variable. For example, the bubble containing the

notation start indicates that the state called start corresponds to a state variable with a

0

value of 0. Each state must have a unique value for the state variable(s).

Transitions between states are marked with a combination of input and output values


10.3 • State Machines with Control Inputs

467

corresponding to the transition. The inputs and outputs are labeled in1, in2, . . . , inx/out1, out2, . . . ,outx. The inputs and outputs are sometimes simply indicated by the value of each variable for each transition. In this case, a legend indicates which variable corresponds to which position in the label.

For example, the legend in the state diagram of Figure 10.8 indicates that the inputs and outputs are labeled in the order in1/out1, out2. Thus if the machine is in the start state and the input in1 goes to 0, there is a transition to the state continue. During this transition, out1 goes to 1 and out2 goes to 0. This is indicated by the notation 0/10 beside the transitional arrow. This is called a conditional transition because the transition depends on the state of in1. The other possibility from the start state is a no-change transition, with both outputs at 0, if in1 1. This is shown as 1/00.

If the machine is in the state named continue, the notation X/01 indicates that the machine makes a transition back to the start state, regardless of the value of in1, and that out1 0 and out2 1 upon this transition. Since the transition always happens, it is called an unconditional transition.

What does this state machine do? We can determine its function by analyzing the state diagram, as follows.

1.There are two states, called start and continue. The machine begins in the start state and waits for a LOW input on in1. As long as in1 is HIGH, the machine waits and the outputs out1 and out2 are both LOW.

2.When in1 goes LOW, the machine makes a transition to continue in one clock pulse. Output out1 goes HIGH.

3.On the next clock pulse, the machine goes back to start. The output out2 goes HIGH and out1 goes back LOW.

4.If in1 is HIGH, the machine waits for a new LOW on in1. Both outputs are LOW again. If in1 is LOW, the cycle repeats.

In summary, the machine waits for a LOW input on in1, then generates a pulse of one clock cycle duration on out1, then on out2. A timing diagram describing this operation is shown in Figure 10.9.

CLK

in1

out1

out2

start start

continue

FIGURE 10.9

Ideal Operation of State Machine in Figure 10.8

Classical Design of State Machines with Control Inputs

We can use the classical design technique of the previous section to design a circuit that implements the state diagram of Figure 10.8.

1.Define the problem. Implement a digital circuit that generates a pulse on each of two outputs, as described above. For this implementation, let us use JK flip-flops for the state logic. If we so chose, we could also use D or T flip-flops.

2.Draw a state diagram. The state diagram is shown in Figure 10.8.


468 C H A P T E R 1 0 • State Machine Design

Table 10.3 State Table for State Diagram in Figure 10.8

Present

Next

Sync.

State

Input

State

Inputs

Outputs

Q

in1

Q

JK

out1

out2

0

0

1

1X

1

0

0

1

0

0X

0

0

1

0

0

X1

0

1

1

1

0

X1

0

1

3.Make a state table. The state table is shown in Table 10.3. The combination of present state and input are listed in binary order, thus making Table 10.3 into a truth table for the next state and output functions. Since there are two states, we require one state variable, Q. The next state of Q, a function of the present state and the input in1, is determined by examining the state diagram. (Thus, if you are in state 0, the next state is 1 if in1 0 and 0 if in1 1. If you are in state 1, the next state is always 0.)

10.4JK Flip-Flop 4. Use flip-flop excitation tables to determine at what states the flip-flop synchronous in-

Table

JK

00X

11X

0X1

1X0

puts must be to make the circuit go from each present state to its next state. Table 10.4 shows the flip-flop excitation table for a JK flip-flop. The synchronous inputs are derived from the present-to-next state transitions in Table 10.4 and entered into Table 10.3. (Refer to the synchronous counter design process in Chapter 9 for more detail about using flip-flop excitation tables.)

5.Write the output values for each present state/input combination. These can be determined from the state diagram and are entered in the last two columns of Table 10.3.

6.Simplify the Boolean expression for each output and synchronous input. The following equations represent the next state and output logic of the state machine:

J Q in1 Q in1 in1

K 1 out1 Q in1

out2 Q in1 Q in1 Q

7. Use the Boolean expressions found in step 6 to draw the required logic circuit.

Figure 10.10 shows the circuit of the state machine drawn as a MAX PLUS II Graphic Design File. Since out1 is a function of the control section and the memory section of the machine, we can categorize the circuit as a Mealy machine. (All counter circuits that we have previously examined have been Moore machines since their outputs are derived solely from the flip-flop outputs of the circuit.)

changes of out-

state_x2a.gdf

waveforms of Fig-

state_x2a.scf

JKFF

NOT

PRN

in1

INPUT

J

OUTPUT

Q

out2

clk

INPUT

K

VCC

CLRN

BAND2

OUTPUT

out1

FIGURE 10.10

Implementation of State Machine of Figure 10.8


10.3 • State Machines with Control Inputs

469

FIGURE 10.11

Simulation of State Machine Circuit of Figure 10.10

Ideally, out1 should not change until the first positive clock edge after in1 goes LOW. However, since out1 is derived from a combinational output, it will change as soon as in1 goes LOW, after allowing for a short propagation delay. Also, since out2 is derived directly from a flip-flop and out1 is derived from the same flip-flop via a gate, out1 stays HIGH for a short time after out2 goes HIGH. (The extra time represents the propagation delay of the gate.)

If output synchronization is a problem (and it may not be), it can be fixed by adding a synchronizing D flip-flop to each output, as shown in Figure 10.12.

JKFF

DFF

INPUT

NOT

PRN

PRN

OUTPUT

in1

J

D

Q

Q

out2

VCC

K

CLRN

CLRN

DFF

BAND2

PRN

OUTPUT

D

Q

out1

clk

INPUT

CLRN

FIGURE 10.12

State Machine with Synchronous Outputs

state_x3a.gdf state_x3a.scf

The state variable is stored as the state of the JK flip-flop. This state is clocked through flip-flop to generate out2 and combined with in1 to generate out1 via another flip-flop. simulation for this circuit, shown in Figure 10.13, indicates that the two outputs are

synchronous with the clock, but delayed by one clock cycle after the state change.

VHDL Implementation of State Machines with Control Inputs

The VHDL code for a state machine with one or more control inputs is similar to that for a machine with no control inputs. The machine states are still defined using a CASE statement, but a case representing a conditional transition will contain an IF statement.