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

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

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

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

Добавлен: 13.06.2025

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

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

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

FIGURE 7.34

Sensors

Example 7.5

1

D Latch Collection of Data

2

3

4

Timing

Pulse

7.3 • Gated Latches

295

Data Logging System

D1

Q1

Q1

ENA

D2

Q2

Q2

ENA

D3

Q3

Q3

ENA

D4

Q4

Q4

ENA

is captured for later analysis by a set of D latches, as shown in Figure 7.34. A timing pulse enables the latches once every five seconds and thus stores the system status as a “snapshot” of the traffic pattern.

Figure 7.35 shows the timing diagram of a typical traffic pattern at the intersection. The D inputs show the cars passing through the intersection in the various lanes. Complete this timing diagram by drawing the Q outputs of the latches.

How should we interpret the Q output waveforms?

FIGURE 7.35

Example 7.5

Latch Configuration and Timing

Diagram


296 C H A P T E R 7 • Introduction to Sequential Logic

SOLUTION Figure 7.35 shows the completed timing diagram. The ENABLE input synchronizes the random sensor pattern to a 5-second standard interval. A HIGH on any Q output indicates a car over a sensor at the beginning of the interval. For example, at the beginning of the first interval, there is a car in the northbound lane (Q1) and one in the

southbound lane (Q2). Similar interpretations can be made for each interval.

Multi-bit Latches in VHDL

K E Y T E R M S

Library of Parameterized Modules (LPM) A standardized set of components for which certain properties can be specified when the component is instantiated.

Parameter (in an LPM component) A property of a component that can be specified when the component is instantiated.

Generic map A VHDL construct that maps one or more parameters of a component to a value for that instance of the component.

Port map A VHDL construct that maps the name of a port in a component to the name of a port, variable, or signal in a design entity that uses the component.

We can easily use VHDL to implement latches with multiple D inputs and Q outputs, but with a common ENABLE line, as in Figure 7.34. Three approaches are:

1.Use a behavioral description, as we did earlier for a single latch (d_lch.vhd). Use STD_LOGIC_VECTOR types for D and Q, rather than STD_LOGIC.

2.Altera recommends using a latch primitive or predefined component, rather than creating your own latch structures. We can use multiple LATCH primitives, instantiated by a GENERATE statement, as we did for multiple instances of a full adder in Chapter 6.

3.Use a latch component from the Library of Parameterized Modules (LPM). These components are specified in the lpm_components package in the lpm library.

Certain properties of an LPM component, such as the number of inputs or outputs, can be specified when the component is instantiated. These properties are referred to as parameters, and are listed in a generic map. For example, to make the latch output and input four bits wide, we set the parameter called LPM_WIDTH to a value of 4. The various parameters of an LPM component can be found in the LPM Quick Reference on the CD that accompanies this book or in the MAX PLUS II Help menu under

Megafunctions/LPM.

An input or output of an LPM component is called a port. A port map is used to make a correspondence between the port names in the component declaration and the port names used in the file containing the component. Since LPM components are declared in a separate package, we must refer to the MAX PLUS II Help or the LPM Quick Reference to determine the port names for a component. LPM components are instantiated the same as any other component.

The three VHDL files that follow each specify a 4-bit latch with common enable, each using one of the above methods.

Behavioral Description:

——ltch4bhv.vhd

——D latch with active-HIGH level-sensitive enable

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;


ltch4bhv.vhd

ltch4prm.vhd

ltch4lpm.vhd

ltch4lpm.scf

7.3 • Gated Latches

297

ENTITY ltch4bhv

IS

PORT(d

:

IN

STD_LOGIC_VECTOR (3 downto 0);

enable

:

IN

STD_LOGIC;

q

:

OUT

STD_LOGIC_VECTOR (3 downto 0));

END ltch4bhv;

a OF ltch4bhv IS

(enable, d)

BEGIN

IF (enable ´1´) THEN q d;

END IF;

END PROCESS;

END a;

4 LATCH Primitives and a GENERATE Statement:

——ltch4prm.vhd

——D latch with active-HIGH level-sensitive enable

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

LIBRARY altera;

USE altera.maxplus2.ALL;

ENTITY ltch4prm

IS

PORT(d_in : IN

STD_LOGIC_VECTOR (3 downto 0);

enable

: IN

STD_LOGIC;

q_out

: OUT

STD_LOGIC_VECTOR (3 downto 0));

END ltch4prm;

ARCHITECTURE a OF ltch4prm IS BEGIN

—— Instantiate a latch from a MAX PLUS II primitive latch4:

FOR i IN 3 downto 0 GENERATE latch_primitive: latch

PORT MAP (d d_in (i), ena enable, q q_out (i)); END GENERATE;

END a;

LPM Latch:

——ltch4lpm.vhd

——4-BIT D latch with active-HIGH level-sensitive enable

——Uses a latch component from the Library of Parameterized

