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

Subversion Repositories m1_core

[/] [m1_core/] [trunk/] [hdl/] [rtl/] [wb_ddr_ctrl/] [ddr_clkgen.v] - Blame information for rev 34

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 34 fafa1971
//---------------------------------------------------------------------------
2
// Wishbone DDR Controller
3
// 
4
// (c) Joerg Bornschein (<jb@capsec.org>)
5
//---------------------------------------------------------------------------
6
 
7
`timescale 1ns / 1ps
8
`include "ddr_include.v"
9
 
10
module ddr_clkgen
11
#(
12
        parameter phase_shift  = 0,
13
        parameter clk_multiply = 13,
14
        parameter clk_divide   = 5
15
) (
16
        input        clk,
17
        input        reset,
18
        output       locked,
19
        //
20
        output       write_clk,
21
        output       write_clk90,
22
        // 
23
        input        ddr_clk_fb,
24
        output       read_clk,
25
        input  [2:0] rot
26
);
27
 
28
 
29
//----------------------------------------------------------------------------
30
// rotary decoder
31
//----------------------------------------------------------------------------
32
rotary rotdec0 (
33
        .clk(       clk        ),
34
        .reset(     reset      ),
35
        .rot(       rot        ),
36
        // output
37
        .rot_btn(   rot_btn    ),
38
        .rot_event( rot_event  ),
39
        .rot_left(  rot_left   )
40
);
41
 
42
reg [1:0] mux_sel;
43
 
44
always @(posedge clk)
45
begin
46
        if (reset)
47
                mux_sel <= 0;
48
        else
49
                if (rot_btn)
50
                        mux_sel <= mux_sel + 1;
51
end
52
 
53
//----------------------------------------------------------------------------
54
// ~133 MHz DDR Clock generator
55
//----------------------------------------------------------------------------
56
wire  read_clk_u, read_clk180_u;
57
wire  dcm_fx_locked;
58
 
59
DCM_SP #(
60
        .CLKDV_DIVIDE(2.0),          // Divide by: 1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0,5.5,6.0,6.5
61
                                 //   7.0,7.5,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0 or 16.0
62
        .CLKFX_DIVIDE(clk_divide),   // Can be any integer from 1 to 32
63
        .CLKFX_MULTIPLY(clk_multiply), // Can be any integer from 2 to 32
64
        .CLKIN_DIVIDE_BY_2("FALSE"), // TRUE/FALSE to enable CLKIN divide by two feature
65
        .CLKIN_PERIOD(),             // Specify period of input clock
66
        .CLKOUT_PHASE_SHIFT("NONE"), // Specify phase shift of NONE, FIXED or VARIABLE
67
        .CLK_FEEDBACK("NONE"),       // Specify clock feedback of NONE, 1X or 2X
68
        .DESKEW_ADJUST("SOURCE_SYNCHRONOUS"), // SOURCE_SYNCHRONOUS, SYSTEM_SYNCHRONOUS or
69
                                 //   an integer from 0 to 15
70
        .DFS_FREQUENCY_MODE("LOW"),  // HIGH or LOW frequency mode for frequency synthesis
71
        .DLL_FREQUENCY_MODE("LOW"),  // HIGH or LOW frequency mode for DLL
72
        .DUTY_CYCLE_CORRECTION("TRUE"), // Duty cycle correction, TRUE or FALSE
73
        .FACTORY_JF(16'hC080),       // FACTORY JF values
74
        .PHASE_SHIFT(0),             // Amount of fixed phase shift from -255 to 255
75
        .STARTUP_WAIT("FALSE")       // Delay configuration DONE until DCM LOCK, TRUE/FALSE
76
) dcm_fx (
77
        .DSSEN(),
78
        .CLK0(),                   // 0 degree DCM CLK output
79
        .CLK180(),                 // 180 degree DCM CLK output
80
        .CLK270(),                 // 270 degree DCM CLK output
81
        .CLK2X(),                  // 2X DCM CLK output
82
        .CLK2X180(),               // 2X, 180 degree DCM CLK out
83
        .CLK90(),                  // 90 degree DCM CLK output
84
        .CLKDV(),                  // Divided DCM CLK out (CLKDV_DIVIDE)
85
        .CLKFX(    read_clk_u ),   // DCM CLK synthesis out (M/D)
86
        .CLKFX180( read_clk180_u), // 180 degree CLK synthesis out
87
        .LOCKED(   dcm_fx_locked), // DCM LOCK status output
88
        .PSDONE(),                 // Dynamic phase adjust done output
89
        .STATUS(),                 // 8-bit DCM status bits output
90
        .CLKFB(),                  // DCM clock feedback
91
        .CLKIN( clk ),             // Clock input (from IBUFG, BUFG or DCM)
92
        .PSCLK( gnd ),             // Dynamic phase adjust clock input
93
        .PSEN( gnd ),              // Dynamic phase adjust enable input
94
        .PSINCDEC( gnd  ),         // Dynamic phase adjust increment/decrement
95
        .RST(reset)                // DCM asynchronous reset input
96
);
97
 
98
//----------------------------------------------------------------------------
99
// BUFG read clock
100
//----------------------------------------------------------------------------
101
BUFG bufg_fx_clk (
102
        .O(read_clk),             // Clock buffer output
103
        .I(read_clk_u)            // Clock buffer input
104
);
105
 
