Sie sind auf Seite 1von 46

FPGA Workshop for beginners

Hacker Space Fest @/tmp/lab Tuesday June 30th, 2009

What are they for ?


Replace any logic circuit : - devices based on CMOS or TTL integrated circuits

What are they for ?


- microprocessors, microcontrollers

What are they for ?


- graphics accelerators (GPUs)

What are they for ?


- full computers, arcade games, ...

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

- High performance - Flexibility - Interfaces - Reduced size

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.

Hardware Description Languages


Describe logic at a higher level of abstraction (like C vs. assembler). Fast creation of big circuits (by synthesis = computer-generated schematics). Allow creation of complex tests and simulations. Verilog and VHDL are popular choices. This workshop focuses on Verilog.

Hardware Description Languages


You need an understanding of the underlying logic schematics to make efficient designs. You can also directly enter schematics into FPGA software, but it is not today's methodology (and experience from previous workshop also shows that GUI has many problems with schematics) Drawing schematics on a piece of paper for your HDL code is a good exercise to get started.

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

Light up all LEDs if one or more pushbuttons are pressed.

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

Light up all LEDs if an odd number of pushbuttons is pressed.

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.

Subtraction, division, ...

Other fundamental operations are computed like in base 10.

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.

That's all, folks !

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 ;)

The frequency divider


A counter can divide a frequency by a power of 2.

The frequency divider


More precisely: the last output of a counter with N bits divides the clock frequency by 2^N. Application: beep generator. Find out how many bits are needed to divide the development kit oscillator's frequency to get a well audible sound (200Hz - 2kHz).

Hands-on #12

Connect a speaker to the FPGA kit, and generate a continuous beep

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

Das könnte Ihnen auch gefallen