-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOscill_adc_clk.v
82 lines (70 loc) · 1.48 KB
/
Oscill_adc_clk.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
72
73
74
75
76
77
78
79
80
81
module Oscill_adc_clk(
rst_n ,
clk ,
adc_clk_sel ,
clk_adc
);
input rst_n ;
input clk ;
input [4:0] adc_clk_sel ;
output clk_adc ;
wire rst_n ;
wire clk ;
wire [4:0] adc_clk_sel ;
reg clk_adc ;
reg [16:0] cnt1 ;
wire add_cnt1 ;
wire end_cnt1 ;
wire [16:0] x ;
reg [16:0] x1 ;
wire [16:0] y ;
//
assign x= 17'b1 << (adc_clk_sel+1);
assign y= 17'b1 << (adc_clk_sel);
always @(posedge clk or negedge rst_n)begin
if(!rst_n)begin
x1 <= 0;
end
else begin
x1 <= x;
end
end
//计数一个波形的总时间
always @(posedge clk or negedge rst_n)begin
if(!rst_n)begin
cnt1 <= 0;
end
else if(add_cnt1)begin
if(end_cnt1)
cnt1 <= 0;
else if(x1!=x)
cnt1 <= 0;
else
cnt1 <= cnt1 + 1;
end
end
assign add_cnt1 = 1;
assign end_cnt1 = add_cnt1 && cnt1== x-1;
//输出占空比为50%的方波
always @(posedge clk or negedge rst_n)begin
if(!rst_n)begin
clk_adc <= 0;
end
else if(cnt1 >=0 && cnt1 < y && x1==x)begin
clk_adc <=1;
end
else begin
clk_adc <=0;
end
end
/*
always @(posedge clk or negedge rst_n)begin
if(!rst_n)begin
clk_adc <= 0;
end
else begin
clk_adc <=~clk_adc;
end
end
*/
endmodule