1 |
8 |
gdevic |
// file: clock_exdes.v
|
2 |
|
|
//
|
3 |
|
|
// (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved.
|
4 |
|
|
//
|
5 |
|
|
// This file contains confidential and proprietary information
|
6 |
|
|
// of Xilinx, Inc. and is protected under U.S. and
|
7 |
|
|
// international copyright and other intellectual property
|
8 |
|
|
// laws.
|
9 |
|
|
//
|
10 |
|
|
// DISCLAIMER
|
11 |
|
|
// This disclaimer is not a license and does not grant any
|
12 |
|
|
// rights to the materials distributed herewith. Except as
|
13 |
|
|
// otherwise provided in a valid license issued to you by
|
14 |
|
|
// Xilinx, and to the maximum extent permitted by applicable
|
15 |
|
|
// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
|
16 |
|
|
// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
|
17 |
|
|
// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
|
18 |
|
|
// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
|
19 |
|
|
// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
|
20 |
|
|
// (2) Xilinx shall not be liable (whether in contract or tort,
|
21 |
|
|
// including negligence, or under any other theory of
|
22 |
|
|
// liability) for any loss or damage of any kind or nature
|
23 |
|
|
// related to, arising under or in connection with these
|
24 |
|
|
// materials, including for any direct, or any indirect,
|
25 |
|
|
// special, incidental, or consequential loss or damage
|
26 |
|
|
// (including loss of data, profits, goodwill, or any type of
|
27 |
|
|
// loss or damage suffered as a result of any action brought
|
28 |
|
|
// by a third party) even if such damage or loss was
|
29 |
|
|
// reasonably foreseeable or Xilinx had been advised of the
|
30 |
|
|
// possibility of the same.
|
31 |
|
|
//
|
32 |
|
|
// CRITICAL APPLICATIONS
|
33 |
|
|
// Xilinx products are not designed or intended to be fail-
|
34 |
|
|
// safe, or for use in any application requiring fail-safe
|
35 |
|
|
// performance, such as life-support or safety devices or
|
36 |
|
|
// systems, Class III medical devices, nuclear facilities,
|
37 |
|
|
// applications related to the deployment of airbags, or any
|
38 |
|
|
// other applications that could lead to death, personal
|
39 |
|
|
// injury, or severe property or environmental damage
|
40 |
|
|
// (individually and collectively, "Critical
|
41 |
|
|
// Applications"). Customer assumes the sole risk and
|
42 |
|
|
// liability of any use of Xilinx products in Critical
|
43 |
|
|
// Applications, subject only to applicable laws and
|
44 |
|
|
// regulations governing limitations on product liability.
|
45 |
|
|
//
|
46 |
|
|
// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
|
47 |
|
|
// PART OF THIS FILE AT ALL TIMES.
|
48 |
|
|
//
|
49 |
|
|
|
50 |
|
|
//----------------------------------------------------------------------------
|
51 |
|
|
// Clocking wizard example design
|
52 |
|
|
//----------------------------------------------------------------------------
|
53 |
|
|
// This example design instantiates the created clocking network, where each
|
54 |
|
|
// output clock drives a counter. The high bit of each counter is ported.
|
55 |
|
|
//----------------------------------------------------------------------------
|
56 |
|
|
|
57 |
|
|
`timescale 1ps/1ps
|
58 |
|
|
|
59 |
|
|
module clock_exdes
|
60 |
|
|
#(
|
61 |
|
|
parameter TCQ = 100
|
62 |
|
|
)
|
63 |
|
|
(// Clock in ports
|
64 |
|
|
input CLK_IN1,
|
65 |
|
|
// Reset that only drives logic in example design
|
66 |
|
|
input COUNTER_RESET,
|
67 |
|
|
output [2:1] CLK_OUT,
|
68 |
|
|
// High bits of counters driven by clocks
|
69 |
|
|
output [2:1] COUNT,
|
70 |
|
|
// Status and control signals
|
71 |
|
|
output LOCKED
|
72 |
|
|
);
|
73 |
|
|
|
74 |
|
|
// Parameters for the counters
|
75 |
|
|
//-------------------------------
|
76 |
|
|
// Counter width
|
77 |
|
|
localparam C_W = 16;
|
78 |
|
|
localparam NUM_C = 2;
|
79 |
|
|
genvar count_gen;
|
80 |
|
|
// When the clock goes out of lock, reset the counters
|
81 |
|
|
wire reset_int = !LOCKED || COUNTER_RESET;
|
82 |
|
|
|
83 |
|
|
reg [NUM_C:1] rst_sync;
|
84 |
|
|
reg [NUM_C:1] rst_sync_int;
|
85 |
|
|
reg [NUM_C:1] rst_sync_int1;
|
86 |
|
|
reg [NUM_C:1] rst_sync_int2;
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
// Declare the clocks and counters
|
90 |
|
|
wire [NUM_C:1] clk_int;
|
91 |
|
|
wire [NUM_C:1] clk_n;
|
92 |
|
|
wire [NUM_C:1] clk;
|
93 |
|
|
reg [C_W-1:0] counter [NUM_C:1];
|
94 |
|
|
|
95 |
|
|
// Instantiation of the clocking network
|
96 |
|
|
//--------------------------------------
|
97 |
|
|
clock clknetwork
|
98 |
|
|
(// Clock in ports
|
99 |
|
|
.CLK_IN1 (CLK_IN1),
|
100 |
|
|
// Clock out ports
|
101 |
|
|
.CLK_OUT1 (clk_int[1]),
|
102 |
|
|
.CLK_OUT2 (clk_int[2]),
|
103 |
|
|
// Status and control signals
|
104 |
|
|
.LOCKED (LOCKED));
|
105 |
|
|
|
106 |
|
|
genvar clk_out_pins;
|
107 |
|
|
|
108 |
|
|
generate
|
109 |
|
|
for (clk_out_pins = 1; clk_out_pins <= NUM_C; clk_out_pins = clk_out_pins + 1)
|
110 |
|
|
begin: gen_outclk_oddr
|
111 |
|
|
assign clk_n[clk_out_pins] = ~clk[clk_out_pins];
|
112 |
|
|
|
113 |
|
|
ODDR2 clkout_oddr
|
114 |
|
|
(.Q (CLK_OUT[clk_out_pins]),
|
115 |
|
|
.C0 (clk[clk_out_pins]),
|
116 |
|
|
.C1 (clk_n[clk_out_pins]),
|
117 |
|
|
.CE (1'b1),
|
118 |
|
|
.D0 (1'b1),
|
119 |
|
|
.D1 (1'b0),
|
120 |
|
|
.R (1'b0),
|
121 |
|
|
.S (1'b0));
|
122 |
|
|
end
|
123 |
|
|
endgenerate
|
124 |
|
|
|
125 |
|
|
// Connect the output clocks to the design
|
126 |
|
|
//-----------------------------------------
|
127 |
|
|
assign clk[1] = clk_int[1];
|
128 |
|
|
assign clk[2] = clk_int[2];
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
// Reset synchronizer
|
132 |
|
|
//-----------------------------------
|
133 |
|
|
generate for (count_gen = 1; count_gen <= NUM_C; count_gen = count_gen + 1) begin: counters_1
|
134 |
|
|
always @(posedge reset_int or posedge clk[count_gen]) begin
|
135 |
|
|
if (reset_int) begin
|
136 |
|
|
rst_sync[count_gen] <= 1'b1;
|
137 |
|
|
rst_sync_int[count_gen]<= 1'b1;
|
138 |
|
|
rst_sync_int1[count_gen]<= 1'b1;
|
139 |
|
|
rst_sync_int2[count_gen]<= 1'b1;
|
140 |
|
|
end
|
141 |
|
|
else begin
|
142 |
|
|
rst_sync[count_gen] <= 1'b0;
|
143 |
|
|
rst_sync_int[count_gen] <= rst_sync[count_gen];
|
144 |
|
|
rst_sync_int1[count_gen] <= rst_sync_int[count_gen];
|
145 |
|
|
rst_sync_int2[count_gen] <= rst_sync_int1[count_gen];
|
146 |
|
|
end
|
147 |
|
|
end
|
148 |
|
|
end
|
149 |
|
|
endgenerate
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
// Output clock sampling
|
153 |
|
|
//-----------------------------------
|
154 |
|
|
generate for (count_gen = 1; count_gen <= NUM_C; count_gen = count_gen + 1) begin: counters
|
155 |
|
|
|
156 |
|
|
always @(posedge clk[count_gen] or posedge rst_sync_int2[count_gen]) begin
|
157 |
|
|
if (rst_sync_int2[count_gen]) begin
|
158 |
|
|
counter[count_gen] <= #TCQ { C_W { 1'b 0 } };
|
159 |
|
|
end else begin
|
160 |
|
|
counter[count_gen] <= #TCQ counter[count_gen] + 1'b 1;
|
161 |
|
|
end
|
162 |
|
|
end
|
163 |
|
|
// alias the high bit of each counter to the corresponding
|
164 |
|
|
// bit in the output bus
|
165 |
|
|
assign COUNT[count_gen] = counter[count_gen][C_W-1];
|
166 |
|
|
end
|
167 |
|
|
endgenerate
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
endmodule
|