Wednesday, March 21, 2018

FPGA selection for beginners

I'm not particularly expert on FPGAs, but I feel like sharing some of the thought process and research I did in getting into tinkering with FPGAs to help other people contemplating such things.

Why FPGAs?

FPGAs are the go-to solution for "digital things that can't be done with Raspberry Pi, Arduino, or other microcontroller plus software." If you want more than a handful of discrete digital devices in your project, an FPGA (or its smaller cousin, a CPLD) can be whatever collection of gates you need. From a more industrial perspective, they are a stepping-stone to the kind of large-scale digital design that goes into developing ASICs and high-powered DSP solutions.

I'll probably discuss later some of the things that are probably not suited for FPGAs and assume for now you at least understand what they are, what they can do, and you just really, really want to use one. You want to buy an FPGA for good reasons and can't decide which: how to choose?

Choose a project before a board

I would first suggest you have at least some kind of concrete project idea in mind first. If your idea goes beyond "blink an LED", you are probably going to need at least some basic connections to other things in the real world, and that constrains your selection.
  • Do you want images to appear on a VGA or HDMI display?
  • Do you want to capture still images or video from a camera?
  • Do you want your thing to connect to an Ethernet, WLAN, Bluetooth, or other network?
  • Is your project going to connect to a USB keyboard, mouse, or itself be a USB peripheral?
  • Do you want to capture or produce audio?
  • Do you want more than 10 digital I/O?
  • Will your project require MB of RAM?
  • Is there going to be a large software component to your project?
This doesn't mean you need a full project plan and design in hand. Maybe you can look at some of the many projects demonstrated on blogs or YouTube videos and say "I'd like to have one of those."

FPGA development has a higher barrier both in terms of cost, difficulty, and complexity than a Raspberry Pi or Arduino. If you don't have a goal in mind, it's harder to maintain your motivation. Furthermore, if you pick a board without these constraints in mind, you might well have to spend another $100 or more on the right board before you can do anything useful.

Most of the constraints are straightforward: if you want to connect to Ethernet, HDMI, or USB, having the appropriate PHY components on board is perhaps essential, and hard to add after the fact. FPGAs are typically weak in A/D and D/A. They have massive I/O but not all boards provide them.

The "external memory" and "software component" points get at some of the broad divisions I would make in the FPGA landscape.

SoC or non-SoC

First, the difference between "SoC" and non-SoC FPGA architectures. SoC stands for "system on a chip", but in FPGAs invariably refers to "hard-core processor." A Xilinx Zynq device includes one or more ARM cores (and a bunch of peripherals) integrated with the FPGA fabric. Intel/Altera do the same, and use an "SoC" qualifier in the product name. These devices mean it is trivial to run Linux or another ARM operating system on the devices without using up any of the logic gates. In contrast, if you don't have an ARM core, but want traditional processing available, you will have to give up a bunch of FPGA resources to a "soft-core" processor like the Xilinx Microblaze or Altera/Intel Nios, which will be much slower than the ARM, and be less compatible with other ARM development.

SoC means you have a powerful processor for free, but also means you need to deal with additional complexity in the project development environment. A plain FPGA can literally be configured as a single NAND gate or 24-bit counter in a dozen lines of code, and get LEDs to do things that depend on switches. An SoC device needs some minimum configuration to put the hard cores into a reasonable state. Many of the external connections on the SoC device board will be dedicated to the ARM core or its associated bus. The vendor IDEs that control these things are made for complex SoC projects, exporting the SoC configuration to independent software teams with GUI-based wizards and huge pages of options, which gets in the way of beginner HDL development.

At this point, if you are thinking "sure, I need all of that to develop my ARM-based operating system" you should double-check that you don't really want a cheaper, lower-overhead solution like a Raspberry Pi. In particular, if you are thinking "I want to design my own ARM CPU," you probably don't. ARM is complex, and protected by ARM lawyers. If you manage to design an ARM-like CPU without infringing on patents, it will be dog-slow compared to a hard core version. Finally, if you really are going to design your own CPU, the software effort will be comparable to the digital design effort, and you will want your own software-based emulation of your architecture to do that. Which brings up the part of the process known as "FPGA Hell."

Your board won't work until it works without a board

Almost certainly, your first project will be downloaded to an FPGA board and literally nothing will happen. Well, something will happen, but you won't see it. You might not even be able to measure it with an oscilloscope or logic analyzer. How do you proceed? Well, you double-check your simulation results and enhance your test bed to check for problems in your design. Your $100 FPGA board was no help. In fact, before you get it to work on that board, you will have to spend a bunch of time figuring out how to simulate and verify your design without touching the hardware. So why not try that first before you spend any money at all?

Working without a board

Download one of the free development environments. From Xilinx, the Vivado WebPack is what you want, the older ISE is necessary if you are targeting old Spartan 6 or other pre-"7" product lines, but you probably should avoid that. For Altera/Intel devices "Quartus Prime Lite" are freely available. Or, try a free HDL environment like GHDL or Icarus Verilog. Figure out how to write a simple design like a counter and verify that it works by coding an HDL test bench or by looking at simulated digital environment. Maybe the desire to use an FPGA will wear off, or at least you will have a few more days to think about which board you want.

Getting back to board selection, external memory is a big differentiator in FPGA boards. Adding a high-capacity RAM to a board that doesn't already include it is impossible or not worth the trouble. If your project needs MB of RAM for high-level software or to hold the images, video, or audio data your device is processing, you will want that on the board. FPGAs with GB of RAM in the package do exist, but you can't afford them for home use, or the license for the development tools that support these high-end chips.

