FPGA Workshop For Beginners: Hacker Space Fest @/tmp/lab Tuesday June 30th, 2009
FPGA Workshop For Beginners: Hacker Space Fest @/tmp/lab Tuesday June 30th, 2009
Project examples
Zet86 80s PC (8086)
Example projects
Apple2fpga (Columbia University)
Example projects
FPGA ARCADE (www.fpgaarcade.com)
Example projects
NSA @ home SHA1 brute force cracking
Example projects
OpenPattern SOHO routers
Example projects
OpenGraphics 3D graphics card
Example projects
NetFPGA high performance routers
Example projects
Milkymist VJ platform
FPGA advantages
FPGA development
Just a purely digital component There are ready for use development kits, with power supply and various peripherals
FPGA development
Design of the logic circuit to put into the FPGA Input of schematics or HDL (Hardware Description Language) The software generates a programming file The file is downloaded into the FPGA The FPGA emulates the user logic circuit
Challenges
Hard to debug. Modern circuits are complex. Schematics can get too big for a person to handle.
Hands-on #1
Getting started with the design tools Goal: Connect the pushbuttons to the LEDs.
Hands-on #1
module tmplab( input [4:0] output[4:0] ); assign leds[0] assign leds[1] assign leds[2] assign leds[3] endmodule buttons, leds = = = = buttons[0]; buttons[1]; buttons[2]; buttons[3];
Logic functions
Building blocks to process binary signals. - NOT (~) - OR (|) - AND (&) - XOR (^) - etc. Verilog syntax is similar to C syntax.
Hands-on #2
Light up the first LED if the first pushbutton is not pressed, turn it off if it is pressed.
Hands-on #3
Light up all LEDs if any or both of the first two pushbuttons is pressed. Tip: wire all_leds; assign leds = {4{all_leds}}; assign all_leds = your code here;
Hands-on #4
Hands-on #5
Light up all LEDs if the first two pushbuttons are pressed at the same time.
Hands-on #6
Light up all LEDs if one of the first two pushbuttons are pressed, but do not light them up if the two buttons are pressed at the same time.
Hands-on #7
Binary arithmetic
All arithmetic operations (addition, multiplication) can be done on binary numbers (base 2) by combining the building blocks we've seen so far. That's how microprocessors and calculators work.
Addition
With two digits
Addition
With many digits
Nothing really new, everything works like base 10 addition from elementary school...
Hands-on #8
Add the values of the first two buttons, and display the result on the LEDs. Using the + operator of Verilog is not allowed (yet).
Hands-on #9
Increment a 4-bit number encoded on the pushbuttons, and display the result in binary, on the LEDs. Without the + operator of Verilog, then with.
Sequential logic
All the functions we've made so far are said combinatorial. Their output only depends on their current input, there is no notion of memory. A logic function that has memory is said to be sequential.
The D flip-flop
The D flip-flop memorizes its input data (D) at each rising edge of the clock.
Hands-on #10
Try the D flip-flop by connecting inputs to buttons, and output to a LED. reg q; always @(posedge buttons[0]) q <= buttons[1]; assign leds[0] = q; NB. q should be of type reg , not wire (just a peculiarity of Verilog without real purpose)
Hands-on #11
Count the number of times the first pushbutton is pressed, and display the result on the LEDs, in binary. Using the + operator of Verilog is recommended.
The D flip-flop and combinatorial functions can be used to build almost any current logic circuit (microprocessor, 3D accelerator, ) But knowing the rules is not knowing how to play ;)
Hands-on #12
Compound circuit
It is possible to generate a series of interrupted beeps by using two frequency dividers and combining their outputs with AND. The low frequency should be 1Hz-4Hz.
Hands-on #13
Generate a series of beeps between 200Hz and 2kHz, modulated between1Hz and 4Hz.
What's next ?
This was only an introduction to design and impementation of trivial logic circuits on FPGAs. - Complex HDL designs - Debugging methodology (simulation, ) - Timing - Performance problems - Microprocessors, buses, memories, ... - And much more !...
Resources
FPGA4fun: www.fpga4fun.com - tutorials, projets ASIC World: www.asic-world.com - tutorials Opencores: www.opencores.org - library of designs Milkymist: www.milkymist.org GRLIB: www.gaisler.com OpenSparc : www.opensparc.org