(Type The Document Title) : LAB # 4 (A)
(Type The Document Title) : LAB # 4 (A)
(Type The Document Title) : LAB # 4 (A)
LAB # 4(a)
Objective
To implement a D flip flop circuit by using data flow modeling.
Circuit Diagram
Coding
//Design module
module dff(q,qbar,d,clk);
input d,clk;
output q,qbar;
wire x,y;
assign x=(d&clk);
assign y=((~d)&clk);
assign q=~(x|qbar);
assign qbar=~(y|q);
endmodule
//stimulus module
module dffa;
reg d,clk;
wire q,qbar;
dff ff(q,qbar,d,clk);
initial
clk=1'b1;
always #5
Truth Table
Timing Diagram
Circuit Diagram
Coding
//Design module
module fa(sum,cout,a,b,cin);
input a,b,cin;
output sum,cout;
assign sum =((a&b&cin)|((~a)&b&(~cin))|((~a)&(~b)&cin)|(a&(~b)&(~cin)));
assign cout=((a&b)|(b&cin)|(a&cin));
endmodule
//stimulus module
module test;
reg a,b,cin;
wire sum,cout;
fa adder(sum,cout,a,b,cin);
Truth Table
Timing Diagram
Circuit Diagram
Coding
//Design module
module msjk(q,qbar,j,k,clk,clear);
input j,k,clk,clear;
output q,qbar;
wire a,b,y,ybar,c,d;
assign a =~(qbar&j&clk&clear);
assign b
=~(q&clk&k);
assign y =~(a&ybar);
assign ybar =~(b&clear&y);
assign c =~(y&(~clk));
assign d
=~(ybar&(~clk));
assign q
=~(c&qbar);
assign qbar =~(d&clear&q);
endmodule
//stimulus module
module test;
reg j,k,clear,clk;
wire q,qbar;
j=1'b0; k=1'b0;
j=1'b0; k=1'b1;
j=1'b1; k=1'b0;
j=1'b1; k=1'b1;
j=1'b0; k=1'b0;
j=1'b0; k=1'b1;
j=1'b1; k=1'b0;
j=1'b1; k=1'b1;
Truth Table
J
0
0
1
1
K
0
1
0
1
Q
Q
0
1
Q
Q
Q
1
0
Q
Comments
No change
Reset
Set
Toggle
Circuit Diagram
Coding
//Design module
module msjk(q,qbar,j,k,clk,clear);
input j,k,clk,clear;
output q,qbar;
wire a,b,y,ybar,c,d;
assign a =~(qbar&j&clk&clear);
assign b =~(q&clk&k);
assign y =~(a&ybar);
assign ybar =~(b&clear&y);
assign c =~(y&(~clk));
assign d =~(ybar&(~clk));
assign q =~(c&qbar);
assign qbar =~(d&clear&q);
endmodule
//4 bit counter design module
module counter(q,qbar,j,k,clk,clear);
Truth Table
Q1
Q2
Q3
Q4
Decimal
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
Timing Diagram
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15