Digital design with CPLD applications and VHDL (R. Dueck, 2000)
.pdf798 |
Answers to Selected Odd-Numbered Problems |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||
|
7.5 ns |
FFC |
1111 1111 1100 |
|
sum1, sum2 |
|
|
|
|
31.5 ns 000 |
0000 0000 0000 |
|
sum11, sum12 |
|||||||||||||||
|
12.5 ns |
FC0 |
1111 1100 0000 |
|
sum3-sum6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
6.29 The 4-bit parallel adder/subtractor is shown in Figure |
|||||||||||||||||||||||||
|
17.5 ns |
F00 |
1111 0000 0000 |
|
sum7, sum8 |
|
||||||||||||||||||||||
|
|
|
|
|
|
ANS6.29a. The component add4, a parallel binary adder, |
||||||||||||||||||||||
|
22.5 ns |
E00 |
1110 0000 0000 |
|
sum9 |
|
|
|
|
|||||||||||||||||||
|
|
|
|
|
|
is shown in Figure ANS6.29b. |
|
|
|
|||||||||||||||||||
|
26.5 ns |
C00 |
1100 0000 0000 |
|
sum10 |
|
|
|
|
|
|
|
||||||||||||||||
|
|
|
|
|
|
|
SUB 1: Input carry is forced HIGH, automatically |
|||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||||
FIGURE ANS6.29A |
A1 |
|
|
INPUT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INPUT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
A2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INPUT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
FIGURE ANS6.29B |
B4 |
|
|
INPUT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||
|
|
|
|
|
|
FULL_ADD |
|
|
|
|
|
|
|
|
||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||
|
|
|
a1 |
|
|
INPUT |
|
|
|
|
|
|
|
|
|
|
|
|
|
OUTPUT |
|
|
c1 |
|||||
|
|
|
|
|
|
|
a |
|
|
c_out |
|
|
|
|||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||
|
|
|
|
|
INPUT |
|
|
|
|
|
OUTPUT |
|
||||||||||||||||
|
|
|
b1 |
|
|
|
|
|
b |
|
|
|
sum |
|
|
|
|
|
sum1 |
|||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||
|
|
|
|
|
INPUT |
|
|
|
|
|
|
|
|
|
||||||||||||||
|
|
|
c0 |
|
|
|
|
|
c_in |
|
|
|
|
|
|
|
|
|
||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FULL_ADD |
|
|
|
|
|
|
|
|
||||||
|
|
|
a2 |
|
|
INPUT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OUTPUT |
|
|
c2 |
||||
|
|
|
|
|
|
|
|
a |
|
|
c_out |
|
|
|
|
|||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||
|
|
|
|
|
INPUT |
|
|
|
|
|
|
OUTPUT |
|
|||||||||||||||
|
|
|
b2 |
|
|
|
|
|
|
b |
|
|
|
sum |
|
|
|
|
|
sum2 |
||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
c_in |
|
|
|
|
|
|
|
|
|
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FULL_ADD |
|
|
|
|
|
|
|
|
||||||
|
|
|
a3 |
|
|
INPUT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OUTPUT |
|
|
c3 |
||||
|
|
|
|
|
|
|
|
a |
|
|
c_out |
|
|
|
|
|||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||
|
|
|
|
|
INPUT |
|
|
|
|
|
|
OUTPUT |
|
|||||||||||||||
|
|
|
b3 |
|
|
|
|
|
|
b |
|
|
|
sum |
|
|
|
|
|
sum3 |
||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
c_in |
|
|
|
|
|
|
|
|
|
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FULL_ADD |
|
|
|
|
|
|
|
|
||||||
|
|
|
a4 |
|
|
INPUT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OUTPUT |
|
|
c4 |
||||
|
|
|
|
|
|
|
|
a |
|
|
c_out |
|
|
|
|
|||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||
|
|
|
|
|
INPUT |
|
|
|
|
|
|
OUTPUT |
|
|||||||||||||||
|
|
|
b4 |
|
|
|
|
|
|
b |
|
|
|
sum |
|
|
|
|
|
sum4 |
||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
c_in |
|
|
|
|
|
|
|
|
|
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Answers to Selected Odd-Numbered Problems |
799 |
||||||
|
|
|
|
addsub4 |
|
|
|
|
|
|||||
A1 |
INPUT |
|
|
|
|
|
|
|
|
|
|
|
||
A1 |
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
||
INPUT |
|
|
|
|
|
|
|
|
|
|
||||
A2 |
A2 |
|
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
||
INPUT |
|
|
|
|
OUTPUT |
|
|
S1 |
|
|||||
A3 |
A3 |
SUM1 |
|
|
|
|
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
|
|
|
|
|
|
OUTPUT |
|
|
|
AND3 |
V |
|
|
|
|
|
|
INPUT |
NOT |
|
|
S_SUM |
|
|
|
|
|
|
|
|
FIGURE ANS6.31
adding 1 to the output sum; the XOR gates act as inverters, making the inputs to the adder equal to the one’s complement of B; the output is A (one’s complement of B) 1 A B
SUB 0: Input carry is forced LOW, adding 0 to the output sum; the XOR gates act as noninverting buffers, making the inputs to the adder equal the true binary value of B; the output is A B 0 A B.
6.31See Figure ANS6.31.
6.33—— addsubv1.vhd
——4-bit parallel adder with overflow detection,
——using a generate statement and components
——overflow: SOP network
ENTITY addsubv1 |
IS |
|
|
PORT( |
|
|
|
sub |
|
: IN |
BIT; |
a, b |
|
: IN |
BIT_VECTOR(4 downto 1); |
c4, |
v |
: OUT |
BIT; |
sum |
|
: BUFFER |
BIT_VECTOR(4 downto 1)); |
END addsubv1; |
|
|
|
ARCHITECTURE adder OF addsubv1 IS —— Component declaration COMPONENT full_add
PORT(
a, b, c_in : IN BIT; c_out, sum : OUT BIT);
800 Answers to Selected Odd-Numbered Problems
END COMPONENT;
—— Define a signal for internal carry bits
SIGNAL |
c |
: |
BIT_VECTOR |
(4 |
downto |
0); |
SIGNAL |
b_comp |
: |
BIT_VECTOR |
(4 |
downto |
1); |
BEGIN
—— Carry input depends on add or subtract (sub=1 for subtract) c(0) <= sub;
adders:
FOR I IN 1 to 4 GENERATE
——invert b for subtract function (b(i) xor 1)
——do not invert b for add function (b(i) xor 0)
b_comp(i) <= b(i) xor sub;
adder: full_add PORT MAP (a(i), b_comp(i), c(i-1), c(i), sum(i));
END GENERATE; |
|
|
|
c4 |
<= |
c(4); |
|
v <= (a(4) and |
b(4) and (not sum(4))) |
||
|
or ((not |
a(4)) and (not b(4)) and sum(4)); |
END adder;
——addsubv2.vhd
——4-bit parallel adder with overflow detection,
——using a generate statement and components
——overflow: xor gate
ENTITY addsubv2 IS |
|
|
PORT( |
|
|
sub |
: IN |
BIT; |
a, b |
: IN |
BIT_VECTOR(4 downto 1); |
c4, v |
: OUT |
BIT; |
sum |
: OUT BIT_VECTOR(4 downto 1)); |
|
END addsubv2; |
|
|
ARCHITECTURE adder OF addsubv2 IS
—— Component declaration |
|
|
COMPONENT full_add |
|
|
PORT( |
|
|
a, b, c_in |
: IN BIT; |
|
c_out, sum |
: OUT BIT); |
|
END COMPONENT; |
|
|
—— Define a signal for internal carry bits |
||
SIGNAL c |
: BIT_VECTOR (4 downto 0); |
|
SIGNAL b_comp |
: BIT_VECTOR (4 downto 1); |
BEGIN
—— Carry input depends on add or subtract (sub=1 for subtract) c(0) <= sub;
adders:
FOR i IN 1 to 4 GENERATE
——invert b for subtract function (b(i) xor 1)
——do not invert b for add function (b(i) xor 0) b_comp(i) <= b(i) xor sub;
adder: full_add PORT MAP (a(i), b_comp(i), c(i-1), c(i), sum(i)); END GENERATE;
c4 <= c(4);
v <= c(4) xor c(3);
END adder;
Answers to Selected Odd-Numbered Problems |
805 |
7.19—— ltch8prm.vhd
—— D latch with active-HIGH level-sensitive enable
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
LIBRARY altera;
USE altera.maxplus2.ALL;
ENTITY ltch8prm IS |
|
|
PORT(d_in |
: IN |
STD_LOGIC_VECTOR(7 downto 0); |
enable |
: IN |
STD_LOGIC; |
q_out |
: OUT STD_LOGIC_VECTOR(7 downto 0)); |
|
END ltch8prm; |
|
|
ARCHITECTURE a OF ltch8prm IS BEGIN
—— Instantiate a latch from a MAX PLUS II primitive latch8:
FOR i IN 7 downto 0 GENERATE latch_primitive: latch
PORT MAP (d => d_in(i), ena => enable, q => q_out(i));
END GENERATE;
END a;
See Figure ANS7.19.
FIGURE ANS7.19
7.21See Figure ANS7.21.
EN/CLK
D
Q1
Q2
FIGURE ANS7.21
806 Answers to Selected Odd-Numbered Problems
FIGURE ANS7.23
7.23 |
See Figure ANS7.23. |
|
|
|
|
||
|
|
||
|
|
||
|
|
||
7.25 |
See Figure ANS7.25. |
|
FIGURE ANS7.25 |
7.27—— dff12lpm.vhd
——12-BIT D flip-flop
——Uses a flip-flop component from the Library of Parameterized Modules (LPM)
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
LIBRARY lpm;
USE lpm.lpm_components.ALL;
ENTITY dff12lpm IS |
|
|
PORT(d_in |
: IN |
STD_LOGIC_VECTOR(11 downto 0); |
clk |
: IN |
STD_LOGIC; |
q_out : OUT |
STD_LOGIC_VECTOR(11 downto 0)); |
|
END dff12lpm; |
|
|
ARCHITECTURE a OF dff12lpm IS
BEGIN
—— Instantiate flip-flop from an LPM component dff12: lpm_ff
GENERIC MAP (LPM_WIDTH => 12)
PORT MAP (data => d_in,
clock => clk,
q => q_out);
END a;
Answers to Selected Odd-Numbered Problems |
807 |
FIGURE ANS7.29
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7.29 |
See Figure ANS7.29. |
7.33 |
The circuit generates a 4-bit binary sequence from 0000 |
||||
7.31 |
See Figure ANS7.31. The circuit generates the following |
|
to 1111, then repeats indefinitely. |
||||
|
|
|
|||||
|
repeating pattern: 111, 110, 101, 100, 011, 010, 001, 000. |
7.35 |
See Figure 7.35. |
||||
|
This is a 3-bit binary down-count sequence. |
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0
1
2
FIGURE ANS7.31
CLK
J
K
PRE
CLR
Q
Q
FIGURE 7.35