Forum Discussion
Clock 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
The code looks good. I still don't know what domains your input/out signals are based in(start, count, out, etc.) but am assuming they're synchronous, except perhaps start which is double-registered and is probably fine if it's not synchronous.
Note that your failures don't look timing related. Timing issues(like when you had hold issues), tend to just miss the window they're targeting. If you're supposed to count to 3 but count to 7 or 8, i.e. are missing by 40-50ns, then it's not timing on those paths. But if everything's in the clock domain I really don't think it's a timing issue. You can do a simulation to check your logic. I did a real quick one and it counted to 3 and then stopped, so it looked right. You could also try SignalTap, which allows you to look at logic "live" while the device is running, and see what is physically happening. - Altera_Forum
Honored Contributor
Hi,
It is me again. I tried implementing my design with no clock mux. I used memory clock enable to control how many clock pulses. Attached is the enable generation diagram and code. However, I am still getting undesired behavior at frequency higher than 100MHz. I checked it using an output counter. Based on enable generation design, the number of clock pulse = count + 1. For example, if I set count to 2 (0010), I will expect to read '3' (0011) from out_counter. However, sometimes I got '3', sometimes '7' (0111), sometimes '8' (1000). I am running out of idea on this undesired behavior. Quartus report said I can achieve ~200MHz. One more point. When I lowered down VCC, I will observe more undeterministic behavior. Any comments or ideas? thanks in advance. - Altera_Forum
Honored Contributor
Hi,
Thanks for all the valuable advice. I will try to modify the design in such a way to use single clock for all the operations (to eliminate the mux). altclkctrl only available for Stratix II device onwards. - Altera_Forum
Honored Contributor
The clock enable timing is similar to the timing of the D input of the register. If the register is using the rising clock edge, then the clock enable has to be valid and stable during the setup and hold window around that rising clock edge just like the D input has to be. The timing analysis will check this for you. You don't need to align the clock enable with the opposite edge of the clock. This works the same way whether the register is created with LPM_FF, RTL, or a DFF primitive in a schematic.
See the thread I referenced in my previous post for things applicable to your other questions. The originator of the other thread had a ripple clock to do a divide-by-n, but the considerations are the same for a gated clock created by a mux. Even if you have no reported setup or hold violations on cross-domain paths going to or from the mux output clock domain, you ought to consider the data-versus-clock-skew uncertainty that Rysc touched on and that I discussed in the other thread. One of my posts in the other thread says you can make the gated-clock warning go way with a clock setting, but that doesn't eliminate the skew consideration. If the output of the clock mux is global with no synchronous cross-domain paths going to or from that domain, then this skew won't matter. Some device families (I don't remember whether this includes Stratix I) allow implementing a clock mux in the clock control block with the altclkctrl megafunction. (The clock control block also is the device structure used to get a signal onto global routing.) If you must use a clock mux, it is better to do it with a clock control block than with logic resources if the clock control block can handle the number of mux inputs you need. The device handbook documents what muxing the clock control block can provide, and I think it's an user guide for altclkctrl that documents how to use the megafunction. - Altera_Forum
Honored Contributor
If you can remove the clock mux, then your analysis will be much more straightforward and you should be in better shape. If it has to be there, then it has to be there, but you need to account for it. I would recommend using TimeQuest too, as it is much better clock mux analysis capabilities. Look at:
http://www.altera.com/support/examples/timequest/exm-tq-clock-mux.html - Altera_Forum
Honored Contributor
one more question. When I used LPM, for example, LPM_FF from Quartus megafunction. Do I need to align the clock_enable to the falling edge of the clock OR it will be taken care by megafunction itself?
- Altera_Forum
Honored Contributor
Hi,
Thanks for your input. Based on what you had said, if I am able to remove the clock mux, then I will be fine, right? Btw, the output of the clock mux is feeding other logic as well. From Quartus report, it seems like I can achieve ~200MHz and based on the timing analysis, no hold time violation. - Altera_Forum
Honored Contributor
You still have a mux on your clock, which pushes the clock edges out in time relative to the main clock, so when the PLL's output feeds logic before and after the MRAM, but not through a mux, you now have potential hold time issues. (I'm assuming this clock mux only feeds the MRAM, and not the rest of the logic around it.) Anyway, do you only use one address port per clock? If so, you can make the MRAM dual-port where one address and r/w port is based on the external clock, and the other port is based on the PLL output.
- Altera_Forum
Honored Contributor
I changed my clock pulse generator to feed the out to serve as clock enable for MRAM. In my design, I have 2 clock source for MRAM, as attached.
The operation sequence desired is: - sel = 0, do some configuration with using ext_clock - change sel = 1 - set start = 1. output from clock pulse generator will feed to MRAM. The number of clock pulse depends on "count" value Quartus give me a warning on gated/ripple clock at the output of clock mux. Anywhere to get rid of this? Btw, output of clock mux is promoted as global signal. With the above implementation, I am still not able to get the desired number of clock pulses. Anything wrong with my implementation? I am using Stratix I device. - Altera_Forum
Honored Contributor
For further discussion of why to use clock enables and the caveats when driving a clock with something like a divide-by-n register, gating logic, or muxing logic, see "Altera Forums > Device Related > FPGA Discussion > derived clock versus clock enable" at http://www.alteraforum.com/forum/showthread.php?t=754.