Home / Learn Verilog / The Flip-Flop: One Bit of Memory
The Flip-Flop: One Bit of Memory
A D flip-flop copies its input to its output on a clock edge and holds it until the next edge.
Quick summaryA D flip-flop copies its input to its output on a clock edge and holds it until the next edge.
How to think about this
What it is
A D flip-flop has data input D, clock input and output Q. At each rising clock edge it samples D and stores it in Q. Between edges Q does not change.
Why it matters
Flip-flops are the memory elements of all synchronous designs: registers, counters, FSM state and pipeline stages are built from them.
Mechanically speaking
In Verilog: always @(posedge clk) q <= d; Synthesis maps this to a flip-flop cell.
Shows up in
- Registers
- Counters and FSMs
- Pipelines
See the sampling
D flip-flop samples D only at the clock edgeVerilog: edit and run
q follows d only at rising edges (t=5, 15, 25...). Changes of d between edges are ignored until the next edge.
- Non-blocking assignment
<=is used for flip-flops (explained later). - Setup time: D must be stable before the edge. Hold time: D must stay stable just after.
- An FPGA contains thousands to millions of flip-flops.
Check yourself
1. A flip-flop updates Q...
On the active clock edge only.
2. Registers are made of...
One flip-flop per bit.