——Modules (LPM)

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

LIBRARY lpm;

USE lpm.lpm_components.ALL;

ENTITY ltch4lpm

IS

PORT(d_in

: IN

STD_LOGIC_VECTOR (3 downto

0);

enable

: IN

STD_LOGIC;

q_out

: OUT

STD_LOGIC_VECTOR (3 downto

0) );

END ltch4lpm;


q_out);

298 C H A P T E R 7 • Introduction to Sequential Logic

ARCHITECTURE a OF ltch4lpm IS

BEGIN

—— Instantiate latch from an LPM component latch4: lpm_latch

GENERIC MAP (LPM_WIDTH 4) PORT MAP (data d_in,

gate enable, q

END a;

All three files can be tested with the same simulation, shown in Figure 7.36. The inputs, d_in, represent a 4-bit group of signals, as do the outputs, q_out. An increasing count, from 5 to C (0101 to 1100) is applied to d_in. This count contains both states (0 and 1) for each input bit. For each applied input state, the output bus, q_out, does not change until the enable line goes HIGH.

FIGURE 7.36

Simulation of a 4-bit D Latch

SECTION 7.3 REVIEW PROBLEM

7.3Write the VHDL code for a 16-bit latch with common active-HIGH enable, using MAX PLUS II latch primitives.

7.4Edge-Triggered D Flip-Flops

K E Y T E R M S

Edge The HIGH-to-LOW (negative edge) or LOW-to-HIGH (positive edge) transition of a pulse waveform.

CLOCK An enabling input to a sequential circuit that is sensitive to the positiveor negative-going edge of a waveform.

Edge-triggered Enabled by the positive or negative edge of a digital waveform.

Edge-sensitive Edge-triggered.

Level-sensitive Enabled by a logic HIGH or LOW level.

Flip-flop A sequential circuit based on a latch whose output changes when its

CLOCK input receives an edge.

In Example 7.4, we saw how a shorter pulse width at the ENABLE input of a gated latch increased the chance of the output being synchronized to the ENABLE pulse waveform. This is because a shorter ENABLE pulse gives less chance for the SET and RESET inputs to change during the time the latch is enabled.

A logical extension of this idea is to enable the latch for such a small time that the width of the ENABLE pulse is almost zero. The best approximation we can make to this is to allow changes to the circuit output only when an enabling, or CLOCK, input receives the edge of an input waveform. An edge is the part of a waveform that is in transition from

7.4 • Edge-Triggered D Flip-Flops

299

LOW to HIGH (positive edge) or HIGH to LOW (negative edge), as shown in Figure 7.37.

We can say that a device enabled by an edge is edge-triggered or edge-sensitive.

FIGURE 7.37

Edges of a CLOCK Waveform

Since the CLOCK input enables a circuit only while in transition, we can refer to it as a “dynamic” input. This is in contrast to the ENABLE input of a gated latch, which is levelsensitive or “static,” and will enable a circuit for the entire time it is at its active level.

FIGURE 7.38

D Flip-Flop Logic Symbol

FIGURE 7.39

D Flip-Flop Equivalent Circuit

Latches vs. Flip-Flops

K E Y T E R M

Edge detector A circuit in an edge-triggered flip-flop that converts the active edge of a CLOCK input to an active-level pulse at the internal latch’s SET and RESET inputs.

A gated latch with a clock input is called a flip-flop. Although the distinction is not always understood, we will define a latch as a circuit with a level-sensitive enable (e.g., gated D latch) or no enable (e.g., NAND latch) and a flip-flop as a circuit with an edge-triggered clock (e.g., D flip-flop). A NAND or NOR latch is sometimes called an SR flip-flop. By our definition this is not correct, since neither of these circuits has a clock input. (An SR flip-flop would be like the gated SR latch of Figure 7.27 with a clock instead of an enable input.)

The symbol for the D, or data, flip-flop is shown in Figure 7.38. The D flip-flop has the same behavior as a gated D latch, except that the outputs change only on the positive edge of the clock waveform, as opposed to the HIGH state of the enable input. The triangle on the CLK (clock) input of the flip-flop indicates that the device is edge-triggered.

Table 7.6 shows the function table of a positive edge-triggered D flip-flop.

Figure 7.39 shows the equivalent circuit of a positive edge-triggered D flip-flop. The circuit is the same as the transparent latch of Figure 7.29, except that the enable input (called CLK in the flip-flop) passes through an edge detector, a circuit that converts a positive edge to a brief positive-going pulse. (A negative edge detector converts a negative edge to a positive-going pulse.)

Table 7.6 Function Table for a Positive

Edge-Triggered D Flip-Flop

CLK

D

Qt 1

Qt 1

Function

0

0

1

Reset

1

1

0

Set

0

X

Qt

Qt

Inhibited

1

X

Qt

Qt

Inhibited

X

Qt

Qt

Inhibited