x393  1.0
FPGAcodeforElphelNC393camera
mmcm_phase_cntr.v
Go to the documentation of this file.
1 
39 `timescale 1ns/1ps
40 
41 // all counters are two-clock cycle nets
43  parameter PHASE_WIDTH= 8, // number of bits for te phase counter (depends on divisors)
44  parameter CLKIN_PERIOD = 0.000, // input period in ns, 0..100.000 - MANDATORY, resolution down to 1 ps
45  parameter BANDWIDTH = "OPTIMIZED", //"OPTIMIZED", "HIGH","LOW"
46  parameter CLKFBOUT_MULT_F = 5.000, // 2.0 to 64.0 . Together with CLKOUT#_DIVIDE and DIVCLK_DIVIDE
47  parameter CLKFBOUT_PHASE = 0.000, // CLOCK FEEDBACK phase in degrees (3 significant digits, -360.000...+360.000)
48  parameter CLKOUT0_PHASE = 0.000, // CLOCK0 phase in degrees (3 significant digits, -360.000...+360.000)
49  parameter CLKOUT1_PHASE = 0.000, // Initial/static fine phase shift, 1/(56*Fvco) actual step
50  parameter CLKOUT2_PHASE = 0.000,
51  parameter CLKOUT3_PHASE = 0.000,
52  parameter CLKOUT4_PHASE = 0.000,
53  parameter CLKOUT5_PHASE = 0.000,
54  parameter CLKOUT6_PHASE = 0.000,
55  parameter CLKOUT0_DUTY_CYCLE= 0.5, // CLOCK 0 output duty factor, 3 significant digits
56  parameter CLKOUT1_DUTY_CYCLE= 0.5,
57  parameter CLKOUT2_DUTY_CYCLE= 0.5,
58  parameter CLKOUT3_DUTY_CYCLE= 0.5,
59  parameter CLKOUT4_DUTY_CYCLE= 0.5,
60  parameter CLKOUT5_DUTY_CYCLE= 0.5,
61  parameter CLKOUT6_DUTY_CYCLE= 0.5,
62  parameter CLKOUT4_CASCADE= "FALSE", // cascades the output6 divider to the input for output 4
63  parameter CLKFBOUT_USE_FINE_PS = "FALSE", // Enable variable fine pase shift. Enable 1/(56*Fvco) phase inceremnts, round-robin
64  parameter CLKOUT0_USE_FINE_PS = "FALSE", // Same fine phase shift for all outputs where this attribute is "TRUE"
65  parameter CLKOUT1_USE_FINE_PS = "FALSE", // Not compatible with fractional divide
66  parameter CLKOUT2_USE_FINE_PS = "FALSE",
67  parameter CLKOUT3_USE_FINE_PS = "FALSE",
68  parameter CLKOUT4_USE_FINE_PS = "FALSE",
69  parameter CLKOUT5_USE_FINE_PS = "FALSE",
70  parameter CLKOUT6_USE_FINE_PS = "FALSE",
71  parameter CLKOUT0_DIVIDE_F = 1.000, // CLK0 outout divide, floating 1.000..128.000
72  parameter CLKOUT1_DIVIDE = 1, // CLK1 outout divide, integer 1..128 (determins a phase step as a fraction of pi/4)
73  parameter CLKOUT2_DIVIDE = 1,
74  parameter CLKOUT3_DIVIDE = 1,
75  parameter CLKOUT4_DIVIDE = 1,
76  parameter CLKOUT5_DIVIDE = 1,
77  parameter CLKOUT6_DIVIDE = 1,
78  parameter COMPENSATION= "ZHOLD", // "ZHOLD",BUF_IN","EXTERNAL","INTERNAL
79  // ZHOLD - provide negative hold time on I/O registers
80  // INTERNAL - using internal compensation no deley is compensated
81  // EXTERNAL - external to the FPGA network is being compensated
82  // BUF_IN - no compensation when clock input is driveen by BUFG/BUFH/BUFR or GT
83  parameter DIVCLK_DIVIDE = 1, // Integer 1..106. Divides all outputs with respect to CLKIN
84  parameter REF_JITTER1 = 0.010, // Expected jitter on CLKIN1 (0.000..0.999)
85  parameter REF_JITTER2 = 0.010,
86  parameter SS_EN = "FALSE", // Enables Spread Spectrum mode
87  parameter SS_MODE = "CENTER_HIGH",//"CENTER_HIGH","CENTER_LOW","DOWN_HIGH","DOWN_LOW"
88  parameter SS_MOD_PERIOD = 10000, // integer 4000-40000 - SS modulation period in ns
89  parameter STARTUP_WAIT = "FALSE" // Delays "DONE" signal until MMCM is locked
90 )
91 (
92  input clkin1, // General clock input
93  input clkin2, // Alternative clock input
94  input sel_clk2, // Clock input select (inverted from MMCME2_ADV !!!)
95  input clkfbin, // Feedback clock input
96  input rst, // asynchronous reset input
97  input pwrdwn, // power down input
98  input psclk, // phase shift clock input
99 
100  input ps_we, // phase shift write eneble
101  input [PHASE_WIDTH-1:0] ps_din, // phase shift data input (2-s complement)
102  output ps_ready, // phase shift change finished
103  output [PHASE_WIDTH-1:0] ps_dout, // current phase shift value
104 
105  output clkout0, // output 0, HPC BUFR/BUFIO capable
106  output clkout1, // output 1, HPC BUFR/BUFIO capable
107  output clkout2, // output 2, HPC BUFR/BUFIO capable
108  output clkout3, // output 3, HPC BUFR/BUFIO capable
109  output clkout4, // output 4, HPC BUFR/BUFIO not capable
110  output clkout5, // output 5, HPC BUFR/BUFIO not capable
111  output clkout6, // output 6, HPC BUFR/BUFIO not capable
112  output clkout0b, // output 0, inverted
113  output clkout1b, // output 1, inverted
114  output clkout2b, // output 2, inverted
115  output clkout3b, // output 3, inverted
116  output clkfbout, // dedicate feedback output
117  output clkfboutb,// inverted feedback output
118  output locked, // PLL locked output
121 );
123  wire psen; // phase shift enable input
124  reg psincdec; // phase shift direction input (1 - increment, 0 - decrement)
125  wire psdone; // phase shift done (12 clocks after psen
127  reg ps_busy=0;
128 // TODO: find out why it was optimized out!
129  reg ps_start0, ps_start; // debugging
130  assign ps_ready=!ps_busy && locked && !ps_start0 && !ps_start;
131  assign psen=ps_start && (diff != 0);
132 // made a difference, so it doesn't seem Vivado extends bits of operands "+", "-"
134  assign ps_dout = ps_dout_r;
136 
137  always @ (posedge psclk) begin
138  if (reset_extended) ps_start0 <= 0;
139  else ps_start0 <= ps_we && ps_ready;
140 
141  if (reset_extended) ps_dout_r <= 0;
142  else if (psen && psincdec) ps_dout_r <= ps_dout_r +1; //SuppressThisWarning ISExst Result of 9-bit expression is truncated to fit in 8-bit target.
143  else if (psen && !psincdec) ps_dout_r <= ps_dout_r -1; //SuppressThisWarning ISExst Result of 32-bit expression is truncated to fit in 8-bit target.
144 
145  if (reset_extended) ps_target <= 0;
146  else if (ps_we && ps_ready) ps_target <= ps_din;
147 
148  if (reset_extended) ps_busy <= 1'b0;
149  else if (ps_start) ps_busy <= (diff!=0);
150 
151 
152  end
153  always @ (posedge psclk) begin
156  end
157 
159  .BANDWIDTH (BANDWIDTH),
163  .CLKIN1_PERIOD (CLKIN_PERIOD),
164  .CLKIN2_PERIOD (CLKIN_PERIOD),
196 // .IS_CLKINSEL_INVERTED (1'b0), // ISE does not have this parameter
197 // .IS_PSEN_INVERTED (1'b0), // ISE does not have this parameter
198 // .IS_PSINCDEC_INVERTED (1'b0), // ISE does not have this parameter
199 // .IS_PWRDWN_INVERTED (1'b0), // ISE does not have this parameter
200 // .IS_RST_INVERTED (1'b0), // ISE does not have this parameter
203  .SS_EN (SS_EN),
204  .SS_MODE (SS_MODE),
207  ) MMCME2_ADV_i (
208  .CLKFBOUT (clkfbout), // output
209  .CLKFBOUTB (clkfboutb), // output
210  .CLKFBSTOPPED (clkfb_stopped), // output
211  .CLKINSTOPPED (clkin_stopped), // output
212  .CLKOUT0 (clkout0), // output
213  .CLKOUT0B (clkout0b), // output
214  .CLKOUT1 (clkout1), // output
215  .CLKOUT1B (clkout1b), // output
216  .CLKOUT2 (clkout2), // output
217  .CLKOUT2B (clkout2b), // output
218  .CLKOUT3 (clkout3), // output
219  .CLKOUT3B (clkout3b), // output
220  .CLKOUT4 (clkout4), // output
221  .CLKOUT5 (clkout5), // output
222  .CLKOUT6 (clkout6), // output
223  .DO (), // Dynamic reconfiguration output[15:0]
224  .DRDY (), // Dynamic reconfiguration output
225  .LOCKED (locked), // output
226  .PSDONE (psdone), // output
227  .CLKFBIN (clkfbin), // input
228  .CLKIN1 (clkin1), // input
229  .CLKIN2 (clkin2), // input
230  .CLKINSEL (~sel_clk2), // input 0: Select CLKIN2, 1: Select CLKIN1 !!!!!!!!!!!!!
231  .DADDR (7'b0), // Dynamic reconfiguration address (input[6:0])
232  .DCLK (1'b0), // Dynamic reconfiguration clock input
233  .DEN (1'b0), // Dynamic reconfiguration enable input
234  .DI (16'b0), // Dynamic reconfiguration data (input[15:0])
235  .DWE (1'b0), // Dynamic reconfiguration Write Enable input
236  .PSCLK (psclk), // input
237  .PSEN (psen), // input
238  .PSINCDEC (psincdec), // input
239  .PWRDWN (pwrdwn), // input
240  .RST (rst) // input
241  );
242 
243 
244 endmodule
245 
11458diffwire[PHASE_WIDTH:0]
11403CLKOUT2_USE_FINE_PS"FALSE"
11404CLKOUT3_USE_FINE_PS"FALSE"
11382BANDWIDTH"OPTIMIZED"
11450ps_dout_rreg[PHASE_WIDTH-1:0]
11400CLKFBOUT_USE_FINE_PS"FALSE"
11454ps_targetreg[PHASE_WIDTH-1:0]
11406CLKOUT5_USE_FINE_PS"FALSE"
[PHASE_WIDTH-1:0] 11433ps_dout
11402CLKOUT1_USE_FINE_PS"FALSE"
11420SS_MODE"CENTER_HIGH"
11401CLKOUT0_USE_FINE_PS"FALSE"
11399CLKOUT4_CASCADE"FALSE"
[PHASE_WIDTH-1:0] 11431ps_din
11408CLKOUT0_DIVIDE_F1.000
11422STARTUP_WAIT"FALSE"
MMCME2_ADV_i MMCME2_ADV
11415COMPENSATION"ZHOLD"
11405CLKOUT4_USE_FINE_PS"FALSE"
11407CLKOUT6_USE_FINE_PS"FALSE"