Advertisement
KLATUBARARA1

Xilinx DCM Digital Clock Manager

Dec 29th, 2013
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2. `include "ddr_include.v"
  3. // Link: für das Pinning via UCF ...pastebin -->cr
  4. /* http://pastebin.com/FLrxELzU */
  5. module ddr_clkgen
  6. #(
  7.     parameter phase_shift  = 0,
  8.     parameter clk_multiply = 13,
  9.     parameter clk_divide   = 5
  10. ) (
  11.     input        clk,
  12.     input        reset,
  13.     output       locked,
  14.     //
  15.     output       read_clk,
  16.     output       write_clk,
  17.     output       write_clk90,
  18.     // DCM phase shift control
  19.     output   reg ps_ready,
  20.     input        ps_up,
  21.     input        ps_down
  22. );
  23.  
  24.  
  25. //----------------------------------------------------------------------------
  26. // ~133 MHz DDR Clock generator
  27. //----------------------------------------------------------------------------
  28. wire  read_clk_u;
  29. wire  dcm_fx_locked;
  30.  
  31. DCM #(
  32.     .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
  33.                                  //   7.0,7.5,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0 or 16.0
  34.     .CLKFX_DIVIDE(clk_divide),   // Can be any integer from 1 to 32
  35.     .CLKFX_MULTIPLY(clk_multiply), // Can be any integer from 2 to 32
  36.     .CLKIN_DIVIDE_BY_2("FALSE"), // TRUE/FALSE to enable CLKIN divide by two feature
  37.     .CLKIN_PERIOD(),             // Specify period of input clock
  38.     .CLKOUT_PHASE_SHIFT("NONE"), // Specify phase shift of NONE, FIXED or VARIABLE
  39.     .CLK_FEEDBACK("NONE"),       // Specify clock feedback of NONE, 1X or 2X
  40.     .DESKEW_ADJUST("SOURCE_SYNCHRONOUS"), // SOURCE_SYNCHRONOUS, SYSTEM_SYNCHRONOUS or
  41.                                  //   an integer from 0 to 15
  42.     .DFS_FREQUENCY_MODE("LOW"),  // HIGH or LOW frequency mode for frequency synthesis
  43.     .DLL_FREQUENCY_MODE("LOW"),  // HIGH or LOW frequency mode for DLL
  44.     .DUTY_CYCLE_CORRECTION("TRUE"), // Duty cycle correction, TRUE or FALSE
  45.     .FACTORY_JF(16'hC080),       // FACTORY JF values
  46.     .PHASE_SHIFT(0),             // Amount of fixed phase shift from -255 to 255
  47.     .STARTUP_WAIT("FALSE")       // Delay configuration DONE until DCM LOCK, TRUE/FALSE
  48. ) dcm_fx (
  49.     .DSSEN(),
  50.     .CLK0(),                   // 0 degree DCM CLK output
  51.     .CLK180(),                 // 180 degree DCM CLK output
  52.     .CLK270(),                 // 270 degree DCM CLK output
  53.     .CLK2X(),                  // 2X DCM CLK output
  54.     .CLK2X180(),               // 2X, 180 degree DCM CLK out
  55.     .CLK90(),                  // 90 degree DCM CLK output
  56.     .CLKDV(),                  // Divided DCM CLK out (CLKDV_DIVIDE)
  57.     .CLKFX(    read_clk_u ),   // DCM CLK synthesis out (M/D)
  58.     .CLKFX180(),               // 180 degree CLK synthesis out
  59.     .LOCKED(   dcm_fx_locked), // DCM LOCK status output
  60.     .PSDONE(),                 // Dynamic phase adjust done output
  61.     .STATUS(),                 // 8-bit DCM status bits output
  62.     .CLKFB(),                  // DCM clock feedback
  63.     .CLKIN(    clk   ),        // Clock input (from IBUFG, BUFG or DCM)
  64.     .PSCLK(    gnd   ),        // Dynamic phase adjust clock input
  65.     .PSEN(     gnd   ),        // Dynamic phase adjust enable input
  66.     .PSINCDEC( gnd   ),        // Dynamic phase adjust increment/decrement
  67.     .RST(      reset )         // DCM asynchronous reset input
  68. );
  69.  
  70. //----------------------------------------------------------------------------
  71. // BUFG read clock
  72. //----------------------------------------------------------------------------
  73. BUFG bufg_fx_clk (
  74.     .O(read_clk),             // Clock buffer output
  75.     .I(read_clk_u)            // Clock buffer input
  76. );
  77.  
  78. //----------------------------------------------------------------------------
  79. // Phase shifted clock for write path
  80. //----------------------------------------------------------------------------
  81. wire  phase_dcm_reset;
  82. wire  phase_dcm_locked;
  83. wire  write_clk_u, write_clk90_u, write_clk180_u, write_clk270_u;
  84. reg   psen, psincdec;
  85. wire  psdone;
  86.  
  87. DCM #(
  88.     .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
  89.                             //   7.0,7.5,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0 or 16.0
  90.     .CLKFX_DIVIDE(2),       // Can be any integer from 1 to 32
  91.     .CLKFX_MULTIPLY(2),     // Can be any integer from 2 to 32
  92.     .CLKIN_DIVIDE_BY_2("FALSE"), // TRUE/FALSE to enable CLKIN divide by two feature
  93.     .CLKIN_PERIOD(),        // Specify period of input clock
  94.     .CLK_FEEDBACK("1X"),    // Specify clock feedback of NONE, 1X or 2X
  95.     .DESKEW_ADJUST("SYSTEM_SYNCHRONOUS"), // SOURCE_SYNCHRONOUS, SYSTEM_SYNCHRONOUS or
  96.                                           //   an integer from 0 to 15
  97.     .DFS_FREQUENCY_MODE("LOW"),  // HIGH or LOW frequency mode for frequency synthesis
  98.     .DLL_FREQUENCY_MODE("LOW"),  // HIGH or LOW frequency mode for DLL
  99.     .DUTY_CYCLE_CORRECTION("TRUE"), // Duty cycle correction, TRUE or FALSE
  100.     .FACTORY_JF(16'hC080),   // FACTORY JF values
  101.     .CLKOUT_PHASE_SHIFT("VARIABLE"), // Specify phase shift of NONE, FIXED or VARIABLE
  102.     .PHASE_SHIFT( phase_shift ), // Amount of fixed phase shift from -255 to 255
  103.     .STARTUP_WAIT("FALSE")   // Delay configuration DONE until DCM LOCK, TRUE/FALSE
  104. ) dcm_phase (
  105.     .DSSEN(),
  106.     .CLK0(   write_clk_u ),      // 0 degree DCM CLK output
  107.     .CLK90(  write_clk90_u ),    // 90 degree DCM CLK output
  108.     .CLK180( write_clk180_u ),   // 180 degree DCM CLK output
  109.     .CLK270( write_clk270_u ),   // 270 degree DCM CLK output
  110.     .CLK2X(),                    // 2X DCM CLK output
  111.     .CLK2X180(),                 // 2X, 180 degree DCM CLK out
  112.     .CLKDV(),                    // Divided DCM CLK out (CLKDV_DIVIDE)
  113.     .CLKFX(),                    // DCM CLK synthesis out (M/D)
  114.     .CLKFX180(),                 // 180 degree CLK synthesis out
  115.     .LOCKED( phase_dcm_locked ), // DCM LOCK status output
  116.     .STATUS(),                   // 8-bit DCM status bits output
  117.     .CLKFB( write_clk ),         // DCM clock feedback
  118.     .CLKIN( read_clk ),          // Clock input (from IBUFG, BUFG or DCM)
  119.     .PSCLK( clk ),               // Dynamic phase adjust clock input
  120.     .PSEN( psen ),               // Dynamic phase adjust enable input
  121.     .PSINCDEC( psincdec ),       // Dynamic phase adjust increment/decrement
  122.     .PSDONE( psdone ),           // Dynamic phase adjust done output
  123.     .RST( phase_dcm_reset )      // DCM asynchronous reset input
  124. );
  125.  
  126. // delayed reset for phase shifting DCM
  127. reg [3:0] reset_counter;
  128. assign phase_dcm_reset = reset | (reset_counter != 0);
  129.  
  130. always @(posedge clk)
  131. begin
  132.     if (reset)
  133.         reset_counter <= 1;
  134.     else begin
  135.         if (dcm_fx_locked & (reset_counter != 0))
  136.             reset_counter <= reset_counter + 1;
  137.     end
  138. end
  139.  
  140. //----------------------------------------------------------------------------
  141. // DCM phase shifting state machine
  142. //----------------------------------------------------------------------------
  143. parameter s_init     = 0;
  144. parameter s_idle     = 1;
  145. parameter s_waitdone = 2;
  146. parameter s_waitdone2= 3;
  147.  
  148. reg [1:0] state;
  149.  
  150. always @(posedge clk)
  151. begin
  152.     if (reset) begin
  153.         state     <= s_init;
  154.         psen      <= 0;
  155.         ps_ready  <= 0;
  156.     end else begin
  157.         case (state)
  158.         s_init: begin
  159.             if (phase_dcm_locked) begin
  160.                 ps_ready  <= 1; // TRUE
  161.                 state     <= s_idle;
  162.             end
  163.         end
  164.         s_idle: begin
  165.  
  166. ….case switch
  167.  
  168. //----------------------------------------------------------------------------
  169. // BUFG write clock
  170. //----------------------------------------------------------------------------
  171. BUFG bufg_write_clk (
  172.     .O(write_clk  ),          // Clock buffer output
  173.     .I(write_clk_u)           // Clock buffer input
  174. );
  175.  
  176. BUFG bufg_write_clk90 (
  177.     .O(write_clk90  ),        // Clock buffer Ooutput
  178.     .I(write_clk90_u)         // Clock buffer Iinput
  179. );
  180.  
  181. //----------------------------------------------------------------------------
  182. // LOCKED logic
  183. //----------------------------------------------------------------------------
  184. reg phase_dcm_locked_delayed;
  185.  
  186. always @(posedge write_clk)
  187. begin
  188.     phase_dcm_locked_delayed <= phase_dcm_locked;
  189. end
  190.  
  191. assign locked = ~reset & phase_dcm_locked_delayed; // Rocket-Launch-&-LLL-Lift_of
  192.  
  193.  
  194. endmodule
  195. FORTH Verilog RAM
  196. http://excamera.com/sphinx/fpga-vhdl-verilog.html#main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement