Digital design with CPLD applications and VHDL (R. Dueck, 2000)
.pdf180 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 |
|
|
|
|
188 |
C H A P T E R 5 • Combinational Logic Functions |
|
|
|
ENTITY mux4 IS |
|
|
|
PORT( |
|
|
|
d0, d1, d2, d3 : IN |
BIT; |
|
|
s |
: IN |
BIT_VECTOR (1 downto 0); |
|
y |
: OUT |
BIT); |
|
END mux4; |
|
|
ARCHITECTURE mux4to1 OF mux4 IS
BEGIN
——Concurrent Signal Assignment
y<= ((not s(1)) and (not s(0)) and d0)
or ((not |
s(1)) and ( |
s(0)) and d1) |
|
or (( |
s(1)) and (not |
s(0)) and |
d2) |
or (( |
s(1)) and ( |
s(0)) and |
d3); |
END mux4to1;
While the concurrent signal assignment is fairly easy to use, it becomes cumbersome for larger multiplexers, such as 8-to-1 or greater.
The entity declaration will be identical for the other VHDL examples. The only change we will make will be to replace the concurrent signal assignment in the architecture body with some other VHDL construct.
Selected Signal Assignment Statement
This construct has the following form (the label is optional):
__label:
WITH __expression SELECT
__signal <= |
__expression WHEN __constant_value, |
|
__expression WHEN __constant_value, |
|
__expression WHEN __constant_value, |
|
__expression WHEN __constant_value; |
The 4-to-1 MUX can be described in VHDL as follows, using a selected signal assignment:
|
|
mux4sel IS |
|
|
|
|
|
|
|
|
mux4sel.vhd |
d0, d1, d2, d3 : IN |
BIT; |
|
|
|
|||
|
|
s |
: IN |
BIT_VECTOR (1 downto 0); |
|
|
y |
: OUT |
BIT); |
|
|
END mux4sel; |
|
|
ARCHITECTURE mux4to1 OF mux4sel IS
BEGIN
M:WITH s SELECT
y <= d0 WHEN “00”,
d1 |
WHEN “01”, |
|
d2 |
WHEN |
“10”, |
d3 |
WHEN |
“11”; |
END mux4to1;
The selected signal assignment evaluates the expression in the WITH clause (in this case, the 2-bit vector, s) and, depending on its value, selects an expression to assign to y. Thus, if s1s0 00, y d0. If s1s0 01, then y d1, and so on for the remaining values of s1s0.
5.3 • Multiplexers |
189 |
CASE Statement within a PROCESS
In our MUX example, we could use a CASE statement as follows:
mux4case.vhd
s |
: IN |
BIT_VECTOR (1 downto 0); |
y |
: OUT |
BIT); |
END mux4case; |
|
|
ARCHITECTURE mux4to1 OF mux4case IS
BEGIN
——CASE statement within a PROCESS
——Monitor select inputs and execute if they change PROCESS (s)
BEGIN
CASE s IS
WHEN “00” |
=> |
y |
<= |
d0; |
WHEN “01” |
=> |
y |
<= |
d1; |
WHEN “10” |
=> |
y |
<= |
d2; |
WHEN “11” |
=> |
y |
<= |
d3; |
WHEN others |
=> |
y |
<= |
‘0’; |
END CASE; |
|
|
|
|
END PROCESS; |
|
|
|
|
END mux4to1; |
|
|
|
|
If the select inputs change, the PROCESS statements are executed. The CASE statement evaluates the select input vector, s, and chooses a signal assignment based on its value. It is good design practice to include a default case (the “others” clause) even when there are no obvious other cases. A default case is essential when using STD_LOGIC types rather than BIT types, as ‘0’ and ‘1’ values do not cover all possible cases for STD LOGIC signals. (Recall from Chapter 4 that STD_LOGIC is a nine-valued logic type, incorporating such things as “Don’t Care” (‘-’), “Unknown” (‘X’), and “High Impedance” (‘Z’), as well as ‘0’ and ‘1’.)
|
Multiplexer Applications |
|
Multiplexers are used for a variety of applications, including selection of one data stream |
|
out of several choices, switching multiple-bit data from several channels to one multiple- |
|
bit output, sharing data on one output over time, and generating bit patterns or waveforms. |
|
Single-Channel Data Selection |
|
The simplest way to use a multiplexer is to switch the select inputs manually in order to di- |
|
rect one data source to the MUX output. Example 5.6 shows a pair of single-pole single- |
|
throw (SPST) switches supplying the select input logic for this type of application. |
|
|
5.6 |
Figure 5.38 shows a digital audio switching system. The system shown can select a signal |
|
from one of four sources (compact disc (CD) players, labelled CD0 to CD3) and direct it to |
|
a digital signal processor (DSP) at its output. We assume we have direct access to the au- |
|
dio signals in digital form. |
|
Make a table listing which digital audio source in Figure 5.38 is routed to the DSP for |
|
each combination of the multiplexer select inputs, S1 and S0. |