10
Solutions to CSE3201 Assignment 4 1. 5.21 (From the textbook, as with the remainder of the questions) Ans. in textbook 2. 5.22 (Just do the code and only show what's in the always block, absolutely no structural code, use only non-blocking assignments.) module johnson8 (Resetn, Clock, Q); input Resetn, Clock; output reg [7:0] Q; reg [7:0] Q; always @(negedge Resetn, posedge Clock) if (!Resetn) Q <= 0; else Q <= {{Q[6:0]}, {Q[7]}}; endmodule 3. 5.23 // Ring counter with synchronous reset module ripplen (Resetn, Clock, Q); parameter n = 8; input Resetn, Clock; output reg [n1:0] Q; always @(posedge Clock) if (!Resetn) begin Q[7:1] <= 0; Q[0] <= 1; end else Q <= {{Q[6:0]}, {Q[7]}}; endmodule 4. 5.25 Page 1 of 10

5ns Solutions to CSE3201 Assignment 4 Tmin tsu

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 5ns Solutions to CSE3201 Assignment 4 Tmin tsu

Solutions to CSE3201 Assignment 41. 5.21 (From the textbook, as with the remainder of the questions)

Ans. in textbook

2. 5.22 (Just do the code and only show what's in the always block, absolutely no structural code, use only non-blocking assignments.)

5.20. module upcount12 (Resetn, Clock, Q);input Resetn, Clock;output reg [3:0] Q;

always@(posedge Clock)if (!Resetn)Q <= 0;

else if (Q == 11)Q <= 0;

elseQ <= Q + 1;

endmodule

5.21. The longest delay in the circuit is the from the output of FF 0 to the input of FF3. This delay totals 5 ns.Thus the minimum period for which the circuit will operate reliably is

Tmin = 5 ns + tsu = 8 ns

The maximum frequency isFmax = 1/Tmin = 125MHz

5.22. module johnson8 (Resetn, Clock, Q);input Resetn, Clock;output reg [7:0] Q;reg [7:0] Q;

always@(negedge Resetn, posedge Clock)if (!Resetn)Q <= 0;

elseQ <= {{Q[6:0]}, {∼Q[7]}};

endmodule

5-8

3. 5.235.23. // Ring counter with synchronous reset

module ripplen (Resetn, Clock, Q);parameter n = 8;input Resetn, Clock;output reg [n−1:0] Q;

always@(posedge Clock)if (!Resetn)begin

Q[7:1] <= 0;Q[0] <= 1;

endelse

Q <= {{Q[6:0]}, {Q[7]}};

endmodule

5.24. (a) Period = 2× n× tp

(b)ResetE

ResetInterval

Count

CounterRing Osc

The counter tallies the number of pulses in the 100 ns time period. Thus

tp =100 ns

2× Count× n

5-9

4. 5.25

! Page 1 of 10

Page 2: 5ns Solutions to CSE3201 Assignment 4 Tmin tsu

5.25.

Q

Clock

D

Q

A

10

10

10

10

A

D

Clock

Q

5.26.ResetStart

3-bit counter

gf

Clock

5.27. With non-blocking assignments, the result of the assignment f <= A[1] & A[0] is not seen by the successiveassignments inside the for loop. Thus, f has an uninitialized value when the for loop is entered. Similarly,each for loop interation sees the unitialized value of f . The result of the code is the sequential circuitspecified by f = f | A[n-1] A[n-2].

5-10

5. 5.26Ans. in textbook

6. 5.28 (Just draw the diagram after carefully looking at the code and show the counting sequence).

C’C”

4

0 L

7. 6.1 (Note: the book writes its state assignment table a little differently than we have, it denotes the inputs with the variable w and places different settings for it in different columns, our notation made it look just like a traditional truth table).

Ans. in textbook

! Page 2 of 10

Page 3: 5ns Solutions to CSE3201 Assignment 4 Tmin tsu

8. 6.3 (Just draw the state transition diagram – no tables please –, label your states in alphabetical order A,B,C, etc. with A being the reset state).

“3

L

I

I ‘8 r—-

/

f/I

I

9. 6.5Ans. in textbook

10. 6.6Ans. in textbook

! Page 3 of 10

Page 4: 5ns Solutions to CSE3201 Assignment 4 Tmin tsu

11. 6.9 (Use the same labeling approach as for 6.3)

QI

VCI

10a

QI)000)QV1

