FPGAs. The alternative to microcontrollers?

Abstract FPGAs (Field Programmable Gate Arrays) are becoming more powerful and cheaper at a faster pace than microcontrollers. Until recently, these huge fully programmable silicon chips were found only in high speed computer peripherals or high performance appliances (medical, aerospace, etc.). The existence of standard IP cores, the advantages of parallel computing, the easiness of firmware development and the possibility of embedding custom processors within an FPGA make them suitable for designs where microcontrollers where in their heart until recently.
Author Joan C. Abelaira

The whole family of Programmable Logic Devices (PLD)

FPGA belong to a group of programmable devices, known collectively as PLD. Other members of this group are:

This article is focused on FPGA and CPLD as they are considered similar devices with subtle (or small) differences.

The difference(s) between FPGA and CPLD.

Both kind of devices are based in a fabric (like a textile) with hundreds of thousands of logic blocks (or logic cells, depending on manufacturer's naming). Each logic block can be configured to implement a logic or arithmetic function, either registered (latched) or not. Interconnections between all these blocks are again highly configurable.

For a CPLD, let's take a Xilinx CoolRunner II device, the basic logic block is called Macrocell and has the structure below. CoolRunner II family offer devices from 32 to 512 macrocells. These CPLDs also contain AIM (Advanced Interconnect Matrix) that is the fabric connecting all macrocells together as well as with I/O Blocks.

 

In a commonplace FPGA, like the well-known Xilinx Spartan 3, the basic block is called CLB (Configurable Logic Block) that contains a 4-bit flexible LUT (Look-up Table) that can act as logic or storage element. Other elements in this kind of FPGA are: Block RAM (internal RAM for data), I/O Blocks (that interface signals to different standards and voltage levels), DCM (Digital Clock Manager) and even DSP slices (blocks with multiplier and accumulator, specifically designed for DSP functions).

The Spartan 3A family has devices from 176 to 5968 CLBs. But the new Virtex-6 family offers you up to 59280 CLBs, 38Mbit of block RAM and 2016 DSP slices. Prices also range from 4 to 5 digits in US dollars.

Programming FPGA

The design configuration to be implemented in any PLD has to be stored in any type of memory. Old systems were based in PROM (one time programmable systems where fuses were blown by a high voltage). Modern FPGA are always reprogrammable but there are different ways to store the configuration:

Summarizing, the most employed systems are FLASH for small-medium CPLDs and SRAM for larger devices.

How can FPGAs compete with microcontrollers?

An FPGA can be seen as a box filled with Lego pieces, ready to assemble whatever you want. An MCU is more like an assembled machine with some flexibility but also some constraints.

MCUs are intended to process a program written by the user by the CPU. The flexibility resides therefore in the program. And CPUs are sequential, they do just one program instruction at a time. Tricks (RTOS) exist to (apparently) execute multiple tasks at a time. These (only program flexibility and sequential processing) are the limitations of MCUs.

FPGAs are far more flexible. They contain no CPU, but a variety of embedded CPUs can easily be implemented. Logical peripherals, like UART, I2C, VGA or USB ports, timers, DMA modules, etc. can be implemented in any number and characteristics. But this is just half of the FPGA advantage. The other half is speed due to parallel computing. For DSP it is common to have to perform long strings of Multiply and Accumulate operations. FPGAs can achieve high computing speeds by performing all these computations in just one clock (also a compromise solution of partially sequential computation can be adopted). Parallel processes also speed up overall efficiency in comparison to MCUs running a multitask process.

Another point of FPGAs is that they can host different, independent logic systems. Multiple CPU cores can be working inside for absolutely unrelated (or not) tasks if needed (for example some small embedded processors can do one task each instead of having a single MCU running a multitask process). And last but not least, there is a huge pin flexibility, so the designer can choose almost whatever pin combination for the design. this eases greatly not only the hardware design but also future updates and changes.

Summarizing, FPGAs will never replace MCUs as they are needed at low cost for many functions with modest speeds and computational load. But as the need for fast intense computation grows even for consumer applications (like computer graphic cards, biometrics signal processing, etc.) they do by parallelizing what MCUs cannot do by increasing the clock frequency.

Languages for FPGA

First FPGA designers (back in the 70's) worked with schematics and single logic gates. Schematics were translated to logic gate netlists, either by computer or humans and then compiled to FPGA configuration. As FPGA grew up and designs became more complex, this schematic-entry was replaced by higher level languages (HDL).

Since the 80's, most FPGA designers use HDL (Hardware Description Logic) languages. There is a plethora  but two of them outstand of the crowd: Verilog and VHDL (a short for VHSIC HDL). Apparently quite similar to each other, but small differences exist. VHDL is more more appropriate for higher levels of abstraction, while Verilog is better for gate level description. Verilog is also easier to learn but lacks some powerful features that VHDL offers. Fortunately enough, a design can contain modules written in both languages.

Comparison of VHDL and Verilog languages
Verilog VHDL
Fixed data types Abstract data types
Interpreted constructs Compiled constructs
Good gate level timing Not good gate level timing
Limited design reusability Good design reusability
Limited design management Good design management
No structure replication Supports structure replication

For those missing C language (or those being so lazy to move forward a new stage), some tools exist that generate Verilog or VHDL files from an ANSI C listing. I personally prefer learning a new language than using even the best machine translator.

A different kind of tools are the HDL coders. These generate HDL code from a system description. For example MATLAB offers the Simulink HDL coder with which the designer can develop a system in Simulink environment, test it, then convert it to HDL. Test benches are also generated. I have tried it and found it extremely powerful.

Final words

As a project engineer, when my solution for a customer needs is to use an MCU the answer is usually something like "ok, do it", not even wondering about the price. The general idea is that an MCU is cheap, easy to program and to manufacture the PCB.

But if my solution suggests an FPGA, curious reactions arise, beginning with the physical ones. Comments like "is it necessary?", "this would go out of the budget", "why that and not an MCU?", and so on. I observe there is a generalized fear to FPGAs, and the less knowledge about them, the more intense the fear. The generalized idea about FPGA is that they are for computer or high-end applications only.

I have also noticed, when I explain and compare an FPGA solution to an MCU solution, the trend of the customer to favour the MCU, by overrating the strong points and underestimating the weaknesses. This another aspect of the FPGA fear.

When a project falls in that field where either an MCU or FPGA solution exists, the FPGA solution most times offers more robustness and flexibility, so in the long run gives more profit, even if some time/ money investment is required in the beginning.