From Hamsterworks Wiki!
This course is currently a work in progress, but aims to be a quick start for hobbyists new to using FPGAs.
Now available in PDF
To tie in with the release of the GadgetFactory LogicStart Megawing (http://www.gadgetfactory.net/logicstart-megawing) I've migrated this whole project onto GitHub, and made it available in PDF form. To download the full PDF click on https://github.com/hamsternz/IntroToSpartanFPGABook/blob/master/IntroToSpartanFPGABook.pdf?raw=true
Contains all that is here and more, and covers both the Digilent Basys2 and Papilio One + LogicStart development boards. I have two proofreaders working their way though it, so it should be much improved.
Why learn to use FPGAs?
- For electronics and microcontroller buffs, the programmable logic on an FPGA is the next step closer to "real hardware"
- The interfacing possibilities are endless - with the right FPGA you can talk to pretty much anything (DVI,HDMI, Fibre Channel, LVDS)
- Designing, prototyping and debugging of designs is fast. When compared to building complex designs with graph paper, discrete logic chips, breadboards and jumper wires the ability to change a high level design and press the "implement" button is magical
- Designing and prototyping hardware is cheap - a mid-range laptop and an FPGA development board is all you need for designs that would cost thousands of dollars to build with discrete logic
- Maybe this will inspire a person with far better ideas than me to create something really cool
Have a look on FPGA_Projects for some of the things that can be done with FPGAs and still fit on a web page.
What I want to do
I want to help hackers take the plunge, purchase an FPGA development board and get their first projects up and running.
What will you learn?
At the end of the modules you should have achieved the following:
- Learnt a subset of VHDL, enough to complete most projects
- Used the simulator to debug issues
- Used all the components on a Spartan-3E FPGA
- Logic blocks
- Block RAM
- Digital Clock Managers
- 18x18 multipliers
- Used nearly all the interfaces on the development board
- Buttons & Switches
- Seven Segment display
- A PMOD connector
- PS/2 (although this interface is relatively complex to use)
- Accessed a project on a FPGA over the USB host port
- You will have built a few custom interfaces that are not on the board
- Audio output
- 3.3V TTL RS-232 to host
This should get you well on the way to implementing your own projects.
How to contact me
Email me at "firstname.lastname@example.org", after removing the "nospam-" bit. Any feedback is welcome!
Here's what I think are the skills required for somebody wanting to learn to program FPGAs:
- Programming ability in a low level language (e.g. 'C' or assembler)
- Familiarity with the basic boolean operations (AND, OR, NOT, XOR)
- An understanding of number representations and binary math
- Understanding of circuit schematics user in digital designs is very helpful
- A PC equivalent to a current entry-level model running either Windows XP, Windows 7 or Linux (Dual core CPU with 2GB RAM, 20GB free disk)
- A broadband connection with an internet plan that enables you to download the multi-GB design software
- A little bit of microcontroller development experience is useful
- Around US$79 + p&p to purchase an FPGA development board, and if you are 'no good with hardware' the recommended model is a Digilent Basys2 from http://www.digilentinc.com/Products/Detail.cfm?Prod=BASYS2, as a lot of the projects focus on the eight slide switches and eight LEDs. If you would like do some soldering or can use a breadboard a Papilio One from http://www.papilio.cc/ is a great option.
Each module has a hands-on project, with the largest similar in size to Papilio S6/Fading counter. This should allow most modules to be completed in an hour.
|Module 1||Getting Prepared||Purchasing your hardware, downloading and installing the development tools.|
|Module 2||Your first design||Wiring switches to LEDs and downloading your design (First_project_help has what to check if it doesn't work)|
|Module 3||Logic operations||Implementing AND, OR, NOT and other operations|
|Module 4||Buses||Using more than one bit at a time|
|Module 5||Binary math||Addition and subtraction|
|Module 6||Counting||Creating counters and the first use of clock signals|
|Module 7||Timing constraints||How fast will a design go?|
|Module 8||Simulating designs||Creating a test bench and running simulations|
|Module 9||Modular designs||Building a design with multiple components|
|Module 10||More complex interfacing||Using the seven segment display (if present)|
|Module 11||Video output||Generating a VGA signal.|
|Module 12||Using on-chip memory||Sequencing light flashes|
|Module 13||Generating analogue signals in a digital world||Building a one-bit DAC to make sounds|
|Module 14||Introduction to finite state machines||Creating a combination lock|
|Module 15||Clock management||Using the clock management resources|
|Module 16||Talking to a PC||Sending data down an RS232 connection|
|Module 17||Receiving data from a PC||Receiving data over a RS232 connection|
|Module 18||Talking to a PC using vendor's API||Using the vendor's API and libraries|
|Module 19||Multiplying||Using the 18x18 multipliers|
|Module 20||Tri state logic||An after-thought|
A good free reference book
Snag yourself a copy of "Free Range VHDL". Available at a web browser near you at http://www.freerangefactory.org/
A note to software-coder types
Your mind is presently wired to think about the flow of instructions in a process running in a memory space. It hurts to escape this! You will get horribly confused.
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.
- Your design works as follows:
- It has the current state stored in flip-flops and registers
- It then computes the next state, based on inputs and current state.
- When the clock ticks it then atomically stores this new state into the state vector.
And that is it - there are no loops (well, not in the sense you think of them now), 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 more 'superscalar', and the mental paradigm that you write your code in a closer match to the underlying hardware. You may find yourself changing a few small habits that will improve the quality of your code.
Size of projects that are possible to implement in an FPGA
A very low end FPGA board (e.g. the XC3S100 on Digilent's BASYS2-100 http://www.digilentinc.com/Products/Detail.cfm?Prod=BASYS2) 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,600,000 gates.
The easiest way to visualize this is to think in terms of solderless breadboards. A 40mm x 90mm breadboard can comfortably fit three 14 pin 7400 series TTL chips and associated wiring, making a small FPGA equivalent to something like a 4.0m x 7.2m array of breadboards, each populated with three TTL logic chips. This makes that large FPGA equivalent to nearly a basketball court full of breadboards!
This much logic allows you to implement pretty much any design you can envisage.
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. Sure it is quick to write but it feels very "fast an loose" - it is very hard to tell what the heck is going on.
But for the size of projects in this course use whatever language you like - it is more about the underlying concept than the code.
If you have any questions I can pretty much read either language.
What development board am I basing a course around?
Commercial FPGA boards are available from Digilent, Terasic and others, with prices from around US$80 (for a Terasic DE0-Nano) to maybe US$2,000 or more for a high end development board. For your extra money you not only get a larger and faster FPGA, but you also get RAM, Flash memory, Ethernet interface(s), Audio codecs, HDMI in/out and other goodies.
The low-cost Terasic DE0-nano has too few onboard interfaces to be fun to learn on, and although the Basys2-100 has a VGA connector, PS/2 plug, LEDs and switches the FPGA is too small for anything but the most basic projects - for example it only has a 9KB of on-chip RAM. The Basys2-250 is a bit better, with 24KB of on-chip RAM - which is enough to implement a small 8 bit computer or a Text mode VGA display. The next step up is something like the Terasic DE0 or Digilent Nexys2, at around US$149, which includes a few MB of RAM and Flash and are aimed at "system on programmable chip" users.
An inexpensive FPGA board is the US$50 Papilio One 250K from Gadget Factory (http://www.papilio.cc/index.php?n=Papilio.Hardware). If you are not adept with soldering you will also need something like an "Arcade Mega Wing" (http://www.papilio.cc/index.php?n=Papilio.ArcadeMegaWing) to allow plugging of standard peripherals such as a PS/2 keyboard or a VGA monitor, although a small amount of soldering may be still needed to install the headers.
I've decided on the Digilent Basys2 as my reference board - it has all the items needed to have useful projects, no soldering required, and costs under $100. Also I find that the Xilinx toolset is also very friendly for first time designers.
As I'm in New Zealand I ordered mine from their ANZ distributor - Black Box Consulting (http://www.blackboxconsulting.com.au/). They normally have everything in stock, so not only is it quicker than ordering from Digilent, the international shipping direct from Digilent is really, really, really high. Why is it you can get a Papilio FPGA board from Seeed Studios for $49.99 incl postage, but it costs US$36.66 to ship a $99 order from Digilent? Black Box Consulting charged a reasonable AU$10.00 for shipping.
NOTE: The BASYS2's on-board oscillator is not very stable - it may pay to get something like SGR-8002DC-PCC-ND from Digikey to provide a reference clock that is stable enough to the FPGA's Digital Clock managers to reliably latch on to. This is only required if you want to use frequencies other than the 100MHz, 50MHz or 25MHz that is on the board. The part number in the reference manual is wrong - it is a SMD part!