At both posedge and negedge in Verilog?

In Verilog, I can use an always block and make it trigger on a positive or negative edge.

Is it possible to trigger the block on both the positive and negative edge, and thus have it basically clocked at twice the rate?

If so, does it incur a resource penalty? Does the compiler need to duplicate the circuit, and generate one that triggers on the positive edge, and one that triggers on the negative?

You can in simulation but the construct can not be synthesized.

For double edge clocking you need to build a circuit yourself from individual rising and falling edge FF's.

Does the compiler need to duplicate the circuit,

No, there is no (at last not yet) automatic conversion to hardware for a double edge clocked construct.

...So I could duplicate the construct manually, and have things running at double speed?

No, if it would be that easy everybody would do it.
The maximum operating frequency of a synchronous circuit is determined by the time it takes for a signal to leave a register, transfers through the logic and then still meet the set-up time of the next register.

If you use the rising and falling clock edge that time has just halved and the amount of logic you can use between registers also halves. The total circuit will not run faster.

Another a pitfall: it halves only if your clock has a perfect 50/50 duty cycle. Which is difficult to achieve so logic designers prefer to use one clock edge only.

• Thanks. So I could duplicate the construct manually, and have things running at double speed? – Rocketmagnet Oct 26 '18 at 9:29
• It should be noted that while it isn't useful in most situations (ie, you could just double your clock rate instead), there are occasions where it is useful, mostly involving very small parts of a larger system that are simple enough to run twice as fast as the whole (and have enough work to do to justify it). Although even there, using a PLL to generate a double speed clock is probably simpler. – Jules Oct 26 '18 at 10:16
• ok. So if my logic was simple enough, there's a chance that it might meet the timing requirements if double clocked? I have seen some Verilog code which calculates the 8b10b encoding in two stages using the rising and falling edges,. So that one symbol is encoded for every clock cycle. – Rocketmagnet Oct 26 '18 at 21:17
• Yes, that can work. I normally 'fold' the logic of multiple loops. The place where I sometimes use rising & falling edge is for synchronizers to reduce the latency. But that also has a risk. – Oldfart Oct 27 '18 at 8:03
• @Rocketmagnet Standard (Widmer) 8B10B encoding is broken into a 6-bit part and a 4-bit part. The 4-bit part depends on the value for the 6-bit part. But there is no reason you can't calculate the whole ten bits in 1 clock cycle on a single edge. Both encoder stages have 6 or less inputs so on a Xilinx 7-series part or similar you would only be looking at 2 levels of LUTs. There is no reason you couldn't run something like that at several hundred MHz. – user4574 Jul 3 '19 at 21:36

Easily.

Schematics:

Code (CLK50 is clock to be doubled):

reg r_clk50=0;

wire w_xor_clk50=(r_clk50 ^ CLK50);

always@(posedge w_xor_clk50) begin

r_clk50=~r_clk50;


// your code on both neg/pos

end