Forum Discussion
Altera_Forum
Honored Contributor
19 years agoClock Pulse Generator
Hi,
I need to generate a deterministic number of clock pulses, using PLL in Stratix device. Here is what I did: PLL --> clk0 --> counter module --> clkena1 --> clk1 I developed a counter module to do clock pulse counting and issue clock enable to the same PLL. clk0 and clk1 are output from PLL running at same frequency/phase. I am able to get the desired behavior if the frequency is below 100MHz. When frequency is above 100MHz, I start to get undeterministic number of clock pulses. From Quartus II timing analysis, it shows Fmax at ~200MHz. Any ideas? any help is much appreciated thanks, james14 Replies
- Altera_Forum
Honored Contributor
Don't use out as a clock, but as a clock enable to the MRAM, and have in(your system clock) feed the MRAM's clock. You'll get the same affect in that the MRAM will only be clock enabled for a certain number of clocks.
It's very important to note gate your clocks whenever you can. When everything has aligned rising edges, then the clock skew essentially cancels out, over both min and max timing models. If one clock has extra delay, you now have skew. So not only are you worried about your data path delay being faster than the desired clock period, you have to worry about it being longer than the clock skew, over both fast and slow corner models. You not only have to monitor setup slack, but also hold slack. (If that all doesn't make sense, that's exactly why to avoid gated clocks, since you then don't have to understand these topics.) Anytime you think of making a modification to the clock, see if it can be done with a PLL or a clock enable instead, since they don't delay the clock edges(assuming all clocks go through the PLL). There are certainly cases where this can't be done, but in many, including this one, you can work around gating your clocks. - Altera_Forum
Honored Contributor
Hi,
Exactly per what you said, the number of clock pulses is not desired, sometime it is 1 clock pulse more, sometime few cycles more. I am developing simple counter internally to count the clock pulses and observed the counter value at the output. The clock is not going offchip. It is used internally as clock to MRAM. Previously, I created a burst counter code to take in PLL clock and upon a signal "start", it will count number of clock pulses and gate off the output. The snippet of code is shown as below: --------------------------------------------- // clock pulse counter module clockBurst ( in, out, start, count ); parameter ST_IDLE=1, ST_COUNT=2, ST_DONE=3; parameter WIDTH = 4; input in; output out; input start; input [WIDTH-1:0] count; reg [1:0] st; reg [1:0] ns; reg [WIDTH-1:0] val; wire done; always @(negedge in) begin st <= ns; end always @(posedge in) begin //st <= ns; if(ns == ST_COUNT) val <= val + 1; else val <= 0; end always @(st or start or done) begin ns = st; case (st) ST_IDLE: begin if(start == 1'b0) ns = ST_IDLE; else ns = ST_COUNT; end ST_COUNT: begin if(~done) ns = ST_COUNT; else ns = ST_DONE; end ST_DONE: begin if(start == 1'b0) ns = ST_IDLE; else ns = ST_DONE; end default: begin ns = ST_IDLE; end endcase end assign out = (st == ST_COUNT)? in : 1'b0; assign done = (val == count)? 1'b1 : 1'b0; endmodule ------------------------------------- "in" is the PLL clock. "out" is the gated clock that the number of pulses rely on "count" value. I will have "start" to trigger the clock counting Under Quartus compilation, it did show me warning message on ripple/gated clock. By using classic timing analyzer, the frequency is ~200MHz. When I ran it, it work for PLL frequency <100MHz and start to have undeterministic clock pulse when frequency go beyond 100MHz. Any ideas? Thanks a lot! - Altera_Forum
Honored Contributor
What's your symptom? One more or less clock then expected, like it's just not enabling/disabling the PLL output fast enough, or random stuff? I'm guessing the first.
What timing engine are you using? That 200MHz report(which leads me to believe you're doing the Classic) means a clock domain can run at 200MHz, i.e. the data path is less than 5ns(not counting clock skew, multicycles, etc.) You've got a path that enables a clock domain. How do you know if that's meeting timing? To be honest, I'm not even sure how to do this at first glance, since the output needs to disable the PLL before it has a chance to disable the next edge coming out(almost like the gating is synchronous). Also, I believe the PLL enable will disable all PLL outputs, which ends the clock to your counter module and makes it all a one-shot process. If it's just a number of clocks internally, use the enable as an enable on all the registers. If it's a clock going off chip, I agree with Avatar and make a 2x clock that drives a toggle register(bringing you back down to 1x) and have the clock enable drive this register. Now everything is nicely synchronous and you should have an easier time doing proper timing analysis. - Altera_Forum
Honored Contributor
Sounds like a Nyquest issue to me.
Why not just take double the clock Fx, pass it through a F/F that is enabled (or not) to pass the /2 clock forward. Am I missing something?