forked from NitinBnittu/Frequency-divider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Divide_by_3_50.v
64 lines (47 loc) · 894 Bytes
/
Divide_by_3_50.v
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
63
64
//design
module d_ff(in,clk,q,qb);
input in,clk;
output reg q,qb;
always@(posedge clk or negedge clk)begin
q=in;
qb=~q;
end
endmodule
module dec(rst,clk,count);
input rst,clk;
output reg [1:0]count;
reg q,qb,freq_out;
always@(posedge clk)begin
if(rst)
count=3'b0;
else
count=count+1;
if(count==2'b11)
count=2'b00;
end
d_ff eey(.in(count[1]),.clk(clk),.q(q),.qb(qb));
always@(*)begin
freq_out=q|count[1];
end
endmodule
//testbench
module tb;
reg rst,clk;
wire[1:0]count;
dec e(.rst(rst),.clk(clk),.count(count));
initial begin
clk=0;
forever #1clk=~clk;
end
initial begin
$monitor("Time=%0t rst=%b count=%b",$time,rst,count);
rst=1;
#5rst=0;
#30$finish;
end
initial
begin
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule