Digital Systems Design Using Verilog 1st Edition Roth Solutions Manual 1
Digital Systems Design Using Verilog 1st Edition Roth Solutions Manual 1
95
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(b)
module SM_desc(X1, X2, CLK, Z1, Z2);
input X1, X2, CLK;
output reg Z1, Z2;
initial begin
state = 2'b00;
nextstate = 2'b00;
Z1 = 1'b0;
Z2 = 1'b0;
end
96
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
always @(state, X1, X2)
begin
Z1 = 1'b0;
Z2 = 1'b0;
case(state)
0: begin
if(X1 == 1'b1) begin
Z2 = 1'b1;
if(X2 == 1'b1)
nextstate = 2'b00;
else begin
Z1 = 1'b1;
nextstate = 2'b01;
end
end
else if(X2 == 1'b1) begin
Z1 = 1'b1;
nextstate = 2'b10;
end
else
nextstate = 2'b11;
end
1: begin
Z1 = 1'b1;
if(X1 == 1'b1) begin
Z2 = 1'b1;
if(X2 == 1'b1)
nextstate = 2'b11;
else
nextstate = 2'b10;
end
else if(X2 == 1'b1)
nextstate = 2'b01;
else
nextstate = 2'b00;
end
2: begin
if(X1 == 1'b1) begin
Z2 = 1'b1;
nextstate = 2'b01;
if(X2 == 1'b0)
Z1 = 1'b1;
end
else if(X2 == 1'b1) begin
Z1 = 1'b1;
nextstate = 2'b00;
end
else begin
nextstate = 2'b11;
end
end
3: begin
if(X1 == 1'b1) begin
Z2 = 1'b1;
if(X2 == 1'b1)
nextstate = 2'b00;
else
nextstate = 2'b01;
end
else
nextstate = 2'b10;
end
97
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
endcase
end
endmodule
5.2
5.3 (a)
98
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(b)
ENTER, LEAVE, READY, RED, GREEN, BLUE used as described in the problem
INC: increment counter by 1
DEC: decrement counter by 1
GE8: counter value is greater then or equal to 8
GE10: counter value is greater then or equal to 10
ODD: counter value is odd
(c)
99
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
5.4 (a)
(b)
(c)
module DIV_SM_desc(CLK, St, Divisor, Dividend, V, Quotient);
input CLK, St;
input [4:0] Divisor;
input [7:0] Dividend;
output reg V;
100
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
output [2:0] Quotient;
initial begin
state = 3'b000;
nextstate = 3'b000;
ACC = 9'b000000000;
RegB = 5'b00000;
end
101
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
default: begin
end
endcase
end
endmodule
5.5
102
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
5.6
5.7
103
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
5.8 (a)
A B
Start 0100011101
Shift #1 0 100011101
Shift #2 01 00011101
Shift #3 010 0011101
Shift #4 0100 011101
Shift #5 0 1000 11101
Add 0 1011 11101
Shift #6 1 0111 1101
Add 1 1010 1101
Shift #7 11 0101 101
Add 11 1000 101
Shift #8 111 0001 01
Add 1010 0001 01
Shift #9 1 0100 0010 1
Shift #10 10 1000 0101
(b)
(c)
104
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(d)
module P5_8(St, Clk, Number, A, Done);
input St, Clk;
input [9:0] Number;
inout [11:0] A;
output reg Done;
initial begin
Atemp = A;
B = 10'b0000000000;
state = 2'b00;
nextstate = 2'b00;
cnt = 4'b0000;
end
assign A = Atemp;
assign C10 = (cnt == 4'b1010) ? 1'b1 : 1'b0;
assign D1_GE5 = (A[3:0] >= 4'b0101)? 1'b1 : 1'b0;
assign D2_GE5 = (A[7:4] >= 4'b0101)? 1'b1 : 1'b0;
105
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
end
endcase
end
endmodule
5.9 (a)
106
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(b)
(c)
module P5_9(clk, St, Mplier, Mcand, Product, Done);
input clk, St;
input [15:0] Mplier, Mcand;
output [30:0] Product;
output Done;
initial begin
State = 2'b00;
A = 16'h0000;
B = 16'h0000;
Counter = 5'b00000;
end
assign M = B[0];
assign Done = (State == 2'b10)? 1'b1: 1'b0;
assign Product = {A[14:0], B};
assign K = (Counter == 5'b01111)? 1'b1 : 1'b0;
assign addout = (K == 1'b0)? (A + Mcand) : (A + (~Mcand) + 16'h0001);
107
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
1: begin
Counter <= Counter + 5'b00001;
if(K == 1'b0) begin
if(M == 1'b1) begin
A <= {Mcand[15], addout[15:1]};
B <= {addout[0], B[15:1]};
end
else begin
A <= {A[15], A[15:1]};
B <= {A[0], B[15:1]};
end
end
else begin
State <= 2'b10;
if(M == 1'b1) begin
A <= {(~Mcand[15]), addout[15:1]};
B <= {addout[0], B[15:1]};
end
else begin
A <= {A[15], A[15:1]};
B <= {A[0], B[15:1]};
end
end
end
2: begin
State <= 2'b00;
end
default: begin
end
endcase
end
endmodule
5.10
108
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
5.11
module test_el;
reg CLK;
reg CALL1, CALL2, FB1, FB2, FS1, FS2, DC;
wire UP, DOWN, DO;
initial begin
CLK = 1'b0;
CALL1 = 1'b0;
CALL2 = 1'b0;
FB1 = 1'b0;
FB2 = 1'b0;
FS1 = 1'b0;
FS2 = 1'b0;
DC = 1'b0;
end
elev_control eltest(CALL1, CALL2, FB1, FB2, FS1, FS2, DC, CLK, UP, DOWN,
DO);
always
#6000 CLK = ~CLK;
always
begin
CALL1 = 1'b1;
#3600;
CALL1 = 1'b0;
#7200;
FB2 = 1'b1;
#3600;
FB2 = 1'b0;
#14400;
FB1 = 1'b1;
#3600;
FB1 = 1'b0;
#3600;
CALL2 = 1'b1;
#3600;
CALL2 = 1'b0;
109
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
#36000;
FB2 = 1'b1;
#3600;
FB2 = 1'b0;
end
endmodule
5.12 (a)
(c)
A B X1 X2 X3 A+ B+ Z1 Z2 Z3
- 1 - 1 - 1 0 0 0 0
0 - 0 1 - 1 0 0 0 0
0 - - 1 1 1 0 0 0 0
1 - 0 - - 0 1 0 0 0
0 0 1 - 0 0 1 0 0 0
0 - - 0 - 0 1 0 0 0
1 - - - - 0 0 1 0 0
- 1 - - - 0 0 1 0 0
- - - 1 - 0 0 1 0 0
0 0 - 0 - 0 0 0 1 0
0 0 0 1 - 0 0 0 0 1
110
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
5.13 (a)
(c)
module Egns_Desc(X1, X2, X3, X4, X5, CLK, Z1, Z2, Z3);
input X1, X2, X3, X4, X5, CLK;
output Z1, Z2, Z3;
initial begin
Q1 = 1'b1;
Q2 = 1'b0;
Q3 = 1'b0;
end
endmodule
111
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
5.14 (a)
(b)
A B C K Kd A+ B+ C+ C0 C1 C2 V
S0 0 0 0 - - 0 0 1 0 0 0 0
S1 0 0 1 1 1 0 1 0 1 1 1 0
0 0 1 0 - 0 0 1 1 1 1 0
0 0 1 - 0 0 0 1 1 1 1 0
S2 1 0 1 0 0 1 0 1 0 0 0
0 1 0 1 1 1 0 1 1 0 0 1
0 1 0 0 - 0 1 1 1 0 0 0
S3 0 1 1 1 0 0 1 1 0 1 0 0
0 1 1 1 1 1 0 1 0 1 0 1
0 1 1 0 - 1 0 0 0 1 0 0
S4 1 0 0 1 1 1 0 1 0 0 1 1
1 0 0 0 - 1 0 0 0 0 1 0
1 0 0 - 0 1 0 0 0 0 1 0
S5 1 0 1 - 0 0 0 1 1 1 1 0
1 0 1 - 1 1 0 1 1 1 1 0
112
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(d) For state assignment S0 = 100000, S1 = 010000… and D flip-flops Q0Q1Q2Q3Q4Q5:
Q0 + = 0
Q1+ = Q0+ Q 1K' + Q1Kd' + Q 5Kd'
Q2+ = Q1KKd + Q2KKd'
Q3+ = Q2K' + Q3KKd'
Q4+ = Q3K' + Q4K' + Q 4Kd'
Q5+ = Q2KKd + Q 3KKd + Q 4KKd + Q 5Kd
V = Q2KKd + Q3KKd + Q4KKd
C0 = Q1 + Q2 + Q5
C1 = Q1 + Q3 + Q5
C2 = Q1 + Q4 + Q5
5.15 (a)
module P5_15(X1, X2, X3, Clk, Z1, Z2, Z3);
input X1, X2, X3, Clk;
output reg Z1, Z2, Z3;
initial begin
state = 2'b00;
nextstate = 2'b00;
end
113
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
end
default: begin
end
endcase
end
endmodule
(b)
A B X1 X2 X3 A+ B+ Z1 Z2 Z3
S0 0 0 1 - - 0 1 0 0 0
0 0 0 0 0 0 1 0 1 0
0 0 0 0 1 1 0 0 1 0
0 0 0 1 0 0 1 0 1 1
0 0 0 1 1 1 0 0 1 1
S1 0 1 - - - 0 0 1 0 0
S2 1 0 - 1 - 1 0 0 0 0
1 0 1 0 - 0 0 1 0 0
1 0 0 0 - 0 1 1 0 1
(c)
5.16 (a) Block diagram is similar to Figure 5-33 with MUX inputs of 1, X1, X2, and X3; ROM outputs
of Z1, Z2 and Z3; 2 bits for test, and 3 bits for the NST and counter.
(b)
114
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(c)
State Q1Q2Q3 Test NST Z1 Z2 Z3
S0 000 01 100 0 0 1
S02 001 11 111 0 0 0
S1 010 10 000 0 0 0
S2 011 00 000 0 0 0
S01 100 10 110 0 0 0
Sx 101 00 011 0 0 0
S03 110 00 010 1 0 0
S04 111 00 011 0 1 0
(d)
module P5_16(X1, X2, X3, CLK, Z1, Z2, Z3);
input X1, X2, X3, CLK;
output Z1, Z2, Z3;
initial begin
PST = 3'b000;
ROM[0] = 8'b01100001;
ROM[1] = 8'b11111000;
ROM[2] = 8'b10000000;
ROM[3] = 8'b00000000;
ROM[4] = 8'b10110000;
ROM[5] = 8'b00011000;
ROM[6] = 8'b00010100;
ROM[7] = 8'b00011010;
end
115
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
5.17 (a)
(b)
Q1Q2Q3 TEST NSF NST Z1 Z2 Z3
000 01 S4 S3 0 0 1
001 10 S2 S0 0 0 0
010 00 S0 S0 0 0 0
011 10 S2 S5 0 0 0
100 11 S1 S6 0 0 0
101 00 S1 S1 1 0 0
110 00 S2 S2 0 1 0
(c) 7 × 11 or 8 × 11
(d) 25 × 5
5.18 (a)
116
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(b)
State ABC Test NSF NST Z1 Z2 Z3
S0 000 01 010 001 0 0 0
S01 001 10 011 101 0 0 0
S03 010 11 110 101 1 0 0
S02 011 00 100 100 0 1 0
S1 100 01 101 100 0 0 0
S2 101 00 000 000 0 0 1
S3 110 10 101 000 0 1 0
(c) Block diagram is similar to Figure 5-29 with inputs of X1 and X2; PLA outputs of Z1, Z2 and Z3;
and a 3-bit, 2-to-1 MUX to select NSF or NST.
5.19 (a) 1. Only Moore outputs; 2. Only 1 decision box per state; 3. NSF for each state should be state
+1
5.20 (a) 1. Only Moore outputs; 2. Only 1 decision box per state; 3. NSF for each state should be state
+1
(b)
5.21 (a) Block diagram is similar to Figure 5-29 with MUX inputs of 1, X1, X2, and X3'; ROM outputs
of Z1, Z2 and Z3; and 3 bits for the NST and counter.
117
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(b)
(c)
ABC Test NST Z1 Z2 Z3
000 01 100 0 0 0
001 11 000 1 0 0
010 01 110 0 0 0
011 00 000 0 1 0
100 10 110 0 0 0
101 00 110 0 1 0
110 00 000 0 0 1
5.22 (a) 1. Convert Mealy outputs to Moore outputs; 2. Only one input tested per state
118
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(b)
Addr Test NSF NST Z1 Z2 Z3
S0 00 S3 S6 0 0 0
S3 11 S1 S1 1 0 0
S1 10 S0 S4 0 0 0
S4 00 S5 S2 0 0 0
S5 11 S0 S0 0 1 0
S6 01 S7 S2 0 0 0
S7 11 S2 S2 0 1 0
S2 11 S0 S0 0 0 1
Test 00 – X1; Test 01 – X2; Test 10 – X3; Test 11 – 1
(c) There are 8 address locations and each have 11 bits (2 test, 3 NSF, 3 NST, 3 outputs) so there
are 8 × 11 bits needed.
(d) 25 inputs are needed (2-bit FF state, 3 inputs) and 5 outputs are needed (2 for next state, 3
outputs) so 25 × 5 bits.
5.23 (a)
(b) Test 00: 1; Test 01: X1; Test 10: X2; Test 11: X3
119
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(c) The circuit has 26 possible inputs (3-bit FF state, 3 inputs) and 5 output functions (3-bit next
state, 2 outputs) so a 26 × 5 bit ROM is required.
(b)
(c) Test 00: 1; Test 01: X1; Test 10: X2; Test 11: X3
120
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
5.25
5.26
5.27 (a)
(b) State Assignment: S0: 100; S1: 010; S2: 001. For D flip-flops Q0Q1Q2:
Q0+ = Q0X1' + Q2
Q1+ = Q0 X1 + Q1 B'
Q2+ = Q1 B
A = Q 0 X1
Z 1 = Q2
121
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
5.28 (a)
Note: R = Reset
(b) State Assignment: S0: 00; S1: 01; S2: 10; S3: 11. For D flip-flops AB:
A B D N R A+ B+ Z0 Z1 Z2 Z3 Z4
S0 0 0 0 0 - 0 0 1 0 0 0 0
0 0 0 1 - 0 1 1 0 0 0 0
0 0 1 - - 1 0 1 0 0 0 0
S1 0 1 0 0 0 0 1 0 1 0 0 0
0 1 0 0 1 0 0 1 1 0 0 0
0 1 - 1 - 1 0 0 1 0 0 0
0 1 1 0 - 1 1 0 1 0 0 0
S2 1 0 0 0 0 1 0 0 0 1 0 0
1 0 0 0 1 0 0 1 0 1 0 0
1 0 0 1 - 1 1 0 0 1 0 0
1 0 1 - - 1 1 0 0 1 0 0
S3 1 1 - - - 0 0 0 0 0 1 1
122
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
(d)
123
© 2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.