A taste of FPGAs: designing hardware in code
An MCU executes instructions in order; an FPGA changes the circuit itself. How the two differ and when an FPGA is needed.
Inside an FPGA (Field Programmable Gate Array) are tens of thousands of small logic blocks and the routing switches that connect them. Load a configuration file and the digital circuit you want is formed inside the chip.
How it differs from an MCU
| MCU | FPGA | |
|---|---|---|
| Operation | Instructions one at a time, in order | Every circuit at the same time |
| Language | C | Verilog, VHDL |
| Strength | Easy and cheap to develop | Nanosecond response, massive parallelism |
| Weakness | Only the peripherals it comes with | Design difficulty and price |
What one line of Verilog means
always @(posedge clk) count <= count + 1;
It looks like count++ in C, but this code creates a circuit: "an adder and a register that add 1 on every clock". The biggest shift in thinking is that the code is not executed; a circuit comes into being.
When to use an FPGA
When processing fast ADC data in real time, when synchronising tens of PWM channels precisely, or when an MCU simply has no time, as in pre-processing camera video. Recently, products with an ARM core and an FPGA in one chip (Zynq and others) are also widely used.