2
\$\begingroup\$

Dividing a clock down in Verilog is a basic exercise, and there are loads of answers online about how to do it. What I want to know is whether it is OK to use a clock that has been divided down using verilog on a real FPGA to clock flip flops.

I'm asking because common knowledge dictates that we should never put combinational logic on a clock line and then use the resulting signal to drive a flip flop's clock.

Sure, a clock divider isn't what we would call combinational logic, but at the end of the day, I would still be putting logic gates between a (presumably) complex clock network and the clock signal of a flip-flop.

It's worth noting that I've certainly done this in some hardware projects and it has worked, but it was on a low performance FPGA. I'm wondering if this would work consistently and reliably on most FPGAs, or if I just got lucky with the chip I was using.

\$\endgroup\$
  • \$\begingroup\$ Use your divider counter as a clock enable for the registers driven by the non-divided clock. \$\endgroup\$ – Tom Carpenter Apr 3 '16 at 17:01
  • \$\begingroup\$ How would I do that? Should I have a sensitivity list like @(enable and posedge clk)? \$\endgroup\$ – johnny_boy Apr 3 '16 at 17:02
  • \$\begingroup\$ always @ (posedge clock) begin if (enable) begin ... end end \$\endgroup\$ – Tom Carpenter Apr 3 '16 at 17:03
  • \$\begingroup\$ Jeez. Can't believe I didn't think of that. Thanks for the suggestion. \$\endgroup\$ – johnny_boy Apr 3 '16 at 17:04
  • \$\begingroup\$ It generally works in FPGAs, but often they include dedicated clock dividers and PLL resources that can be used for this. \$\endgroup\$ – pjc50 Apr 3 '16 at 17:13
2
\$\begingroup\$

Theres a few things to consider

  1. The chip needs to actually have the routing to bring a clock signal from a register output into a clock net. Most FPGAs i've worked with can but do check.

  2. Clock nets are a limited resource, while some chips can clock flip flops off normal nets doing so is likely to have worse timing behaviour.

  3. You are likely to need to manually tell the timing analyser what you are doing to get proper timing behaviour/analysis, the details of this are likely to be chip specific.

  4. There is likely to be substantial phase-skew between the original clock and the generated clock.

  5. To ensure the clock is clean it should come directly from a register output, not from combinatorial logic.

Overall you can do it but I would consider it a last resort. Most of the time you can get similar results with a lot less headaches by using enable signals and/or by using multiple outputs from the chip's pll.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.