c?00t7’0SI0Vd/()

/i49

ecJ1

0/!

O/O(4.t1Vb0)vit)

1i4”25

*OHjku

oL9.9

52

oI

4

! Page 4 of 10

Page 5: 5ns Solutions to CSE3201 Assignment 4 Tmin tsu

c, SeAp

C

Al I/ (/\/

/

IPP’

J

t2 0101 0c,

10 0

0I I

6 ‘

c: cC2! C

O C

10 0

0 0 0I )

c’ •::/ I, 0 0

,c

S0 + cJ

k

c, SeAp

C

Al I/ (/\/

/

IPP’

J

t2 0101 0c,

10 0

0I I

6 ‘

c: cC2! C

O C

10 0

0 0 0I )

c’ •::/ I, 0 0

,c

S0 + cJ

k

! Page 5 of 10

Page 6: 5ns Solutions to CSE3201 Assignment 4 Tmin tsu

12. 6.106.10. Verilog code for the solution given in problem 6.9 is

module prob8 10 (Clock, Resetn, w1, w2, z);input Clock, Resetn, w1, w2;output reg z;reg [2:1] y, Y;wire k;parameter [2:1] A = 2’b00, B = 2’b01, C = 2’b10, D = 2’b11;

// Define the next state and output combinational circuitsassign k = w1 ∧ w2;always@(k, y)case (y)A: if (k) begin

Y = A; z = 0;end

else beginY = B; z = 0;

endB: if (k) begin

Y = A; z = 0;end

else beginY = C; z = 0;

endC: if (k) begin

Y = A; z = 0;end

else beginY = D; z = 0;

endD: if (k) begin

Y = A; z = 0;end

else beginY = D; z = 1;

endendcase

// Define the sequential blockalways@(negedge Resetn, posedge Clock)if (Resetn == 0) y <= A;else y <= Y;

endmodule

6-7

13. 6.14

! Page 6 of 10

Page 7: 5ns Solutions to CSE3201 Assignment 4 Tmin tsu

6.13. Verilog code for the solution given in problem 6.12 is

module prob8 13 (Clock, Resetn, w, p);input Clock, Resetn, w;output p;reg [3:1] y, Y;parameter [3:1] A = 3’b000, B = 3’b001, C = 3’b010, D = 3’b011, E = 3’b100, F = 3’b101;

// Define the next state combinational circuitalways@(w, y)case (y)A: if (w) Y = C;else Y = B;

B: if (w) Y = E;else Y = D;

C: if (w) Y = D;else Y = E;

D: if (w) Y = F;else Y = A;

E: if (w) Y = A;else Y = F;

F: if (w) Y = C;else Y = B;

default: Y = 3’bxxx;endcase

// Define the sequential blockalways@(negedge Resetn, posedge Clock)if (Resetn == 0) y <= A;else y <= Y;

// Define outputassign p = (y == F);

endmodule

6.14. The timing diagram is

Clock

a

b

y y2,

SumMoore

SMealy

6-9

14. 6.15Ans. in textbook

15. 6.20

--4--

C-)rJ

1

U

—LI‘S0

I-0--

‘A

j

0—

S—.0

—ri

\A1

0—

-c:0—-

V

I’

V

! Page 7 of 10

Page 8: 5ns Solutions to CSE3201 Assignment 4 Tmin tsu

16. 6.23

/20/0S

0/015SjOi/Sh

