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

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

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

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

Добавлен: 13.06.2025

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

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

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

180 C H A P T E R 5 • Combinational Logic Functions

FIGURE 5.29

3-bit Encoder (No Input Priority)

Table 5.4 Partial Truth Table for a 3-bit Encoder

D7

D6

D5

D4

D3

D2

D1

Q2

Q1

Q0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

1

0

0

1

0

0

0

0

0

1

0

0

1

0

0

0

0

0

1

0

0

0

1

1

0

0

0

1

0

0

0

1

0

0

0

0

1

0

0

0

0

1

0

1

0

1

0

0

0

0

0

1

1

0

1

0

0

0

0

0

0

1

1

1

Priority Encoder

The shortcoming of the encoder circuit shown in Figure 5.29 is that it can generate wrong

codes if more than one input is active at the same time. For example, if we make D3 and D5

HIGH at the same time, the output is neither 011 or 101, but 111; the output code does not

correspond to either active input.

One solution to this problem is to assign a priority level to each input and, if two or

more are active, make the output code correspond to the highest-priority input. This is

called a priority encoder. Highest priority is assigned to the input whose subscript has the

largest numerical value.

EXAMPLE 5.5

Figures 5.30a through c show a priority encoder with three different combinations of in-

puts. Determine the resultant output code for each figure. Inputs and outputs are active

HIGH.

FIGURE 5.30

Example 5.5

Priority Encoder Inputs


5.2 • Encoders

181

Solution

Figure 5.30a: The highest-priority active input is D5. D4 and D1 are ignored. Q2Q1Q0101.

Figure 5.30b: The highest-priority active input is D4. D1 is ignored. Q2Q1Q0 100.

Figure 5.30c: The highest-priority active input is D7. All other inputs are ignored.

Q2Q1Q0 111.

N O T E

The encoding principle of a priority encoder is that a low-priority input must not change the code resulting from a higher-priority input.

For example, if inputs D3 and D5 are both active, the correct output code is Q2Q1Q0 101. The code for D3 would be Q2Q1Q0 011. Thus, D3 must not make Q1 1. The Boolean expressions for Q2, Q1, and Q0 covering only these two codes are:

Q2

D5

(HIGH if D5

is active.)

Q1

D3D5

(HIGH if D3

is active AND D5 is NOT active.)

Q0

D3

D5

(HIGH if D3

OR D5 is active.)

The truth table of an 3-bit priority encoder is shown in Table 5.5.

Table 5.5 Truth Table for an 3-bit Priority Encoder

D7

D6

D5

D4

D3

D2

D1

Q2

Q1

Q0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

1

0

0

1

0

0

0

0

0

1

X

0

1

0

0

0

0

0

1

X

X

0

1

1

0

0

0

1

X

X

X

1

0

0

0

0

1

X

X

X

X

1

0

1

0

1

X

X

X

X

X

1

1

0

1

X

X

X

X

X

X

1

1

1

Restating the encoding principle, a bit goes HIGH if it is part of the code for an active input AND it is NOT kept LOW by an input with a higher priority. We can use this principle to develop a mechanical method for generating the Boolean equations of the outputs.

1. Write the codes in order from highest to lowest priority, as in Table 5.6.

Table 5.6 Binary Outputs and

Corresponding Decimal Values

Q2

Q1

Q0

Code Value

1

1

1

7

1

1

0

6

1

0

1

5

1

0

0

4

0

1

1

3

0

1

0

2

0

0

1

1

0

0

0

0


182 C H A P T E R 5 • Combinational Logic Functions

hi_pri8a.vhd

hi_pri8b.vhd hi_pri8b.scf

2.Examine each code. For a code with value n, add a Dn term to each Q equation where there is a 1. For example, for code 111, add the term D7 to the equations for Q2, Q1, and Q0. For code 110, add the term D6 to the equations for Q2 and Q1. (Steps 1 and 2 generate the nonpriority encoder equations listed earlier.)

3.Modify any Dn terms to ensure correct priority. Every time you write a Dn term, look at the previous lines in the table. For each previous code with a 0 in the same column as the 1 that generates Dn, use an AND function to combine Dn with a corresponding D. For example, code 101 generates a D5 term in the equations for Q2 and Q0. The term in the Q2 equation need not be modified because there are no previous codes with a 0 in

the same column. The term in the Q0 equation must be modified since there is a 0 in the Q0 column for code 110. This generates the term D6D5.

The equations from the 3-bit encoder of Figure 5.29 are modified by the priority encoding principle as follows:

Q2 D7 D6 D5 D4

Q1 D7 D6 D5D4D3 D5D4D2

Q0 D7 D6D5 D6D4D3 D6D4D2D1

VHDL Priority Encoder

The most obvious way to program a priority encoder inVHDL is to use the equations derived in the previous section in a set of concurrent signal assignment statements, as follows.

