Tutorial - Lesson 7 Solution PDF
Tutorial - Lesson 7 Solution PDF
Tutorial - Lesson 7 Solution PDF
__________________________________________________________________________________________________
Lesson 7 (solution)
Flip-flops, Registers, Counters
1(a)
2(a)
module JKflipflop (J, K, Clock, Q, Qbar);
input J, K, Clock;
output reg Q, Qbar;
else
begin
Q <= Qbar;
Qbar <= Q;
end
end
endmodule
EE402/EE415 Digital System & HDLs Tutorial
__________________________________________________________________________________________________
3 (a)
module UpDownCounter (R, Reset, Clock, L, E, up_down, Q);
input [3:0]R;
input Reset, Clock, L, E, up_down;
output reg [3:0]Q;
if(!Reset)
Q <= 0;
else if (L)
Q <= R;
else if (E)
Q <= Q + (up_down? 1: -1);
endmodule
4
module RingCounter (Reset, Clock, Q);
integer k;
end
end
endmodule
EE402/EE415 Digital System & HDLs Tutorial
__________________________________________________________________________________________________
5(a)
module SRflipflop(S, R, Clock, Q, Qbar);
input S, R, Clock;
output reg Q, Qbar;
else
begin
Q <= 1'bx;
Qbar <= 1'bx;
end
end
endmodule
EE402/EE415 Digital System & HDLs Tutorial
__________________________________________________________________________________________________
Q2 Q1 Q0
0 0 0
0 0 1
0 1 0
1 1 1
then it repeats.
6(b)
if (Q[0])
Q[1] <= ~Q[1];
else
Q[1] <= Q[1];
if (Q[1])
Q[2] <= ~Q[2];
else
Q[2] <= Q[2];
end
end
endmodule
EE402/EE415 Digital System & HDLs Tutorial
__________________________________________________________________________________________________
2(b)
3(b)
5(b)
6(b)