Hardware, Software & Product Development | Sparx EngineeringHardware, Software & Product Development | Sparx EngineeringHardware, Software & Product Development | Sparx EngineeringHardware, Software & Product Development | Sparx Engineering
  • Home
  • Expertise
    • Software Engineering
    • Electrical Engineering
    • Chemical Products and Services
    • Biomedical Engineering
    • Mechanical Engineering
    • Production Management
    • Automation
    • Industrial Design
  • Blog
  • About Us
NextPrevious

Talking RS-232 with Cyclone II FPGA, Part 1

By dfohl | Software | 0 comment | 22 February, 2013 | 0

I’ve been interested in learning how to program FPGAs, and I recently purchased a Cyclone II FPGA Starter Board from Altera to learn some of those skills.

It comes with a few tutorials on how to make the LEDs blink and such, but nothing more than that.  That’s great, but if you’re wanting to do any kind of numeric processing, there’s no way that blinking LEDs can give you the feedback you need to determine if your algorithms are right.  You need some way to be able to communicate over a serial port.  I’ll present a series of posts on how to get you up and running with a new dev kit.  In this first one, we’ll simply create a project that echoes your serial port back to you.  In that process, we’ll learn how to create projects, place and map pins, and program the FPGA.

You may want to follow along with Altera’s LED blinker tutorial in parallel, in case I left some steps out.

First thing, get rid of the outdated Quartus CDs that came in the box, and download and install the most recent version of Quartus II Web Edition directly from Altera.  This is a huge download, so use a fast connection!

This takes a while to install too, but go ahead and accept the defaults and grab a cup of coffee.  Once it’s finished installing, you’re ready to roll with FPGAs.  Click the icon to launch Quartus II Web Edition, select File > New, and create a new project.

fpga tutorial 1

On the first page of the wizard, set up your working directory and project name.  Note that you probably don’t want to take the defaults here, as they put everything into your install directory, and also note it doesn’t automatically create a subdirectory with the name of your project, so you have to specify that yourself.  Go ahead and use “C:fpgaserialecho” as the directory, and “serialecho” as the name.

fpga tutorial 2

Page 2, just click Next.

On page 3, choose the Cyclone II family, and the device name is “EP2C20F484C7”, as you can see by looking at the chip.  (Ignore the “n” at the end of the name—that just means it’s a lead free chip, as you can see in section 6-2 of the Cyclone II Handbook).

fpga tutorial 3

On page 4 and 5, just click Next and Finish to create your new project.

Now, we need a top-level schematic to lay out our components.  So click File>New, and choose Block Diagram/Schematic File.

fpga tutorial 4

That’ll create your design canvas, which you should see on your screen.  So now save it (you have to click “Save As”), and feel free to take the default name, which should be the same as your project.

Great!  Now all we have to do is add I/O pins for the serial port, and hook everything up.  Let’s do that now.

To add the pins, you could double-click the canvas and search for the I/O pins among the symbols, but there’s a shortcut.  The icon right above the canvas that looks like this  is a pin placement shortcut.  Use this to place one input pin and one output pin on the canvas.  Double-click the names of these to rename them to “232_in”, and “232_out” respectively.

Now we have to hook them up.  Since echo is simply looping the Rx back onto the Tx line, all we have to do is connect the two symbols with a wire.  The final diagram should look like this.

fpga tutorial 5

Now the final design step is to assign the pins in our diagram to actual pins on the chip.  To prepare for this, choose Processing > Start > Start Analysis & Elaboration.  This will churn for a while and lets Quartus pre-populate your pin settings with the names of the pins you’ve given above.

Now select Assignments > Pin Planner.  For this step, we have to look up in the design spec which FPGA pin ID’s correspond to the serial pins.  We find that the the 232 input is F14, and the output is G12.  We add those locations to the editor, and it should end up looking like this:

fpga tutorial 6

You’ll also note that on your canvas, it adds a note to each pin symbol.

fpga tutorial 7

And that’s it!  We can now compile the project and load it onto your FPGA board.  Press the play icon to compile it.  To the right there’s a diamond-shaped icon that gives the tooltip “Programmer”—click that one to bring up the programming dialog.  With your FPGA dev board plugged into the USB port and turned on, click the Hardware Setup button, select the USB-Blaster option from that dropdown box and press Close.

Now you should be able to use your favorite terminal tool at 115200 baud and see data being echoed back to you over a serial port.  I only had to use a gender changer to hook it up to a standard serial cable, but when using a USB-serial adapter, I also had to add a null-modem adapter.  If one doesn’t work, then try the other.  If neither work, then make sure you’ve got your pins assigned correctly; I initially had the assignments reversed and it took me a good fifteen minutes before I figured out what was wrong.

Next time we’ll look at adding some custom components for encoding and decoding between these serial streams into actual bytes on the FPGA.

This blog post is Part 1 in a series. To view Part 2, you’ll want to Go Here. To view Part 3, you’ll want to Go Here.

Altera, Cyclone, Dev Kits, FPGA, Quartus II, Tutorial
dfohl

dfohl

More posts by dfohl

Related Post

  • Talking RS-232 with Cyclone II FPGA, Part 2

    By dfohl | 0 comment

    In my previous blog post on RS-232 with the Altera Cyclone II FPGA, I demonstrated how to create a serial echo by simply connecting the Tx wire and the Rx wire together.  That’s a greatRead more

  • Communicating with your Cyclone II FPGA over serial port, Part 3: Number Crunching

    By dfohl | 4 comments

    In my first blog post on communicating with the Altera Cyclone II FPGA, I demonstrated how to create a serial echo by simply connecting the Tx wire and the Rx wire together.  Then in my second post IRead more

  • Sparx Selected to Join Altera FPGA Design Services Network

    By paulh | 0 comment

    Altera contacted Sparx in March to set up a qualification meeting for an invitation to the their Design Services Network (DSN). The purpose of Altera’s DSN is to create a highly visible worldwide network of qualifiedRead more

  • How to Model NPT Threads in Solidworks

    By rmontifar | 2 comments

    National Pipe Thread Taper or NPT threaded pipes and fittings are deployed in a variety of fields where transportation or containment of liquids, gases, steam, or hydraulic fluid is required. The NPT geometry allows internalRead more

  • Capturing Keypress With Windows Message Filter

    By bjohnson | 3 comments

    Recently I ran in to a situation where I had to capture keystrokes at the application level and launch an action based on the keystroke.  I tried using the ‘keyPress’ event for the main form,Read more

Leave a Comment

Cancel reply

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

NextPrevious
  • Home
  • Expertise
  • Blog
  • About Us
Sparx Technologies, LLC. dba Sparx Engineering © 2009 - 2020 | All Rights Reserved
  • Home
  • Expertise
    • Software Engineering
    • Electrical Engineering
    • Chemical Products and Services
    • Biomedical Engineering
    • Mechanical Engineering
    • Production Management
    • Automation
    • Industrial Design
  • Blog
  • About Us
Hardware, Software & Product Development | Sparx Engineering