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

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

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

270

C H A P T E R 6 • Digital Arithmetic and Arithemtic Circuits

Speed grade A specification that indicates the internal delay time that can be expected of a CPLD.

Subtrahend The number in a subtraction operation that is subtracted from another number.

Sum The result of an addition operation.

Sum bit (single-bit addition) The least significant bit of the sum of two 1-bit binary numbers.

True-magnitude form A form of signed binary number whose magnitude is represented in true binary.

Unsigned binary arithmetic Arithmetic operations performed using unsigned binary numbers.

Unsigned binary number A binary number whose sign is not indicated by a sign bit. A positive sign is assumed unless explicitly stated otherwise.

P R O B L E M S

Section 6.1 Digital Arithmetic

6.1Add the following unsigned binary numbers.

a.10101 1010

b.10101 1011

c.1111 1111

d.11100 1110

e.11001 10011

f.111011 101001

6.2Subtract the following unsigned binary numbers.

a.1100 100

b.10001 1001

c.10101 1100

d.10110 1010

e.10110 1001

f.10001 1111

g.100010 10111

h.1100011 100111

Section 6.2 Representing Signed Binary Numbers

6.3Write the following decimal numbers in 8-bit true-magni- tude, 1’s complement, and 2’s complement forms.

a.110

b.67

c.54

d.93

e.0

f.1

g.127

h.127

Section 6.3 Signed Binary Arithmetic

6.4Perform the following arithmetic operations in the truemagnitude (addition only), 1’s complement, and 2’s complement systems. Use 8-bit numbers consisting of a sign bit and 7 magnitude bits. (The numbers shown are in the decimal system.)

Convert the results back to decimal to prove the correctness of each operation. Also demonstrate that the idea of adding a negative number to perform subtraction is not valid for the true-magnitude form.

a.37 25

b.85 40

c.95 63

d.63 95

e.23 50

f.120 73

g.73 120

6.5What are the largest positive and negative numbers, expressed in 2’s complement notation, that can be represented by an 8-bit signed binary number?

6.6Perform the following signed binary operations, using 2’s complement notation where required. State whether or not sign bit overflow occurs. Give the signed decimal equivalent values of the sums in which overflow does not occur.

a.01101 00110

b.01101 10110

c.01110 01001

d.11110 00010

e.11110 00010

6.7Without doing any binary complement arithmetic, indicate which of the following operations will result in 2’s complement overflow. (Assume 8-bit representation consisting of a sign bit and 7 magnitude bits.) Explain the reasons for each choice.

a.109 36

b.109 36

c.65 72

d.110 29

e.117 11

f.117 11

6.8Explain how you can know, by examining sign or magnitude bits of the numbers involved, when overflow has occurred in 2’s complement addition or subtraction.

Section 6.4 Hexadecimal Arithmetic

6.9Add the following hexadecimal numbers.

a.27H 16H

b.87H 99H

c.A55H C5H

d.C7FH 380H

e.1FFFH A80H

6.10Subtract the following hexadecimal numbers.

a.F86H 614H

b.E72H 229H

c.37FFH 137FH

d.5764H ACBH

e.7D30H 5D33H

f.5D33H 7D30H

g.813AH A318H

Section 6.5 Numeric and Alphanumeric Codes

6.11Convert the following decimal numbers to true binary, 8421 BCD code, and Excess-3 code.

a.70910

b.188910

c.239510

d.125910

e.397210

f.773010

6.12Make a table showing the equivalent Gray codes corresponding to the range from 010 to 3110.

6.13Write your name in ASCII code.

6.14Encode the following text into ASCII code: “10% off purchases over $50. (Monday only)”

6.15Decode the following string of ASCII code.

57 41 52 4E 49 4E 47 21 20 54 68 69 73 20 63 6F 6D

6D 61 6E 64 20 65 72 61 73 65 73 20 36 34 30 4D 20

6F 66 20 6D 65 6D 6F 72 79 2E

Section 6.6 Binary Adders and Subtractors

6.16Write the truth table for a half adder, and from the table

derive the Boolean expressions for both Co (carry output) and (sum output) in terms of inputs A and B. Draw the half adder circuit.

6.17Write the truth table for a full adder, and from the table derive the simplest possible Boolean expressions for COUT and in terms of A, B, and CIN.

