OpenCores
URL https://opencores.org/ocsvn/amber/amber/trunk

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [system/] [clocks_resets.v] - Blame information for rev 82

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Clock and Resets                                            //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Takes in the 200MHx board clock and generates the main      //
10
//  system clock. For the FPGA this is done with a PLL.         //
11
//                                                              //
12
//  Author(s):                                                  //
13
//      - Conor Santifort, csantifort.amber@gmail.com           //
14
//                                                              //
15
//////////////////////////////////////////////////////////////////
16
//                                                              //
17
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
18
//                                                              //
19
// This source file may be used and distributed without         //
20
// restriction provided that this copyright statement is not    //
21
// removed from the file and that any derivative work contains  //
22
// the original copyright notice and the associated disclaimer. //
23
//                                                              //
24
// This source file is free software; you can redistribute it   //
25
// and/or modify it under the terms of the GNU Lesser General   //
26
// Public License as published by the Free Software Foundation; //
27
// either version 2.1 of the License, or (at your option) any   //
28
// later version.                                               //
29
//                                                              //
30
// This source is distributed in the hope that it will be       //
31
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
32
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
33
// PURPOSE.  See the GNU Lesser General Public License for more //
34
// details.                                                     //
35
//                                                              //
36
// You should have received a copy of the GNU Lesser General    //
37
// Public License along with this source; if not, download it   //
38
// from http://www.opencores.org/lgpl.shtml                     //
39
//                                                              //
40
//////////////////////////////////////////////////////////////////
41 82 csantifort
`include "system_config_defines.vh"
42
`include "global_timescale.vh"
43 2 csantifort
 
44
 
45
//
46
// Clocks and Resets Module
47
//
48
 
49
module clocks_resets  (
50
input                       i_brd_rst,
51
input                       i_brd_clk_n,
52
input                       i_brd_clk_p,
53
input                       i_ddr_calib_done,
54
output                      o_sys_rst,
55
output                      o_sys_clk,
56
output                      o_clk_200
57
 
58
);
59
 
60
 
61
wire                        calib_done_33mhz;
62
wire                        rst0;
63
 
64
assign o_sys_rst = rst0 || !calib_done_33mhz;
65
 
66
 
67
 
68
`ifdef XILINX_FPGA
69
 
70
    localparam                  RST_SYNC_NUM = 25;
71
    wire                        pll_locked;
72
    wire                        clkfbout_clkfbin;
73
    reg [RST_SYNC_NUM-1:0]      rst0_sync_r    /* synthesis syn_maxfan = 10 */;
74
    reg [RST_SYNC_NUM-1:0]      ddr_calib_done_sync_r    /* synthesis syn_maxfan = 10 */;
75
    wire                        rst_tmp;
76
    wire                        pll_clk;
77
 
78
    (* KEEP = "TRUE" *)  wire brd_clk_ibufg;
79
 
80
 
81
    IBUFGDS # (
82
         .DIFF_TERM  ( "TRUE"     ),
83
         .IOSTANDARD ( "LVDS_25"  ))  // SP605 on chip termination of LVDS clock
84
         u_ibufgds_brd
85
        (
86
         .I  ( i_brd_clk_p    ),
87
         .IB ( i_brd_clk_n    ),
88
         .O  ( brd_clk_ibufg  )
89
         );
90
 
91
 
92
    assign rst0             = rst0_sync_r[RST_SYNC_NUM-1];
93
    assign calib_done_33mhz = ddr_calib_done_sync_r[RST_SYNC_NUM-1];
94
    assign o_clk_200        = brd_clk_ibufg;
95
 
96
 
97
    `ifdef XILINX_SPARTAN6_FPGA
98
    // ======================================
99
    // Xilinx Spartan-6 PLL
100
    // ======================================
101
        PLL_ADV #