106
//----------------------------------------------------------------------------
107
// ~133 MHz DDR Clock generator
108
//----------------------------------------------------------------------------
109
wire  phase_dcm_reset;
110
wire  phase_dcm_locked;
111
wire  write_clk_u, write_clk90_u, write_clk180_u, write_clk270_u;
112
wire  write_clk_fb;
113
 
114
DCM_SP #(
115
        .CLKDV_DIVIDE(2.0), // Divide by: 1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0,5.5,6.0,6.5
116
                            //   7.0,7.5,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0 or 16.0
117
        .CLKFX_DIVIDE(2),       // Can be any integer from 1 to 32
118
        .CLKFX_MULTIPLY(2),    // Can be any integer from 2 to 32
119
        .CLKIN_DIVIDE_BY_2("FALSE"), // TRUE/FALSE to enable CLKIN divide by two feature
120
        .CLKIN_PERIOD(),       // Specify period of input clock
121
        .CLK_FEEDBACK("1X"),  // Specify clock feedback of NONE, 1X or 2X
122
        .DESKEW_ADJUST("SYSTEM_SYNCHRONOUS"), // SOURCE_SYNCHRONOUS, SYSTEM_SYNCHRONOUS or
123
                                            //   an integer from 0 to 15
124
        .DFS_FREQUENCY_MODE("LOW"),  // HIGH or LOW frequency mode for frequency synthesis
125
        .DLL_FREQUENCY_MODE("LOW"),  // HIGH or LOW frequency mode for DLL
126
        .DUTY_CYCLE_CORRECTION("TRUE"), // Duty cycle correction, TRUE or FALSE
127
        .FACTORY_JF(16'hC080),   // FACTORY JF values
128
        .CLKOUT_PHASE_SHIFT("VARIABLE"), // Specify phase shift of NONE, FIXED or VARIABLE
129
        .PHASE_SHIFT( phase_shift ), // Amount of fixed phase shift from -255 to 255
130
        .STARTUP_WAIT("FALSE")   // Delay configuration DONE until DCM LOCK, TRUE/FALSE
131
) dcm_phase (
132
        .DSSEN(),
133
        .CLK0(   write_clk_u ),      // 0 degree DCM CLK output
134
        .CLK90(  write_clk90_u ),    // 90 degree DCM CLK output
135
        .CLK180( write_clk180_u ),   // 180 degree DCM CLK output
136
        .CLK270( write_clk270_u ),   // 270 degree DCM CLK output
137
        .CLK2X(),                    // 2X DCM CLK output
138
        .CLK2X180(),                 // 2X, 180 degree DCM CLK out
139
        .CLKDV(),                    // Divided DCM CLK out (CLKDV_DIVIDE)
140
        .CLKFX(),                    // DCM CLK synthesis out (M/D)
141
        .CLKFX180(),                 // 180 degree CLK synthesis out
142
        .LOCKED( phase_dcm_locked ), // DCM LOCK status output
143
        .PSDONE(),                   // Dynamic phase adjust done output
144
        .STATUS(),                   // 8-bit DCM status bits output
145
        .CLKFB( write_clk_fb ),      // DCM clock feedback
146
        .CLKIN( read_clk ),          // Clock input (from IBUFG, BUFG or DCM)
147
        .PSCLK( clk ),               // Dynamic phase adjust clock input
148
        .PSEN( rot_event ),          // Dynamic phase adjust enable input
149
        .PSINCDEC( rot_left ),       // Dynamic phase adjust increment/decrement
150
        .RST( phase_dcm_reset )      // DCM asynchronous reset input
151
);
152
 
153
 
154
assign write_clk_fb = (mux_sel == 'b00) ? write_clk_u :
155
                      (mux_sel == 'b01) ? write_clk90_u :
156
                      (mux_sel == 'b10) ? write_clk180_u :
157
                                          write_clk270_u;
158
 
159
reg [3:0] reset_counter;
160
assign phase_dcm_reset = reset | (reset_counter != 0);
161
 
162
always @(posedge clk)
163
begin
164
        if (reset)
165
                reset_counter <= 1;
166
        else begin
167
                if (dcm_fx_locked & (reset_counter != 0))
168
                        reset_counter <= reset_counter + 1;
169
        end
170
end
171
 
172
 
173
//----------------------------------------------------------------------------
174
// BUFG write clock
175
//----------------------------------------------------------------------------
176
 
177
BUFG bufg_write_clk (
178
        .O(write_clk  ),          // Clock buffer output
179
        .I(write_clk_u)           // Clock buffer input
180
);
181
 
182
BUFG bufg_write_clk90 (
183
        .O(write_clk90  ),        // Clock buffer output
184
        .I(write_clk90_u)         // Clock buffer input
185
);
186
 
187
//----------------------------------------------------------------------------
188
// LOCKED logic
189
//----------------------------------------------------------------------------
190
reg phase_dcm_locked_delayed;
191
 
192
always @(posedge write_clk)
193
begin
194
        phase_dcm_locked_delayed <= phase_dcm_locked;
195
end
196
 
197
assign locked = ~reset & phase_dcm_locked_delayed;
198
 
199
 
200
endmodule

powered by: WebSVN 2.1.0

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