top_mmcme2.v 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. input [7:0] ClkDiv1_i,
  94. input [7:0] ClkDiv2_i,
  95. input [7:0] ClkDiv3_i,
  96. input [7:0] ClkDiv4_i,
  97. input [7:0] ClkDiv5_i,
  98. input [7:0] ClkDiv6_i,
  99. input [7:0] ClkDiv7_i,
  100. output SRDY,
  101. output LOCKED_OUT,
  102. output CLK0OUT,
  103. output CLK1OUT,
  104. output CLK2OUT,
  105. output CLK3OUT,
  106. output CLK4OUT,
  107. output CLK5OUT,
  108. output CLK6OUT
  109. );
  110. //-------------------------------------------------------------------------------------------
  111. // These signals are used as direct connections between the MMCM_ADV and the
  112. // MMCM_DRP.
  113. (* mark_debug = "true" *) wire [15:0] di;
  114. (* mark_debug = "true" *) wire [6:0] daddr;
  115. (* mark_debug = "true" *) wire [15:0] dout;
  116. (* mark_debug = "true" *) wire den;
  117. (* mark_debug = "true" *) wire dwe;
  118. wire dclk;
  119. wire rst_mmcm;
  120. wire drdy;
  121. reg current_state;
  122. reg [7:0] sstep_int ;
  123. reg init_drp_state = 1;
  124. // These signals are used for the BUFG's necessary for the design.
  125. wire CLKIN_ibuf;
  126. wire clkin_bufgout;
  127. wire clkfb_bufgout;
  128. wire clkfb_bufgin;
  129. wire clk0_bufgin;
  130. wire clk0_bufgout;
  131. wire clk1_bufgin;
  132. wire clk1_bufgout;
  133. wire clk2_bufgin;
  134. wire clk2_bufgout;
  135. wire clk3_bufgin;
  136. wire clk3_bufgout;
  137. wire clk4_bufgin;
  138. wire clk4_bufgout;
  139. wire clk5_bufgin;
  140. wire clk5_bufgout;
  141. wire clk6_bufgin;
  142. wire clk6_bufgout;
  143. wire LOCKED;
  144. //-------------------------------------------------------------------------------------------
  145. assign CLKIN_ibuf = CLKIN;
  146. //
  147. BUFG BUFG_IN (.O (clkin_bufgout), .I (CLKIN_ibuf));
  148. BUFG BUFG_FB (.O (clkfb_bufgout), .I (clkfb_bufgin));
  149. BUFG BUFG_CLK0 (.O (clk0_bufgout), .I (clk0_bufgin));
  150. BUFG BUFG_CLK1 (.O (clk1_bufgout), .I (clk1_bufgin));
  151. BUFG BUFG_CLK2 (.O (clk2_bufgout), .I (clk2_bufgin));
  152. BUFG BUFG_CLK3 (.O (clk3_bufgout), .I (clk3_bufgin));
  153. BUFG BUFG_CLK4 (.O (clk4_bufgout), .I (clk4_bufgin));
  154. BUFG BUFG_CLK5 (.O (clk5_bufgout), .I (clk5_bufgin));
  155. BUFG BUFG_CLK6 (.O (clk6_bufgout), .I (clk6_bufgin));
  156. //
  157. // ODDR registers used to output clocks
  158. ODDR ODDR_CLK0 (.Q(CLK0OUT), .C(clk0_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  159. ODDR ODDR_CLK1 (.Q(CLK1OUT), .C(clk1_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  160. ODDR ODDR_CLK2 (.Q(CLK2OUT), .C(clk2_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  161. ODDR ODDR_CLK3 (.Q(CLK3OUT), .C(clk3_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  162. ODDR ODDR_CLK4 (.Q(CLK4OUT), .C(clk4_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  163. ODDR ODDR_CLK5 (.Q(CLK5OUT), .C(clk5_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  164. ODDR ODDR_CLK6 (.Q(CLK6OUT), .C(clk6_bufgout), .CE(1'b1), .D1(1'b1), .D2(1'b0), .R(RST), .S(1'b0));
  165. //
  166. // MMCM_ADV that reconfiguration will take place on
  167. //
  168. // BANDWIDTH: : "HIGH", "LOW" or "OPTIMIZED"
  169. // DIVCLK_DIVIDE : Value from 1 to 106
  170. // CLKFBOUT_MULT_F : Value from 2 to 64
  171. // CLKFBOUT_PHASE :
  172. // CLKFBOUT_USE_FINE_PS : "TRUE" or "FALSE",
  173. // CLKIN1_PERIOD : Value from 0.968 to 100.000. Set the period (ns) of input clocks
  174. // REF_JITTER1 :
  175. // CLKIN2_PERIOD :
  176. // REF_JITTER2 :
  177. // CLKOUT parameters:
  178. // DIVIDE : Value from 1 to 128
  179. // DUTY_CYCLE : 0.01 to 0.99 - This is dependent on the divide value.
  180. // PHASE : 0.0 to 360.0 - This is dependent on the divide value.
  181. // USE_FINE_PS : TRUE or FALSE
  182. // Misc parameters
  183. // COMPENSATION
  184. // STARTUP_WAIT
  185. //
  186. MMCME2_ADV #(
  187. .BANDWIDTH ("OPTIMIZED"),
  188. .DIVCLK_DIVIDE (1),
  189. .CLKFBOUT_MULT_F (13),
  190. .CLKFBOUT_PHASE (0.0),
  191. .CLKFBOUT_USE_FINE_PS("FALSE"),
  192. .CLKIN1_PERIOD (8.130081300813),
  193. .REF_JITTER1 (0.010),
  194. .CLKIN2_PERIOD (10.000),
  195. .REF_JITTER2 (0.010),
  196. .CLKOUT0_DIVIDE_F (6),
  197. .CLKOUT0_DUTY_CYCLE (0.5),
  198. .CLKOUT0_PHASE (0.0),
  199. .CLKOUT0_USE_FINE_PS ("FALSE"),
  200. .CLKOUT1_DIVIDE (6),
  201. .CLKOUT1_DUTY_CYCLE (0.5),
  202. .CLKOUT1_PHASE (0.0),
  203. .CLKOUT1_USE_FINE_PS ("FALSE"),
  204. .CLKOUT2_DIVIDE (6),
  205. .CLKOUT2_DUTY_CYCLE (0.5),
  206. .CLKOUT2_PHASE (0.0),
  207. .CLKOUT2_USE_FINE_PS ("FALSE"),
  208. .CLKOUT3_DIVIDE (6),
  209. .CLKOUT3_DUTY_CYCLE (0.5),
  210. .CLKOUT3_PHASE (0.0),
  211. .CLKOUT3_USE_FINE_PS ("FALSE"),
  212. .CLKOUT4_DIVIDE (6),
  213. .CLKOUT4_DUTY_CYCLE (0.5),
  214. .CLKOUT4_PHASE (0.0),
  215. .CLKOUT4_USE_FINE_PS ("FALSE"),
  216. .CLKOUT4_CASCADE ("FALSE"),
  217. .CLKOUT5_DIVIDE (6),
  218. .CLKOUT5_DUTY_CYCLE (0.5),
  219. .CLKOUT5_PHASE (0.0),
  220. .CLKOUT5_USE_FINE_PS ("FALSE"),
  221. .CLKOUT6_DIVIDE (6),
  222. .CLKOUT6_DUTY_CYCLE (0.5),
  223. .CLKOUT6_PHASE (0.0),
  224. .CLKOUT6_USE_FINE_PS ("FALSE"),
  225. .COMPENSATION ("ZHOLD"),
  226. .STARTUP_WAIT ("FALSE")
  227. ) mmcme2_test_inst (
  228. .CLKFBOUT (clkfb_bufgin),
  229. .CLKFBOUTB (),
  230. .CLKFBSTOPPED (),
  231. .CLKINSTOPPED (),
  232. // .ClkDiv1_i (ClkDiv1_i),
  233. // .ClkDiv2_i (ClkDiv2_i),
  234. // .ClkDiv3_i (ClkDiv3_i),
  235. // .ClkDiv4_i (ClkDiv4_i),
  236. // .ClkDiv5_i (ClkDiv5_i),
  237. // .ClkDiv6_i (ClkDiv6_i),
  238. // .ClkDiv7_i (ClkDiv7_i),
  239. .CLKOUT0 (clk0_bufgin),
  240. .CLKOUT0B (),
  241. .CLKOUT1 (clk1_bufgin),
  242. .CLKOUT1B (),
  243. .CLKOUT2 (clk2_bufgin),
  244. .CLKOUT2B (),
  245. .CLKOUT3 (clk3_bufgin),
  246. .CLKOUT3B (),
  247. .CLKOUT4 (clk4_bufgin),
  248. .CLKOUT5 (clk5_bufgin),
  249. .CLKOUT6 (clk6_bufgin),
  250. .DO (dout),
  251. .DRDY (drdy),
  252. .DADDR (daddr),
  253. .DCLK (dclk),
  254. .DEN (den),
  255. .DI (di),
  256. .DWE (dwe),
  257. .LOCKED (LOCKED),
  258. .CLKFBIN (clkfb_bufgout),
  259. .CLKIN1 (clkin_bufgout),
  260. .CLKIN2 (),
  261. .CLKINSEL (1'b1),
  262. .PSDONE (),
  263. .PSCLK (1'b0),
  264. .PSEN (1'b0),
  265. .PSINCDEC (1'b0),
  266. .PWRDWN (1'b0),
  267. .RST (rst_mmcm)
  268. );
  269. // MMCM_DRP instance that will perform the reconfiguration operations
  270. mmcme2_drp #(
  271. // Register the LOCKED signal with teh MMCME3_ADV input clock.
  272. // The LOCKED_IN (LOCKED from the MMCME3_ADV) is fed into a register and then
  273. // passed the LOCKED_OUT when REGISTER_LOCKED is set to "Reg" or when set to
  274. // "NoReg" LOCKED_IN is just passed on to LOCKED_OUT without being registered.
  275. .REGISTER_LOCKED ("Reg"),
  276. // Use the registered LOCKED signal from the MMCME3 also for the DRP state machine.
  277. .USE_REG_LOCKED ("No"),
  278. // Possible combination of above two parameters:
  279. // | REGISTER_LOCKED | USE_REG_LOCKED | |
  280. // |-----------------|----------------|--------------------------------------------|
  281. // | "NoReg" | "No" | LOCKED is just passed through mmcme3_drp |
  282. // | | | and is used as is with the state machine |
  283. // | "NoReg" | "Yes" | NOT ALLOWED |
  284. // | "Reg" | "No" | LOCKED is registered but the unregistered |
  285. // | | | version is used for the state machine. |
  286. // | "Reg" | "Yes" | LOCKED is registered and the registered |
  287. // | | | version is also used by the state machine. |
  288. //
  289. //***********************************************************************
  290. // State 1 Parameters - These are for the first reconfiguration state.
  291. //***********************************************************************
  292. // Set the multiply to 6.0 with 0 deg phase offset, optimized bandwidth, input divide of 1
  293. .S1_CLKFBOUT_MULT(13),
  294. .S1_CLKFBOUT_PHASE(000_000),
  295. .S1_CLKFBOUT_FRAC(000),
  296. .S1_CLKFBOUT_FRAC_EN(0),
  297. .S1_BANDWIDTH("OPTIMIZED"),
  298. .S1_DIVCLK_DIVIDE(1),
  299. // Set clockout0 to a divide of 6.0 (unity gain), 0 deg phase offset, 50/50 duty cycle
  300. .S1_CLKOUT0_DIVIDE(6),
  301. .S1_CLKOUT0_PHASE(000_000),
  302. .S1_CLKOUT0_DUTY(50000),
  303. .S1_CLKOUT0_FRAC(000),
  304. .S1_CLKOUT0_FRAC_EN(0),
  305. // Set clockout 1 to a divide of 1, 0 deg phase offset, 50/50 duty cycle
  306. .S1_CLKOUT1_DIVIDE(1),
  307. .S1_CLKOUT1_PHASE(000_000),
  308. .S1_CLKOUT1_DUTY(50000),
  309. // Set clockout 2 to a divide of 2, 0 deg phase offset, 50/50 duty cycle
  310. .S1_CLKOUT2_DIVIDE(2),
  311. .S1_CLKOUT2_PHASE(000_000),
  312. .S1_CLKOUT2_DUTY(50000),
  313. // Set clockout 3 to a divide of 3, 0 deg phase offset, 50/50 duty cycle
  314. .S1_CLKOUT3_DIVIDE(3),
  315. .S1_CLKOUT3_PHASE(000_000),
  316. .S1_CLKOUT3_DUTY(50000),
  317. // Set clockout 4 to a divide of 4, 0 deg phase offset, 50/50 duty cycle
  318. .S1_CLKOUT4_DIVIDE(4),
  319. .S1_CLKOUT4_PHASE(000_000),
  320. .S1_CLKOUT4_DUTY(50000),
  321. // Set clockout 5 to a divide of 5, 0 deg phase offset, 50/50 duty cycle
  322. .S1_CLKOUT5_DIVIDE(5),
  323. .S1_CLKOUT5_PHASE(000_000),
  324. .S1_CLKOUT5_DUTY(50000),
  325. // Set clockout 6 to a divide of 10, 0 deg phase offset, 50/50 duty cycle
  326. .S1_CLKOUT6_DIVIDE(10),
  327. .S1_CLKOUT6_PHASE(000_000),
  328. .S1_CLKOUT6_DUTY(50000),
  329. //***********************************************************************
  330. // State 2 Parameters - These are for the second reconfiguration state.
  331. //***********************************************************************
  332. .S2_CLKFBOUT_MULT(13),
  333. .S2_CLKFBOUT_PHASE(000_000),
  334. .S2_CLKFBOUT_FRAC(000),
  335. .S2_CLKFBOUT_FRAC_EN(0),
  336. .S2_BANDWIDTH("OPTIMIZED"),
  337. .S2_DIVCLK_DIVIDE(1),
  338. // Set clockout 0 to a divide of 4.750, 0 deg phase offset, 50/50 duty cycle
  339. .S2_CLKOUT0_DIVIDE(7),
  340. .S2_CLKOUT0_PHASE(000_000),
  341. .S2_CLKOUT0_DUTY(50000),
  342. .S2_CLKOUT0_FRAC(000),
  343. .S2_CLKOUT0_FRAC_EN(0),
  344. // Set clockout 1 to a divide of 1, 45.0 deg phase offset, 50/50 duty cycle
  345. .S2_CLKOUT1_DIVIDE(1),
  346. .S2_CLKOUT1_PHASE(045_000),
  347. .S2_CLKOUT1_DUTY(50000),
  348. // Set clock out 0 to a divide of 1, 90.0 deg phase offset, 50/50 duty cycle
  349. .S2_CLKOUT2_DIVIDE(1),
  350. .S2_CLKOUT2_PHASE(090_000),
  351. .S2_CLKOUT2_DUTY(90000),
  352. // Set clockout3 to a divide of 1, 135.0 deg phase offset, 50/50 duty cycle
  353. .S2_CLKOUT3_DIVIDE(1),
  354. .S2_CLKOUT3_PHASE(135_000),
  355. .S2_CLKOUT3_DUTY(50000),
  356. // Set clockout4 to a divide of 1, 180.0 deg phase offset, 50/50 duty cycle
  357. .S2_CLKOUT4_DIVIDE(1),
  358. .S2_CLKOUT4_PHASE(180_000),
  359. .S2_CLKOUT4_DUTY(50000),
  360. // Set clockout5 to a divide of 1, 225.0 deg phase offset, 50/50 duty cycle
  361. .S2_CLKOUT5_DIVIDE(1),
  362. .S2_CLKOUT5_PHASE(225_000),
  363. .S2_CLKOUT5_DUTY(50000),
  364. // Set clockout6 to a divide of 1, 270.0 deg phase offset, 50/50 duty cycle
  365. .S2_CLKOUT6_DIVIDE(1),
  366. .S2_CLKOUT6_PHASE(270_000),
  367. .S2_CLKOUT6_DUTY(50000)
  368. ) mmcme2_drp_inst (
  369. .SADDR (STATE),
  370. .SEN (sstep_int[0]),
  371. .RST (RST),
  372. .SRDY (SRDY),
  373. .SCLK (clkin_bufgout),
  374. .DO (dout),
  375. .DRDY (drdy),
  376. .LOCK_REG_CLK_IN (clkin_bufgout),
  377. .LOCKED_IN (LOCKED),
  378. .DWE (dwe),
  379. .DEN (den),
  380. .DADDR (daddr),
  381. .DI (di),
  382. .DCLK (dclk),
  383. .RST_MMCM (rst_mmcm),
  384. .LOCKED_OUT (LOCKED_OUT)
  385. );
  386. //***********************************************************************
  387. // Additional STATE and SSTEP logic for push buttons and switches
  388. //***********************************************************************
  389. // The following logic is not required but is being used to allow the DRP
  390. // circuitry work more effectively with boards that use toggle switches or
  391. // buttons that may not adhere to the single clock requirement.
  392. //
  393. // Only start DRP after initial lock and when STATE has changed
  394. always @ (posedge clkin_bufgout or posedge SSTEP)
  395. if (SSTEP) sstep_int <= 8'h80;
  396. else sstep_int <= {1'b0, sstep_int[7:1]};
  397. //
  398. //-------------------------------------------------------------------------------------------
  399. endmodule