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

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

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

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

Добавлен: 13.06.2025

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

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

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

10.2

• State Machines with No Control Inputs

461

Table 10.2 State Table for a 3-bit Gray Code Counter

Synchronous

Present State

Next State

Inputs

Q2Q1Q0

Q2Q1Q0

D2D1D0

000

001

001

001

011

011

010

110

110

011

010

010

100

000

000

101

100

100

110

111

111

111

101

101

the present state is 010, the next state is not 011, as we would expect, but 110, which we derive by examining the state diagram.

Why list the present states in binary order, rather than the same order as the output sequence? By doing so, we can easily simplify the equations for the D inputs of the flipflops by using a series of Karnaugh maps. This is still possible, but harder to do, if we list the present states in order of the output sequence.

4.Use flip-flop excitation tables to determine at what states the flip-flop synchronous inputs must be to make the circuit go from each present state to its next state. This is not necessary if we use D flip-flops, since Q follows D. The D inputs are the same as the next state outputs. For JK or T flip-flops, we would follow the same procedure as for the design of synchronous counters outlined in Chapter 9.

5.Simplify the Boolean expression for each synchronous input. Figure 10.5 shows three Karnaugh maps, one for each D input of the circuit.

Q0

0

1

Q0

0

1

Q0

0

1

Q2 Q1

Q2 Q1

Q2 Q1

00

0

0

00

0

1

00

1

1

2

1

Q

Q

Q2

Q0

01

1

0

01

1

1

01

0

0

Q1 Q0

Q1

0

Q

11

1

1

11

1

1

Q2 Q0

11

1

0

Q2 Q1

10

0

1

10

0

0

10

0

0

D2

D1

D0

FIGURE 10.5

Karnaugh Maps for 3-bit Gray Code Counter

The K-maps yield three Boolean equations:

D2 Q1Q0 Q2Q0

D1 Q1Q0 Q2Q0

D0 Q2 Q1 Q2Q1

6.Draw the logic circuit for the state machine. Figure 10.6 shows the circuit for a 3-bit Gray code counter, drawn as a Graphic Design File in MAX PLUS II. A simulation for this circuit is shown in Figure 10.7, with the outputs shown as individual waveforms and as a group with a binary value.


462

Q2

NOT

Q1

NOT

Q0

NOT

AND2

AND2

AND2

AND2

AND2

AND2

OR2

OR2

OR2

DFF

DFF

DFF

PRN

Q2

PRN

Q1

PRN

Q0

D

Q

D

Q

D

Q

CLRN

CLRN

CLRN

INPUT

OUTPUT

CLK

Q0

OUTPUT

Q1

OUTPUT

Q2

FIGURE 10.6

Logic Diagram of a 3-bit Gray Code Counter


10.2 • State Machines with No Control Inputs

463

gray_ct3.gof gray_ct3.scf

FIGURE 10.7

Simulation of a 3-bit Gray Code Counter (from Graphic Design File)

VHDL Design of State Machines

K E Y T E R M S

Enumerated type A user-defined type in VHDL in which all possible values of a

named identifier are listed in a type definition statement.

State machines can be defined in VHDL within a CASE statement. The VHDL code below illustrates the principle, using the 3-bit Gray code counter as an example.

––gray_ct1.vhd

––3-bit Gray code counter

––(state machine with decoded outputs)

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

ENTITY gray_ct1 IS

PORT(

clk

: IN

STD_LOGIC;

q

: OUT

STD_LOGIC_VECTOR(2 downto 0));

END gray_ct1;

s6, s7);

gray_ct1.vhd

BEGIN

PROCESS (clk)

BEGIN

IF clk’EVENT AND clk = ‘1’ THEN

CASE state IS

WHEN s0 => state <= s1;

WHEN s1 => state <= s2;

WHEN s2 => state <= s3;

WHEN s3 => state <= s4;

WHEN s4 => state <= s5;


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

WHEN s5 =>

state <= s6;

WHEN s6=>

state <= s7;

WHEN s7 =>

state <= s0;

END CASE;

END IF;

END PROCESS;

WITH state SELECT

q <= “000”

WHEN s0,

“001”

WHEN s1,

“011”

WHEN s2,

“010”

WHEN s3,

“110”

WHEN s4,

“111”

WHEN s5,

“101”

WHEN s6,

“100”

WHEN s7;

END a;

Recall that the format of a CASE statement is:

CASE __expression IS

WHEN__constant_value =>

__statement; __statement;

WHEN__constant_value => __statement; __statement;

WHEN OTHERS => __statement; __statement;

END CASE;

The keyword expression in the CASE statement refers to a signal called state that we define to represent the state variables within the machine. For each possible value of state, we make an assignment indicating the next state of the machine. For example, the clause (WHEN s0 => (state <= s1)); indicates a transition from state s0 to state s1. The actual output values of the counter are assigned in a selected signal assignment statement after the PROCESS statement.

Notice that the signal state can have one of eight different values, from s0 to s7. Until now, we have seen signals with values such as ‘1’ (BIT or STD_LOGIC types), “011” (BIT_VECTOR or STD_LOGIC_VECTOR types), or 7 (INTEGER types). The signal state is of type STATE_TYPE, which is a user-defined enumerated type. An enumerated type is simply a list of all values a signal, variable, or port of that type is allowed to have.

For example, we could define a type called DIRECTION with four values, with the statement:

TYPE DIRECTION IS (up, down, left, right);

We could then define a signal called position of type DIRECTION:

SIGNAL position: DIRECTION:

An IF statement or other construct could then assign one of the four defined values of type DIRECTION to the signal called position:


10.3 • State Machines with Control Inputs

465

IF (x=‘0’ and y=‘0’) THEN

position <= down;

ELSIF (x=‘0’ and y=‘1’) THEN

position <= left;

ELSIF (x=‘1’ and y=‘0’) THEN

position <= up;

ELSE

position <= right;

END IF;

Thus the named identifier position of type DIRECTION can take on only the four values specified in the enumerated type definition.

An alternative way to encode the 3-bit counter is to include output assignments within the body of the CASE statement. Each case then has more than one statement, as indicated in the following VHDL code.

-- gray_ct2.vhd

-- 3-bit Gray code counter

-- (outputs defined within states)

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

ENTITY gray_ct2 IS

PORT(

clk

: IN

STD_LOGIC;

q

: OUT

STD_LOGIC_VECTOR(2 downto 0));

END gray_ct2;

ARCHITECTURE a OF gray_ct2 IS

TYPE STATE_TYPE IS (s0, s1, s2, s3, s4, s5, s6, s7);

SIGNAL state: STATE_TYPE;

BEGIN

PROCESS (clk)

BEGIN

IF clk’EVENT AND clk = ‘1’ THEN

CASE state IS

WHEN s0 =>

state <= s1;

q <= “001”;

gray_ct2.vhd

<= s2;

“011”;

WHEN s2 =>

state <= s3;

q <= “010”;

WHEN s3 =>

state <= s4;

q <= “110”;

WHEN s4 =>

state <= s5;

q <= “111”;

WHEN s5 =>

state <= s6;

q <= “101”;

WHEN s6 =>

state <= s7;

q <= “100”;

WHEN s7 =>