Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Digital design with CPLD applications and VHDL (R. Dueck, 2000)

.pdf
Скачиваний:
259
Добавлен:
12.08.2013
Размер:
9 Mб
Скачать

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

Figure 7.40 shows a circuit that acts as a simplified positive edge detector. Edge detection depends on the fact that a gate output does not switch immediately when its input switches. There is a delay of about 3 to 10 ns from input change to output change, called propagation delay.

FIGURE 7.40

Positive Edge Detector

When input x, shown in the timing diagram of Figure 7.40, goes from LOW to HIGH, the inverter output, x, goes from HIGH to LOW after a short delay. This delay causes both x and x to be HIGH for a short time, producing a high-going pulse at the circuit output immediately following the positive edge at x.

When x returns to LOW, x goes HIGH after a delay. However, there is no time in this sequence when both AND inputs are HIGH. Therefore, the circuit output stays LOW after the negative edge of the input waveform.

Figure 7.41 shows how the D flip-flop circuit operates. When D 0 and the edge detector senses a positive edge at the CLK input, the output of the lower NAND gate steers a low-going pulse to the RESET input of the latch, thus storing a 0 at Q. When D 1, the upper NAND gate is enabled. The edge detector sends a high-going pulse to the upper steering gate, which transmits a low-going SET pulse to the output latch. This action stores a 1 at Q.

FIGURE 7.41

Operation of a D Flip-Flop

 

 

 

7.4 •

Edge-Triggered D Flip-Flops

301

 

 

 

 

EXAMPLE 7.6

Figure 7.42 shows a MAX PLUS II Graphic Design File with a D latch and a D flip-

 

flop connected to the same data input and clock. Create a MAX PLUS II simulation that

 

illustrates the difference between the latch (level-sensitive enable) and the flip-flop (edge-

 

triggered clock).

 

 

 

 

 

 

 

 

 

LATCH

 

 

 

 

 

 

INPUT

 

 

 

 

 

 

 

D

 

D

 

OUTPUT

Q_latch

 

INPUT

 

Q

 

CLK

 

ENA

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DFF

PRN

 

 

D

OUTPUT

Q_flip_flop

Q

 

CLRN

 

 

FIGURE 7.42

D Latch and D Flip-Flop

SOLUTION The simulation, shown in Figure 7.43, has a 200 ns grid. Several points on the waveform indicate the similarities and differences between the latch and flip-flop operation.

FIGURE 7.43

Simulation showing the Difference between D Latch and D Flip Flop

latch_ff.gdf latch_ff.scf

2.D goes LOW at 2 s. Both Q outputs go LOW at 2.8 s since the positive edge of the CLK and its HIGH level occur at the same time.

3.The D input goes HIGH at 4.4 s, in the middle of a CLK pulse. Since the CLK line is HIGH, Q_ latch changes immediately. Q_ flip_ flop does not change until the next positive edge, at 6 s.

4.D goes LOW at 7.8 s. Q_latch also changes at this time, since CLK is HIGH. Q_ flip_ flop changes on the next positive edge, at 9.2 s.

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

 

Note that the latch output is in an unknown state until the first CLK pulse, whereas the

 

flip-flop output is LOW, even before the first CLK pulse. This is because Altera CPLDs

 

have power-on reset circuitry that ensures that flip-flop outputs in a CPLD are LOW im-

 

mediately after power is applied to the device. The MAX PLUS II simulator accounts for

 

this condition.

 

 

EXAMPLE 7.7

Two positive edge-triggered D flip-flops are connected as shown in Figure 7.44a. Inputs D0

 

and CLK are shown in the timing diagram. Complete the timing diagram by drawing the

 

waveforms for Q0 and Q1, assuming that both flip-flops are initially reset.

FIGURE 7.44

 

Example 7.7

 

Circuit and Timing Diagram

 

SOLUTION Figure 7.44b shows the output waveforms. Q0 follows D0 at each point where the clock input has a positive edge. One result of this is that the HIGH pulse on D0 between clock pulses 5 and 6 is ignored, since D0 0 on positive edges 5 and 6.

Since D1 Q0 and Q1 follows D1, the waveform at Q1 is the same as at Q0, but delayed by one clock cycle. If Q0 changes due to CLK, we assume that the value of D1 is the same as Q0 just before the clock pulse. This is because delays within the circuitry of the flip-flops ensure that their outputs will not change for several nanoseconds after an applied clock pulse. Therefore, the level at D1 remains constant long enough for it to be clocked into the second flip-flop.

The data entering the circuit at D0 are moved, or shifted, from one flip-flop to the next. This type of data movement, called “serial shifting,” is frequently used in data communi-

cation and digital arithmetic circuits.

 

 

SECTION 7.4 REVIEW PROBLEM

7.4Which part of a D flip-flop accounts for the difference in operation between a D flipflop and a D latch? How does it work?

7.5 • Edge-Triggered JK Flip-Flops

303

7.5 Edge-Triggered JK Flip-Flops

FIGURE 7.45

Edge-Triggered JK Flip-Flops

K E Y T E R M

Toggle Alternate between opposite binary states with each applied clock pulse.

A versatile and widely used sequential circuit is the JK flip-flop.

Figure 7.45 shows the logic symbols of a positiveand a negative-edge triggered JK flip-flop. J acts as a SET input and K acts as a RESET input, with the output changing on the active clock edge in response to J and K. When J and K are both HIGH, the flip-flop will toggle between opposite logic states with each applied clock pulse. The function tables of the devices in Figure 7.45 are shown in Table 7.7.

Figure 7.46 shows the simplified circuit of a negative-edge triggered JK flip-flop. The circuit is like that of a gated SR latch with an edge detector (an SR flip-flop), except that there are two extra feedback lines from the latch outputs to the steering gate inputs. This extra feedback is responsible for the flip-flop’s toggling action.

Figure 7.47 illustrates how the additional two lines cause the flip-flop to toggle. The cross-feedback from Q to K and from Q to J enables one, but not both, of the steering gates. The edge detector just after the CLK input produces a short positive-going pulse upon detecting a negative edge on the CLK waveform. The enabled steering gate complements and transmits this pulse to the latch, activating either the set or reset function. This in turn changes the latch state and enables the opposite steering gate.

Since all inputs of the steering gates must be HIGH to enable one of the latch functions, J and K must both be HIGH to sustain a repeated toggling action. Under these conditions, Q and Q alternately enable one of the steering gates.

Table 7.7 Function Tables for Edge-Triggered JK Flip-Flops

CLK

J

K

 

Qt 1

Qt 1

 

Function

CLK

J

K

 

Qt 1

Qt 1

 

Function

0

0

 

Qt

Qt

 

No change

0

0

 

Qt

Qt

 

No change

0

1

 

0

1

 

Reset

0

1

 

0

1

 

Reset

1

0

 

1

0

 

Set

1

0

 

1

0

 

Set

1

1

 

Qt

Qt

 

Toggle

1

1

 

Qt

Qt

 

Toggle

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

X

X

 

Qt

Qt

 

Inhibited

0

X

X

 

Qt

Qt

 

Inhibited

1

X

X

 

Qt

Qt

 

Inhibited

1

X

X

 

Qt

Qt

 

Inhibited

X

X

 

Qt

Qt

 

Inhibited

X

X

 

Qt

Qt

 

Inhibited

 

 

 

 

 

 

 

 

Positive Edge-Triggered

 

 

Negative Edge-Triggered

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

FIGURE 7.46

JK Flip-Flop Circuit (Simplified)

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

 

FIGURE 7.47

 

Toggle Action of a JK Flip-Flop

 

 

EXAMPLE 7.8

The J, K, and CLK inputs of a negative edge-triggered JK flip-flop are as shown in the tim-

 

