0
0
Verilogprogramming~10 mins

D flip-flop with clock edge in Verilog - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - D flip-flop with clock edge
Wait for clock edge
Detect rising edge?
NoWait
Yes
Capture D input
Update Q output
Hold Q until next clock edge
The D flip-flop waits for a rising clock edge, then captures the input D and updates output Q, holding it steady until the next clock edge.
Execution Sample
Verilog
module d_flip_flop(
  input clk,
  input d,
  output reg q
);
  always @(posedge clk) q <= d;
endmodule
This code defines a D flip-flop that updates output q to input d on the rising edge of clock clk.
Execution Table
Stepclkdposedge clk?Actionq (output)
100NoNo updatex (unknown initial)
210YesCapture d=00
311NoNo update0
401NoNo update0
511YesCapture d=11
600NoNo update1
710YesCapture d=00
💡 Simulation ends after step 7; flip-flop updates only on rising clock edges.
Variable Tracker
VariableStartAfter Step 2After Step 5After Step 7
clk0111
d0010
qx010
Key Moments - 3 Insights
Why does q not change when clk is 1 but no rising edge occurs?
Because the flip-flop updates q only on the rising edge of clk, not when clk stays high (see steps 2 to 3 in execution_table).
What happens to q before the first clock edge?
q is unknown (x) initially and only gets a defined value after the first rising edge (step 2).
Why does q hold its value between clock edges?
Because the flip-flop only updates q on clock rising edges, it holds the last captured value otherwise (see steps 3,4,6).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of q after step 5?
A0
B1
Cx
DUndefined
💡 Hint
Check the 'q (output)' column at step 5 in the execution_table.
At which step does the first rising edge of clk occur?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look at the 'posedge clk?' column in the execution_table.
If d was 1 at step 7, what would q be after step 7?
A0
Bx
C1
DNo change
💡 Hint
Refer to the action 'Capture d=...' on rising edges in the execution_table.
Concept Snapshot
D flip-flop captures input D on rising clock edge.
Syntax: always @(posedge clk) q <= d;
Q holds last captured value until next rising edge.
Initial q is unknown until first clock edge.
Used to store 1-bit data synchronized to clock.
Full Transcript
A D flip-flop waits for a rising clock edge to capture the input value D and update its output Q. Initially, Q is unknown. When the clock rises from 0 to 1, the flip-flop copies D to Q. Between clock edges, Q holds its value steady. This behavior is shown step-by-step in the execution table, where only at steps with a rising clock edge does Q change. This is important for storing data synchronized to a clock signal in digital circuits.