vhd

IS

PORT(

d : IN BIT_VECTOR(7 downto 0); q : OUT BIT_VECTOR (2 downto 0));

END hi_pri8a;

ARCHITECTURE a OF hi_pri8a IS

BEGIN

——Concurrent Signal Assignments

q(2) <= d(7) or d(6) or d(5) or d(4);

q(1) <= d(7) or d(6)

or ((not d(5)) and (not d(4)) and d(3)) or ((not d(5)) and (not d(4)) and d(2));

q(0) <= d(7) or ((not d(6)) and d(5))

or ((not d(6)) and (not d(4)) and d(3))

or ((not d(6)) and (not d(4)) and (not d(2)) and d(1));

END a;

Although this code works, it is not terribly elegant, nor does it give any insight into the operation of the encoder circuit. Also, if we expand our encoder output by one or more bits, the equations become more cumbersome with each new bit and soon become impractically large and susceptible to typing errors. A VHDL conditional signal assignment statement is an ideal alternative for use in a priority encoder circuit. A section of VHDL code using this format is shown below.

–— hi_pri8b.vhd ENTITY hi_pri8b IS PORT(

d : IN BIT_VECTOR (7 downto 0); q : OUT INTEGER RANGE 0 to 7);

END hi_pri8b;


5.2 • Encoders

183

ARCHITECTURE a OF hi_pri8b IS

BEGIN

—— Conditional Signal Assignment encoder:

q <= 7 WHEN d(7)=‘1’ ELSE 6 WHEN d(6)=‘1’ ELSE 5 WHEN d(5)=‘1’ ELSE 4 WHEN d(4)=‘1’ ELSE 3 WHEN d(3)=‘1’ ELSE 2 WHEN d(2)=‘1’ ELSE 1 WHEN d(1)=‘1’ ELSE 0;

END a;

Output q is defined as type INTEGER. Since it ranges from 0 to 7, the MAX PLUS II VHDL compiler will automatically assign three outputs: Q2, Q1, and Q0. The conditional signal assignment statement evaluates the first WHEN clause to determine if its condition (d(7) ‘1’) is true. If so, it assigns q the value of 7 (Q2Q1Q0 111). If the first condition is false, the next WHEN clause is evaluated, assigning q the value 6 (Q2Q1Q0 110) if true, and so on until all WHEN clauses have been evaluated. If no clause is true, then the default value (0: Q2Q1Q0 000) is assigned to the output.

In the conditional signal assignment, the highest-priority condition is examined first. If it is true, the output is assigned according to that condition and no further conditions are evaluated. If the first condition is false, the condition of next priority is evaluated, and so on until the end. Thus, a low-priority input cannot alter the code resulting from an input of higher priority, as required by the priority encoding principle.

The effect is similar to that of an IF statement, where a sequence of conditions is evaluated, but only one output assignment is made. However, an IF statement must be used within a PROCESS statement, if we choose to use it. The IF statement for a priority encoder is as shown below.

PROCESS (d)

BEGIN

IF (d(7)

= ‘1’) THEN

q

<=

7;

ELSIF

(d(6) = ‘1’) THEN

q

<=

6;

ELSIF (d(1) = ‘1’ THEN q <= 1;

ELSE

q <= 0; END IF;

END PROCESS;

Figure 5.31 shows the simulation of an 3-bit priority encoder. The d inputs are shown separately, so that we can easily determine which inputs are active. The q outputs are grouped so as to show the encoded output value as a hexadecimal number.

BCD Priority Encoder

A BCD priority encoder, illustrated in Figure 5.32, accepts ten inputs and generates a BCD code (0000 to 1001), corresponding to the highest-priority active input. The truth table for this circuit is shown in Table 5.7, with a simulation of the circuit shown in Figure 5.33.


184 C H A P T E R 5 • Combinational Logic Functions

FIGURE 5.31

Simulation File for a 3-bit Priority Encoder

HIPR/BCD

D0

D1

D2

Q3

D3

Q2

D4

Q1

D5

Q0

D6

D7

D8

D9

FIGURE 5.32

BCD Priority Encoder

Table 5.7 Truth Table of a BCD Priority Encoder

D9

D8

D7

D6

D5

D4

D3

D2

D1

Q3

Q2

Q1

Q0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

1

0

0

0

1

0

0

0

0

0

0

0

1

X

0

0

1

0

0

0

0

0

0

0

1

X

X

0

0

1

1

0

0

0

0

0

1

X

X

X

0

1

0

0

0

0

0

0

1

X

X

X

X

0

1

0

1

0

0

0

1

X

X

X

X

X

0

1

1

0

0

0

1

X

X

X

X

X

X

0

1

1

1

0

1

X X

X

X

X

X

X

1

0

0

0

1

X X X X X

X X

X

1

0

0

1

FIGURE 5.33

Simulation File for a BCD Priority Encoder