Comparing Common Digital Logic Components

Despite how far they’ve come since their early days and the wide range of applications they’re used for, FPGAs are still a relatively niche technology compared to other digital logic components like microcontrollers and ASICs. In this section, we’ll compare these three technologies. You’ll see why FPGAs are a good solution for some problems but not others, and how they have tough competition from other devices, especially microcontrollers.

FPGAs vs. Microcontrollers

Microcontrollers are everywhere. If you aren’t an embedded software engineer, you may not realize how many toys, tools, gadgets, and devices are controlled with small and inexpensive microcontrollers: everything from TV remote controls to coffee makers to talking toys. If you’re an electronics hobbyist, you might be familiar with the Arduino, which is powered by a small microcontroller from Atmel (now Microchip Technology, the same company that owns what used to be Actel). Millions of Arduinos have been sold to hobbyists around the world. They’re cheap, fun, and relatively easy to work with.

So why are microcontrollers everywhere, but not FPGAs? Why isn’t there an FPGA controlling your coffee maker or making your Elmo doll come to life? The main reason is cost. The consumer electronics industry, which uses the largest number of microcontrollers overall, is incredibly sensitive to cost. Consumers like you and I want the least expensive products we can possibly buy, and the companies that make those products will shave off every penny possible to make that happen.

Microcontrollers come in seemingly endless varieties, with each one designed for a very specific purpose. This helps companies drive costs down. For example, if your product needs one analog-to-digital converter (ADC), two USB interfaces, and at least 30 general purpose input/output (GPIO) pins, there’s a microcontroller with exactly those specifications. What if you realize you only need one USB interface? There’s probably a different microcontroller with those specifications, too. With such variety, there’s no need to pay for extra features. Companies can find a microcontroller with the bare minimum of what they need, and save money in the
process.

FPGAs, on the other hand, are much more general. With a single FPGA, you might create five ADC interfaces and no USB interface, or three USB and no ADC interfaces. You pretty much have a blank slate at your disposal. As you’ll learn, however, FPGAs need to have many internal wires (called routing) to support all these different possibilities, and all that routing adds cost and complexity. In many cases, you’ll end up paying more for extra features and flexibility that you don’t need.

Another contributing factor to cost is quantity. If you buy 10 million microcontrollers, which is not unrealistic in the field of consumer electronics, you’ll pay less per chip than you would if you only bought 100,000. FPGAs, meanwhile, are typically produced and sold in relatively low quantities, so they cost more per unit. It’s a bit of a chicken-and-egg situation, where FPGAs could be less expensive if there were more of them, but for there to be more of them, they would have to be less expensive. If the costs were the same as with microcontrollers, would there be more FPGAs in use? I think it’s likely that there would be, but FPGAs are also more complicated to use, so that works against them as well.

Since microcontrollers are designed for specific purposes, they can be very easy to set up. You can get a basic design up and running on a microcontroller in a few hours. By contrast, you need to program everything inside the FPGA, and this is very time-consuming. Although there are some hard IP blocks to get you started, the majority of the device is programmable logic—that blank slate we talked about—that you need to design yourself. Writing all the code to do what you need also takes longer in a language like Verilog or VHDL than C, which is commonly used to program microcontrollers. With C, you’re writing code at a higher level, so you can do more with a single line. With Verilog and VHDL you’re writing at a much lower level: individual gates and wires are literally being created with your code. You can think of low-level programming like working with individual LEGO bricks and high-level programming like working with preconstructed LEGO sets. This adds complexity, which adds time, which also increases costs. Engineers want the simplest solution, and most often a microcontroller is simpler than an FPGA.

Another factor to consider is how much power the device consumes. Many electronic devices run off batteries, and it’s critical to maximize their lifetime by making the devices as low-power as possible. The more power they use, the more often you’ll have to change the batteries, which is something nobody wants to do. Again, since a microcontroller is designed for a specific use, it can be optimized to draw incredibly little power, enabling a single AAA battery to power a Bluetooth mouse for months, for example. FPGAs, with all their routing resources, are simply unable to compete with microcontrollers in terms of power consumption. That’s not to say you can’t use an FPGA in a battery-powered application, but head-to-head the microcontroller will win that battle every time.

Summarizing, microcontrollers almost always dominate in terms of cost, ease of use, and power consumption. So why would anyone use an FPGA over a microcontroller? There are other factors to consider, such as speed and flexibility, and here the tables turn in favor of the FPGA. When I say speed, I mean two things: bandwidth and computations. Bandwidth is the rate of data transfer across a path. FPGAs can have incredibly large bandwidth, much more than any microcontroller could ever attain. They can process hundreds of gigabits per second with no trouble at all. This
might be use1ful, for example, when driving multiple 4K displays. FPGAs are often used in video editing hardware that requires enormous amounts of bandwidth to keep up with the data streams. Their high bandwidth allows them to move tremendous amounts of data from various external interfaces (USB-C, Ethernet, ADCs, memories, and more) at very fast rates.

As for computational speed, the number of mathematical computations an FPGA can perform in a second dwarfs anything a microcontroller can do. A microcontroller usually has just one processor, and with all computations going through the same processor, the number of computations that can be performed each second is limited. An FPGA, on the other hand, can run many computations in parallel. For example, you can run hundreds of multiplication operations at the same time, something that simply isn’t possible with a microcontroller. This might be useful when running large mathematical filters on data, which often involve many multiplication and
addition operations occurring at very fast rates.

The other major benefit of an FPGA is its flexibility. I said microcontrollers come in endless varieties, but of course, this is a slight exaggeration. If your design has some particularly exotic requirement—say, if it needs 16 ADC interfaces—there might not be any microcontroller in the world that will meet your needs. FPGAs are much less limited. As I’ve mentioned, an FPGA is like a blank slate that can be programmed to do almost anything, providing you with tremendous flexibility to tackle a wide range of digital logic problems.

When you have an engineering problem, you need to choose the best tool possible to solve it. Often a microcontroller works very well, but occasionally it simply won’t work due to speed or flexibility issues. In those situations, an FPGA is a good candidate. However, there’s also another kind of device worth considering: an ASIC.

FPGAs vs. ASICs

An ASIC is a type of integrated circuit designed for a particular use. Unlike an FPGA, which can suit any number of uses, an ASIC is designed to be really good at one thing. You might think that it would always be better to have the flexibility of an FPGA, but there are trade-offs to consider. We’ve already compared FPGAs to microcontrollers in terms of cost, ease of use, power, speed, and flexibility. Let’s now compare FPGAs and ASICs along those same lines.

ASICs are incredibly expensive to make in low quantities because they have a large nonrecurring engineering (NRE) cost: you need to pay a lot of money up front to a semiconductor foundry (or fab) to get that first ASIC chip. Often the NRE on an ASIC design can run into the millions of dollars. Whether or not you choose to design an ASIC highly depends on how many chips you’ll need. If you’re making low quantities of something, even into the tens of thousands, it’s unlikely you’ll ever be able to recover the upfront cost of an ASIC. If you need millions of chips, however, then an ASIC starts to become an attractive option, since each chip after the first one is very cheap (often under $1). Compare that to an FPGA, where a single chip often costs more than $10, and you start to see that FPGAs just don’t make financial sense in large volumes. Generalizing, in smaller quantities FPGAs usually win against ASICs, but in larger quantities they can’t compete as well.

An area where FPGAs always win out over ASICs is in terms of ease of use. The process of designing an ASIC is very complicated. Plus, you need to make sure your design is free of bugs before you go to the fab to make the chip, or you’ll have wasted your NRE. Most FPGAs, on the other hand, can be fixed in the field (hence field programmable), so even if you find a bug after shipping your product to customers, you can update the code and remedy the issue. That’s simply not possible with an ASIC. Therefore, you must spend significant engineering time and effort verifying that your ASIC design is as bug-free as possible before getting it fabricated. There’s actually an entire discipline called verification engineering that does just this, something we’ll explore in more detail in Chapter 5.