ing diagram in Figure 7.48. Complete the timing diagram by drawing the waveforms for Q

 

and Q. Indicate which function (no change, set, reset, or toggle) is performed at each clock

 

pulse. The flip-flop is initially reset.

 

FIGURE 7.48

 

Example 7.8

 

Timing Diagram (Negative-Edge-Triggered JK Flip-Flop)

 

SOLUTION The completed timing diagram is shown in Figure 7.48. The outputs change

 

only on the negative edges of the CLK waveform. Note that the same output sometimes re-

 

sults from different inputs. For example, the function at clock pulse 4 is reset and the func-

 

tion at pulses 5 and 6 is no change, but the Q waveform is LOW in each case.

 

 

EXAMPLE 7.9

The toggle function of a JK flip-flop is often used to generate a desired output sequence

 

from a series of flip-flops. The circuit shown in Figure 7.49 is configured so that all flip-

 

flops are permanently in toggle mode.

 

Assume that all flip-flops are initially reset. Draw a timing diagram showing the CLK,

 

Q0, Q1, and Q2 waveforms when eight clock pulses are applied. Make a table showing each

7.5 • Edge-Triggered JK Flip-Flops

305

FIGURE 7.49

Example 7.9

Circuit

combination of Q2, Q1, and Q0. What pattern do the outputs form over the period shown on the timing diagram?

SOLUTION The circuit timing diagram is shown in Figure 7.50. All flip-flops are in toggle mode. Each time a negative clock edge is applied to the flip-flop CLK input, the Q output will change to the opposite state.

Table 7.8 Sequence of Outputs for Circuit in Figure 7.49

Clock

Pulse Q2 Q1 Q0

0 0 0 0

1 0 0 1

2 0 1 0

3 0 1 1

4 1 0 0

5 1 0 1

6 1 1 0

7 1 1 1

8 0 0 0

FIGURE 7.50

Example 7.9

Timing Diagram

For flip-flop 0, this happens with every clock pulse, since it is clocked directly by the CLK waveform. Each of the other flip-flops is clocked by the Q output waveform of the previous stage. Flip-flop 1 is clocked by the negative edge of the Q0 waveform. Flip-flop 2 toggles when Q1 goes from HIGH to LOW.

Table 7.8 shows the flip-flop outputs after each clock pulse. The outputs form a 3-bit number that counts from 000 to 111 in binary sequence, then returns to 000 and repeats.

This flip-flop circuit is called a 3-bit asynchronous counter.

 

 

Synchronous versus Asynchronous Circuits

K E Y T E R M S

Synchronous Synchronized to the system clock.

Asynchronous Not synchronized to the system clock

The asynchronous counter in Figure 7.49 has the advantage of being simple to construct and analyze. However, because it is asynchronous (that is, not synchronized to a single clock), it is seldom used in modern digital designs. The main problem with this and other asynchronous circuits is that their outputs do not change at the same time, due to delays in the flip-flops. This yields intermediate states that are not part of the desired output sequence.

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

Figure 7.51 shows a simulation of a circuit similar to that in Figure 7.49. The outputs are shown separately, and also as a group labeled Q[2..0] that shows the combined binary value of the outputs.

asynch3.gdf

asynch3.scf

FIGURE 7.51

Simulation of a 3-bit Asynchronous Counter

Figure 7.52 shows a detail of the simulation at the point where the output goes from 7 to 0 (111 to 000). At 300 ns, the circuit output is 111. A negative clock edge, applied to flip-flop 0, makes Q0 toggle after a short delay. The output is now 110 ( 610). The resulting negative edge on Q0 clocks flip-flop 1, making it toggle, and yields a new output of 100 ( 410). The negative edge on Q1 clocks flip-flop 2, making the output equal to 000 after a short delay.

FIGURE 7.52

Detail of simulation for a 3-bit

Asynchronous Counter

