How do FPGAs work and when are they used?


Im really confused by what field programmable gate arrays are and what they do. What is digital logic also and how do FPGAs relate to CPUs? Please eli5

In: Engineering

Wait, you don’t understand digital logic? Then you don’t stand a chance of understanding FPGAs. So let’s start there:

Digital logic circuits do (almost) everything based on “logic states”, and there are only 2 possible states in a binary digital logic circuit. We call these “on and off”, or “true and false”, or “1 and 0”. For example, imagine a light bulb wired to a battery through two switches in series, A and B. The light is turned on only if both A *and* B are turned on. So that’s a binary digital logic AND gate.

Make the same circuit, but put switches A and B in parallel. That’s an OR gate.

In integrated circuits, we use transistors in stead of switches. They operate a lot like tiny electronically-controlled switches. And we make other logic gates besides AND and OR. And more complex things made of logic gates.

Putting lots and lots of them together with various gates’ outputs feeding the inputs of others, and those feeding the inputs of others, allows the construction of very complex logical computations. That’s how we build up very complex devices like microprocessors (CPUs). You can make binary digital logic gates do a lot of things if you are willing to use lots and lots of them.

An FPGA contains a lot of logic gates built up into standard groups. They also contain the equivalent of fuses which can allow those units to be configured and connected to each other in a variety of ways. Using those “fuses” and configuring the FPGA correctly, you can build up a custom circuit virtually of your choosing. A lot of stuff gets wasted, but it’s still a hell of a lot cheaper to make a small number of custom programmed FPGAs than it is to make truly custom-designed integrated circuits. It only becomes economical to make true custom ICs if you can sell a lot of them.

disclaimer : I’m not trained in any of this I’m just a nerd and starting to mess around with fpga’s. if anything is patently wrong and there are people qualified to correct me here I’d welcome it.

digital logic as I understand it is a combination of boolean algebra and digital circuit design. a digital circuit is a circuit that has two types of signals high and low voltages (current?) and are typically represented with 1s and 0’s. boolean algebra is a type of mathematics that has only two values (1’s and 0’s) it happens to map nicely on to digital circuit design because we can think of circuits as functions and use mathematics to compose and simplify circuits the and and or logic gates are analogous to boolean multiplication and addition. there are also not gates and a negation operator.

there is neat bit of math that any boolean expression can be written as the sum of products ( xd + xa + bd …. ) = some expresion (or alternatively as the product of sums) since they are analogous (isomorphic???) to the and or and not gates of a digital circuits it implies that any digital circuit can be made out of only those three gates.

fpgas and cpus are similar in that they are both machines without a fixed functionality beforehand but the mechanism by which they work is different.

a cpu on its own is not particularly interesting (its just a finite state machine I guess) but is more interesting in conjunction with computer memory. in order to understand how a cpu works you need to understand two simpler machines multiplexers and de-multiplexers

multiplexers take a set of input signals and output a single signal.

de-multiplexers take a single input signal and output a set of signals.

multiplexers are useful in that they let you filter out signals that are on the compute (all the components are connected in common to a “bus”) but not meant to turn on a specific component the best example would be computer memory each “cell” of memory has a “address” (multiplexer) data sent without that “address” won’t be saved in that cell.

de-multiplexers are useful in that they let you coordinate components say you want a computer to load a piece of memory into another location in memory (maybe you want to add it to something first) in order to do that the memory cell that has the value to be loaded must be “told” to send what’s in it’s memory and another memory “cell” has to be “told” to listen simultaneously.

multiplexers and de-multiplexers can be put together so that one set of signals will produce another. this is the mechanism behind how a cpu works the cpu has a set of multiplexers that listen for “instructions” those “instructions” turn on the circuitry required to do what the “instruction” is supposed to do. the computer works then by via a small program or a special set of circuitry called a control matrix (more mux de-mux stuff) reads through computer memory sequentially (unless told to jmp) the cpu “reads” each instruction via a multiplexer and executes the instruction via de-multiplexer. crucially the only component of hardware that really changes is the contents of computer memory. the functionality of the cpu (its instruction set) is fixed as are its peripherals (mostly)

a fpga is a machine thats programmability comes from the ability to connect and disconnect internal components between it’s input and output instead of reading signals from a mutable source (memory) and executing fixed outputs like a cpu. I’d say it’s sort of like a programmable breadboard instead of cpu.

I’m sure it’s more complicated in production but as mentioned above you can represent any digital circuit with nothing but nand gates (or nors) so if you had a set of switches that either included a nand gate or excluded it from the path from the input to the output you could make a arbitrary circuit. importantly by flipping those switches you are physically connecting the input to the output its not being “processed” the electricity just goes from point A to point B this is relevant because one it can be faster. it can actually run things in parallel not just fake it like a cpu. and some others.