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

Subversion Repositories amber

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

Go to most recent revision | 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 63 csantifort
`include "system_config_defines.v"
42 2 csantifort
 
43
 
44
//
45
// Clocks and Resets Module
46
//
47
 
48
module clocks_resets  (
49
input                       i_brd_rst,
50
input                       i_brd_clk_n,
51
input                       i_brd_clk_p,
52
input                       i_ddr_calib_done,
53
output                      o_sys_rst,
54
output                      o_sys_clk,
55
output                      o_clk_200
56
 
57
);
58
 
59
 
60
wire                        calib_done_33mhz;
61
wire                        rst0;
62
 
63
assign o_sys_rst = rst0 || !calib_done_33mhz;
64
 
65
 
66
 
67
`ifdef XILINX_FPGA
68
 
69
    localparam                  RST_SYNC_NUM = 25;
70
    wire                        pll_locked;
71
    wire                        clkfbout_clkfbin;
72
    reg [RST_SYNC_NUM-1:0]      rst0_sync_r    /* synthesis syn_maxfan = 10 */;
73
    reg [RST_SYNC_NUM-1:0]      ddr_calib_done_sync_r    /* synthesis syn_maxfan = 10 */;
74
    wire                        rst_tmp;
75
    wire                        pll_clk;
76
 
77
    (* KEEP = "TRUE" *)  wire brd_clk_ibufg;
78
 
79
 
80
    IBUFGDS # (
81
         .DIFF_TERM  ( "TRUE"     ),
82
         .IOSTANDARD ( "LVDS_25"  ))  // SP605 on chip termination of LVDS clock
83
         u_ibufgds_brd
84
        (
85
         .I  ( i_brd_clk_p    ),
86
         .IB ( i_brd_clk_n    ),
87
         .O  ( brd_clk_ibufg  )
88
         );
89
 
90
 
91
    assign rst0             = rst0_sync_r[RST_SYNC_NUM-1];
92
    assign calib_done_33mhz = ddr_calib_done_sync_r[RST_SYNC_NUM-1];
93
    assign o_clk_200        = brd_clk_ibufg;
94
 
95
 
96
    `ifdef XILINX_SPARTAN6_FPGA
97
    // ======================================
98
    // Xilinx Spartan-6 PLL
99
    // ======================================
100
        PLL_ADV #
101
            (
102
             .BANDWIDTH          ( "OPTIMIZED"        ),
103
             .CLKIN1_PERIOD      ( 5                  ),
104
             .CLKIN2_PERIOD      ( 1                  ),
105
             .CLKOUT0_DIVIDE     ( 1                  ),
106
             .CLKOUT1_DIVIDE     (                    ),
107
             .CLKOUT2_DIVIDE     ( `AMBER_CLK_DIVIDER ),   // = 800 MHz / LP_CLK_DIVIDER
108
             .CLKOUT3_DIVIDE     ( 1                  ),
109
             .CLKOUT4_DIVIDE     ( 1                  ),
110
             .CLKOUT5_DIVIDE     ( 1                  ),
111
             .CLKOUT0_PHASE      ( 0.000              ),
112
             .CLKOUT1_PHASE      ( 0.000              ),
113
             .CLKOUT2_PHASE      ( 0.000              ),
114
             .CLKOUT3_PHASE      ( 0.000              ),
115
             .CLKOUT4_PHASE      ( 0.000              ),
116
             .CLKOUT5_PHASE      ( 0.000              ),
117
             .CLKOUT0_DUTY_CYCLE ( 0.500              ),
118
             .CLKOUT1_DUTY_CYCLE ( 0.500              ),
119
             .CLKOUT2_DUTY_CYCLE ( 0.500              ),
120
             .CLKOUT3_DUTY_CYCLE ( 0.500              ),
121
             .CLKOUT4_DUTY_CYCLE ( 0.500              ),
122
             .CLKOUT5_DUTY_CYCLE ( 0.500              ),
123
             .COMPENSATION       ( "INTERNAL"         ),