6.18From the equations in Problems 6.16 and 6.17, draw a circuit showing a full adder constructed from two half adders.

6.19Evaluate the Boolean expression for and COUT of the full adder in Figure 6.7 for the following input values. What is the binary value of the outputs in each case?

a.A 0, B 0, CIN 0

b.A 0, B 1, CIN 0

c.A 0, B 1, CIN 1

d.A 1, B 1, CIN 1

6.20Verify the summing operation of the circuit in Figure 6.10, as follows. Determine the output of each full adder based on the inputs shown below. Calculate each sum manually and compare it to the 5-bit output

(C4 4 3 2 1) of the parallel adder circuit.

Problems 271

a.A4 A3 A2 A1 0100, B4 B3 B2 B1 1001

b.A4 A3 A2 A1 1010, B4 B3 B2 B1 0110

c.A4 A3 A2 A1 0101, B4 B3 B2 B1 1101

d.A4 A3 A2 A1 1111, B4 B3 B2 B1 0111

6.21Briefly describe the differences in the underlying design strategies of the ripple carry adder and the fast carry adder (i.e., what makes the fast carry faster than the ripple carry?). What is the main limitation for the fast carry circuit?

6.22Write the general form of the fast carry equation. Use it

to generate Boolean expression for C1, C2, and C3 for a fast carry adder.

6.23The following equation describes the carry output function for a parallel binary adder:

COUT A4 B4 A3 B3 (A4 B4)

A2 B2 (A4 B4)(A3 B3)

A1 B1 (A4 B4)(A3 B3)(A2 B2)

CIN (A4 B4)(A3 B3)(A2 B2)

(A1 B1)

Briefly explain how to interpret the third term of this equation.

6.24Write a VHDL file for an 8-bit parallel adder, using eight instances of a full adder component.

6.25Create a simulation for the 8-bit adder of Problem 6.24, showing a representative sample of sums. How many different sums would be required to show all possible combinations of inputs?

6.26Write a VHDL file that creates a 12-bit adder using a GENERATE statement.

6.27Create a simulation file for the 12-bit adder of Problem 6.26 showing only one transition, as follows. Set input a to 000 from 0 to 500 ns, then 001 from 500 ns to 1 s. Set input b to FFF from 0 to 1 s. From the simulation, determine the internal delays from a1 to each of the sum bits. Confirm your observations with the delay matrix from a timing analysis.

6.28Use MAX PLUS II to create a Graphic Design File for a 2’s complement subtractor based on a 4-bit parallel binary adder. Explain how the circuit generates the 2’s complement of B for the subtraction A B.

6.29Use MAX PLUS II to create a Graphic Design File for a 2’s complement adder/subtractor based on a 4-bit parallel binary adder. Explain how the circuit is programmed to add or subtract and how it produces the 2’s complement of B for the subtraction A B.

6.30Use MAX PLUS II to draw a circuit that will detect an overflow condition in a 4-bit 2’s complement adder/ subtractor. The detector output should go HIGH upon overflow detection. Draw the circuit truth table, explain what all input and output variables are, and show any Boolean equations you need to complete the circuit design.

6.31Modify the 4-bit adder/subtractor drawn in Figure 6.15 to include an overflow detection circuit.

272

C H A P T E R 6 • Digital Arithmetic and Arithemtic Circuits

6.32Create a simulation for the 4-bit adder/subtractor with overflow detection (Problem 6.31), using the following representative hexadecimal input values: F 1 10 (carry, but no overflow); 7 1 8 (overflow, but no carry); 8 8 10 (carry and overflow); 0 1 F (result 1).

6.33Modify the VHDL file for the 4-bit parallel binary adder/subtractor (addsub4g.vhd) to include an overflow detection circuit. Use two different methods.

6.34What is the permissible range of values that a sum or difference, x, can have in a 16-bit parallel binary adder if it is written as:

a.A signed binary number

b.An unsigned binary number

Section 6.7 BCD Adders

6.35What is the maximum BCD sum of two 3-digit BCD numbers plus an input carry? How many digits are needed to display the result?

6.36What is the maximum BCD sum of two 4-digit BCD numbers plus an input carry? How many digits are needed to display the result?

6.37Based on the answers to Problems 6.35 and 6.36, formulate a general rule to calculate the maximum BCD sum of two n-digit BCD numbers plus a carry bit.

