-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmg_clkdiv.v
58 lines (52 loc) · 1.02 KB
/
smg_clkdiv.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
`timescale 1ns/1ps
////////////////////////////////
//module name: smg_clkdiv
////////////////////////////////
module smg_clkdiv
(
input clk_50MHz,
input rst,
output reg clk_1khz,
output reg clk_1hz,
output reg rdsig_nextdata
);
reg[15:0] cnt1;
reg[9:0] cnt2;
reg clk_1hz_buf;
//1khz分频
always @(posedge clk_50MHz or negedge rst)
begin
if(!rst)begin
clk_1khz <= 1'b0;
cnt1 <= 16'd0;
end
else if(cnt1 == 16'd24999)begin
clk_1khz <= !clk_1khz;
cnt1 <= 16'd0;
end
else begin
cnt1 <= cnt1 + 16'd1;
end
end
//1hz分频
always @(posedge clk_1khz or negedge rst)
begin
if(!rst)begin
clk_1hz <= 1'b0;
cnt2 <= 10'd0;
end
else if(cnt2 == 10'd499)begin
clk_1hz <= !clk_1hz;
cnt2 <= 10'd0;
end
else begin
cnt2 <= cnt2 + 10'd1;
end
end
//得到fifo读取信号:1hz信号下降沿后,持续50MHz的一个时钟周期的高电平
always @(posedge clk_50MHz)
begin
clk_1hz_buf <= clk_1hz;
rdsig_nextdata <= clk_1hz_buf & (~clk_1hz);
end
endmodule