Digital System Design
CPLDs vs FPGAs
Once a design grows beyond a handful of gates, wiring individual chips together stops being practical. Programmable logic lets you build the circuit inside a single device by loading a configuration. The two main families are the CPLD (Complex Programmable Logic Device) and the FPGA (Field-Programmable Gate Array). They solve similar problems in very different ways, and knowing which to pick is a core skill in digital system design.
Learning objectives
By the end of this lesson you will be able to:
- Describe the internal structure of a CPLD and of an FPGA.
- Explain what a look-up table (LUT) is and write its configuration bits.
- Estimate how many LUTs a wide function needs.
- Choose between a CPLD and an FPGA for a given requirement.
How a CPLD is built
A CPLD is a collection of PAL-style blocks joined by a central switching matrix. Each block contains a programmable AND array that feeds a fixed OR gate, which gives a sum of products, followed by a macrocell. The macrocell holds a flip-flop and a multiplexer that lets the output be registered or combinational.
Key properties of a CPLD:
- Product-term logic. Functions are implemented as sums of products, so wide AND-OR logic maps naturally.
- Non-volatile configuration. Most CPLDs store their configuration in flash or EEPROM cells on the chip, so the design is active the moment power is applied.
- Predictable timing. Every signal passes through the same switching matrix, so pin-to-pin delay is nearly the same for every path.
- Modest size. A CPLD typically holds from a few dozen to a few thousand macrocells.
How an FPGA is built
An FPGA is an array of small configurable logic blocks surrounded by a sea of programmable routing. Each block contains one or more look-up tables and flip-flops. Modern devices also include dedicated block RAM, multiplier or DSP blocks, clock management and high-speed I/O.
A k-input LUT is a tiny memory with 2^k storage bits. The k inputs act as the address, and the stored bit at that address is the output. Because the stored bits can be anything, a k-input LUT can implement any Boolean function of k variables. A 4-input LUT has 16 configuration bits and a 6-input LUT has 64.
Key properties of an FPGA:
- LUT-based logic. Arithmetic, state machines and random logic map well to LUTs and flip-flops.
- Volatile configuration in most devices. The configuration is held in SRAM cells, so it must be reloaded from external flash or a processor every time power is applied. Some families use flash cells instead.
- Large capacity. Devices range from thousands to millions of LUTs.
- Routing-dependent timing. Delay depends on how far apart the placed blocks are, so timing is known only after place and route.
Side-by-side comparison
| Feature | CPLD | FPGA |
|---|---|---|
| Basic logic element | Product-term block and macrocell | LUT and flip-flop |
| Configuration storage | Usually non-volatile | Usually SRAM (volatile) |
| Instant-on at power-up | Yes | No, needs a load step |
| Timing | Predictable | Depends on routing |
| Capacity | Small to medium | Medium to very large |
| Embedded memory and DSP | Rarely | Common |
| Typical use | Glue logic, simple controllers | Processing, interfaces, prototypes |
Worked example 1: Writing the LUT configuration
Implement F = AB + C'D in a 4-input LUT with inputs ordered A, B, C, D, where A is the most significant address bit.
Step 1. List which addresses make F equal to 1.
- AB = 1 when A = 1 and B = 1: addresses 1100, 1101, 1110, 1111, which are 12, 13, 14, 15.
- C'D = 1 when C = 0 and D = 1: addresses 0001, 0101, 1001, 1101, which are 1, 5, 9, 13.
Step 2. Combine them. F is 1 at addresses 1, 5, 9, 12, 13, 14 and 15, and 0 at the other nine.
Step 3. Write the stored bits from address 0 to address 15:
| Address | 0-3 | 4-7 | 8-11 | 12-15 |
|---|---|---|---|---|
| Stored bits | 0100 | 0100 | 0100 | 1111 |
The full 16-bit configuration is 0100 0100 0100 1111. Loading these bits is exactly what "programming" the LUT means. You can confirm any entry with the truth table generator.
Worked example 2: Counting LUTs for a wide function
An AND of n inputs is associative, so it can be built as a tree. Each k-input LUT combines up to k signals into one, which removes k - 1 signals from the pool. The number of LUTs is therefore the smallest whole number that reduces n signals to 1:
LUTs = ceil((n - 1) / (k - 1))
For 4-input LUTs, k - 1 = 3.
- 8-input AND: ceil(7 / 3) = 3 LUTs. Two LUTs each take four inputs, and a third LUT ANDs their two outputs.
- 16-input AND: ceil(15 / 3) = 5 LUTs. Four LUTs take four inputs each, and a fifth combines the four results.
- 7-input parity (XOR): ceil(6 / 3) = 2 LUTs. The first LUT takes four inputs, and the second takes its output plus the remaining three.
This formula works for AND, OR and XOR chains. Functions that are not associative can need more LUTs, so treat it as a lower bound for general logic.
Worked example 3: Macrocell capacity in a CPLD
Suppose each macrocell in a CPLD provides 5 product terms. A function written as a minimal sum of products with 8 terms does not fit in one macrocell.
- Terms needed: 8.
- Terms per macrocell: 5.
- Macrocells needed: ceil(8 / 5) = 2.
Many CPLDs let a macrocell borrow product terms from a neighbour, but borrowing adds delay. This is one reason CPLD timing is only predictable for functions that fit the available terms. Simplifying your logic first, for example with the K-map solver, reduces the term count directly.
Choosing the right device
Ask these questions in order:
- Must the circuit work immediately at power-up with no external memory? That points to a CPLD.
- Does the design need memory blocks, multipliers or tens of thousands of logic cells? That points to an FPGA.
- Is cost and power for a tiny design the main concern? A CPLD is often simpler and cheaper.
- Will the design change often during development? Both are re-programmable, but FPGAs offer far more room to grow.
Common mistakes
- Treating a LUT as a gate. A LUT is a memory. Its cost does not depend on how complicated the function looks, only on the number of inputs.
- Forgetting FPGA configuration is volatile. A board with an SRAM FPGA needs a configuration source, and it takes time to load.
- Assuming FPGA timing is fixed. Two builds of the same design can have different delays after routing.
- Ordering LUT inputs inconsistently. Decide which input is the most significant address bit before writing the bits.
Practice problems
Problem 1. How many configuration bits does a 5-input LUT hold?
Answer: 2^5 = 32 bits.
Problem 2. How many 4-input LUTs are needed for a 13-input AND?
Answer: ceil(12 / 3) = 4 LUTs.
Problem 3. Write the 16-bit configuration of a 4-input LUT (inputs A, B, C, D, A most significant) that implements F = A XOR B.
Answer: 0000 1111 1111 0000. The output is 1 when A and B differ, which is addresses 4 to 11. Inputs C and D do not affect it.
Problem 4. A small controller must start working the instant power is applied and has only 40 macrocells worth of logic. Which device fits best?
Answer: A CPLD, because its configuration is usually non-volatile and the design is small.
Frequently asked questions
Is an FPGA faster than a CPLD? Not always. An FPGA can run far more logic in parallel and at higher clock rates, but a CPLD gives short, predictable delays for simple logic. Speed depends on the design.
Can an FPGA replace a microcontroller? Yes, an FPGA can implement a processor core or do the job directly in hardware. A microcontroller is usually easier and cheaper when the task is mostly sequential software.
Why do FPGAs need a configuration file? Because most store their logic in SRAM, which loses its contents without power. The file, called a bitstream, is loaded each time the device starts.
Next lesson: continue with Introduction to Verilog to start describing these circuits in a hardware description language.