Thus, the output goes through two short intermediate states that are not in the desired output sequence. Instead of going directly from 111 to 000, as in Figure 7.50, the output goes in the sequence 111–110–100–000. We see in Figure 7.51 that the counter output goes through one or more intermediate transitions after each negative edge of the Q0 waveform. In other words, intermediate states arise whenever a change propagates through more than one flip-flop. This happens because the flip-flops are clocked from different sources.

sync3.gdf

sync3.scf

 

VCC

 

 

 

 

 

 

 

JKFF

 

JKFF

AND2

JKFF

 

 

 

J

PRN

J

PRN

J

PRN

 

 

Q

Q

Q

 

 

K

CLRN

K

 

K

CLRN

 

 

 

CLRN

 

 

CLK

INPUT

 

 

 

 

 

 

 

 

 

 

 

OUTPUT

 

 

 

 

 

 

 

Q2

 

 

 

 

 

 

OUTPUT

 

 

 

 

 

 

Q1

 

 

 

 

 

 

OUTPUT

 

 

 

 

 

 

Q0

 

 

 

 

 

 

 

FIGURE 7.53

3-bit Synchronous Counter

7.5 • Edge-Triggered JK Flip-Flops

307

Figure 7.53 shows the circuit of a 3-bit synchronous counter. Unlike the circuit in Figure 7.49, the flip-flops in this circuit are clocked from a common source. Therefore, flip-flop delays do not add up through the circuit, and all the outputs change at the same time. Figure 7.54 shows a simulation of the circuit of Figure 7.53. Note that the outputs progress in a binary sequence, and there are no intermediate states.

FIGURE 7.54

Simulation of a 3-bit Synchronous Counter

The circuit works as follows:

1.Flip-flop 0 is configured for toggle mode (J0K0 11). Since the flip-flops in Figure 7.53 are positive edge-triggered, Q0 toggles on each positive clock edge.

2.Q0 is connected to inputs J1 and K1. Since these inputs are tied together, only two states are possible: no change (JK 00) or toggle (JK 11). If Q0 1, Q1 toggles. Otherwise, it does not change. This results in a Q1 waveform that toggles at half the rate of Q0.

3.J2 and K2 are both tied to the output of an AND gate. The AND gate output is HIGH if both Q1 and Q0 are HIGH. This makes Q2 toggle, since J2K2 11. In all other cases, there is no change on Q2. The result of this is that Q2 toggles every fourth clock pulse, the only times when Q1 and Q0 are both HIGH.

Asynchronous Inputs (Preset and Clear)

K E Y T E R M S

Synchronous inputs The inputs of a flip-flop that do not affect the flip-flop’s Q outputs unless a clock pulse is applied. Examples include D, J, and K inputs.

Asynchronous inputs The inputs of a flip-flop that change the flip-flop’s Q outputs immediately, without waiting for a pulse at the CLK input. Examples include preset and clear inputs.

Preset An asynchronous set function.

Clear An asynchronous reset function.

The D, J, and K inputs of the flip-flops examined so far are called synchronous inputs. This is because any effect they have on the flip-flop outputs is synchronized to the CLK input.

Another class of input is also provided on many flip-flops. These inputs, called asynchronous inputs, do not need to wait for a clock pulse to make a change at the output. The two functions usually provided are preset, an asynchronous set function, and clear, an

asynchronous reset function. These functions are generally active LOW, and are abbreviated PRE and CLR.

Figure 7.55 shows a modification to the JK flip-flop of Figure 7.46. The PRE and CLR inputs have direct access to the latch gates of the flip-flop and thus are not affected by the

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

FIGURE 7.55

PRE and CLR Inputs

 

CLK input. They act exactly the same as the SET and RESET inputs of an SR latch and will

 

override any synchronous input functions currently active.

 

 

EXAMPLE 7.10

The waveforms for the CLK, J, K, PRE, and CLR inputs of a negative edge-triggered JK

 

flip-flop are shown in the timing diagram of Figure 7.56. Complete the diagram by draw-

 

