The idea: turn the flip-flops into a shift register for the tester

A chip that comes out of the factory may have a defect: a broken wire, a short, a gate that never switches. A tester can only drive the input pins and watch the output pins. Inside, the state machine's flip-flops are hard to reach. To put a state machine into one chosen state you may need many clocks, or the state may never be reachable at all. And a wrong bit in a flip-flop may never reach a pin. Scan design fixes both problems. It puts a small 2:1 mux in front of every flip-flop. With one extra pin, scan enable (SE), all flip-flops join into one long shift register, the scan chain. The tester can then write any state into it and read any state out of it.

Left: a plain D flip-flop with input D from the logic. Right: a scan cell, the same flip-flop with a 2:1 mux on D. Mux input 0 is D from the logic, input 1 is SI, the scan input from the previous cell. The select is SE. SE = 0 gives normal mode, SE = 1 gives shift mode.
A scan cell is a flip-flop with a mux on D. SE picks the logic (0) or the previous flip-flop (1).

The page uses a 3-flop state machine. Its next-state logic has three gates: G1 makes D0 = Q1 AND Q2, G2 makes D1 = Q0 OR Q2, G3 makes D2 = NOR(Q0, Q1). Wires at 1 are blue and wires at 0 grey. The tester panel shows what it sends, what it expects and what it reads. The clock log has one row per rising edge.

Scan cells and the chain

A mux-D scan cell is a D flip-flop with a 2:1 mux on its D input. In the SkyWater 130 nm library it is the cell sdfxtp_1. Its pins are D (from the logic), SCD (scan data in, called SI here), SCE (scan enable, SE here), CLK and Q. The design tool replaces every flip-flop with this cell and wires each Q to the next cell's SI. On this page the chain is scan_in → FF0 → FF1 → FF2 → scan_out, the same order as the scan step of ASIC Design Flow.

  • SE = 0, normal mode. Each mux passes D. The chip works as designed. Run it with SE = 0 and the machine steps 000 → 001 → 011 → 110 → 010 → 000 (Q0 Q1 Q2). It never reaches 100, 101 or 111 (Demo: normal mode, SE = 0, the FSM runs).
  • SE = 1, shift mode. Each mux passes SI. At every edge FF0 takes scan_in, FF1 takes Q0, FF2 takes Q1, and the old Q2 leaves on scan_out. To load Q0 Q1 Q2 = 0 1 1, scan_in sends 1, 1, 0. The first bit sent travels furthest, to FF2. The chain holds 100, then 110, then 011 (Demo: shift in 011 in 3 clocks). Any of the 8 states can be loaded in 3 clocks, even the three the machine never reaches by itself.

How a flip-flop works and how shift registers move bits is on Sequential Logic and Shift Registers and Counters. This page is about what the mux adds.

Shift, capture, shift

A test pattern for a scan design is a state to load. The tester applies it in three phases.

phaseSEclockswhat happens
shift in (load)1n = 3the pattern goes in bit by bit through scan_in
capture01one normal clock: every flip-flop takes D from the logic
shift out (unload)1n = 3the captured state comes out on scan_out, Q2 first

The capture clock tests the logic between the flip-flops. Load 0 1 1 and the good logic computes D0 = 1·1 = 1, D1 = 0 + 1 = 1, D2 = NOT(0 + 1) = 0. The chip captures 1 1 0. The tester reads scan_out just before each unload edge, so it sees Q2, Q1, Q0 = 0, 1, 1 and compares them with what a good chip must give. One pattern takes 3 + 1 + 3 = 7 clocks (Demo: one test, good chip (7 clocks)). The tester only ever compares bits with stored answers. Its patterns and answers come from an ATPG tool, which is on Stuck-At Fault Testing.

Test time: (n + 1)·P + n clocks

The unload of one response and the load of the next pattern are the same shifts: while the old bits leave on scan_out, the new bits enter on scan_in. So each pattern costs n shift clocks plus 1 capture clock, and only the last response needs extra shifts. With n flip-flops in the chain and P patterns, a test takes (n + 1)·P + n clocks. For n = 3: 1 pattern takes 7, 2 patterns take 4·2 + 3 = 11 (Demo: 2 patterns, unload overlaps load), and all 8 states take 4·8 + 3 = 35 (Demo: all 8 patterns, fast (35 clocks)).

