Hi! I’m Mike Field (aka [email protected]).
I want to help hackers take the plunge into the world of FPGAs-- Starting at purchasing an FPGA development board, and all the way through the process of getting their first project up and running. In this eBook, we will discuss the low level details of working with FPGAs, rather than diving straight into the System on a Chip (SOAC) level.
I grew up in the '80s, when the 8-bit computer scene was happening, and on the back of my VIC 20 there was an edge connector where you could attach 'stuff'. Armed with vero-board and a soldering iron, I made a few interfaces-- but my designs soon got larger than my pocket money could support.
On my way to becoming a professional programmer, I toyed with digital logic and what was then called microelectronics-- designing with simple logic chips on a solderless breadboard-- and spent many evenings with graph paper sketching out and trying designs. Some even up to the scale of small CPUs!
In the late '90s and early 2000s, microcontrollers with flash memory came on the scene, and I returned to playing with them as a hobby. They were cheap, relatively powerful and very accessible, but in the back of my mind were the graph paper designs of my late teenage years. I wanted to design the CPU, not just use it.
One day, while reading Slashdot, I stumbled onto FPGAs and was hooked!
I’m hoping that this book will inspire a person with far better ideas than me to create something really cool. Hopefully, you are that person!
Field Programmable Gate Arrays are, in essence, a chip full of digital logic (and other bits and pieces) where the connections between the components have not been decided upon at time of manufacture. Software tools are used to generate "configuration files" that contain the connections and initial values of all the components, which can then be downloaded to the FPGA.
The distinguishing feature from other technology is that (usually) the designs are completely 'soft'. That is, if power is removed you have a blank FPGA that can then be programmed with a different design (although most FPGAs can automatically download the design from a FLASH ROM chip).
FPGAs first came to market in the late '80s. Initially, they were seen as very large PLAs (Programmable Logic Arrays). During the early '90s, their increasing size and flexibility allowed them to be used in networking and telecommunications applications as they separate the hardware and logic design phases of product development. This split development model allowed hardware vendors to quickly engineer solutions without the expense and time required to commission Application Specific Integrated Circuits (ASICs).
During the late '90s, FPGAs became more and more commonplace, replacing ASICs or enabling the use of advanced algorithms in consumer and industrial products-- for example, the system monitoring the data center where I work at is based around a Xilinx FPGA, and Xilinx FPGAs are used inside some HP storage subsystems I use.
In the 2000s, educational institutes began integrating FPGAs into their digital design courses, and vendors were keen to supply them with development boards knowing that familiarity with the technology would help develop their markets. These boards (and their design software) are now available to the hobbyist community, opening up to the average hobbyist, a new world of adventure and excitement. For the price of a solderless breadboard, power supply and a few ICs, you can have the equivalent of hundreds of thousands of discrete logic chips to play with.
Want to calculate MD5 checksums in hardware? Sure! Want to implement an arcade game off the schematics? Why not! Design your own CPU? You can do that too-- actually, you can design a complete computer if you really want to! With one of these development boards, you have access to more resources than a corporation could muster 20 years ago!
For electronics and microcontroller buffs, the programmable logic on an FPGA is up there, next to working with "real hardware". The interfacing possibilities are endless-- with the right FPGA, you can talk to pretty much anything (DVI, HDMI, Fibre Channel, LVDS, PCIe, LVCMOS, LVTTL).
Unlike working with chips and wires, the design, prototyping and debugging phases of a project using an FPGA are very fast. In the past, designing and building complex projects required the use of graph paper, discrete logic chips, breadboards and jumper wires, making it a slow and tedious project. However, in the world of FPGAs, after updating your design, all you have to do is press the "implement" button.
In addition to being fast to use, designing and prototyping hardware is cheap-- a mid-range laptop and an FPGA development board is all you need for designs that would cost tens of thousands of dollars to build with discrete logic. For hobbyists, the best part is that when you are finished with one project, you can easily reuse your development board for the next.
By the end of this eBook, you should have:
-
A working knowledge of a subset of VHDL-- enough to complete most projects
-
Familiarity with the ISIM simulator, and have used it to debug an issue or two
-
Familiarity with all the major components of the Spartan-3E FPGA
-
Used nearly all the interfaces on your chosen FPGA development board
-
Transferred data to an FPGA over the USB host port (which is often overlooked in other books!)
-
You may have even built a few custom interfaces that are not on the board
These skills will send you well on your way to implementing your own projects such as:
-
Servo and motor drivers
-
Sensor interfaces for robotics
-
Digital Signal Processing for audio, video, or RF signals
-
Interfacing with any of the hundreds of low cost sensors that are now available, including but not limited to accelerometers and gyroscopes
-
You could even consider building your own CPU
If you are a coder, then your mind is presently wired to think about the flow of instructions running through a processor, running in a memory space. It really hurts to escape this mindset but please persist-- you will need to escape it if you are to make the most of FPGAs.
Implementing efficient designs requires a very different way of thinking. In general, memory access is cheap, branches are inexpensive, parallelization is easy and serialization is hard. You need to be acutely aware of timings at design time rather than profiling code after implementation looking for hot spots.
When you get confused, the things to remember are:
-
You are not writing a program
-
You are designing something akin to a (Very Very Very Very) VLIW CPU that only has a single instruction
-
It has the current state vector (stored in flip-flops and registers)
-
It uses the current state and any inputs to compute the next state
-
When the clock 'ticks' it will then atomically stores this new state into the state vector.
That’s it-- there are no loops (at least not in the sense you think of them now), there is no "do this then do that", there is no "flow" through the code-- it is all concurrent. There is pretty much only one unit of time-- a single tick of a clock signal. It can be quite freaky at times!
The good thing is that as a result of this mind shift you will start thinking in a more 'superscalar' way, and as a result, your code will be a closer match to the underlying hardware. You may find yourself changing a few small habits that will improve the quality of your code.
A very low end FPGA (e.g. the Spartan 3E - 100 is equivalent to approximately 100,000 logic gates-- or 25,000 TTL logic chips. The largest FPGA in the same product range has 16 times as many logic elements with an 'equivalent gate count' of 1.6 million gates.
The easiest way to visualize this is to think in terms of solderless breadboards. A 40mm x 90mm breadboard can comfortably fit three 7400 series TTL chips and associated wiring, making the small FPGA equivalent to a 4.0m x 7.2m array of breadboards, each populated with three TTL logic chips. A large FPGA is equivalent to nearly a basketball court full of breadboards!
Having this much logic allows you to implement pretty much any design you can envision, and makes you appreciate the job that the design software does for you.
Today there are two dominant Hardware Description Languages (HDLs) in use-- Verilog and VHDL.
-
VHDL is based on ADA, is strongly typed and very verbose.
-
Verilog is more like C-- loosely typed with lots of punctuation.
Both languages are pretty much equally expressive-- anything you can do using one language you can also do in the other, and they can even be mixed and matched in the same project with far more fluidity than mixing languages in software design.
For me, I find that the explicitness of VHDL makes it more explainable. I’m also from outside of the USA-- where VHDL seems to be the de facto standard for research and industry. I find Verilog code a bit like Perl. It is quick to write but it feels very "fast and loose"-- sometimes, it is very hard to tell what the heck is going on.
For the size of projects in this course, use whatever language you like-- it is more about the underlying concept than the code.
You won’t need it at the moment, but if you want to learn the other 90% of the VHDL language that is not covered here, snag yourself a copy of "Free Range VHDL". It is available on a web browser near you, at http://www.freerangefactory.org/