High-performance is not hobby territory

Generally speaking, if you need to use high-speed digital connections like PCI or LVDS, you will be looking at high-performance chips that are not supported by the free editions of the software. You likely won't be able to afford the chips or development boards, either. And, no, mining cryptocurrency will not pay for your hobby: cryptocurrencies are now being designed specifically to defeat FPGA implementations, and real ASICs that cost many thousands of dollars are sucking away all available profit until the bottom falls out.

Other board criteria

Another differentiator in these boards is design quality and the availability of tutorial and educational material to get started. Digilent (for Xilinx) and Terasic (for Intel/Altera) seem to be the primary vendors targeting the academic market: you get academic discounts if you have a .edu e-mail address, they come with plenty of documentation and sample projects, and are used by lots of university classes with their own material online.

Cheap online marketplace knockoffs and eBay used boards are to be avoided. You don't want to have to reverse engineer where an unknown, inaccessible engineer took shortcuts or had a component changed because it was a  few cents cheaper in the Shenzhen market. A used board is likely going to be an older FPGA that might not be supported by the current development tools.

Development tools tend to be very finicky about exactly which OS host they are on. I ran into real problems using a 2016 Vivado release on Ubuntu 16.04 because of a showstopper bug on Xeon processors, where the solution was "use Ubuntu 14.04 or wait for the next Vivado release." Be prepared to dedicate your development machine to match what the FPGA vendor wants. Synthesis and place-and-route can easily demand 8 GB of RAM or more. I build a dedicated Linux machine for this purpose, and running a VM on an Intel Mac was significantly slower.

A few random boards

Digilent Arty A7: this is what I bought. $99 is a pretty good price, it comes with external RAM and Ethernet. Somewhat limited I/O. The Artix is the non-SoC Xilinx line, so the "run Linux" examples are using the Microblaze architecture, and you use a noticeable fraction of the FPGA on the memory interface.  I don't understand the appeal of the S7 version which lacks the Ethernet in exchange for more logic.

Digilent Basys 3: targeted at education, but has no external RAM. In my mind, that severely limits what you can do with it. It has an external VGA port built-in, but where are you going to store the images to appear on the screen?

Digilent Zybo Z7: This is an SoC Zynq based line, and is the newer replacement for other Digilent Zybo chips. You get the ARM core(s) plus a bunch of peripherals, but it's pricier.

$200 is my rough ceiling for "you can't afford the project even if you can afford the board." If you are experienced enough to know why you want an expensive board, you don't need my advice.

Terasic: I find their product line confusing. But the same principles apply: SoC variants and external RAM and peripherals take on lots of different combinations. If you need to pay more than $200 on the board, you probably are buying too much board.

Numato: they have a couple intriguing sub-$50 boards (Elbert v2, Mimas v2), but use older Spartan chips. 

Nandland Go Board: a good effort for introductory materials. I think they are very limited in peripherals and capability, and you are probably better off with a slightly pricier board.

Lattice "ICE40" and similar boards: Lattice is a third- or fourth-place vendor in the market. The main attraction here is "completely free development toolchain" which is a defensible ideological position, but the chips that support that ideology are small and limited compared to the Xilinx and Intel/Altera options.

Xess.Com: has a couple of compact boards, and a number of interesting PMod expansion boards. All open-source designs, and a introductory book FPGAs, Now What? [PDF] which I found useful even though I was retargeting it to my Arty board.

Other introductory material

This is a very complex technology, where the technology goes through a bunch of product evolution, so material goes quickly out-of-date. The educational board vendors (Digilent & Terasic) seem to do a pretty good job of maintaining introductory demonstration projects.

I found it useful to use the Xess "FPGAs, Now What?" book, along with Free Range Factory's "Free Range VHDL" book. Peter Ashenden's The Designer's Guide to VHDL is a thorough introduction to the VHDL language which was useful as a follow-on. I was somewhat disappointed in Blaine Readler's VHDL By Example, which seemed to veer away as soon as it approached any tricky part of the language.

I think a strong case can be made that System Verilog is preferable to VHDL. The main drawback of Verilog is a much weaker approach to typing, which allows it to be more concise as well. It superficially resembles C, but resemblance to software languages is more of a trap than a help. One must always remember that the process of FPGA development is designing hardware (on which software may run).


  1. Nice overview.

    Just wanted to mention that "FPGA Hell" can be mitigated by Altera/Intel's SignalTap and Xilinx's Vivado Debug and Integrated Logic Analyzer (ILA) blocks which allow you to capture waveforms of the signals inside your FPGA design.

    Sure, simulation ideally catches all of your design issues but that's the nominal case. Also that leap to writing testbenches can be daunting for beginners. It can be nice when you're starting out to be able to see your signals.

    I also recommend that beginners play around with Xilinx's Virtual I/O blocks (I'm not sure if Altera has an equivalent). You can set and monitor signals as if they were brought out to switches or LEDs, but you can control and see them virtually in Vivado. It's also a nice introduction to using an IP flow where you specify the parameters of a block, generate it, and instantiate it in your design.

    1. Thanks for the comment. Getting used to the vendor's debug tools is essential, but for the complete beginner, I think you are as likely to run into problems getting the debug tools to work as they are to help. If you are able to get SignalTap or ILA to give useful information, you are likely to be beyond the "my LED doesn't blink" stage.

      Re: the "virtual I/O blocks", thanks for the pointer. It looks to me like Terasic's demo apps for their Altera boards all have a GUI with point and click, but I don't know what is behind that.