element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • 'Choose another store...'
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
FPGA
  • Technologies
  • More
FPGA
Blog Blog 3: Interfacing with FPGAs - LEDs, switches, 7 segment displays
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
FPGA requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: rsjawale24
  • Date Created: 5 Aug 2022 6:54 PM Date Created
  • Views 952 views
  • Likes 4 likes
  • Comments 0 comments
  • 7 Ways to Leave Your Spartan-6
  • fpga_projects
  • xilinx
  • fpga
  • arty s7
  • spartan-7
  • Spartan_Migration
Related
Recommended

Blog 3: Interfacing with FPGAs - LEDs, switches, 7 segment displays

rsjawale24
rsjawale24
5 Aug 2022

In my last two blogs, I talked only about VHDL codes and the implementation of digital logic design in Vivado. In this blog, I will be working on the hardware aspects.

I received the Arty-S7 board from e14 for the Spartan_Migration challenge. I will use the board to perform simple experiments to show how to control hardware such as switches, LEDs, using FPGAs. Then for an advanced project, I will use the board to implement an IR-based object counter project by adding an IR sensor.

Arty S7 Board

Let's take a look at the board first -

It came in a nicely packed box with ARTY S7 written on top. It mentions that it is for makers and hobbyists and after experimenting with the board, I can agree. It is pretty simple to get started with the board, and Digilent provides ample resources online to get started with the Arty S7 board. You can find them here.

image

The FPGA board looks like this

image

It has plenty of switches that can be used for inputs (4 push buttons and 4 toggle switches) = 8 inputs!!

It also has 4 LEDs +2 RGB LEDs from LD0 to LD5 apart from that, there are 4 ports (PMOD connectors) with 8 I/O pins per port that can be used for interfacing with other components such as displays, Bluetooth modules, etc as some of the other challenges have shown it in their blogs.

Powering it up!

Let's try powering on the board.

Upon powering it on, the pre-loaded program starts running inside the Spartan-7 FPGA and the LEDs start "running" from left to right and right to left.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Playing with the toggle switches, the LEDs just glows, corresponding to the switch toggled. The push buttons change the status of the 2 RGB LEDs to Off, R, G, and B states, respectively.

Constraints file and Programming the FPGA

Now let's try to implement a simple hardware-controlled logic gate such as AND gate that I implemented in the last blog. Here, I will use the toggle switches as inputs to the AND gate and one of the LEDs as an output for the AND gate.

The entire process of writing the code remains the same as last blog, except that now we have to define that the inputs are actual inputs from the real world (hardware) and the output is an actual real-world device (LED). To do so, we have to write a constraints file in Vivado. A constraints file will "map" our input and output signals that we have defined in the VHDL code to the physical pins on the FPGA, where we will connect our switches and LEDs.

Since the PCB for the Arty S7 is already there, we cannot change the connections of these hardware components with the FPGA chip, so for defining the constraints file, I will first take a look at the datasheet to check the connections of these switches and LEDs with the pins of the FPGA so that we can define our constraints.

The connection diagram below shows the connections of the physical pins with the external components. We have to define these physical pins in the constraints file.

image

Here the toggle switches/slide switches are connected to the FPGA's H14, H18, G18, and M5 pins. I will use the H14 and H18 as inputs. Similarly, for the LEDs, I will require only 1 LED to show the output; I will use the LD2 connected to the E18 pin of the FPGA.

To define a constraint file, there are two methods -

  • Most of the blogs that I read here used the master XDC file to define the constraints. A master XDC file is available for download from the digilent website. The master XDC file contains all the external components that are present on the Arty S7 board mapped to the respective pins. This method is relatively easy as all the peripherals are already listed in the master XDC file and the user just has to uncomment the required lines. Personally, I do not prefer this method as every time; I have to delete or comment the constraints that are not in use for my project.

  • The second method is by defining our own constraints using the I/O floor planning window. This is my preferred method because this gives the user flexibility in case you are working on a standalone FPGA chip instead of an evaluation board. You need not worry about the syntax, as the I/O floor planning will automatically generate the XDC file for you. The user just needs to know the correct logic for the particular device. Here, for the switches and LEDs, it is LVCMOS33.

To define the constraints, first, open the implemented design in Vivado (after running synthesis and implementation)

image

Then from the drop-down menu at the top right corner, select I/O planning.

It will open a new tab below named I/O ports. This will automaticall detect the I/O ports from our VHDL code.

image

Just for reference, this was my entity for AND gate -

entity logic_gates is
    Port ( A : in STD_LOGIC;
           B : in STD_LOGIC;
           C : out STD_LOGIC);
end logic_gates;

The I/O floor planning automatically detected 3 ports, 2 inputs, and 1 output. Now from the drop-down menu for each pin, I can select the package pin as mentioned above. The switches are H14 and H18 and LED with E 18 pin with LVCMOS33 logic for all. Once everything is defined in floor planning just click on save and vivado will prompt you to save and name the XDC file.

I have shown how the automatically generated XDC file looks like

image

Now again, run the synthesis and implementation after generating the XDC file. Finally, for the last step, generate a bitstream; If the XDC is correct, this will generate a file that has to be loaded into the FPGA. The bit file will program the FPGA with our code, and it is expected that the FPGA will give the results as seen in the simulations.

To program the FPGA with our bit file, click on hardware manager -> open target -> program device. This will open a prompt to program the device (FPGA) with the bit file.

image

That's it. Now the FPGA has our program inside the core. Let's give it a try. The initial demo program is erased from the FPGA, and now I will try if my implemented AND gate works or not.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

The above video shows all the logic combinations for a 2-bit input using the switches. It can be seen that only for both the switches ON (11) combination, the LED is ON, and for all other combinations, the LED remains OFF.

Hence, it is verified that our VHDL code actually works as expected inside the FPGA, and we also saw how to interface external real-world components with the FPGA and control them.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube