# How do I redirect/regenerate an input clock to an output pin in my FPGA design (Verilog)

I've got an ADC that requires me to send it 20 clock pulses when requesting to read data out of its internal register (after I've triggered it to read data from my sensor).

I was able to simulate this just fine in ModelSim but I'm new to Verilog and didn't realize that I would run into problems during synthesis when creating the pulse train like this:

reg [4:0] counter = 5'b10100;
parameter counter = 0;

always (posedge clk and negedge clk)
begin
if (counter > 0)
begin
counter <= counter - 1;
serial_out <= ~serial_out;
end
end


I tried splitting this into 2 always blocks: one which sets serial_out to 1 on a posedge clk and another which sets serial_out to 0 during negedge clk, both checking if the counter is greater than 0. This is problematic because I'm attempting to drive counter in two places and get errors stating "can't resolve multiple constant driver for net counter .."

Perhaps there is a better way to do this?

I've seen some posts suggesting to double the clk frequency to read the data off of the posedge of the clock. This would work but I need to keep the clock at 30 MHz (can't go to 60 MHz for other reasons).

How would you suggest that I conditionally route/replicate 20 pulses of my always-on periodic 30 MHz input clock to an output pin?

Any help will be greatly appreciated.

• You need to use a gated clock. electronics.stackexchange.com/questions/352464/… – Oldfart Jul 9 '18 at 19:18
• Thanks I just reworked my FSM and incorporated a gated clock. The simulation checks out. I think I've got a good pulse train now to work with when I do my synthesis. – reacher33 Jul 19 '18 at 20:50

• The ALTDDIO_OUT is dedicated logic that switches between two signals when the clock changes. You could do the same with flip flops if they were clocked at the double frequency since you need to react to the falling clock edge, but the dedicated logic wins out as you can just feed it two trivial signals ('1' to be transmitted after a low→high transition, and '0' after a high→low transition). – Simon Richter Jul 19 '18 at 21:43