-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsys.v
75 lines (68 loc) · 1.67 KB
/
sys.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
`timescale 1 ns / 1 ps
// ===============================
// Global System Signal Generation
//
// Low-level hardware configuration
// to generate the global clk signal
// and asynchronous rst_n signal.
//
// =====
// Usage
// =====
//
// Top-level designs must include
// the following HDL:
//
// // =====================
// // Global System Signals
// // (clk, rst_n)
// // =====================
// wire clk, rst_n;
// sys sys_inst(
// .CLK_IN(CLK_IN),
// .clk(clk),
// .rst_n(rst_n)
// );
//
// By Nathan Petersen
// April 1, 2020
//
// ===============================
module sys(CLK_IN, clk, rst_n);
input CLK_IN;
output clk, rst_n;
// =======================
// System Clock Generation
//
// Generate 120MHz clock signal for
// our logic using the device PLL.
// =======================
wire pll_locked;
pll myPLL(
.clock_in(CLK_IN),
.global_clock(clk),
.locked(pll_locked)
);
// =======================
// Global Asynchronous Reset
//
// From: https://stackoverflow.com/questions/38030768
//
// Lattice iCE40 FPGAs do not have a global reset signal!
//
// Therefore, we can simulate one by using the PLL LOCK output.
// When the FPGA first powers on, the PLL must initialize and
// acquire a lock onto the input reference clock. This takes
// 10s of cycles, so we simply assert the reset signal while
// the PLL is not locked.
//
// Since it is unclear if the PLL LOCK output is in our clock
// domain, we synchronize it before using it to prevent
// meta-stability issues.
//
// =======================
reg [3:0] pll_locked_ff;
always @(posedge CLK_IN)
pll_locked_ff <= {pll_locked_ff, pll_locked};
assign rst_n = pll_locked_ff[3];
endmodule