FPGAs and Microcontrollers
FPGA is an initialism for Field Programmable Gate Array. They are digital logic chips that can be programmed with new logic designs in the same way that microcontrollers can be programmed with new firmware. On a microcontroller, a program is a series of instructions the CPU executes one at a time. Each instruction takes time to execute, program memory to store, and may access locations in RAM.
Designs for FPGAs are different from programs in microcontrollers. The design defines a series of digital logic circuits, the connections, RAM and ROMs they may use, multipliers, etc. Each element of the design consumes a physical location of the FPGA. In a microcontroller instructions are executed one at a time. In an FPGA all elements of the design can be active at once. This makes FPGAs very powerful. In fact, an FPGA can implement a microcontroller in addition to custom logic.
Inside many modern FPGAs there is an array of 4-input logic function generators, single bit storage elements, and other small bits of general purpose logic connected by a routing matrix. The image below is what a logic slice from the MachXO2 FPGA in the #TinyFPGA A-Series boards looks like.
MachXO2 FPGA Logic Slice. From the MachXO2 User Guide - http://www.latticesemi.com/view_document?document_id=38834
Rather than using individual 2-input logic gates, the LUT4 logic function generators or Look-Up Tables can generate any 4-bit logic function. The output of the logic generator can either be routed to another LUT4 elsewhere, or can be stored in the D Flip-Flop immediately connected to the output of the LUT4.
Many FPGA architectures group slices into larger elements. In the MachXO2 series from Lattice they are called PFUs, or Programmable Function Units. Since addition, subtraction, and comparison operators are so common, there is an optimized carry-chain between neighboring slices that allows for faster execution of such operations.
MachXO2 FPGA Programmable Function Unit. From the MachXO2 User Guide - http://www.latticesemi.com/view_document?document_id=38834
Between the PFUs is a routing matrix with many wires and switching matrices that allow for connections between PFUs and other components in the FPGA. In addition to the PFUs, FPGAs may contain other modules like RAMs, clocks, PLLs, non-volatile memory, and even hard-coded peripherals like SPI and i2c masters and slaves. The picture below is the basic layout of the MachXO2-1200 FPGA in the TinyFPGA A2 board.
MachXO2-1200 FPGA Top View. From the MachXO2 User Guide -http://www.latticesemi.com/view_document?document_id=38834
Every programmable element within an FPGA stores is programming locally. The LUT4 function generators for example contain 16-bits of information. The 4 bits of input can be interpreted as a numerical index into that information and the output is the value at that location. All of the routing programming contains storage bits that define how the design connects the various components. This configuration is stored in volatile storage elements. When the power goes off, they lose their state.
This means FPGAs need to be reprogrammed every time they power-on. Luckily there are automated mechanisms for FPGAs to load their configuration from an external flash memory, or even an internal flash memory on power-on.
In the #TinyFPGA A-Series this configuration flash is built into the FPGA itself. In the #TinyFPGA B-Series boards this configuration flash is on a separate SPI flash chip integrated on the board. Once a design is synthesized, it can be programmed onto the configuration flash on the board.
Developing for FPGAs
FPGAs come in chip packages that are difficult to integrate into hobbyist projects. Therefore there are development boards for FPGAs that...
Read more »