-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path37_div3_v2.v
71 lines (64 loc) · 1 KB
/
37_div3_v2.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
65
66
67
68
69
70
71
module test_div3_v2(clkin,rst_n,clkout);
input clkin;
input rst_n;
output clkout;
reg pos,neg;
reg [1:0] cnt1,cnt2;
always @(posedge clkin or negedge rst_n)
begin
if(!rst_n)
cnt1<=2'd0;
else
begin
if(cnt1<2'd2)
cnt1<=cnt1+1'b1;
else
cnt1<=2'd0;
end
end
always @(posedge clkin or negedge rst_n)
begin
if(!rst_n)
begin
pos<=1'b0;
end
else
begin
case(cnt1)
2'd0:pos<=1'b1;
2'd1:pos<=1'd0;
2'd2:pos<=1'd0;
default:pos<=1'b0;
endcase
end
end
always @(negedge clkin or negedge rst_n)
begin
if(!rst_n)
cnt2<=2'd0;
else
begin
if(cnt2<2'd2)
cnt2<=cnt2+1'b1;
else
cnt2<=2'd0;
end
end
always @(negedge clkin or negedge rst_n)
begin
if(!rst_n)
begin
neg<=1'b0;
end
else
begin
case(cnt2)
2'd0:neg<=1'b1;
2'd1:neg<=1'd0;
2'd2:neg<=1'd0;
default:neg<=1'b0;
endcase
end
end
assign clkout=pos||neg;
endmodule