Get Started on FPGA Programming With $20

Huobur
The Startup
Published in
7 min readNov 29, 2020

If you are reading now, I assume that you are somewhat (to very much) curious on FPGA. Unlike other programming learning process, FPGA seems to be much harder to get started. But as long as you want to learn, this article can get your feet wet quickly without costing much. And I assume that you have absolutely no FPGA programming experience.

What you should get

There are lots of options to get started, here we are going to use Altera Cyclone II FPGA chipset, the dev board on Amazon is $19.99. (EP2C5T144 Altera Cyclone II FPGA Mini Development Board). To be honest, I cheated at little on the article title to lure you here, sorry about that. You will also need a USB Blaster (less than $10 on Amazon) to connect your PC (Windows or Linux) to program the FPGA dev board and a 5v power supply (less than $10 on Amazon) to power the board. I was hoping you’ve already had the USB Blaster and the power supply from some other of your projects and I also heard that people got the whole set on Ebay for less than $20. So that’s about it on what you need on the hardware side.

What you should install

On the software IDE, we are going to use “Altera Quartus II v13.0sp1” which is the lowest version of the software free on the net. Please note that Intel acquired Altera about 5 years ago, so you’ll see a lot of material and references from both company names, but they are just one company now. We are also going to use the IDE on Windows platform and here is the link you need to download and install “Quartus II Software (includes Nios II EDS)” on your Windows system: https://fpgasoftware.intel.com/13.0sp1/?edition=web&platform=windows

(if you prefer working on Linux, you can just download the same version for the Linux platform and install on your system. The Linux IDE is actually smaller and simpler to install as we’ll show you on the Windows installation process to see why)

There are two more things you need to do before we can start our project:

  1. We need to download and install “Cyclone II, Cyclone III, Cyclone IV device support (includes all variations)” under “Device” section of the website download page. (see how to install below)
  2. We need to install the driver for USB Blaster. we can just open “Control Panel” after clicking on Windows Start icon, and then and search for “Other devices” under “Device Manager” to locate USB Blaster
Right click on "USB-Blaster" and select "Update Drivers"
On the "Update Drivers - USB-Blaster" popup page, select "Browse my computer for drivers"
select "Browse..." to the driver directory: "C:\altera\13.0sp1\quartus\drivers\usb-blaster"
then click on "Next" and on the next page,
select "Install" and then click on "Close" after the driver is successfully installed.

Once the proper driver is install, “Altera USB-Blaster” item will show in “Universal Serial Bus Controllers”. Please remember to plug the USB Blaster to your PC to implement this step! We will also plug the other end of USB Blaster on “JTAG” connector on the board for our project. (we are going to ignore the the connector “AS” next to “JTAG” connector in our project)

Note: on Linux platform, the above two steps are included in the IDE installation process.

Our Project

Our “Hello, World” project is not to show the text on our screen, but to see something happening on the dev board: there are a push button (key) and 3 LEDs by one side of the board close to JTAG connector, marked as “key JTAG D5 D4 D2” on the board. Our project is to program the FPGA board to show a visible LED pattern, and then change the pattern by press the push button.

The push button and LEDS are connected and accessible to pins on the dev board, we are going to program and manipulate the pins to implement our project.

There are two popular FPGA programming languages: VHDL and Verilog. Here we are going to use VHDL.

“Hello, FPGA!”

With all of the above preparation, let’s start our project by launch “Quartus II 13.0sp1” installed on your system.

Install the supported device if you have not done so:

Click on “Tools”, and then select “Install devices…” to install “cyclone_web-13.0.1.232.qdz” downloaded earlier.

To create a project, from “File” dropdown menu, select “New Project Wizard…”, click on “Next” on the Introduction.

Page 1:

On “Directory, Name, Top-Level Entity [Page 1 of 5]”, fill in blanks as the following
“What is the working directory for this project”
C:/Projects/Altera/MyProj
(You have to create the folder before you can select the above folder)
“What is the name of this project”
MyProj
“What is the name of top-level design entity for this project?”
MyProj
Click on “Next”