102
            (
103
             .BANDWIDTH          ( "OPTIMIZED"        ),
104
             .CLKIN1_PERIOD      ( 5                  ),
105
             .CLKIN2_PERIOD      ( 1                  ),
106
             .CLKOUT0_DIVIDE     ( 1                  ),
107
             .CLKOUT1_DIVIDE     (                    ),
108
             .CLKOUT2_DIVIDE     ( `AMBER_CLK_DIVIDER ),   // = 800 MHz / LP_CLK_DIVIDER
109
             .CLKOUT3_DIVIDE     ( 1                  ),
110
             .CLKOUT4_DIVIDE     ( 1                  ),
111
             .CLKOUT5_DIVIDE     ( 1                  ),
112
             .CLKOUT0_PHASE      ( 0.000              ),
113
             .CLKOUT1_PHASE      ( 0.000              ),
114
             .CLKOUT2_PHASE      ( 0.000              ),
115
             .CLKOUT3_PHASE      ( 0.000              ),
116
             .CLKOUT4_PHASE      ( 0.000              ),
117
             .CLKOUT5_PHASE      ( 0.000              ),
118
             .CLKOUT0_DUTY_CYCLE ( 0.500              ),
119
             .CLKOUT1_DUTY_CYCLE ( 0.500              ),
120
             .CLKOUT2_DUTY_CYCLE ( 0.500              ),
121
             .CLKOUT3_DUTY_CYCLE ( 0.500              ),
122
             .CLKOUT4_DUTY_CYCLE ( 0.500              ),
123
             .CLKOUT5_DUTY_CYCLE ( 0.500              ),
124
             .COMPENSATION       ( "INTERNAL"         ),
125
             .DIVCLK_DIVIDE      ( 1                  ),
126
             .CLKFBOUT_MULT      ( 4                  ),   // 200 MHz clock input, x4 to get 800 MHz MCB
127
             .CLKFBOUT_PHASE     ( 0.0                ),
128
             .REF_JITTER         ( 0.005000           )
129
             )
130
            u_pll_adv
131
              (
132
               .CLKFBIN     ( clkfbout_clkfbin  ),
133
               .CLKINSEL    ( 1'b1              ),
134
               .CLKIN1      ( brd_clk_ibufg     ),
135
               .CLKIN2      ( 1'b0              ),
136
               .DADDR       ( 5'b0              ),
137
               .DCLK        ( 1'b0              ),
138
               .DEN         ( 1'b0              ),
139
               .DI          ( 16'b0             ),
140
               .DWE         ( 1'b0              ),
141
               .REL         ( 1'b0              ),
142
               .RST         ( i_brd_rst          ),
143
               .CLKFBDCM    (                   ),
144
               .CLKFBOUT    ( clkfbout_clkfbin  ),
145
               .CLKOUTDCM0  (                   ),
146
               .CLKOUTDCM1  (                   ),
147
               .CLKOUTDCM2  (                   ),
148
               .CLKOUTDCM3  (                   ),
149
               .CLKOUTDCM4  (                   ),
150
               .CLKOUTDCM5  (                   ),
151
               .CLKOUT0     (                   ),
152
               .CLKOUT1     (                   ),
153
               .CLKOUT2     ( pll_clk           ),
154
               .CLKOUT3     (                   ),
155
               .CLKOUT4     (                   ),
156
               .CLKOUT5     (                   ),
157
               .DO          (                   ),
158
               .DRDY        (                   ),
159
               .LOCKED      ( pll_locked        )
160
               );
161
    `endif
162
 
163
 
164
    `ifdef XILINX_VIRTEX6_FPGA
165
    // ======================================
166
    // Xilinx Virtex-6 PLL
167
    // ======================================
168
        MMCM_ADV #
169
        (
170
         .CLKIN1_PERIOD      ( 5                    ),   // 200 MHz
171
         .CLKOUT2_DIVIDE     ( `AMBER_CLK_DIVIDER   ),
172 43 csantifort
         .CLKFBOUT_MULT_F    ( 6                    )    // 200 MHz x 6 = 1200 MHz
173 2 csantifort
         )
174
        u_pll_adv