A timeline of 11 clocks for 2 patterns: clocks 1 to 3 shift in pattern 1 with SE = 1, clock 4 captures with SE = 0, clocks 5 to 7 shift out response 1 while pattern 2 shifts in, clock 8 captures, clocks 9 to 11 shift out response 2. Below it the formula (n + 1) times P plus n = 4 times 2 plus 3 = 11.
Unloading one response and loading the next pattern share the same shift clocks.

Real chips have far more flip-flops. With 10,000 flip-flops in one chain and 1,000 patterns, a test takes 10,001 · 1,000 + 10,000 = 10,011,000 clocks: 200.22 ms at a 50 MHz scan clock. Tester time costs money, so designers split the flip-flops into many short chains that shift in parallel, each with its own scan_in and scan_out pin. With 100 chains of 100 flip-flops the same test takes 101 · 1,000 + 100 = 101,100 clocks, or 2.02 ms.

chains × lengthpatternsclocksat 50 MHz
1 × 3 (this page)8350.7 µs
1 × 10,0001,00010,011,000200.22 ms
100 × 1001,000101,1002.02 ms

Finding a stuck-at fault

Pick the fault G1 output stuck-at-0: a defect ties the AND gate's output to 0, so D0 is 0 whatever Q1 and Q2 are. Load 0 1 1 again. The good chip captures 1 1 0, the faulty chip 0 1 0. On the unload the tester reads 0, 1, 0 where it expects 0, 1, 1. The third bit out, Q0, is wrong, so the chip fails (Demo: G1 stuck-at-0 caught by 011).

A pattern finds a fault only if it makes the faulty line take the opposite value. Load 1 0 0 instead: the AND gate sees Q1 = Q2 = 0, so a good chip also has D0 = 0. Both chips capture 0 1 0 and the faulty chip passes (Demo: pattern 100 misses that fault). Of the 8 possible patterns, only 011 and 111 catch G1 stuck-at-0. A different fault needs different patterns: G3 stuck-at-1 forces D2 = 1, and pattern 100 catches it because a good chip computes D2 = NOT(1 + 0) = 0. The tester reads 1, 1, 0 instead of 0, 1, 0 (Demo: G3 stuck-at-1 caught by 100).

Scan is what makes this work for a state machine. Without it, the tester would have to find a sequence of inputs that walks the machine into a state that activates the fault, and then another sequence that carries the wrong bit to a pin. With scan, every flip-flop is both a test input and a test output, so the logic between them can be tested like plain combinational logic, one pattern at a time.

Built-in self test: LFSR and MISR

A chip can also test itself. Built-in self test (BIST) puts the pattern source and the answer checker on the chip. An LFSR (linear-feedback shift register) makes the patterns: with feedback Q1 XOR Q2 (x³ + x² + 1) and seed 100, a 3-bit LFSR gives 100, 010, 101, 110, 111, 011, 001, every state but 000. A MISR (multiple-input signature register) is an LFSR that also XORs each response into its state. After the last pattern it holds a short signature. Only the signature is compared with the good one, so no tester has to store every response.

An LFSR feeds 7 patterns into the scan chain; the captured responses go into a MISR. For the good chip the 7 responses 010, 000, 010, 010, 110, 110, 011 end in signature 111. With G1 stuck-at-0 the responses for 111 and 011 become 010, and the signature is 100. With G3 stuck-at-1 the signature is 110.
Seven LFSR patterns, one 3-bit signature: 111 for a good chip, 100 or 110 with a fault.

In the figure the MISR starts at 000 and folds in one 3-bit response per pattern. The good chip ends at 111. G1 stuck-at-0 changes two responses (for patterns 111 and 011) and the signature ends at 100. G3 stuck-at-1 ends at 110. A short signature can hide a fault when a wrong set of responses happens to give the good signature (aliasing). With a k-bit MISR the chance is about 2−k, so real MISRs are 32 bits or more. The LFSR itself is on Shift Registers and Counters.

