FPGA
- Details
- Last Updated: Monday, 22 July 2024 05:50
- Published: Monday, 19 June 2023 19:12
- Hits: 650
FPGA = Field Programmable Gate Array
As an electrical engineer, you should try to learn "How to build a digital circuit on FPGA". FPGA are compact chip, that have millions of gates on it. You can build any custom digital logic with FPGA. FPGA are an essential device for any Electrical Engineer to have fun with.
If you are a VLSI designer, you probably know how to write RTL in Verilog. In an FPGA too, we write RTL, and then the tools that come with FPGA, build a custom digital circuit based off that RTL. This allows us to quickly test our digital circuit, as well as build prototypes, without going thru expensive time consuming process of having a fab fabricate your digital design. FPGA also allow you to learn how to code in Verilog, and test your logic without writing any testbenches. Nowadays, FPGA have millions of gates on them, which you can use to make a full blown microprocessor on an FPGA.
One good video series on FPGA by DigiKey (total 12 videos): https://www.youtube.com/playlist?list=PLEBQazB0HUyT1WmMONxRZn9NmQ_9CIKhb
Early FPGA started in 1983 with Altera and then with Xilinx in 1985. Later Actel and Lattice Semiconductor joined the FPGA race. Xilinx was later bought by AMD, Altera was bought by Intel while Actel was bought by Microsemi, which was itself bought by MicroChip Tech. By 2015, Xilinx (50%), Altera (35%) and Actel (10%) and Lattice (3%) captured almost all of the FPGA market. As of 2020, 100's of millions of gates are being put on a single FPGA chip in 5nm nodes, with FPGA revenue exceeding $8B. FPGA are being increasingly used in low end embedded devices, and expected to grow at a CAGR of 10%.
Main FPGA product lines of these 3 companies are:
- Xilinx: They provide low cost Spartan family (made in higher nm tech as 28nm), as well as high perf Virtex family (made in lower nm tech as 16nm as of 2020). They have multiple generations, with Xilinx 7 series introduced in 2010, which is the most popular one.
- Spartan: Spartan family is the oldest and lowest cost FPGA. Spartan 7 intoduced in 2017 lacks high BW transceivers.
- Artix: Artix family is similar to Spartan, as it's low cost. However, Artix-7 have high BW transceivers, and that's what we'll be using for our training.
- Kinetx: Kinetix family delivers mid range performance at much lower cost than Virtex.
- Virtex: Virtex family is most advanced and highest performance. Several gen from Virtex-E to Virtex UltraScale+. It has lot of prebuilt logic for commonly used functions as multiplication, etc to improve performance.
- Zynq: Zynq 7000 were developed as SoC (System on chip). Zynq-7000 integrate a complete ARM Cortex A9 MPCore-processor-based 28 nm system. It made FPGA processor centric, which could boot at start up, and load OS.
- Altera:
- Startix: Startix series were Alter'a highest BW devices with up to 1 Million logic elements.
- Altec: Actel's portfolio of FPGAs is based on two types of technologies:
- Antifuse-based FPGAs: Axcelerator, SX-A, eX, and MX families
- Flash-based FPGAs: Fusion, PolarFire, IGLOO, and ProASIC3 families
Training on Digilent BASYS3 Board with Artix 7 FPGA using Xilinx Vivado Tools:
"Digilent BASYS3 Board" is the recommended Board for Introductory users wanting to learn FPGA basics. It has Xilinx "Artix 7 FPGA" chip on it. I have this Board, and all my tutorials are based off it.
Buying the Board. ouple of options:
- Digilent directly sells these Board for $150-$175. Direct link to Buy: https://digilent.com/shop/basys-3-artix-7-fpga-trainer-board-recommended-for-introductory-users/
- During Black Friday 2023, they had flash sale for 40% off. Link: https://slickdeals.net/f/17056897-digilent-zynq-based-development-boards-sale-40-off
- It's commonly used in students' courses, so it's easy to get a used one for < $100. I bought mine for $65. If you keep looking, you will find one around that price. Amazon and ebay are good places to look fora used one.
- Amazon (brand new, direct from Digilent, sells for same price of $170) => https://www.amazon.com/Digilent-Basys-Artix-7-Trainer-Board/dp/B00NUE1WOG
- Ebay link (used ones): https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=Digilent+BASYS3+Artix+7+FPGA&_sacat=0&LH_TitleDesc=0&_odkw=Digilent+BASYS3+Board+with+Artix+7+FPGA&_osacat=0
- One such Board for $125 (active as of 07/01/2023) => https://www.ebay.com/itm/266321136009
Steps on Linux OS (Ubuntu Cinnamon 22.04.2 LTS) for Installing Vivado 2023.1:
- Once you have the Board, download and install Vivldo from Xilinx website. You will need to make an AMD a/c (as Xilinx is now part of AMD). Provide your personal details accurately for Export Control Requirements. Once you do that, you can download any of the 3 "Vivalo ML edition" provided. The self extracting option for Window/Linux are more suitable, since they don't require huge files to be downloaded in 1 go. The 3rd option of downloading tar.gz file has 110G of file to be downloaded, which errors out almost all the time after downloading part of the file. Details here => https://digilent.com/reference/programmable-logic/guides/installing-vivado-and-vitis. Steps are:
- Download AMD Linux bin file => https://www.xilinx.com/support/download.html. Since we are doing it on Linux, we'll choose 3rd from top which is "Linux Self Extracting Web installer" => Xilinx_Unified_2023.1_0507_1903_Lin64.bin (~265 MB)
- Open a Linux Terminal and Go to Dir where Installer was downloaded. Most likely in /home/<user/Downloads dir. Run these 3 cmds:
- sudo apt install libtinfo5 libncurses5 => We need to install these 2, else we get stuck at "Generating installed device list" later during installation. Thread: https://support.xilinx.com/s/article/63794?language=en_US
- chmod +x Xilinx_Unified_2023.1_0507_1903_Lin64.bin;
- sudo ./Xilinx_Unified_2023.1_0507_1903_Lin64.bin
- A new gui will appear which will guide thru installation process. Enter amd login/password. Choose "Vivado" as "Product to install" and NOT "Vitis", as "Vitis" is too large. Choose "Vivado 2023.1 ML free Edition". This takes up abot 40GB of space. It will go thru 3 step process of downloading a 20GB file, installing and then "Final processing for device". Downloading a 20GB filw will easily take an hour, installing is couple of minutes, and Final processsing is also a few minutes. It will get stuck on final processing if we haven't done step 2.1 above. If it does get stuck, cancel,then run this on any terminal (sudo apt install libtinfo5 libncurses5), and then reexecute the binary (step 2.3). Once installation is done, the software will be installed in /tools/Xilinx/Vivado dir.
- Once Vivado software is installed, install cable drivers (need only for Linux0 as it doesn't come with the drivers. Run below cmds on terminal
- cd /tools/Xilinx/Vivado/2023.1/data/xicom/cable_drivers/lin64/install_script/install_drivers
- ./install_drivers => This should show "INFO: Driver installation successful." at the end, along with a warning. Ignore the warning.
- Install Digilent's Board files.
- Download from github: https://github.com/Digilent/vivado-boards/archive/master.zip
- Go to the dir where downloaded, and Extract it by right clicking on file (in Files window, NOt on terminal). It will extract files.
- On terminal. run cmd => cp -rf /home/kagrawal/Downloads/vivado-boards-master/new/board_files /tools/Xilinx/Vivado/2023.1/data/boards/board_files => This copies all files.
- sudo chmod -R 777 /tools/Xilinx/ => For now set all permissions to all subdir and files for Vivado.That way, we avoid getting "Permission denied' errors later. Or you can login as root as shown below in step 4.1.
- Launch Vivado. Follow the instructions provided here: https://digilent.com/reference/programmable-logic/guides/getting-started-with-vivado
- Open a terminal, and login as root (may not be needed if all permissions are set up for all vivado dir) : sudo -i => logs in as root
- mkdir /home/<user>/Vivado_training
- cd /home/<user>/Vivado_training
- source /tools/Xilinx/Vivado/2023.1/settings64.sh (Or can also use dot space (i.e . ) instead of source to execute)
- vivado => (use sudo vivado if you aren't logged in as root). This will launch Vivado. If it shows error as "permission denied", then you need to login as root. Vivado gui will open up. Choose Tasks->Open Hardware manager. It will show "Hardware Manager" as not connected on the new pop up.
- Now connect your FPGA to your laptop via the USB cable provided. Flip SW16 on Digilent Board (switch near the mini usb cable). It should turn lights on, and will start counting from 0000 to 9999. "Hardware Manager" will show Digilent Board name. So, everything working at this point. Few Troubleshooting Tips:
- If Board doesn't power on, it may be due to power switch jumper on top left (JP2) not set to usb. Make sure the bottom 2 pins of the 3 pins are connected via jumper. If the top 2 pin of jumper re connected, that imples that the power is coming from an external source, which is not true in our case. We are powering via micro USB.
- If Programming our own verilog code, we have 3 options via switch jumper on top right (JP1) = QSPI, JTAG (via micro usb) and USB (which is not micro usb, but regular USB right next to JP1). We'll user jumper to connect middle 2 pins of JP1 that will allow us to use JTAG for programming.
- Now we can try a new project. Follow instructions on link above to create a new project.
- There are many videos on xilix website with all code provided.
Project 1 on designing a simple inverter to flip LED:
The simplest circuit that you can build on an FPGA is a simple inverter. There's a very good series on this. Just follow the instruction to get the implement the inverter to flip switches.
Series of Videos to by "ENGRTUTOR Channel"=> https://www.youtube.com/@ENGRTUTOR
Basically, this is what you do in above project is this:
- Connect an inverter between 2 pins of FPGA. One input pin of FPGA is connected to the switch, while other output pin of FPGA is connected to the LED. We implement an inverter in FPGA and connect it b/w these 2 pins. Now, the output will be inverse of the input. So, when switch is turned on (i.e connected to 3.3V supply or binary 1), the LED turns off (or binary 0), and vice versa.
Follow below 4 videos for FPGA tutorial (The project is using Vivado 2020, but we are using Vivado 2023, so not everything on GUI of below videos will be the same as yours, but that doesn't matter, it will still work):
- Intro to Basys 3 Board: https://www.youtube.com/watch?v=fWgi3a6A9Vo
- Part 1: Writing Verilog code for Inverter: https://www.youtube.com/watch?v=8qiizRqUh8Y
- Part 2: Writing Verilog TestBench to test our inverter: https://www.youtube.com/watch?v=8kud2Y8y4nk
- Part 3: Downloading Bitstream on FPGA: https://www.youtube.com/watch?v=4Nv1z0w7IXM
Project 2 on designing a MicroBlaze Processor and run C programs on it:
The most advanced circuit that you can build on an FPGA is a microcontroller. It's very satisfying to be able to build a processor and run C program on it.
AMD's MicroBlaze Microcontroller is provided with Xilinx repository. It has all the Verilog code that you can look at and then synthesize it and generate a bitstream. Then compile a simple C program, and run it on FPGA on this MicroBlaze processor. Really easy and fun.
There's a good series on this on youtube Channel (drselim) => https://www.youtube.com/playlist?list=PLbFgDf51ZkCEJb9MvxKIs-0q2obouwf-f
This playlist has videos starting with an adder, mux and then then going on with Micro Blaze Micro controller, with the last tutorial on VGA connector.
There's also a video on Xilinx website for building MicroBlaze Microcontroller on FPGA => https://www.xilinx.com/video/software/microblaze-quickstart-video.html