175
          (
176
           .CLKFBOUT     ( clkfbout_clkfbin ),
177
           .CLKFBOUTB    (                  ),
178
           .CLKFBSTOPPED (                  ),
179
           .CLKINSTOPPED (                  ),
180
           .CLKOUT0      (                  ),
181
           .CLKOUT0B     (                  ),
182
           .CLKOUT1      (                  ),
183
           .CLKOUT1B     (                  ),
184
           .CLKOUT2      ( pll_clk          ),
185
           .CLKOUT2B     (                  ),
186
           .CLKOUT3      (                  ),
187
           .CLKOUT3B     (                  ),
188
           .CLKOUT4      (                  ),
189
           .CLKOUT5      (                  ),
190
           .CLKOUT6      (                  ),
191
           .DRDY         (                  ),
192
           .LOCKED       ( pll_locked       ),
193
           .PSDONE       (                  ),
194
           .DO           (                  ),
195
           .CLKFBIN      ( clkfbout_clkfbin ),
196
           .CLKIN1       ( brd_clk_ibufg    ),
197
           .CLKIN2       ( 1'b0             ),
198
           .CLKINSEL     ( 1'b1             ),
199
           .DCLK         ( 1'b0             ),
200
           .DEN          ( 1'b0             ),
201
           .DWE          ( 1'b0             ),
202
           .PSCLK        ( 1'd0             ),
203
           .PSEN         ( 1'd0             ),
204
           .PSINCDEC     ( 1'd0             ),
205
           .PWRDWN       ( 1'd0             ),
206
           .RST          ( i_brd_rst         ),
207
           .DI           ( 16'b0            ),
208
           .DADDR        ( 7'b0             )
209
           );
210
    `endif
211
 
212
 
213
    BUFG u_bufg_sys_clk (
214
         .O ( o_sys_clk  ),
215
         .I ( pll_clk    )
216
         );
217
 
218
 
219
    // ======================================
220
    // Synchronous reset generation
221
    // ======================================
222
    assign rst_tmp = i_brd_rst | ~pll_locked;
223
 
224
      // synthesis attribute max_fanout of rst0_sync_r is 10
225
    always @(posedge o_sys_clk or posedge rst_tmp)
226
        if (rst_tmp)
227
          rst0_sync_r <= {RST_SYNC_NUM{1'b1}};
228
        else
229
          // logical left shift by one (pads with 0)
230
          rst0_sync_r <= rst0_sync_r << 1;
231
 
232
    always @(posedge o_sys_clk or posedge rst_tmp)
233
        if (rst_tmp)
234
            ddr_calib_done_sync_r <= {RST_SYNC_NUM{1'b0}};
235
        else
236
            ddr_calib_done_sync_r <= {ddr_calib_done_sync_r[RST_SYNC_NUM-2:0], i_ddr_calib_done};
237
 
238
    `endif
239
 
240
 
241
 
242
`ifndef XILINX_FPGA
243
 
244 14 csantifort
real      brd_clk_period = 6000;  // use starting value of 6000pS
245
real      pll_clk_period = 1000;  // use starting value of 1000pS
246
real      brd_temp;
247
reg       pll_clk_beh;
248
reg       sys_clk_beh;
249
integer   pll_div_count = 0;
250 2 csantifort
 
251 14 csantifort
// measure input clock period
252 2 csantifort
initial
253
    begin
254 14 csantifort
    @ (posedge i_brd_clk_p)
255
    brd_temp = $time;
256
    @ (posedge i_brd_clk_p)
257
    brd_clk_period = $time - brd_temp;
258
    pll_clk_period = brd_clk_period / 4;
259 2 csantifort
    end
260
 
261 14 csantifort
// Generate an 800MHz pll clock based off the input clock
262
always @( posedge i_brd_clk_p )
263
    begin
264
    pll_clk_beh = 1'd1;
265
    # ( pll_clk_period / 2 )
266
    pll_clk_beh = 1'd0;
267
    # ( pll_clk_period / 2 )
268
 
269
    pll_clk_beh = 1'd1;
270
    # ( pll_clk_period / 2 )
271
    pll_clk_beh = 1'd0;
272
    # ( pll_clk_period / 2 )
273
 
274
    pll_clk_beh = 1'd1;
275
    # ( pll_clk_period / 2 )
276
    pll_clk_beh = 1'd0;
277
    # ( pll_clk_period / 2 )
278
 
279
    pll_clk_beh = 1'd1;
280
    # ( pll_clk_period / 2 )
281
    pll_clk_beh = 1'd0;
282
 
283
    end
284
 
285
// Divide the pll clock down to get the system clock
286
always @( pll_clk_beh )
287
    begin
288
    if ( pll_div_count == (
289
        `AMBER_CLK_DIVIDER
290
        * 2 ) - 1 )
291
        pll_div_count <= 'd0;
292
    else
293
        pll_div_count <= pll_div_count + 1'd1;
294
 
295
    if ( pll_div_count == 0 )
296
        sys_clk_beh = 1'd1;
297
    else if ( pll_div_count ==
298
        `AMBER_CLK_DIVIDER
299
        )
300
        sys_clk_beh = 1'd0;
301
    end
302
 
303
assign o_sys_clk        = sys_clk_beh;
304 2 csantifort
assign rst0             = i_brd_rst;
305
assign calib_done_33mhz = 1'd1;
306
assign o_clk_200        = i_brd_clk_p;
307
 
308
`endif
309
 
310
 
311
endmodule
312
 
313
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.