FPGAs 101: A Beginner’s Guide
For the binary minded among you, no you haven’t missed parts 1 through 4. This is a brief introduction to my favorite electronic device: the Field Programmable Gate Array (FPGA). When I talk to people about FPGAs, I hear a lot of statements like, “I don’t know how they work,” “They’re too complicated,” or “I can’t program them in C.” Because I’d hate to see such amazing devices brushed off so easily, I’ll attempt to address some of these common concerns below.
What is a Field Programmable Gate Array?
Here’s the long answer: From the name, one might infer that it is a programmable structure of logic gates. This is close, but not accurate because the internal logic array isn’t actually implemented with gates. Instead, we refer to the blocks in the array as logic elements. These normally consist of a lookup table (LUT) that implements an arbitrary logic function as well as some supporting circuitry like multiplexers, adders, and flip-flops. You’ll often hear this array of logic elements referred to as the “FPGA fabric.”
Figure 1: Sample of an FPGA logic element. (Image source: Wikimedia Commons)
To simplify, I like to think of an FPGA as a box of colorful, non-trademarked building blocks for creating digital circuits. I can connect the blocks together any way that I want to fit my application. If you can describe how a digital circuit behaves, you can create it inside an FPGA with enough logic elements. Need 25 PWM outputs? No problem. Need a special communication protocol? Write some hardware to handle it.
Why would I need an FPGA?
An FPGA is used to implement a digital system, but a simple microcontroller can often achieve the same effect. Microcontrollers are inexpensive and easy to drop down on a PCB. FPGAs are powerful tools, but may not be a good fit for every case. They have more power, layout, and external circuit requirements that can be prohibitive. Using an FPGA that is considerably more expensive and has lots of special requirements might seem like a ludicrous notion.
You may have already guessed the first reason you might need an FPGA: flexibility. Having configurable logic blocks means you’re never stuck with your hardware. You can never run out of timers or UARTs as long as you have logic elements available to create another one. Being able to reconfigure down the road can also extend the life cycle of a product as technology and requirements change.
The second reason is speed. A microcontroller executes instructions one at a time, sequentially. An FPGA structure is inherently parallel because of its hardware nature. This allows things to occur simultaneously which is useful for operations like the FFT or graphics processing which can be expensive on a sequential processor. FPGAs also have more high-speed I/O options than a typical microcontroller like LVDS and transceivers capable of 10+ Gbps for protocols like HDMI.
How do I program an FPGA?
FPGAs use a special type of language called HDL, or Hardware Description Language. There are two primary flavors: Verilog and VHDL. Nearly every development suite like Quartus or Vivado will support both so which you decide to use is a matter of preference. These languages are then “synthesized”, which is analogous to compilation for microcontrollers. The synthesis tool tells the FPGA how to connect its logic elements to create the effect described by your code. Remembering that your code is being translated into hardware and not CPU instructions is important to remember when you’re first getting started.
To make development easier, FPGA vendors supply you with a catalog of commonly used code blocks that can be easily dropped into a design. These include things like multipliers, RAM, communication blocks, and more. They can be configured and added into your design without ever having to look at the HDL code involved, speeding up your development time.
Figure 2: Partial block diagram showing IP blocks from Xilinx’s catalog and HLS. (Image source: eewiki.net)
Some vendors also have High Level Synthesis (HLS) tools that can translate a function written in C or C++ into a block of HDL code. Using these tools greatly reduces the barrier to entry for developers with a software background by abstracting away some of the low-level details.
Still not convinced? One of my favorite features of an FPGA is the ability to use a soft processor. This is a complete processor built from the FPGA’s logic elements. With this, you can build custom supporting hardware for the processor and write your application in C. A simple soft processor system can be set up and programmed in just a few minutes. If you still need a traditional processor, take a look at SoCs which have an FPGA and a hard ARM processor in a single package.
To summarize, FPGAs are more expensive and more difficult to work with than a typical microcontroller, but they can offer much more power and flexibility should you require it. As technology improves and FPGAs become less expensive with higher levels of integration, they could even replace traditional microcontrollers. So, if any of this sounds interesting to you, get started with FPGAs now so you can stay ahead of the curve. If you’re looking for a low-cost development board to start with, check out these boards featuring each of our FPGA suppliers: the DE10-Lite from Terasic, the Arty from Digilent, the Mobile Dev Board from Lattice, or the Maker Kit from Microsemi.