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

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

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

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

Добавлен: 13.06.2025

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

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

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

424 C H A P T E R 9 • Counters and Shift Registers

FIGURE 9.69

Simulation of a 4-bit Serial Shift Register with Parallel Load

Table 9.14 summarizes the various possible inputs to each flip-flop as a function of S1 and S0.

Table 9.14 Flip-Flop Inputs as a Function of S1S0 in a Universal Shift Register

S1

S0

Function

D3

D2

D1

D0

0

0

Hold

Q3

Q2

Q1

Q0

0

1

Shift Right

RSI*

Q3

Q2

Q1

1

0

Shift Left

Q2

Q1

Q0

LSI**

1

1

Load

P3

P2

P1

P0

*RSI Right-shift input **LSI Left-shift input

EXAMPLE 9.14

Create a simulation file to verify the operation of the universal shift register of Figure 9.70.

Solution Figure 9.71 shows a possible solution. The following functions are tested:

hold, right shift (LSI ignored), hold, left shift (RSI ignored), load FH, asynchronous clear,

load FH, shift right for two clocks, shift left for three clocks.


INPUT

S1

NOT

INPUT

S0

NOT

INPUT

P0

INPUT

P1

INPUT

P2

INPUT

INPUT

P3

LSI

INPUT

RSI

AND3

AND3

AND3

AND3

AND3

AND3

AND3

AND3

AND3

AND3

AND3

AND3

AND3

AND3

AND3

AND3

OR4

OR4

OR4

OR4

DFF

DFF

DFF

DFF

D3

PRN

Q3

D2

PRN

Q2

D1

PRN

Q1

D0

PRN

Q0

D

Q

D

Q

D

Q

D

Q

CLRN

CLRN

CLRN

CLRN

INPUT

CLOCK

INPUT

CLEAR

OUTPUT

Q0

OUTPUT

S1

S0

Q1

OUTPUT

0

0

HOLD

Q2

0

1

SHIFT RIGHT

OUTPUT

Q3

1

0

SHIFT LEFT

1

1

LOAD

FIGURE 9.70

4-bit Universal Shift Register

425


426 C H A P T E R 9 • Counters and Shift Registers

FIGURE 9.71

Example 9.14

Simulation of a 4-bit Universal Shift Register

SECTION 9.7 REVIEW PROBLEM

9.7Can the D flip-flops in Figure 9.58 be replaced by JK flip-flops? If so, what modifications to the existing circuit are required?

9.8Programming Shift Registers in VHDL

K E Y T E R M S

Structural design A VHDL design technique that connects predesigned components using internal signals.

Dataflow design A VHDL design technique that uses Boolean equations to define

relationships between inputs and outputs.

Behavioral design A VHDL design technique that uses descriptions of required behavior to describe the design.

As with other circuit applications, we can take several approaches to programming shift registers in VHDL. Three basic design techniques are structural, dataflow, and behavioral descriptions. We will use each of these techniques to design a 4-bit shift register, such as the one shown in Figure 9.58.

Structural Design

Structural design is like taking components out of a bin and connecting them together to make a circuit. We can use the DFF component from the MAX PLUS II primitives library and instantiate enough components to make a shift register, with connections made

srg4strc.vhd

srgstrc.scf

9.8 • Programming Shift Registers in VHDL

427

by internal signals. The code to make a 4-bit shift register using the structural design technique is shown here in the file srg4strc.vhd.

——srg4strc.vhd

——Structural description of a 4-bit serial shift register ieee;

ieee.std_logic_1164.ALL; altera;

USE altera.maxplus2.ALL;

ENTITY srg4strc IS

PORT(

serial_in, clk : IN

STD_LOGIC;

qo

: BUFFER

STD_LOGIC_VECTOR(3 downto 0) );

END srg4strc;

ARCHITECTURE right_shift of srg4strc IS

COMPONENT DFF

PORT (d : IN STD_LOGIC;

clk : IN STD_LOGIC;

q : OUT STD_LOGIC); END COMPONENT;

BEGIN

flip_flop_3: dff

PORT MAP (serial_in, clk, qo(3) );

dffs:

FOR i IN 2 downto 0 GENERATE flip_flops_2_to_0: dff

PORT MAP (qo(i + 1), clk, qo(i) );

END GENERATE;

END right_shift;

The design entity srg4strc.vhd instantiates four D flip-flops from the altera. maxplus2 package and connects them by assigning common inputs and outputs to related components. A different way of writing the component instantiations would be as follows.

flip_flop_3: dff

PORT MAP (serial_in, clk, qo(3) ); flip_flop_2: dff

PORT MAP(qo(3), clk, qo(2) ); flip_flop_1: dff

