-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd_flipflop.v
More file actions
62 lines (46 loc) · 772 Bytes
/
d_flipflop.v
File metadata and controls
62 lines (46 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module d_flipflop(q, qbar, d, clk);
output q, qbar;
input d, clk;
/* Behavioral
reg q, qbar;
always @(posedge clk) begin
case (d)
0: q = 0;
1: q = 1;
endcase
assign qbar = ~q;
end
*/
/* Dataflow
reg q, qbar;
always @(posedge clk) begin
q = d;
qbar = ~q;
end
*/
/* Structural */
wire dbar, out1, out2;
not n0(dbar, d);
nand n1(out1, d, clk);
nand n2(out2, dbar, clk);
nand n3(q, out1, qbar);
nand n4(qbar, out2, q);
endmodule
/* Testbench
module testbench;
reg clk, d;
wire q, qbar;
d_flipflop ff(q, qbar, d, clk);
initial begin
clk = 1'b0;
forever #10 clk = ~clk;
end
initial begin
d = 0;
#100 d = 1;
end
initial begin
$monitor(" D = %b Q = %b Qbar = %b", d, q, qbar);
end
endmodule
*/