6.38Derive the Boolean expression for a BCD carry output as a function of the sum of two BCD digits.

6.39Draw the circuit for a binary-to-BCD code converter.

6.40Write a VHDL file to implement a binary-to-BCD code converter for a BCD adder. Use a selected signal assignment or CASE statement.

6.41Write a VHDL file that uses the binary-to-BCD code converter of Problem 6.40 and a 4-bit parallel binary adder as components in a BCD adder.

6.42Write a VHDL file that uses a code converter and parallel adder as components in a design that will add two 2-digit BCD numbers and produce a 212 digit result.

6.43Draw the block diagram of a circuit that will add two 3-digit BCD numbers and display the result as a series of decimal digits. How many digits will the output display?

A N S W E R S T O S E C T I O N R E V I E W P R O B L E M S

Section 6.1a

 

 

 

6.1

101000;

 

6.2

100000.

Section 6.1b

 

 

 

6.3

11;

6.4

1

 

 

Section 6.3

 

 

 

6.5

11100000;

6.6

100000.

Section 6.4

 

 

 

6.7a

11701H

6.7b

1281H

Section 6.5

6.8 “True or False: 1/4 1/2”

Section 6.6a

6.9 Figures 6.32 and 6.33 show the propagation paths for the carry bits.

Fast carry: 3 gates

Ripple carry: 8 gates

Section 6.6b

6.10a Signed: 2048 x 2047 (11 magnitude bits, 1 sign bit)

6.10b Unsigned: 0 x 4095 (12 magnitude bits, no sign bit: positive implied)

Section 6.7

6.11 Maximum BCD sum 1001 1001 1001 1001 1001 1001 1 1001 1001 1000BCD 199810. This sum requires a 312 -digit numerical display.

Answers to Section Review Problems

273

a1

INPUT

AND2

 

INPUT

 

b1

 

 

OR2

 

 

a2

INPUT

AND2

 

INPUT

 

b2

 

 

OR2

 

 

a3

INPUT

AND2

 

INPUT

 

b3

 

 

OR2

 

 

a4

INPUT

AND2

 

INPUT

 

b4

 

 

OR2

 

 

c0

INPUT

 

 

 

 

OR2

 

 

AND2

c1

OUTPUT

c1

 

 

 

 

 

 

OR3

 

 

AND2

c2

OUTPUT

c2

 

 

 

 

 

AND3

 

 

 

 

OR4

 

 

AND2

c3

OUTPUT

c3

 

 

 

AND3

 

 

 

AND4

 

 

 

OR6

 

 

AND2

 

 

c4

OUTPUT

c4

AND3

 

 

AND4

 

 

GND

 

 

AND6

 

 

VCC

FIGURE 6.32

Fast Carry from A4/B4 to C4.

 

A4B4

 

A4 B4

 

A3B3

A2B2

A3 B3

C4

A2 B2

 

A1B1

 

A1 B1

 

C0

FIGURE 6.33

Ripple Carry from C0 to C4

C H A P T E R 7

Introduction to Sequential Logic

O U T L I N E

C H A P T E R O B J E C T I V E S

7.1 Latches

Upon successful completion of this chapter, you will be able to:

7.2NAND/NOR Latches Explain the difference between combinational and sequential circuits.

7.3 Gated Latches

Define the set and reset functions of an SR latch.

7.4Edge-Triggered D Draw circuits, function tables, and timing diagrams of NAND and NOR

Flip-Flops

latches.

7.5Edge-Triggered JK Explain the effect of each possible input combination to a NAND and a

 

Flip-Flops

 

NOR latch, including set, reset, and no change functions, as well as the am-

7.6

Edge-Triggered T

 

biguous or forbidden input condition.

 

Flip-Flops

Design circuit applications that employ NAND and NOR latches.

7.7

Timing Parameters

Describe the use of the ENABLE input of a gated SR or D latch as an en-

 

 

 

able/inhibit function and as a synchronizing function.

 

 

Outline the problems involved with using a level-sensitive ENABLE input

 

 

 

on a gated SR or D latch.

 

 

Explain the concept of edge-triggering and why it is an improvement over

 

 

 

level-sensitive enabling.

 

 

Draw circuits, function tables, and timing diagrams of edge-triggered D,

 

 

 

JK, and T flip-flops.

 

 

Describe the toggle function of a JK flip-flop and a T flip-flop.

 

 

