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.
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.
| phase | SE | clocks | what happens |
|---|---|---|---|
| shift in (load) | 1 | n = 3 | the pattern goes in bit by bit through scan_in |
| capture | 0 | 1 | one normal clock: every flip-flop takes D from the logic |
| shift out (unload) | 1 | n = 3 | the 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)).
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 × length | patterns | clocks | at 50 MHz |
|---|---|---|---|
| 1 × 3 (this page) | 8 | 35 | 0.7 µs |
| 1 × 10,000 | 1,000 | 10,011,000 | 200.22 ms |
| 100 × 100 | 1,000 | 101,100 | 2.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.
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_1is 20.02 µm² andsdfxtp_1is 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
References
Bushnell and Agrawal, Essentials of Electronic Testing for Digital, Memory and Mixed-Signal VLSI Circuits, chapters 14 (scan design) and 15 (BIST)
Weste and Harris, CMOS VLSI Design, 4th ed., section 15.6 (design for testability)