0
votes

the data is input in the first posedge clock but the output should present after 2 clock cycles.

i've tried using #delay but not quite getting it.

clk=0;
forever #10 clk = ~clk;
always @ (posedge clk) begin //synchronous rst
#60 q<=d;
end
1
A flip-flop can be thought of as (i) a one clock cycle delay, (ii) a one-bit memory or (iii) a sampling circuit. Given (i), you need 2 flip-flops, connected in series, with the Q output of the first connected to the D input of the second. - Matthew Taylor
thanks for answer....can designing a latch instead of flip flop can help in this ? - Ansuman Mishra
Why do you want a latch? - Moberg

1 Answers

4
votes

One way to solve your problem would be to have 2 flip-flops.

reg q1, q2;
always @(posedge clk) begin
   q1 <= d;
   q2 <= q1;
end

Now, q2 will follow the input with a 2 clock-cycle latency, which is what you wanted.