Describe the operation of the asynchronous preset and clear functions of D,

 

 

 

JK, and T flip-flops and be able to draw timing diagrams showing their

 

 

 

functions.

Use MAX PLUS II to create simple circuits and simulations with D latches and D, JK, and T flip-flops.

Create simple flip-flop designs using VHDL.

The digital circuits studied to this point have all been combinational circuits, that is, circuits whose outputs are functions only of their present inputs. A particular set of input

states will always produce the same output state in a combinational circuit.

275

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

This chapter will introduce a new category of digital circuitry: the sequential circuit. The output of a sequential circuit is a function both of the present input conditions and the previous conditions of the inputs and/or outputs. The output depends on the sequence in which the inputs are applied.

We will begin our study of sequential circuits by examining the two most basic sequential circuit elements: the latch and the flip-flop, both of which are part of the general class of circuits called bistable multivibrators. These are similar devices, each being used to store a single bit of information indefinitely. The difference between a latch and a flipflop is the condition under which the stored bit is allowed to change.

Latches and flip-flops are also used as integral parts of more complex devices, such as programmable logic devices (PLDs), usually when an input or output state must be stored.

7.1 Latches

K E Y T E R M S

Sequential circuit A digital circuit whose output depends not only on the present combination of inputs, but also on the history of the circuit.

Latch A sequential circuit with two inputs called SET and RESET, which make the latch store a logic 0 (reset) or 1 (set) until actively changed.

SET 1. The stored HIGH state of a latch circuit.

2. A latch input that makes the latch store a logic 1.

RESET 1. The stored LOW state of a latch circuit.

2. A latch input that makes the latch store a logic 0.

All the circuits we have seen up to this point have been combinational circuits. That is, their present outputs depend only on their present inputs. The output state of a combinational circuit results only from a combination of input logic states.

The other major class of digital circuits isthe sequential circuit. The present outputs of a sequential circuit depend not only on its present inputs, but also on its past input states.

The simplest sequential circuit is the SR latch, whose logic symbol is shown in Figure 7.1a. The latch has two inputs, SET (S) and RESET (R), and two complementary outputs, Q and Q. If the latch is operating normally, the outputs are always in opposite logic states.

FIGURE 7.1

SR Latch (Active HIGH Inputs)

The latch operates like a momentary-contact pushbutton with START and STOP functions, shown in Figure 7.2. A momentary-contact switch operates only when it is held down. When released, a spring returns the switch to its rest position.

Suppose the switch in Figure 7.2 is used to control a motor starter. When you push the START button, the motor begins to run. Releasing the START switch does not turn the motor off; that can be done only by pressing the STOP button. If the motor is running,

7.1 • Latches

277

FIGURE 7.2

Industrial Pushbutton (e.g.,

Motor Starter)

pressing the START button again has no effect, except continuing to let the motor run. If the motor is not running, pressing the STOP switch has no effect, since the motor is already stopped.

There is a conflict if we press both switches simultaneously. In such a case we are trying to start and stop the motor at the same time. We will come back to this point later.

The latch SET input is like the START button in Figure 7.2. The RESET input is like the STOP button.

N O T E

By definition:

A latch is set when Q 1 and Q 0.

A latch is reset when Q 0 and Q 1.

The latch in Figure 7.1 has active-HIGH SET and RESET inputs. To set the latch, make R 0 and make S 1. This makes Q 1 until the latch is actively reset, as shown in the timing diagram in Figure 7.1b. To activate the reset function, make S 0 and make R 1. The latch is now reset (Q 0) until the set function is next activated.

Combinational circuits produce an output by combining inputs. In sequential circuits, it is more accurate to think in terms of activating functions. In the latch described, S and R are not combined by a Boolean function to produce a particular result at the output. Rather, the set function is activated by making S 1, and the reset function is activated by making R 1, much as we would activate the START or STOP function of a motor starter by pressing the appropriate pushbutton.

The timing diagram in Figure 7.1b shows that the inputs need not remain active after the set or reset functions have been selected. In fact, the S or R input must be inactive before the opposite function can be applied, in order to avoid conflict between the two functions.

EXAMPLE 7.1

Latches can have active-HIGH or active-LOW inputs, but in each case Q 1 after the set

 

function is applied and Q 0 after reset. For each latch shown in Figure 7.3, complete the

 