Page 2:

On “Add Files [page 2 of 5]”
Click “Next” as we’ll add files later on

Page 3:

On “Family & Device Settings [Page 3 of 5]”
In “Family:” dropdown list, select “Cyclone II”
In “Available devices:” table, select “EP2C5T144C8”
Click “Next”

Page 4:

On “EDA Tool Settings [page 4 of 5]”
Click “Next”

Page 5:

On “Summary [page 5 of 5]”
Click “Finish”

(the software pops up messages to ask you to buy software, you can just cancel to ignore them for this project)

From “File” menu, select “New…”
Under “Design Files”, select “VHDL File”
and click on “OK”

Copy the following VHDL code into the new file:

-- MyProj "Hello, FPGA"
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity MyProj is
Port (PB : in STD_lOGIC; -- pin 144
LED0 : out STD_lOGIC; -- pin 3
LED1 : out STD_lOGIC; -- pin 7
LED2 : out STD_lOGIC); -- pin 9
end MyProj;
architecture Behavioral of MyProj is
begin
LED0 <= not PB;
LED1 <= PB;
LED2 <= not PB;
end Behavioral;

Save the file as “MyProj.vhd” as VDHL program extension is .vhd

In VHDL programming language, “ — “ two dashes lead to comment line. Here we use “IEEE” standard logic library. In the “entity” section, the name “MyProj” has to match the “top-level design entity” name above in “[page 1 of 5]”. We also define all ports here. PB represents the push button which is used for input and connected to pin 144 on the board; 3 LEDs are the outputs connected to pin 3, 7 and 9 respectively on the board. In the “architecture Behavioral” section, LED1 is assigned to the same state as PB, and LED0 and LED2 are assigned to the opposite states to that of LED1. When you push the button, the 3 LED states will change which you can observe. We are not going to talk more about VHDL programming language here, which you can learn from tons of sources on the net.

At this point, we should be able to compile the program by clicking on “Processing” and select “Start compilation” with success if all syntaxes are correct. The compilation result should look something similar to the following:

However, we need to “hook up” the defined in and out logic to the actual pins on the board:

Click on “Assignments” and then select “Pin Planner”

You can either work on the chip image or the table to connect the pins, but the result should show as the following screen shot on the table:

From the table, you can click on the space under “Location” to select the pins from the dropdown list.

Now, you can compile it again. With a success of the compilation, we can now run it on the board:

From “Tools”, select “Programmer”, The programmer dialog box will pop up:

there are several steps we need to take care of:

  1. By clicking on “Hardware Setup…”, we should be able to select “USB-Blaster” from the “Available hardware items” table.

2. By clicking on “Add Device…”, we will select “Cyclone II” device family and “EP2C5T144” device:

3. By clicking on “Add File…”, we should be able to select “MyProj.sof” from the “output_files” folder:

After the 3 steps above, it should look similar to the following:

Please note that “Program/Configure” should be checked!

Now, by clicking on “Start” button on the left, the program is downloaded and run on the FPGA board, you should see the results from lit LED patterns. By pressing the PB on the board, the LED pattern will change as we designed!

Bonus

If you are wondering how Verilog program would work immediately, you can download http://doolittle.icarus.com/~larry/vhd2vl/ on Linux (I usually just use Windows WSL on my system):

$ tar — extract — file vhd2vl-2.5.tar.gz
$ ./vhd2vl MyProj.vhd > MyProj.v

note that Verilog file’s extension is .v

You can then create another project to play with Verilog version of your project.

Homework

The Cyclone II dev board actually has an EEPROM chip on it, you can create a .jic file to flash on to it such that next time you power up your board, it’ll run your program last time flashed on it.

Tip

If you have a hard time to read text on the board or the chip, you can take a good picture with your smart phone and look at it in an enlarged image.

Recommendation:

“Go Board” is recommended by the educational materials and projects on nandland.com

References:

[1] www.altera.com

[2] www.nandland.com

--

--