Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
18 years ago

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,

james

14 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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.