timing diagram shown. Q is initially LOW in both cases. (The state of Q before the first ac-

 

tive SET or RESET is unknown unless specified, since the present state depends on previ-

 

ous history of the circuit.)

FIGURE 7.3

 

Example 7.1

 

SR Latch

 

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

SOLUTION The Q and Q waveforms are shown in Figure 7.3. Note that the outputs respond only to the first set or reset command in a sequence of several pulses.

EXAMPLE 7.2

Figure 7.4 shows a latching HOLD circuit for an electronic telephone. When HIGH, the

 

HOLD output allows you to replace the handset without disconnecting a call in progress.

FIGURE 7.4

Example 7.2

Latching HOLD Button

The two-position switch is the telephone’s hook switch (the switch the handset pushes down when you hang up), shown in the off-hook (in-use) position. The normally closed pushbutton is a momentary-contact switch used as a HOLD button. The circuit is such that the HOLD button does not need to be held down to keep the HOLD active. The latch “remembers” that the switch was pressed, until told to “forget” by the reset function.

Describe the sequence of events that will place a caller on hold and return the call from hold. Also draw timing diagrams showing the waveforms at the HOLD input, hook switch inputs, S input, and HOLD output for one hold-and-return sequence. (HOLD output 1 means the call is on hold.)

SOLUTION To place a call on hold, we must set the latch. We can do so if we press and hold the HOLD switch, then the hook switch. This combines two HIGHs—one from the HOLD switch and one from the on-hook position of the hook switch—into the AND gate, making S 1 and R 0. Note the sequence of events: press HOLD, hang up, release HOLD. The S input is HIGH only as long as the HOLD button is pressed. The handset can be kept on-hook and the HOLD button released. The latch stays set, as S R 0 (neither SET not RESET active) as long as the handset is on-hook.

To restore a call, lift the handset. This places the hook switch into the off-hook position and now S 0 and R 1, which resets the latch and turns off the HOLD condition.

Figure 7.5 shows the timing diagram for the sequence described.

FIGURE 7.5

Example 7.2

HOLD Timing Diagram

7.2 • NAND/NOR Latches

279

SECTION 7.1 REVIEW PROBLEM

7.1A latch with active-HIGH S and R inputs is initially set. R is pulsed HIGH three times, with S 0. Describe how the latch responds.

7.2NAND/NOR Latches

An SR latch is easy to build with logic gates. Figure 7.6 shows two such circuits, one made from NOR gates and one from NANDs. The NAND gates in the second circuit are drawn in DeMorgan equivalent form.

FIGURE 7.6

SR Latch Circuits

The two circuits both have the following three features:

1.OR-shaped gates

2.Logic level inversion between the gate input and output

3.Feedback from the output of one gate to an input of the opposite gate

During our examination of the NAND and NOR latches, we will discover why these features are important.

A significant difference between the NAND and NOR latches is the placement of SET and RESET inputs with respect to the Q and Q outputs. Once we define which output is Q and which is Q, the locations of the SET and RESET inputs are automatically defined.

In a NOR latch, the gates have active-HIGH inputs and active-LOW outputs. When the input to the Q gate is HIGH, Q 0, since either input HIGH makes the output LOW. Therefore, this input must be the RESET input. By default, the other is the SET input.

In a NAND latch, the gate inputs are active LOW (in DeMorgan equivalent form) and the outputs are active HIGH. A LOW input on the Q gate makes Q 1. This, therefore, is the SET input, and the other gate input is RESET.

Since the NAND and NOR latch circuits have two binary inputs, there are four possible input states. Table 7.1 summarizes the action of each latch for each input combination. The functions are the same for each circuit, but they are activated by opposite logic levels.

Table 7.1 NOR and NAND Latch Functions

S

R

Action (NOR Latch)

S

R

Action (NAND Latch)

 

 

 

 

 

 

0

0

Neither SET nor RESET

0

0

Both SET and RESET

 

 

active; output does not

 

 

active; forbidden condi-

 

 

change from previous

 

 

tion

 

 

state

 

 

 

0

1

RESET input active

0

1

SET input active

1

0

SET input active

1

0

RESET input active

1

1

Both SET and RESET

1

1

Neither SET nor RESET

 

 

active; forbidden condi-

 

 

active; output does not

 

 

tion

 

 

change from previous

 

 

 

 

 

state