-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock_gen.v
executable file
·42 lines (35 loc) · 948 Bytes
/
clock_gen.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
`timescale 1ns / 1ps
module clock_gen(
clk_in,
clk_debounce
);
input clk_in;
output reg clk_debounce=0;
// reset values for counters
localparam debounce = 32'd99_999;
// Initialize and declare ccounters
reg [31:0] counter_debounce = 0;
always @(posedge clk_in) begin
if (counter_debounce == debounce) begin
counter_debounce <= 0;
clk_debounce <= ~clk_debounce;
end
else
counter_debounce <= counter_debounce + 1'b1;
end
endmodule
// generate 25MHz clock from 100MHz clock on board
module clock_gen_display(clk, clk_pix);
input clk;
output clk_pix;
reg clk_display=0;
reg [1:0] counter=0;
always @(posedge clk) begin
counter <= counter + 1;
if (counter == 1) begin
counter <= 0;
clk_display = ~clk_display;
end
end
assign clk_pix = clk_display;
endmodule