-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfrequency_by_n.v
59 lines (43 loc) · 863 Bytes
/
frequency_by_n.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
//design
module freq ( clk ,rst,out_clk);
input clk,rst;
output reg out_clk;
parameter N=3; //(N+1)*2 is the nummber of time clock will divide
reg [N:0]count;
always @(posedge clk or posedge rst)
begin
if (rst)begin
count <= 0;
out_clk<=0;
end
else if(count==N)
begin
count<=0;
out_clk= ~out_clk;
end
else
count=count+1;
end
endmodule
//testbench
module tb;
reg clk,rst;
wire out_clk;
freq q1(clk,rst,out_clk);
initial begin
clk = 1'b0;
forever #1 clk = ~clk;
end
initial
begin
$monitor($time,"clk=%b rst=%b out_clk = %b",clk,rst,out_clk);
rst =1;
#5 rst =0;
#50 $finish;
end
initial
begin
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule