Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • RTL Foundations36
  • Combinational Design25
  • Sequential Design27
    • Flip-Flops and Registers
      • Edge-Triggered State Elements
      • D Flip-Flop with Asynchronous Reset
      • Synchronous Reset and Register Enable
      • Clock Enable vs Gated Clock
      • A Hold Violation, Worked
    • Counters and Timers
    • Shift Registers and LFSRs
    • Pipelining
    • Stalls, Bubbles and Hazards
    • Retiming
  • FSM & Control27
  • Timing & Clocking39
  • Reset & CDC34
  • Memory & Buses57
  • Advanced RTL28
  • Senior & Interview76
  • Glossary and Notation
Loading lesson

←Flip-Flops and Registers
  1. Topics
  2. RTL Design
  3. Sequential Design
  4. Flip-Flops and Registers
  5. Edge-Triggered State Elements
On this page

    Part 3 of 9, lesson 1 of 27Part 3 of 9/Sequential/Lesson 1 of 27Intermediate

    Edge-Triggered State Elements

    A D flip-flop copies D to Q at the clock edge, with setup, hold, and clock-to-q timing.

    A flop copies D to Q only at the clock edge, so every later question about setup, hold and reset starts here. Code it with a blocking assignment or a delay and simulation can disagree with the hardware.

    After this lesson you can: state what a D flip-flop does at an edge, define setup, hold and clock-to-Q, and compute the minimum clock period for a register-to-register path.

    How a D flip-flop samples

    A D flip-flop copies D to Q at each rising edge and ignores D otherwise. After edge n, Q holds the D value from just before that same edge: Q_after(n) = D_before(n). In RTL the update uses a nonblocking assignment so Q changes just after the edge; in hardware the same update arrives after the clock-to-Q delay.

    The waveform comes from simulating the module under Testbench. Inputs change mid-cycle, away from the edge.

    • Slot 1: d is 0 before the first edge, so q reads 0 just after it.

    • Slot 2: d is 1 before the second edge, while q observed just after the first edge still reads 0.

    • Slot 3: q observed just after the edge reads 1, the d value from just before that same edge.

    • Slot 4: d is 0 before the next edge, while q observed just after the previous edge still reads 1.

    • Slot 5: q observed just after the edge reads 0, the d value from just before that same edge.

    Setup, hold, and clock-to-q

    D must be stable around the edge: setup time before it and hold time after it. A change inside that window can capture the wrong value or cause metastability.

    tsetup​;before the edgethold​;after the edge

    Parameter

    Meaning

    Violated when…

    Fixed by

    t_setup

    D must be stable this long before the edge

    Logic is too slow

    Faster/shorter logic, pipelining, lower clock rate

    t_hold

    D must stay stable this long after the edge

    Path is too fast (data races through)

    Delay padding, usually added by the tools

    t_clk→q

    Delay from the edge to Q changing

    —

    Part of the path delay budget

    Setup violations are cured by slowing the clock; hold violations are not, because they exist at every frequency. That is why hold fixing is done by tools during physical design, and RTL authors mostly worry about setup.

    Common mistakes

    A latch is transparent while its enable is active; a flip-flop only passes data at the edge. Internally, a flop is two latches in series with opposite enables (master and slave), which is why it never passes D straight through to Q.

    Never describe a flip-flop with a blocking assignment, a combinational feedback, or a delay (#). Use always_ff @(posedge clk) q <= d;. Anything else may simulate differently from the hardware.

    Check yourself A path from flop A to flop B has t_clk→q = 0.15 ns, logic delay 0.9 ns, t_setup = 0.1 ns. What is the shortest clock period it allows?

    T ≥ 0.15 + 0.9 + 0.1 = 1.15 ns (about 870 MHz), before any clock uncertainty.

    Testbench

    The D flip-flop with a testbench that changes D mid-cycle and checks Q after each edge.

    dff.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    module dff (
      input  logic clk, d,
      output logic q
    );
      always_ff @(posedge clk) q <= d;        // sample d at every rising edge
    endmodule
    
    module tb_dff;
      timeunit 1ns; timeprecision 1ps;
      logic clk = 0, d = 0, q;
      dff dut (.*);
      always #5 clk = ~clk;
      int errors = 0;
      logic prev_d = 0;
    
      initial begin
        // Change d mid-cycle (on the falling edge) so it is stable around the rising edge.
        repeat (8) begin
          @(negedge clk) d = $urandom_range(0, 1);
          @(posedge clk);
          prev_d = d;                         // value present at the edge
          #1;
          if (q !== prev_d) begin             // after the edge q holds what d was AT the edge
            errors++;
            $display("ERROR time=%0t: q=%b, expected d at the edge=%b", $time, q, prev_d);
          end
        end
        if (errors == 0) $display("PASS: q equals the value d had at the clock edge");
        else $fatal(1, "FAIL: D flip-flop check, errors=%0d", errors);
        $finish;
      end
    endmodule
    • After edge n, Q holds the D value from just before that edge. Use a nonblocking assignment in always_ff.

    • D must be stable for setup before the edge and hold after it; a change inside the window can capture the wrong value or cause metastability.

    • A slower clock cures setup violations but not hold violations.

    Rule of thumb: a flop passes data only at the edge; a latch passes it while its enable is active.

    • Practice: Synchronous D flip-flop with reset

    • Code lab: 8-bit D flip-flop

    • Interview: run a mock interview on this topic

    Related topics

    • Setup, hold and slack

    • Synchronizers and metastability

    • A hold violation, worked

    Previous

    62 / 350

    Next: D Flip-Flop with Asynchronous Reset

    Up next

    Up nextD Flip-Flop with Asynchronous Reset

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Synchronous Reset and Register Enable
    • Clock Enable vs Gated Clock
    • A Hold Violation, Worked
    Q after each edge equals D before that edgeclkdq
    D is read just before each rising edge. Q is observed just after that same edge.