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
| `timescale 1ns/1ns
module dff (
output reg q,
output qn,
input d,clk,reset
);
always @(posedge clk or negedge reset) begin
if(!reset)
q<=1'b0;
else
q<=d;
end
assign qn=~q;
endmodule
module mod3(
output clk_3,
input clk,reset
);
wire q0,q1,qn0,qn1,rst,rst2,temp;
wire q0_dly, q1_dly;
dff dff0(q0,qn0,qn0,clk,rst);
dff dff1(q1,qn1,qn1,qn0,rst);
assign #2 q0_dly = q0;
assign #1 q1_dly = q1;
assign clk_3=q1_dly;
assign rst2=reset & ~(q0_dly & q1_dly); //this expression1 does not work
assign rst=reset & temp; //this expression2 works
assign temp=~(q0_dly & q1_dly);
endmodule
module tb_mod3;
reg clk, reset;
wire clk_div3;
initial begin
clk = 0;
forever #10 clk = ~clk;
end
initial begin
reset = 0;
#150;
reset = 1;
end
mod3 uut (
.clk_3 (clk_div3),
.clk (clk),
.reset (reset)
);
endmodule |