-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockGenerator.v
More file actions
49 lines (43 loc) · 1.44 KB
/
ClockGenerator.v
File metadata and controls
49 lines (43 loc) · 1.44 KB
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
`timescale 1ns / 1ps
module ClockGenerator(
input sys_clkn,
input sys_clkp,
input [23:0] ClkDivThreshold,
output reg FSM_Clk,
output reg ILA_Clk
);
//Generate high speed main clock from two differential clock signals
wire clk;
reg [23:0] ClkDiv = 24'd0;
reg [23:0] ClkDivILA = 24'd0;
IBUFGDS osc_clk(
.O(clk),
.I(sys_clkp),
.IB(sys_clkn)
);
// Initialize the two registers used in this module
initial begin
FSM_Clk = 1'b0;
ILA_Clk = 1'b0;
end
// We derive a clock signal that will be used for sampling signals for the ILA
// This clock will be 10 times slower than the system clock.
always @(posedge clk) begin
if (ClkDivILA == 10) begin
ILA_Clk <= !ILA_Clk;
ClkDivILA <= 0;
end else begin
ClkDivILA <= ClkDivILA + 1'b1;
end
end
// We will derive a clock signal for the finite state machine from the ILA clock
// This clock signal will be used to run the finite state machine for the I2C protocol
always @(posedge ILA_Clk) begin
if (ClkDiv == ClkDivThreshold) begin
FSM_Clk <= !FSM_Clk;
ClkDiv <= 0;
end else begin
ClkDiv <= ClkDiv + 1'b1;
end
end
endmodule