VLSI_Toolkit

Interactive chip-design tools for beginners

Number conversion, MOSFET, RISC-V, pipeline, timing and FSM tools for chip design. Free, and it all runs in your browser.

Buy us a chai
Word width

K-Map Solver

✓ Tested Prime implicants are checked against a brute-force search of every cube, minimal SOP and POS against an exhaustive search, every form on every input, and the generated Verilog in Icarus Verilog with its own testbench, every night.

Function

Variables

Click a cell on the map to switch it between 0 and 1; switch to Click: X (or right-click a cell) to mark don't cares. Or type m(1, 3, 7) + d(5), maxterms M(0, 4), or an expression such as A'B + C.

Karnaugh map

Rows and columns run in Gray code (00, 01, 11, 10), so neighbouring cells differ in one input, and the edges wrap round. A group of 2k cells drops k inputs. Tap a term to pick out its group.

Optimized

Prime implicants

Prime implicant chart

A column with a single ✕ is a minterm only one prime covers: that prime is essential. Don't cares are not columns: they may be covered but never have to be.

How it was solved

Verilog


        
Self-checking testbench

          

Runs every input combination, skips the don't cares and prints PASS or each mismatch. iverilog -o sim kmap.v tb.v && vvp sim

Notes

Reading a K-map
  • Each cell is one minterm; the small number is its index (the inputs read as a binary number, first input most significant).
  • Group 1s in rectangles of 1, 2, 4, 8 or 16 cells. Groups may wrap round the edges and may overlap. Bigger groups give shorter terms.
  • Inside a group, an input that changes is dropped; one that stays 0 appears complemented (A′), one that stays 1 appears as is (A).
  • Five variables use two 4 × 4 maps, one for A = 0 and one for A = 1. Cells in the same place on both maps are neighbours, so a group can sit on both.
SOP and POS

Grouping the 1s gives a sum of products (SOP): AND gates feeding an OR, or NAND–NAND. Grouping the 0s gives F′ as an SOP; De Morgan turns it into a product of sums (POS): OR gates feeding an AND, or NOR–NOR. Neither is always smaller, so the tool builds both.

Don't cares

An input combination that never happens (BCD codes 10 to 15, for example) is a don't care, X. It may be covered if that makes a group bigger, and left out otherwise. Prime implicants may use them; the cover only has to reach the real 1s.

Quine–McCluskey and Petrick's method

The K-map is the picture; Quine–McCluskey is the same idea as a procedure, so it works for any number of inputs. List the minterms by how many 1s they have, merge pairs that differ in one bit (writing − for the dropped bit), and repeat until nothing merges. Whatever never merged is a prime implicant.

The chart then shows which primes cover which minterms. Essential primes go in first. If some minterms are still uncovered, Petrick's method writes the choice as a product of sums, (P1 + P2)(P2 + P3)…, multiplies it out and keeps the cheapest product: fewest terms, then fewest literals. This tool searches that choice exactly, so the SOP and POS it gives are truly minimal.

Beyond two levels: factoring and XOR

Factoring pulls common pieces out of the minimal SOP or POS: AC + BC + AD + BD = (A + B)(C + D), 4 literals instead of 8. Fewer literals means fewer transistors and less wiring; the price is more gate levels.

XOR forms help where K-maps cannot: a checkerboard map (parity, adders, comparators) has no two adjacent 1s, so its SOP is as long as possible, while A ⊕ B ⊕ C needs only three literals. The tool computes the Reed–Muller form (an XOR of AND terms) for every choice of complemented inputs and keeps the shortest.

The optimized expression is the form with the fewest literals, then the fewest 2-input gates.