One large benefit to an ASIC is that it can be optimized for low power. ASICs are finely tuned for their specific application; they have what they need and no more. Meanwhile, recall that an FPGA has a significant number of wires and interconnections, which give it its flexibility but mean it uses more power. A further advantage ASICs have over FPGAs is that they can use fabrication techniques that optimize them for low power at the transistor level. For a real-life example, when Bitcoin was new, people were using their home computers (CPUs) to mine it. This draws a lot of power per Bitcoin mined. Eventually, people realized that FPGAs could be programmed to mine Bitcoins, using less power than CPUs. Electrical power is expensive, so mining Bitcoins with FPGAs was more profitable. Further down the line, people realized that ASICs could mine Bitcoins even faster and using even less power than FPGAs. It became worth the up-front cost to create an ASIC dedicated to Bitcoin mining, because the cost savings from the lower power consumption were so significant. Today, Bitcoins are mined almost exclusively with ASICs.

When it comes to speed, FPGAs and ASICs both have large bandwidth and can move lots of data around. They’re also both very capable at math operations, particularly multiplication and addition, and both can do those operations in parallel. ASICs have a small edge in this category: because they’re built specifically for one purpose, they can often run a bit faster
than FPGAs.

FPGAs, on the other hand, offer significantly more flexibility than ASICs. Having flexibility in what your design can do is very valuable, especially if you’re working on a project that isn’t clearly defined. Unlike ASICs, which are fixed, FPGAs can be reprogrammed over and over again, with features and functionality added or removed. Additionally, ASICs take a long time to design, make, and verify, but you can get started with an FPGA right away, so the speed of progress can be faster.

In general, ASICs win against FPGAs on cost when the volumes are very high, but not when they’re low. They beat FPGAs on power consumption and have a slight edge on speed, but they lose to FPGAs on flexibility and ease of use. In reality, though, ASICs and FPGAs often go hand in hand. When a company wants to design an ASIC, it will typically start by designing a prototype with an FPGA, and then produce the ASIC. This method allows engineers to work with the hardware sooner and gain confidence in the product, prior to spending millions of dollars on a custom chip. The engineers can work through the bugs in the Verilog or VHDL code using the FPGA prototype, and fix issues when it’s inexpensive and simpler to do so. This code isn’t throwaway code either, since the same Verilog or VHDL used on an FPGA can be used to create an ASIC.

FPGAs vs. Microcontrollers vs. ASICs

That was a lot to take in, so let’s briefly summarize what we’ve just discussed about FPGAs, microcontrollers, and ASICs. Table 1-1 provides an overview of where each type of device sits on the scale across different parameters. There are always exceptions, but the table provides a good generalization.

Cost is often the dominant factor in why a microcontroller or an ASIC is chosen over an FPGA for large-volume applications. They’re simply cheaper, and that counts in industries that are highly sensitive to cost. When performance is the most important consideration and the high initial cost and level of complexity are acceptable, ASICs are often preferred. The sweet spot for FPGAs is applications that are low volume but require high speed in terms of either bandwidth or computations, or require a very flexible and unique design (like having 16 ADCs to interface to).

Ultimately, FPGAs, microcontrollers, and ASICs are three tools in the engineer’s toolbox. When looking at the requirements of your particular problem, you’ll need to decide which of these tools provides the best solution. You wouldn’t use a hammer to turn a screw; knowing which tool to use for which application is critical to becoming a strong engineer. The act of examining multiple possibilities and selecting a technical solution is often referred to in engineering as a trade study.

I love FPGAs, but when I look at a technical problem, often the right solution is a microcontroller: they’re easy to use and inexpensive. A microcontroller isn’t always the right solution, though. Sometimes you need more speed, or the problem is one that microcontrollers just aren’t designed for. Selecting the right tool for your problem will make solving the problem much more enjoyable. And as you’ll hopefully see, working with FPGAs is certainly enjoyable! It’s like working with LEGO or building a house in Minecraft. Using simple, low-level building blocks, you can create something wonderfully complex.

FPGA-101

If you enjoyed this, order the book!

Getting Started with FPGAs

For the most thorough introduction to FPGAs

Over 300 pages of beginner friendly, easy-to-understand FPGA content

Pre-Order Now!

Available Nov. 21

DETAILS / PRE-ORDER