top_mmcme2.v 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. //------------------------------------------------------------------------------------------
  2. // ____ ____
  3. // / /\/ /
  4. // /___/ \ /
  5. // \ \ \/ � Copyright 2019 Xilinx, Inc. All rights reserved.
  6. // \ \ This file contains confidential and proprietary information of Xilinx, Inc.
  7. // / / and is protected under U.S. and international copyright and other
  8. // /___/ /\ intellectual property laws.
  9. // \ \ / \
  10. // \___\/\___\
  11. //
  12. //-------------------------------------------------------------------------------------------
  13. // Device: 7-Series
  14. // Author: Tatsukawa, Kruger, Defossez
  15. // Entity Name: top_mmcme2
  16. // Purpose: This is a basic demonstration of the MMCM_DRP
  17. // connectivity to the MMCM_ADV.
  18. // Tools: Vivado_2019.1 or newer
  19. // Limitations:
  20. //
  21. // Vendor: Xilinx Inc.
  22. // Version: 1.40
  23. // Filename: top_mmcme2.v
  24. // Date Created: 30-Jul-2014
  25. // Date Last Modified: 25-Jun-2019
  26. //-------------------------------------------------------------------------------------------
  27. // Disclaimer:
  28. // This disclaimer is not a license and does not grant any rights to the materials
  29. // distributed herewith. Except as otherwise provided in a valid license issued to you
  30. // by Xilinx, and to the maximum extent permitted by applicable law: (1) THESE MATERIALS
  31. // ARE MADE AVAILABLE "AS IS" AND WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL
  32. // WARRANTIES AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED
  33. // TO WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR
  34. // PURPOSE; and (2) Xilinx shall not be liable (whether in contract or tort, including
  35. // negligence, or under any other theory of liability) for any loss or damage of any
  36. // kind or nature related to, arising under or in connection with these materials,
  37. // including for any direct, or any indirect, special, incidental, or consequential
  38. // loss or damage (including loss of data, profits, goodwill, or any type of loss or
  39. // damage suffered as a result of any action brought by a third party) even if such
  40. // damage or loss was reasonably foreseeable or Xilinx had been advised of the
  41. // possibility of the same.
  42. //
  43. // CRITICAL APPLICATIONS
  44. // Xilinx products are not designed or intended to be fail-safe, or for use in any
  45. // application requiring fail-safe performance, such as life-support or safety devices
  46. // or systems, Class III medical devices, nuclear facilities, applications related to
  47. // the deployment of airbags, or any other applications that could lead to death,
  48. // personal injury, or severe property or environmental damage (individually and
  49. // collectively, "Critical Applications"). Customer assumes the sole risk and
  50. // liability of any use of Xilinx products in Critical Applications, subject only to
  51. // applicable laws and regulations governing limitations on product liability.
  52. //
  53. // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE AT ALL TIMES.
  54. //
  55. // Contact: e-mail hotline@xilinx.com phone + 1 800 255 7778
  56. //-------------------------------------------------------------------------------------------
  57. // Revision History:
  58. // Rev: 30-Apr-2014 - Tatsukawa
  59. // Initial code release
  60. // Rev: 25-Jun-2019 - Defossez
  61. // Add possibility to register the LOCKED signal.
  62. //-------------------------------------------------------------------------------------------
  63. //
  64. `timescale 1ps/1ps
  65. //
  66. //-------------------------------------------------------------------------------------------
  67. // Entity pin description
  68. //-------------------------------------------------------------------------------------------
  69. // Inputs
  70. // SSTEP: Start a reconfiguration. It should only be pulsed for one clock cycle.
  71. // STATE: Determines which state the MMCM_ADV will be reconfigured to. A value
  72. // of 0 correlates to state 1, and a value of 1 correlates to state 2.
  73. // RST: RST will reset the entire reference design including the MMCM_ADV.
  74. // CLKIN: Clock for the MMCM_ADV CLKIN as well as the clock for the MMCM_DRP module
  75. // SRDY: Pulses for one clock cycle after the MMCM_ADV is locked and the
  76. // MMCM_DRP module is ready to start another re-configuration.
  77. // Outputs
  78. // LOCKED_OUT: MMCM is locked after configuration or reconfiguration.
  79. // CLK0OUT: These are the clock outputs from the MMCM_ADV.
  80. // CLK1OUT: These are the clock outputs from the MMCM_ADV.
  81. // CLK2OUT: These are the clock outputs from the MMCM_ADV.
  82. // CLK3OUT: These are the clock outputs from the MMCM_ADV.
  83. // CLK4OUT: These are the clock outputs from the MMCM_ADV.
  84. // CLK5OUT: These are the clock outputs from the MMCM_ADV.
  85. // CLK6OUT: These are the clock outputs from the MMCM_ADV.
  86. //-------------------------------------------------------------------------------------------
  87. module top_mmcme2
  88. (
  89. input SSTEP,
  90. input STATE,
  91. input RST,
  92. input CLKIN,
  93. output SRDY,
  94. output LOCKED_OUT,
  95. output CLK0OUT,
  96. output CLK1OUT,
  97. output CLK2OUT,
  98. output CLK3OUT,
  99. output CLK4OUT,
  100. output CLK5OUT,
  101. output CLK6OUT
  102. );
  103. //-------------------------------------------------------------------------------------------
  104. // These signals are used as direct connections between the MMCM_ADV and the
  105. // MMCM_DRP.
  106. (* mark_debug = "true" *) wire [15:0] di;
  107. (* mark_debug = "true" *) wire [6:0] daddr;
  108. (* mark_debug = "true" *) wire [15:0] dout;
  109. (* mark_debug = "true" *) wire den;
  110. (* mark_debug = "true" *) wire dwe;
  111. wire dclk;
  112. wire rst_mmcm;
  113. wire drdy;
  114. reg current_state;
  115. reg [7:0] sstep_int ;
  116. reg init_drp_state = 1;
  117. // These signals are used for the BUFG's necessary for the design.
  118. wire CLKIN_ibuf;
  119. wire clkin_bufgout;
  120. wire clkfb_bufgout;
  121. wire clkfb_bufgin;
  122. wire clk0_bufgin;
  123. wire clk0_bufgout;
  124. wire clk1_bufgin;
  125. wire clk1_bufgout;
  126. wire clk2_bufgin;
  127. wire clk2_bufgout;
  128. wire clk3_bufgin;
  129. wire clk3_bufgout;
  130. wire clk4_bufgin;
  131. wire clk4_bufgout;
  132. wire clk5_bufgin;
  133. wire clk5_bufgout;
  134. wire clk6_bufgin;
  135. wire clk6_bufgout;
  136. wire LOCKED;
  137. //-------------------------------------------------------------------------------------------
  138. assign CLKIN_ibuf = CLKIN;
  139. //
  140. BUFG BUFG_IN (.O (clkin_bufgout), .I (CLKIN_ibuf));
  141. BUFG BUFG_FB (.O (clkfb_bufgout), .I (clkfb_bufgin));
  142. BUFG BUFG_CLK0 (.O (clk0_bufgout), .I (clk0_bufgin));
  143. BUFG BUFG_CLK1 (.O (clk1_bufgout), .I (clk1_bufgin));
  144. BUFG BUFG_CLK2 (.O (clk2_bufgout), .I (clk2_bufgin));
  145. BUFG BUFG_CLK3 (.O (clk3_bufgout), .I (clk3_bufgin));
  146. BUFG BUFG_CLK4 (.O (clk4_bufgout), .I (clk4_bufgin));
  147. BUFG BUFG_CLK5 (.O (clk5_bufgout), .I (clk5_bufgin));
  148. BUFG BUFG_CLK6 (.O (clk6_bufgout), .I (clk6_bufgin));
  149. //
  150. // ODDR registers used to output clocks
  151. ODDR ODDR_CLK0 (.Q(CLK0OUT), .C(clk0_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  152. ODDR ODDR_CLK1 (.Q(CLK1OUT), .C(clk1_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  153. ODDR ODDR_CLK2 (.Q(CLK2OUT), .C(clk2_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  154. ODDR ODDR_CLK3 (.Q(CLK3OUT), .C(clk3_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  155. ODDR ODDR_CLK4 (.Q(CLK4OUT), .C(clk4_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  156. ODDR ODDR_CLK5 (.Q(CLK5OUT), .C(clk5_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  157. ODDR ODDR_CLK6 (.Q(CLK6OUT), .C(clk6_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  158. //
  159. // MMCM_ADV that reconfiguration will take place on
  160. //
  161. // BANDWIDTH: : "HIGH", "LOW" or "OPTIMIZED"
  162. // DIVCLK_DIVIDE : Value from 1 to 106
  163. // CLKFBOUT_MULT_F : Value from 2 to 64
  164. // CLKFBOUT_PHASE :
  165. // CLKFBOUT_USE_FINE_PS : "TRUE" or "FALSE",
  166. // CLKIN1_PERIOD : Value from 0.968 to 100.000. Set the period (ns) of input clocks
  167. // REF_JITTER1 :
  168. // CLKIN2_PERIOD :
  169. // REF_JITTER2 :
  170. // CLKOUT parameters:
  171. // DIVIDE : Value from 1 to 128
  172. // DUTY_CYCLE : 0.01 to 0.99 - This is dependent on the divide value.
  173. // PHASE : 0.0 to 360.0 - This is dependent on the divide value.
  174. // USE_FINE_PS : TRUE or FALSE
  175. // Misc parameters
  176. // COMPENSATION
  177. // STARTUP_WAIT
  178. //
  179. MMCME2_ADV #(
  180. .BANDWIDTH ("OPTIMIZED"),
  181. .DIVCLK_DIVIDE (1),
  182. .CLKFBOUT_MULT_F (6),
  183. .CLKFBOUT_PHASE (0.0),
  184. .CLKFBOUT_USE_FINE_PS("FALSE"),
  185. .CLKIN1_PERIOD (10.000),
  186. .REF_JITTER1 (0.010),
  187. .CLKIN2_PERIOD (10.000),
  188. .REF_JITTER2 (0.010),
  189. .CLKOUT0_DIVIDE_F (6),
  190. .CLKOUT0_DUTY_CYCLE (0.5),
  191. .CLKOUT0_PHASE (0.0),
  192. .CLKOUT0_USE_FINE_PS ("FALSE"),
  193. .CLKOUT1_DIVIDE (6),
  194. .CLKOUT1_DUTY_CYCLE (0.5),
  195. .CLKOUT1_PHASE (0.0),
  196. .CLKOUT1_USE_FINE_PS ("FALSE"),
  197. .CLKOUT2_DIVIDE (6),
  198. .CLKOUT2_DUTY_CYCLE (0.5),
  199. .CLKOUT2_PHASE (0.0),
  200. .CLKOUT2_USE_FINE_PS ("FALSE"),
  201. .CLKOUT3_DIVIDE (6),
  202. .CLKOUT3_DUTY_CYCLE (0.5),
  203. .CLKOUT3_PHASE (0.0),
  204. .CLKOUT3_USE_FINE_PS ("FALSE"),
  205. .CLKOUT4_DIVIDE (6),
  206. .CLKOUT4_DUTY_CYCLE (0.5),
  207. .CLKOUT4_PHASE (0.0),
  208. .CLKOUT4_USE_FINE_PS ("FALSE"),
  209. .CLKOUT4_CASCADE ("FALSE"),
  210. .CLKOUT5_DIVIDE (6),
  211. .CLKOUT5_DUTY_CYCLE (0.5),
  212. .CLKOUT5_PHASE (0.0),
  213. .CLKOUT5_USE_FINE_PS ("FALSE"),
  214. .CLKOUT6_DIVIDE (6),
  215. .CLKOUT6_DUTY_CYCLE (0.5),
  216. .CLKOUT6_PHASE (0.0),
  217. .CLKOUT6_USE_FINE_PS ("FALSE"),
  218. .COMPENSATION ("ZHOLD"),
  219. .STARTUP_WAIT ("FALSE")
  220. ) mmcme2_test_inst (
  221. .CLKFBOUT (clkfb_bufgin),
  222. .CLKFBOUTB (),
  223. .CLKFBSTOPPED (),
  224. .CLKINSTOPPED (),
  225. .CLKOUT0 (clk0_bufgin),
  226. .CLKOUT0B (),
  227. .CLKOUT1 (clk1_bufgin),
  228. .CLKOUT1B (),
  229. .CLKOUT2 (clk2_bufgin),
  230. .CLKOUT2B (),
  231. .CLKOUT3 (clk3_bufgin),
  232. .CLKOUT3B (),
  233. .CLKOUT4 (clk4_bufgin),
  234. .CLKOUT5 (clk5_bufgin),
  235. .CLKOUT6 (clk6_bufgin),
  236. .DO (dout),
  237. .DRDY (drdy),
  238. .DADDR (daddr),
  239. .DCLK (dclk),
  240. .DEN (den),
  241. .DI (di),
  242. .DWE (dwe),
  243. .LOCKED (LOCKED),
  244. .CLKFBIN (clkfb_bufgout),
  245. .CLKIN1 (clkin_bufgout),
  246. .CLKIN2 (),
  247. .CLKINSEL (1'b1),
  248. .PSDONE (),
  249. .PSCLK (1'b0),
  250. .PSEN (1'b0),
  251. .PSINCDEC (1'b0),
  252. .PWRDWN (1'b0),
  253. .RST (rst_mmcm)
  254. );
  255. // MMCM_DRP instance that will perform the reconfiguration operations
  256. mmcme2_drp #(
  257. // Register the LOCKED signal with teh MMCME3_ADV input clock.
  258. // The LOCKED_IN (LOCKED from the MMCME3_ADV) is fed into a register and then
  259. // passed the LOCKED_OUT when REGISTER_LOCKED is set to "Reg" or when set to
  260. // "NoReg" LOCKED_IN is just passed on to LOCKED_OUT without being registered.
  261. .REGISTER_LOCKED ("Reg"),
  262. // Use the registered LOCKED signal from the MMCME3 also for the DRP state machine.
  263. .USE_REG_LOCKED ("No"),
  264. // Possible combination of above two parameters:
  265. // | REGISTER_LOCKED | USE_REG_LOCKED | |
  266. // |-----------------|----------------|--------------------------------------------|
  267. // | "NoReg" | "No" | LOCKED is just passed through mmcme3_drp |
  268. // | | | and is used as is with the state machine |
  269. // | "NoReg" | "Yes" | NOT ALLOWED |
  270. // | "Reg" | "No" | LOCKED is registered but the unregistered |
  271. // | | | version is used for the state machine. |
  272. // | "Reg" | "Yes" | LOCKED is registered and the registered |
  273. // | | | version is also used by the state machine. |
  274. //
  275. //***********************************************************************
  276. // State 1 Parameters - These are for the first reconfiguration state.
  277. //***********************************************************************
  278. // Set the multiply to 6.0 with 0 deg phase offset, optimized bandwidth, input divide of 1
  279. .S1_CLKFBOUT_MULT(6),
  280. .S1_CLKFBOUT_PHASE(000_000),
  281. .S1_CLKFBOUT_FRAC(000),
  282. .S1_CLKFBOUT_FRAC_EN(0),
  283. .S1_BANDWIDTH("OPTIMIZED"),
  284. .S1_DIVCLK_DIVIDE(1),
  285. // Set clockout0 to a divide of 6.0 (unity gain), 0 deg phase offset, 50/50 duty cycle
  286. .S1_CLKOUT0_DIVIDE(6),
  287. .S1_CLKOUT0_PHASE(000_000),
  288. .S1_CLKOUT0_DUTY(50000),
  289. .S1_CLKOUT0_FRAC(000),
  290. .S1_CLKOUT0_FRAC_EN(0),
  291. // Set clockout 1 to a divide of 1, 0 deg phase offset, 50/50 duty cycle
  292. .S1_CLKOUT1_DIVIDE(1),
  293. .S1_CLKOUT1_PHASE(000_000),
  294. .S1_CLKOUT1_DUTY(50000),
  295. // Set clockout 2 to a divide of 2, 0 deg phase offset, 50/50 duty cycle
  296. .S1_CLKOUT2_DIVIDE(2),
  297. .S1_CLKOUT2_PHASE(000_000),
  298. .S1_CLKOUT2_DUTY(50000),
  299. // Set clockout 3 to a divide of 3, 0 deg phase offset, 50/50 duty cycle
  300. .S1_CLKOUT3_DIVIDE(3),
  301. .S1_CLKOUT3_PHASE(000_000),
  302. .S1_CLKOUT3_DUTY(50000),
  303. // Set clockout 4 to a divide of 4, 0 deg phase offset, 50/50 duty cycle
  304. .S1_CLKOUT4_DIVIDE(4),
  305. .S1_CLKOUT4_PHASE(000_000),
  306. .S1_CLKOUT4_DUTY(50000),
  307. // Set clockout 5 to a divide of 5, 0 deg phase offset, 50/50 duty cycle
  308. .S1_CLKOUT5_DIVIDE(5),
  309. .S1_CLKOUT5_PHASE(000_000),
  310. .S1_CLKOUT5_DUTY(50000),
  311. // Set clockout 6 to a divide of 10, 0 deg phase offset, 50/50 duty cycle
  312. .S1_CLKOUT6_DIVIDE(10),
  313. .S1_CLKOUT6_PHASE(000_000),
  314. .S1_CLKOUT6_DUTY(50000),
  315. //***********************************************************************
  316. // State 2 Parameters - These are for the second reconfiguration state.
  317. //***********************************************************************
  318. .S2_CLKFBOUT_MULT(7),
  319. .S2_CLKFBOUT_PHASE(000_000),
  320. .S2_CLKFBOUT_FRAC(000),
  321. .S2_CLKFBOUT_FRAC_EN(0),
  322. .S2_BANDWIDTH("OPTIMIZED"),
  323. .S2_DIVCLK_DIVIDE(1),
  324. // Set clockout 0 to a divide of 4.750, 0 deg phase offset, 50/50 duty cycle
  325. .S2_CLKOUT0_DIVIDE(7),
  326. .S2_CLKOUT0_PHASE(000_000),
  327. .S2_CLKOUT0_DUTY(50000),
  328. .S2_CLKOUT0_FRAC(000),
  329. .S2_CLKOUT0_FRAC_EN(0),
  330. // Set clockout 1 to a divide of 1, 45.0 deg phase offset, 50/50 duty cycle
  331. .S2_CLKOUT1_DIVIDE(1),
  332. .S2_CLKOUT1_PHASE(045_000),
  333. .S2_CLKOUT1_DUTY(50000),
  334. // Set clock out 0 to a divide of 1, 90.0 deg phase offset, 50/50 duty cycle
  335. .S2_CLKOUT2_DIVIDE(1),
  336. .S2_CLKOUT2_PHASE(090_000),
  337. .S2_CLKOUT2_DUTY(90000),
  338. // Set clockout3 to a divide of 1, 135.0 deg phase offset, 50/50 duty cycle
  339. .S2_CLKOUT3_DIVIDE(1),
  340. .S2_CLKOUT3_PHASE(135_000),
  341. .S2_CLKOUT3_DUTY(50000),
  342. // Set clockout4 to a divide of 1, 180.0 deg phase offset, 50/50 duty cycle
  343. .S2_CLKOUT4_DIVIDE(1),
  344. .S2_CLKOUT4_PHASE(180_000),
  345. .S2_CLKOUT4_DUTY(50000),
  346. // Set clockout5 to a divide of 1, 225.0 deg phase offset, 50/50 duty cycle
  347. .S2_CLKOUT5_DIVIDE(1),
  348. .S2_CLKOUT5_PHASE(225_000),
  349. .S2_CLKOUT5_DUTY(50000),
  350. // Set clockout6 to a divide of 1, 270.0 deg phase offset, 50/50 duty cycle
  351. .S2_CLKOUT6_DIVIDE(1),
  352. .S2_CLKOUT6_PHASE(270_000),
  353. .S2_CLKOUT6_DUTY(50000)
  354. ) mmcme2_drp_inst (
  355. .SADDR (STATE),
  356. .SEN (sstep_int[0]),
  357. .RST (RST),
  358. .SRDY (SRDY),
  359. .SCLK (clkin_bufgout),
  360. .DO (dout),
  361. .DRDY (drdy),
  362. .LOCK_REG_CLK_IN (clkin_bufgout),
  363. .LOCKED_IN (LOCKED),
  364. .DWE (dwe),
  365. .DEN (den),
  366. .DADDR (daddr),
  367. .DI (di),
  368. .DCLK (dclk),
  369. .RST_MMCM (rst_mmcm),
  370. .LOCKED_OUT (LOCKED_OUT)
  371. );
  372. //***********************************************************************
  373. // Additional STATE and SSTEP logic for push buttons and switches
  374. //***********************************************************************
  375. // The following logic is not required but is being used to allow the DRP
  376. // circuitry work more effectively with boards that use toggle switches or
  377. // buttons that may not adhere to the single clock requirement.
  378. //
  379. // Only start DRP after initial lock and when STATE has changed
  380. always @ (posedge clkin_bufgout or posedge SSTEP)
  381. if (SSTEP) sstep_int <= 8'h80;
  382. else sstep_int <= {1'b0, sstep_int[7:1]};
  383. //
  384. //-------------------------------------------------------------------------------------------
  385. endmodule