Quick Quartus: Verilog

← Back to E15 Lab page ←

Please contact me if you find any errors or other problems (e.g., something is unclearly stated) in this web page

This document presents a (very) quick introduction to the use of Quartus to design a system using verilog.

The Basics
Adding a clock
Adding a counter
Simulation
Some Useful References

The Basics

  1. Start Quartus (it is in the "Altera" folder in the Windows Start menu).
  2. Select "Create a New Project (New Project Wizard)"
  3. Hit "Next >" to get past "Introduction" page.
  4. On the next page ("Directory, Name, Top-Level Entity [page 1 of 5]") choose a working directory (preferably one you can access from anywhere on campus) and choose a project name.  Then hit "Next >"
  5. Hit "Next >" (from "Add Files [page 2 of 5]").
  6. On the next page ("Family and Device Settings [page 3 of 5]"):
    1. choose Family: "Cyclone II"
    2. choose Available Devices: "EP2C35F672C6" (the number on the large chip on the DE2 Altera board).  Note, these are not alphabetical, so you need to scroll through the choices.
    3. hit "Next >"
  7. Important - this is different than what we did for schematic entry. 
    On the next page ("EDA Tool Settings [page 4 of 5]"), under "Tool Type→Simulation" pick "ModelSim-Altera" for the "Tool name".  Then hit "Next >".  (Note: this is only necessary for projects that you will be simulating; if you don't expect to simulate, you don't need to do this.  Also, if you only want to simulate, you can use ModelSim alone without Quartus; you'll learn about this in class (the process is much faster).).
  8. Hit "Finish" ("Summary [page 5 of 5]")
  9. From the Quartus main menu choose "File→New→Verilog HDL File" then "OK"
  10. Enter the text below into the file and save in a file "E15Lab2_Simple.v".  Note that the file name and module name should be the same as the top level entity (the name you chose previously).  As with "C," there are no rules about indenting - but be neat and be consistent.
  11. Go to "Assignment→Import Assignments..." and choose the E15DE2_IO.qsf file.  This should automatically assign the proper pins.
  12. Compile your code, then program the device.  Verify that it works as expected.

Adding A Predefined Circuit Element

We can also add our own circuits to those supplied by Altera.  In particular, it will sometimes be useful to add a slow clock and a counter so that we can cylce through multiple inputs.  Let's start with the clock.

  1. Add the file  "E15Clock1Hz.v" to your working directory.  You'll learn what's in the .v file later.  Essentially it takes the 50MHz clock on the DE2 board and converts it to a 1Hz clock.
  2. Go to "Project→Add/Remove Files in Project..." and add "E15Clock1Hz.v" to the project.
  3. Create a new verilog file called "E15Lab2_LessSimple.v" and enter the following text.  Save it in your working directory.
  4. Now make this new file the active one by going to the "Project Navigator" pane, choosing the "Files" tab.  Then right-click on "E15Lab2_LessSimple.v" and choose "Set as top-level entity".
  5. Compile and download.  Figure out what it should do, and verify that it works as expected.  Try to use KEY[0] to keep the middle LED on the I/O board turned on. Fun, fun, fun...

The return of the counter

  1. Now add the file  "E15Counter.v" to your working directory and include it in your project.  This file counts up to a predetermined maximum count (like the one you used in lab 1).
  2. Create a new file ("E15Lab2_EvenLessSimple.v") with the following code:
  3. Save the file and make it the top-level entity, compile it, and run it.  Make sure you understand what it is doing (you'll be using "E15Clock1Hz.v" and "E15Counter.v" later in the lab).

Simulation

  1. Go to the "Project Navigator" pane and set "E15Lab2_Simple.v" as the top level entity.
  2. Compile it, and then go to "Tools→Run EDA Simulation Tool→EDA RTL Simulation".  A program called "ModelSim" should start.  (Note: we are doing a functional simulation only, the actual timing of signals (e.g., gate delays...) is not considered)
  3. In the "Library" pane, expand the "work" library (at bottom of window).  Double click "E15Lab2_Simple" to load the design.
  4. Either go to "View→Wave" or enter "View wave" (without quotes) in the transcript window.  This opens a waveform viewer.
  5. In the "Objects" pane select "KEY[0]" and "KEY[1]".  RIght click on the selection and choose "Add→To wave→Selected signals".
  6. In the "Transcript" pane enter "add wave LEDY_M"
  7. Right click on the KEY[0] signal in the waveform viewer, select "Clock..." and set it to a square wave with a period of 100 simulation units:

    Notice that a command (something like "force -freeze {sim:/E15Lab2_Simple/KEY[0]} 1 0, 0 {50 ps} -r 100") appears in the transcript window.  This is telling ModelSim that we want a repeating clock with a 50% duty cycle.  More commands are here.
  8. For "KEY[1]" use:
  9. Now let simulate.  Go to "Simulate→Run→Run 100".  This tells the simulator to run for 100 time steps.  The "Wave" pane has the results of the simulation:
  10. Increase the length of the simulation by typing "run 200" in the "Transcript" pane.  The simulation now runs for 200 more cycles.  You can right-click on the "Wave" pane and select "Zoom Full" (or just press "F" on the keyboard).
  11. It is also possible to run a simulation from a script.  Create a file by going to "File→New→Source→Do" and enter the following:
    restart -force -nowave
    delete wave *
    add wave KEY(1:0)
    add wave LEDY_M
    force -freeze KEY(0) 0 0, 1 {10 ns} -r 20 ns
    force -freeze KEY(1) 0 0, 1 {20 ns} -r 40 ns
    run 200 ns
    More ".do" commands are here.
  12. Save as "myfirst.do"
    *IMPORTANT*  If you make changes to the ".do" file, you must save them before they take effect.
  13. In the transcript window enter "do myfirst.do".   This will run all the commands in the ".do" file, resulting in the following waveform.

    *IMPORTANT*  If you make changes to the ".do" file, you must save them before they take effect.

Some Useful References (specifically for ModelSim and ".do" files)

 

← Back to E15 Lab page ←

Please contact me if you find any errors or other problems (e.g., something is unclearly stated) in this web page