L00/0,00I/9/10Q/10.51Q10/0h(LiQQ20a/Qi100‘710001@0-

11001QOC)IV)

sd

“7)

V’)

‘I 0 4—

C

1

fl

0

C—’

0 ÷ F +

-+-‘

2

0‘2z

cs

:

I

V.,

0—

00

z1cjvJ

00

C-

——c)

I1’

-Th

_- -

I

——

0—Ic.

! Page 8 of 10

Page 9: 5ns Solutions to CSE3201 Assignment 4 Tmin tsu

17. 6.29Ans. in textbook

18. 6.306.30. The Verilog code based on the style of code in Figure 6.29 is

module prob8 30 (Clock, Resetn, D, N, z);input Clock, Resetn, D, N;output z;reg [3:1] y, Y;wire [1:0] K;parameter [3:1] S1 = 3’b000, S2 = 3’b001, S3 = 3’b010, S4 = 3’b011, S5 = 3’b100;

// Define the next state combinational circuitassign K = {D, N};always@(K, y)case (y)S1: if (K == 2’b00) Y = S1;else if (K == 2’b01) Y = S3;else if (K == 2’b10) Y = S2;else Y = 3’bxxx;

S2: if (K == 2’b00) Y = S2;else if (K == 2’b01) Y = S4;else if (K == 2’b10) Y = S5;else Y = 3’bxxx;

S3: if (K == 2’b00) Y = S3;else if (K == 2’b01) Y = S2;else if (K == 2’b10) Y = S4;else Y = 3’bxxx;

S4: if (K == 2’b00) Y = S1;else Y = 3’bxxx;

S5: if (K == 2’b00) Y = S3;else Y = 3’bxxx;

default: Y = 3’bxxx;endcase

// Define the sequential blockalways@(negedge Resetn, posedge Clock)if (Resetn == 0) y <= S1;else y <= Y;

// Define outputassign z = (y == S4) | (y == S5);

endmodule

6-19! Page 9 of 10

Page 10: 5ns Solutions to CSE3201 Assignment 4 Tmin tsu

19. 6.316.31. The Verilog code based on the style of code in Figure 6.34 is

module prob8 31 (Clock, Resetn, D, N, z);input Clock, Resetn, D, N;output z;reg [3:1] y;wire [1:0] K;parameter [3:1] S1 = 3’b000, S2 = 3’b001, S3 = 3’b010, S4 = 3’b011, S5 = 3’b100;

assign K = {D, N};// Define the sequential blockalways@(negedge Resetn, posedge Clock)if (Resetn == 0) y <= S1;elsecase (y)S1: if (K == 2’b00) y <= S1;

else if (K == 2’b01) y <= S3;else if (K == 2’b10) y <= S2;else y <= 3’bxxx;

S2: if (K == 2’b00) y <= S2;else if (K == 2’b01) y <= S4;else if (K == 2’b10) y <= S5;else y <= 3’bxxx;

S3: if (K == 2’b00) y <= S3;else if (K == 2’b01) y <= S2;else if (K == 2’b10) y <= S4;else y <= 3’bxxx;

S4: if (K == 2’b00) y <= S1;else y <= 3’bxxx;

S5: if (K == 2’b00) y <= S3;else y <= 3’bxxx;

default: y <= 3’bxxx;endcase

// Define outputassign z = (y == S4) | (y == S5);

endmodule

6.32. The Verilog code based on the style of code in Figure 6.29 is

module prob8 32 (Clock, Resetn, D, N, z);input Clock, Resetn, D, N;output reg z;reg [2:1] y, Y;wire [1:0] K;parameter [2:1] S1 = 2’b00, S2 = 2’b01, S3 = 2’b10;

cont’d

6-20

20. 6.40

-+-‘

2

0‘2z

cs

:

I

V.,

0—

00

z1cjvJ

00

C-

——c)

I1’

-Th

_- -

I

——

0—Ic.

! Page 10 of 10