🔧 DFT Blog

Part 2 of 11

Digital Design Fundamentals

The foundation you need before diving into DFT

By Praveen Kumar Vagala

1,156 views

Combinational vs Sequential Logic

This is the most fundamental concept in digital design.

Combinational Logic

No memory. Output depends only on current inputs.

┌───────────┐ Input ──│ Logic │──► Output └───────────┘ Output = f(current inputs)

Examples: Adders, MUX, Decoders, ALU

// 2:1 MUX - Pure combinational
module mux2to1 (
    input  a, b, sel,
    output y
);
    assign y = sel ? b : a;
endmodule

Sequential Logic

Has memory (flip-flops). Output depends on inputs AND previous state.

┌───────────┐ Input ──│ Logic │──► Output │ ↑ │ │ [FF] │ ← Memory! └───────────┘ Output = f(inputs + stored state)

Examples: Counters, FSMs, Registers, Shift Registers

// Counter - Sequential (has memory)
module counter4 (
    input            clk, rst_n, en,
    output reg [3:0] count
);
    always @(posedge clk or negedge rst_n) begin
        if (!rst_n)
            count <= 4'b0;
        else if (en)
            count <= count + 1;
    end
endmodule

Setup and Hold Time

This is critical for DFT - most scan failures relate to timing!

The Concept

Clock Period = 10ns ___________ ___________ CLK ___| |_________| |___ ↑ ↑ Rising Edge 1 Rising Edge 2 |← Tcq →|← Combinational Logic →|← Setup →| |←―――― Data Path ―――――――――→|

Setup Time

Data must be stable BEFORE the clock edge.

Setup Time |←――――→| DATA ━━━━━━━━━━━━━╲ ╲━━━━━━ CLK ________┌──────┐________ ↑ Clock Edge

Setup Violation: Data arrives too late → FF captures wrong value.

Hold Time

Data must stay stable AFTER the clock edge.

|←――→| Hold Time DATA ━━━━━━━━━━━━━━━━╲ ╲━━━ CLK ________┌──────┐________ ↑ Clock Edge

Hold Violation: Data changes too fast → FF captures garbage.

Timing Equations

Setup Check:
  Tclk_to_q + Tcomb + Tsetup < Clock_Period
  
Hold Check:  
  Tclk_to_q + Tcomb > Thold

Metastability

When setup/hold is violated, the flip-flop enters an undefined state.

Normal: Input → FF → Clean 0 or 1 Metastable: Input → FF → ??? → Eventually settles ↑ Unknown delay! Could be 0 or 1!

Solution: Synchronizer

Async Input → [FF1] → [FF2] → [FF3] → Safe Output ↑ ↑ ↑ May be Likely Safe meta stable

Two or three flip-flops in series. Each stage reduces metastability probability exponentially.

Clock Domain Crossing (CDC)

When signals move between different clock domains:

CLK_A Domain CLK_B Domain ┌───────────┐ ┌───────────┐ │ Logic │────────────│ Logic │ │ │ Danger! │ │ └───────────┘ └───────────┘ ↑ ↑ CLK_A CLK_B (different!)

Solutions

MethodUse Case
2-FF SynchronizerSingle-bit signals
Gray-coded FIFOMulti-bit data
Handshake ProtocolControl signals
MUX RecirculationSynchronized data

Finite State Machine (FSM)

Sequential circuits that move through defined states.

┌──────┐ start ┌─────────┐ done ┌────────┐ ────►│ IDLE │────────►│ RUNNING │───────►│ FINISH │ └──────┘ └─────────┘ └───┬────┘ ↑ │ └──────────────────────────────────┘

FSM Template

module fsm (
    input      clk, rst_n,
    input      start, done,
    output reg busy, complete
);
    // State encoding
    localparam IDLE    = 2'b00;
    localparam RUNNING = 2'b01;
    localparam FINISH  = 2'b10;
    
    reg [1:0] state, next_state;
    
    // State register (sequential)
    always @(posedge clk or negedge rst_n) begin
        if (!rst_n)
            state <= IDLE;
        else
            state <= next_state;
    end
    
    // Next state logic (combinational)
    always @(*) begin
        next_state = state;  // Default: stay
        case (state)
            IDLE:    if (start) next_state = RUNNING;
            RUNNING: if (done)  next_state = FINISH;
            FINISH:  next_state = IDLE;
        endcase
    end
    
    // Output logic
    assign busy     = (state == RUNNING);
    assign complete = (state == FINISH);
endmodule

Key Takeaways

  1. Combinational: No memory, output = f(inputs)
  2. Sequential: Has FFs, output = f(inputs + state)
  3. Setup: Data stable BEFORE clock edge
  4. Hold: Data stable AFTER clock edge
  5. Metastability: Use synchronizers for async signals
  6. CDC: Different clocks need special handling