Learning to program FPGA’s

About two months ago a couple of guys from Labitat (including myself) decided to meet up every other week for an FPGA playpen.

I have worked a little with FPGA’s back when I was studying at the university, but have since forgotten most of it, so I will be starting out with the basics and slowly move on to more advanced aspects of designing logic for FPGA’s.

The first couple of times was used to get everything set-up (I’m using a Mac, so this involves a virtual machine running Windows 7 32Bit) and getting a super simple “Hello world” design implemented and running.

I’m using the AVNET Xilinx® Spartan®-3A Evaluation Kit, which in addition to a Spartan 3A FPGA, uses a Cypress PSoC as the USB programming interface, and both serial and parallel flash from Spansion. The board is fairly simplistic – there are not a lot of interface connectors or displays – only 4 diodes for testing output, 4 capacitive touch buttons wired via the PSoC to the FPGA and a tiny I2C temperature sensor from Texas Instruments.

The kit includes a regular USB cable and MiniProg programming unit for the Cypress PSoC in case you need to update the firmware (I did) or simply want to play around with the PSoC.

“Hello World” design in VHDL

The first implementation is from the “ISE FPGA Design Introduction” available at the AVNET Resource Center.

The guide is written for Xilinx ISE 10.1, but the major parts are almost identical with the newer 12.1 release of the free Xilinx ISE Webpack.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
 
entity simple_count is
    Port ( clock : in  STD_LOGIC;
           enable : in  STD_LOGIC;
           leds : out  STD_LOGIC_VECTOR (3 downto 0));
end simple_count;
 
architecture Behavioral of simple_count is
 
signal count: std_logic_vector (3 downto 0) := "0000";
 
begin
 
process (clock) 
begin
   if clock='1' and clock'event then
		if enable='1' then
			count <= count + 1;
		end if;
   end if;
end process;
 
leds <= count(3 downto 0);
 
end Behavioral;

In the above design, the ‘clock’ is connected to the 16MHz clock input on the FPGA, the ‘enable’ is connected to button 1, and the ‘leds’ bus is connected to the 4 LEDs on the board. The UCF file for use with the AVNET Xilinx® Spartan®-3A Evaluation Kit is listed below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
NET "clock" TNM_NET = clock;
TIMESPEC TS_clock = PERIOD "clock" 62.5 ns HIGH 50%;
 
NET "clock" LOC = C10;
NET "enable" LOC = K3;
NET "leds<0>" LOC = D14;
NET "leds<1>" LOC = C16;
NET "leds<2>" LOC = B14;
NET "leds<3>" LOC = D13;
 
NET "clock" IOSTANDARD = "LVCMOS33";
NET "enable" IOSTANDARD = "LVCMOS33";
NET "leds<0>" IOSTANDARD = "LVCMOS33";
NET "leds<1>" IOSTANDARD = "LVCMOS33";
NET "leds<2>" IOSTANDARD = "LVCMOS33";
NET "leds<3>" IOSTANDARD = "LVCMOS33"

When you press button 1, the counter will be incremented and the LEDs will flash very quickly. When you release button 1, ‘enable’ will go low and the counter will stop being incremented. This will result in the LEDs showing the counter value from when the button was released.

It’s a very simple design, but what I like about it is that even as a beginner, it’s possible to understand all the steps involved. Next time we will go a little further, but still keep it as simple as possible.

3 thoughts on “Learning to program FPGA’s”

  1. Milos Pekar says:

    Dear Thomas,
    I’m a student and I’m interested in FPGAs, but I’m a rookie. I’m using the same AVNET Xilinx® Spartan®-3A Evaluation Kit you were talking about, which includes Spartan 3A FPGA, . I was wondering if you could tell me more about connecting the board itself to PC (do I use the PSoC or USB cable alone) and how can I implement the VHDL code, written in Xilinx ISE 10.1 Project Navigator, on FPGA? The more details, the better.
    My code is OK, but when I get to iMPACT I choose “Configure device using Boundary Scan chain” and then there’s a message “Can not find cable, check cable setup”. I don’t know what to do since all I’ve got is FPGA board, PSoC and regular USB 2.0 cable.
    So, if you could please give me precise instruction on what to do (how should I physically connect board and PC and how should I implement the code) I would be very grateful.
    Some details: I’m using Windows XP 32 bit OS, ISE Design Suite 10.1 and AVNET Xilinx® Spartan®-3A Evaluation Kit (XC3S400A-4FTG256C).
    Kind regards!

  2. Hi Milos,

    When I have been using this board, I have used the USB connection to program the FPGA (or to be precise I program the flash memory, that configures the FPGA during startup). I have used the little PSoC programmer, to update the firmware on the PSoC. I can’t remember exactly what the problem was, but I haven’t used it since, only the USB connection on the board.

    It’s been awhile since I have played with it, but if I remember correctly, I installed a driver from the CD, and I used a newer version of ISE, something like 12 or 13… There seems to be some differences between the different versions, stuff that worked on version 12, needed some fixes to work on 13, but I don’t remember any problems in actually programming the board.

    I started by following a guide to the specific card with a simple led blink program, and I suggest you do the same… there was a very nice description of all the steps needed to make a project, configure it, select IO pins and do the actual programming.

    I think there was a special AVNET program that I used to do the actual programming, but it should be available on the CD or from the resource center on AVNET.

    I hope the above helps a bit in the right direction. I don’t have the board in front of me at the moment, so this is just off the top of my head.

    /Thomas

  3. Milos Pekar says:

    Thanks, Thomas!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>