PORT MAP(qo(2), clk, qo(1) ); flip_flop_0: dff

PORT MAP(qo(1), clk, qo(0) );

Since the component ports are in the sequence (D, clk, Q), the component instantiations shown above imply that the D input of a flip-flop is fed by the Q of the previous flip-flop.

The port identifier qo is defined as mode BUFFER, not as OUT, because it is sometimes used as an input and sometimes as an output. A port of mode OUT can only be used as an output. A port of mode BUFFER has a feedback connection so that the output can be reused in the programmed AND matrix of the CPLD macrocell. Figure 9.72 illustrates the difference between these modes.

Rather than defining connections in the component instantiations, we would also be able to use an internal signal to connect the flip-flops. This method allows us to use a port of mode OUT, rather than BUFFER. The file srg4str2.vhd shows this alternative way.


428

C H A P T E R

9

• Counters and Shift Registers

AND

n

D

Q

PIN

Matrix

CLK

a. Driver of mode OUT

FIGURE 9.72

OUT vs. BUFFER

AND

D

Q

PIN

n

Matrix

Feedback to

CLK

AND matrix

b. Driver of mode BUFFER

— —srg4str2.vhd

—— Structural description of a 4-bit serial shift register LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

LIBRARY altera;

USE altera.maxplus2.ALL;

ENTITY srg4str2 IS

PORT (

serial_in, clk : IN STD_LOGIC;

qo

: OUT STD_LOGIC_VECTOR(3 downto 0) );

END srg4str2;

ARCHITECTURE right_shift of srg4str2 IS

srg4str2.vhd

COMPONENT DFF

srg4str2.scf

: IN STD_LOGIC;

PORT (d

clk : IN STD_LOGIC; q : OUT STD_LOGIC);

END COMPONENT;

SIGNAL connect : STD_LOGIC_VECTOR(3 downto 0);

BEGIN

flip_flop_3: dff

PORT MAP (serial_in, clk, connect(3) ); dffs:

FOR i IN 2 downto 0 GENERATE flip_flops_2_to_0: dff

PORT MAP (connect(i + 1), clk, connect(i) );

END GENERATE;

qo <= connect; END right_shift;

In this case, the internal signal connect is used to tie the flip-flops together. The circuit output derives from a signal assignment statement at the end of the file. Since the internal signal connect is used to fulfil the flip-flop input/output functions, qo can be defined solely as an output.

Dataflow Design

Dataflow design describes a design entity in terms of the Boolean relationships between different parts of the circuit. The Boolean relationships in a 4-bit shift register are defined by the expressions for the flip-flop synchronous inputs:


srg4dflw.vhd

srg4dflw.scf

15 Next States

in a Serial

Q2 Q1 Q0

Q3 Q2 Q1

9.8 • Programming Shift Registers in VHDL

429

D3 serial_in

D2 Q3

D1 Q2

D0 Q1

The design entity srg4dflw.vhd illustrates the use of the dataflow design method for a 4-bit serial shift register.

——srg4dflw.vhd

——Dataflow description of a 4-bit serial shift register LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

ENTITY srg4dflw IS

PORT (

serial_in, clk : IN

STD_LOGIC;

q

: BUFFER

STD_LOGIC_VECTOR(3 downto 0) );

END srg4dflw;

ARCHITECTURE right_shift of srg4dflw IS

SIGNAL d : STD_LOGIC_VECTOR(3 downto 0);

BEGIN

PROCESS (clk)

BEGIN

—— Define a 4-bit D flip-flop

IF clk’EVENT and clk = ‘1’ THEN q <= d;

END IF;

END PROCESS;

d <= serial_in & q(3 downto 1); END right_shift;

Before the flip-flops can be connected, they must be defined in a PROCESS statement. The statements inside the process are sequential, as they must be to define a flipflop, but the process itself is a concurrent statement. Signals are applied concurrently (simultaneously) to the construct implied by the process (the flip-flops) and all other concurrent constructs in the design entity (the connections between q and d and the serial input).

A signal assignment statement implements the Boolean equations for the shift register. It is written as a single statement for efficiency, but could also be written as four separate assignment statements, as follows:

d(3) <= serial_in;

d(2) <= q(3);

d(1) <= q(2);

d(0) <= q(1);

We must define q as mode BUFFER, since we are using it as both input and output.

Behavioral Design

We can create a VHDL design entity from the description of its desired behavior. In the case of a shift register, we know that after a clock pulse all data move over one position and the first flip-flop in the chain accepts a bit from a serial input, as indicated in Table 9.15. We can use this behavioral description to implement a serial shift register, as shown in the VHDL file srg4behv.vhd.