What scan costs

  • Area. Each flip-flop gets a mux. In sky130, dfxtp_1 is 20.02 µm² and sdfxtp_1 is 26.28 µm², about 30 % more per flip-flop.
  • Delay. The mux sits on the D path, so every path into a flip-flop gets a little longer.
  • Pins and wires. scan_in, scan_out and SE per chain, and a wire from each cell to the next.
  • Power. During shifts almost every flip-flop toggles at once, more than in normal use, so scan clocks run slower than the system clock.

See also Stuck-at Faults and Test Generation for the combinational test generation that scan chains make possible.

What the page leaves out

  • How patterns are chosen. ATPG, fault lists and fault coverage are on Stuck-At Fault Testing.
  • Primary inputs and outputs. The state machine here has none; a real test also drives input pins and strobes output pins during capture.
  • At-speed tests. Delay faults need two fast capture clocks (launch and capture), not one slow one.
  • Test compression, JTAG (IEEE 1149.1) boundary scan, and partial scan.
  • Serial BIST. Real logic BIST shifts the LFSR's bits into many chains and folds the scan_out streams into the MISR bit by bit; the figure folds whole responses.

On the mind map

Open the Computer Architecture mind mapComputerArchitectureAbstraction and numbers: layers and bit patternsAbstraction and numbersCombinational logic: output depends only on inputsCombinational logicSequential logic: state held by a clockSequential logicMIPS software: how C becomes machine wordsMIPS softwareThe processor: datapath plus controlThe processorPipelines and parallelism: more instructions at oncePipelines and parallelismMemory and I/O: small fast near, big slow farMemory and I/OLatches and flip-flopsLatches and flip-flopslatch is level, flip-flop is edgeFlip-flops and counter designFlip-flops and counter designexcitation = characteristic backwardsLatch from transistorsLatch from transistorstransmission gates plus inverter loopCMOS layout, DRC, LVSCMOS layout, DRC, LVSDRC: can it be built? LVS: right circuit?Timing analysisTiming analysissetup limits clock, hold limits short pathsAsync FIFO (CDC)Async FIFO (CDC)Gray pointers cross; flags clear lateStuck-at fault testingStuck-at fault testingActivate, propagate, justify: D-algorithmStatic Timing AnalysisStatic Timing AnalysisSlack = required − arrival, every nodeLogical effort sizingLogical effort sizingd = gh + p; equal effort F^(1/N)Scan chainsShift in, capture once, shift outFinite state machinesFinite state machinesMoore: output from state; Mealy: +inputsASMD chart and datapathASMD chart and datapathTransfers land at the edge leaving the state1011 Sequence Detector1011 Sequence DetectorA wrong bit keeps the longest prefixFSM in SystemVerilogFSM in SystemVerilogenum, always_ff, always_comb; default!Shift registers and countersShift registers and countersChained flip-flops shift or count each clockOpen the Computer Architecture mind mapComputer Architecturestate held by a clockSequential logicLatches and flip-flopsLatches and flip-flopslatch is level, flip-flop is edgeFlip-flops and counter designFlip-flops and counter designexcitation = characteristic backwardsLatch from transistorsLatch from transistorstransmission gates plus inverter loopCMOS layout, DRC, LVSCMOS layout, DRC, LVSDRC: can it be built? LVS: right circuit?Timing analysisTiming analysissetup limits clock, hold limits short pathsAsync FIFO (CDC)Async FIFO (CDC)Gray pointers cross; flags clear lateStuck-at fault testingStuck-at fault testingActivate, propagate, justify: D-algorithmStatic Timing AnalysisStatic Timing AnalysisSlack = required − arrival, every nodeLogical effort sizingLogical effort sizingd = gh + p; equal effort F^(1/N)Scan chainsShift in, capture once, shift outFinite state machinesFinite state machinesMoore: output from state; Mealy: +inputsASMD chart and datapathASMD chart and datapathTransfers land at the edge leaving the state1011 Sequence Detector1011 Sequence DetectorA wrong bit keeps the longest prefixFSM in SystemVerilogFSM in SystemVerilogenum, always_ff, always_comb; default!Shift registers and countersShift registers and countersChained flip-flops shift or count each clock
This page on the Computer Architecture mind map · 76 pages in 7 branches · open it to see the whole map and test yourself in recall mode.