ing the waveform for output Q.

FIGURE 7.56

Example 7.10

Waveforms

SOLUTION The Q waveform is shown in Figure 7.56. The asynchronous inputs cause an immediate change in Q, whereas the synchronous inputs must wait for the next negative clock edge. If asynchronous and synchronous inputs are simultaneously active, the asynchronous inputs have priority. This occurs in two places: pulse 3 (K, PRE) and pulse 10

(J, CLR).

The diagram shows the synchronous functions (no change, reset, set, and toggle) at each clock pulse and the asynchronous functions (preset and clear) at the corresponding transi-

tion points.

The function table of a negative edge-triggered JK flip-flop with preset and clear functions is shown in Table 7.9.

 

 

 

7.5

Edge-Triggered JK Flip-Flops

309

Table 7.9 Function Table of a Negative Edge-Triggered JK Flip-Flop with Preset and Clear

 

Functions

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

PRE CLR

CLK

J

K

 

Qt 1

Qt 1

 

Function

Synchronous Functions

1

1

 

0

0

 

Qt

Qt

 

No change

 

 

1

1

 

0

1

 

0

1

 

Reset

 

 

 

1

1

 

1

0

 

1

0

 

Set

 

 

 

1

1

 

1

1

 

Qt

Qt

 

Toggle

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Asynchronous Functions

0

1

 

X

X

X

 

1

0

 

Preset

 

 

 

1

0

 

X

X

X

 

0

1

 

Clear

 

 

 

0

0

 

X

X

X

 

1

1

 

Forbidden

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

1

 

0

X

X

 

Qt

Qt

 

Inhibited

 

 

1

1

 

1

X

X

 

Qt

Qt

 

Inhibited

 

 

1

1

 

X

X

 

Qt

Qt

 

Inhibited

 

 

 

 

 

X Don’t care

HIGH-to-LOW transition

 

 

 

 

 

 

 

 

Qt Present state of Q

LOW-to-HIGH transition

 

 

 

 

 

 

 

 

Qt 1 Next state of Q

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

N O T E

 

 

 

 

 

 

 

If preset and clear functions are not used, they should be disabled by connecting

 

 

 

 

them to logic HIGH (for active-LOW inputs). This prevents them from being acti-

 

 

 

 

vated inadvertently by circuit noise. The synchronous functions of some flip-flops

 

 

 

 

will not operate properly unless PRE and CLR are HIGH. In MAX PLUS II, the

 

 

 

 

asynchronous inputs of all flip-flop primitives are set to a default level of HIGH.

 

 

 

Using Asynchronous Reset in a Synchronous Circuit

 

 

 

 

 

K E Y T E R M

 

 

 

 

 

 

 

Master Reset An asynchronous reset input used to set a sequential circuit to a

 

 

 

 

known initial state.

 

 

 

 

 

 

 

Figure 7.57 shows an application of asynchronous clear inputs in a 3-bit synchronous

 

 

counter. An input called RESET is tied to the asynchronous CLR inputs of all flip-

 

 

flops. The counter output is set to 000 when the RESET line goes LOW.

 

 

VCC

 

 

 

 

 

 

 

JKFF

 

JKFF

AND2

JKFF

 

 

 

 

 

 

 

 

 

 

PRN

PRN

 

J

PRN

 

 

J

 

Q

 

 

Q

J

Q

 

 

 

 

 

 

K

CLRN

K

 

K

CLRN

 

 

 

CLRN

 

 

CLK

INPUT

 

 

 

 

 

 

INPUT

 

 

 

 

OUTPUT

 

RESET

 

 

 

 

Q2

 

 

 

 

 

 

 

 

 

 

 

OUTPUT

Q1

 

 

 

 

 

 

OUTPUT

 

 

 

 

 

 

Q0

 

 

 

 

 

 

 

FIGURE 7.57

 

 

 

 

 

 

 

Synchronous Counter with Asynchronous Reset