124
             .DIVCLK_DIVIDE      ( 1                  ),
125
             .CLKFBOUT_MULT      ( 4                  ),   // 200 MHz clock input, x4 to get 800 MHz MCB
126
             .CLKFBOUT_PHASE     ( 0.0                ),
127
             .REF_JITTER         ( 0.005000           )
128
             )
129
            u_pll_adv
130
              (
131
               .CLKFBIN     ( clkfbout_clkfbin  ),
132
               .CLKINSEL    ( 1'b1              ),
133
               .CLKIN1      ( brd_clk_ibufg     ),
134
               .CLKIN2      ( 1'b0              ),
135
               .DADDR       ( 5'b0              ),
136
               .DCLK        ( 1'b0              ),
137
               .DEN         ( 1'b0              ),
138
               .DI          ( 16'b0             ),
139
               .DWE         ( 1'b0              ),
140
               .REL         ( 1'b0              ),
141
               .RST         ( i_brd_rst          ),
142
               .CLKFBDCM    (                   ),
143
               .CLKFBOUT    ( clkfbout_clkfbin  ),
144
               .CLKOUTDCM0  (                   ),
145
               .CLKOUTDCM1  (                   ),
146
               .CLKOUTDCM2  (                   ),
147
               .CLKOUTDCM3  (                   ),
148
               .CLKOUTDCM4  (                   ),
149
               .CLKOUTDCM5  (                   ),
150
               .CLKOUT0     (                   ),
151
               .CLKOUT1     (                   ),
152
               .CLKOUT2     ( pll_clk           ),
153
               .CLKOUT3     (                   ),
154
               .CLKOUT4     (                   ),
155
               .CLKOUT5     (                   ),
156
               .DO          (                   ),
157
               .DRDY        (                   ),
158
               .LOCKED      ( pll_locked        )
159
               );
160
    `endif
161
 
162
 
163
    `ifdef XILINX_VIRTEX6_FPGA
164
    // ======================================
165
    // Xilinx Virtex-6 PLL
166
    // ======================================
167
        MMCM_ADV #
168
        (
169
         .CLKIN1_PERIOD      ( 5                    ),   // 200 MHz
170
         .CLKOUT2_DIVIDE     ( `AMBER_CLK_DIVIDER   ),
171 43 csantifort
         .CLKFBOUT_MULT_F    ( 6                    )    // 200 MHz x 6 = 1200 MHz
172 2 csantifort
         )
173
        u_pll_adv
174
          (
175
           .CLKFBOUT     ( clkfbout_clkfbin ),
176
           .CLKFBOUTB    (                  ),
177
           .CLKFBSTOPPED (                  ),
178
           .CLKINSTOPPED (                  ),
179
           .CLKOUT0      (                  ),
180
           .CLKOUT0B     (                  ),
181
           .CLKOUT1      (                  ),
182
           .CLKOUT1B     (                  ),
183
           .CLKOUT2      ( pll_clk          ),
184
           .CLKOUT2B     (                  ),
185
           .CLKOUT3      (                  ),
186
           .CLKOUT3B     (                  ),
187
           .CLKOUT4      (                  ),
188
           .CLKOUT5      (                  ),
189
           .CLKOUT6      (                  ),
190
           .DRDY         (                  ),
191
           .LOCKED       ( pll_locked       ),
192
           .PSDONE       (                  ),
193
           .DO           (                  ),
194
           .CLKFBIN      ( clkfbout_clkfbin ),
195
           .CLKIN1       ( brd_clk_ibufg    ),
196
           .CLKIN2       ( 1'b0             ),
197
           .CLKINSEL     ( 1'b1             ),
198
           .DCLK         ( 1'b0             ),
199
           .DEN          ( 1'b0             ),
200
           .DWE          ( 1'b0             ),
201
           .PSCLK        ( 1'd0             ),
202
           .PSEN         ( 1'd0             ),
203
           .PSINCDEC     ( 1'd0             ),
204
           .PWRDWN       ( 1'd0             ),
205
           .RST          ( i_brd_rst         ),
206
           .DI           ( 16'b0            ),
207
           .DADDR        ( 7'b0             )
208
           );
209
    `endif
210
 
211
 
212
    BUFG u_bufg_sys_clk (
213
         .O ( o_sys_clk  ),
214
         .I ( pll_clk    )
215
         );
216
 
217
 
218
    // ======================================
219
    // Synchronous reset generation
220
    // ======================================
221
    assign rst_tmp = i_brd_rst | ~pll_locked;
222
 
223
      // synthesis attribute max_fanout of rst0_sync_r is 10
224
    always @(posedge o_sys_clk or posedge rst_tmp)
225
        if (rst_tmp)
226
          rst0_sync_r <= {RST_SYNC_NUM{1'b1}};
227
        else
228
          // logical left shift by one (pads with 0)
229
          rst0_sync_r <= rst0_sync_r << 1;
230
 
231
    always @(posedge o_sys_clk or posedge rst_tmp)
232
        if (rst_tmp)
233
            ddr_calib_done_sync_r <= {RST_SYNC_NUM{1'b0}};
234
        else
235
            ddr_calib_done_sync_r <= {ddr_calib_done_sync_r[RST_SYNC_NUM-2:0], i_ddr_calib_done};
236
 
237
    `endif
238
 
239
 
240
 
241
`ifndef XILINX_FPGA
242
 
243 14 csantifort
real      brd_clk_period = 6000;  // use starting value of 6000pS
244
real      pll_clk_period = 1000;  // use starting value of 1000pS
245
real      brd_temp;
246
reg       pll_clk_beh;
247
reg       sys_clk_beh;
248
integer   pll_div_count = 0;
249 2 csantifort
 
250 14 csantifort
// measure input clock period
251 2 csantifort
initial
252
    begin
253 14 csantifort
    @ (posedge i_brd_clk_p)
254
    brd_temp = $time;
255
    @ (posedge i_brd_clk_p)
256
    brd_clk_period = $time - brd_temp;
257
    pll_clk_period = brd_clk_period / 4;
258 2 csantifort
    end
259
 
260 14 csantifort
// Generate an 800MHz pll clock based off the input clock
261
always @( posedge i_brd_clk_p )
262
    begin
263
    pll_clk_beh = 1'd1;
264
    # ( pll_clk_period / 2 )
265
    pll_clk_beh = 1'd0;
266
    # ( pll_clk_period / 2 )
267
 
268
    pll_clk_beh = 1'd1;
269
    # ( pll_clk_period / 2 )
270
    pll_clk_beh = 1'd0;
271
    # ( pll_clk_period / 2 )
272
 
273
    pll_clk_beh = 1'd1;
274
    # ( pll_clk_period / 2 )
275
    pll_clk_beh = 1'd0;
276
    # ( pll_clk_period / 2 )
277
 
278
    pll_clk_beh = 1'd1;
279
    # ( pll_clk_period / 2 )
280
    pll_clk_beh = 1'd0;
281
 
282
    end
283
 
284
// Divide the pll clock down to get the system clock
285
always @( pll_clk_beh )
286
    begin
287
    if ( pll_div_count == (
288
        `AMBER_CLK_DIVIDER
289
        * 2 ) - 1 )
290
        pll_div_count <= 'd0;
291
    else
292
        pll_div_count <= pll_div_count + 1'd1;
293
 
294
    if ( pll_div_count == 0 )
295
        sys_clk_beh = 1'd1;
296
    else if ( pll_div_count ==
297
        `AMBER_CLK_DIVIDER
298
        )
299
        sys_clk_beh = 1'd0;
300
    end
301
 
302
assign o_sys_clk        = sys_clk_beh;
303 2 csantifort
assign rst0             = i_brd_rst;
304
assign calib_done_33mhz = 1'd1;
305
assign o_clk_200        = i_brd_clk_p;
306
 
307
`endif
308
 
309
 
310
endmodule
311
 
312
 

powered by: WebSVN 2.1.0

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