CS232 Lab 2: Programming Hardware

Main course page

The purpose of this lab is to get you working with larger, pre-built modules in Quartus and to begin programming the DE1 hardware boards.

This lab you will need to complete on your own.


  1. Start Quartus. Follow the new project wizard and create a new directory for lab 2. Call your first project flash. This is the name of the project and the top level entity, but it will not be the only design file you create and use. You will be placing multiple design files into the same directory so you can include one or more designs into the top-level entity.
  2. Select File->New and create a new VHDL file. VHDL is a programming language for specifying hardware configurations. Use the Edit->Insert Template option to select the Unsigned Adder full design template.

  3. Change unsigned_adder to boxdriver in both the entity and architecture declarations. Then save the file as boxdriver.vhd.

    Simplify the template so it has only a single input signal (delete input b). Then remove the generic block and make both the input and output be unsigned (3 downto 0). The inputs are now unsigned binary vectors with 4 bits, indexed from 3 down to 0, with index 3 being the most significant bit.

  4. Delete the addition line in the architecture block and then insert the template for a conditional signal assignment using Edit->Insert Template.

    Your goal is to make a decoder for the two most significant bits. i.e, the 0th bit is set to 1 when the input encodes the numbers 0 through 3, the 1th bit is set to 1 when the input encodes the numbers 4 through 7, and 2th bit is set to 1 when the input encodes the numbers 8 through 11, and the 3th biti s set fo 1 when the input encodes the numbers 12 through 15. Here is an example of code that handles the 0th bit:

    result(0) <= '1' when a = "0000" or a = "0001" or a = "0010" or a = "0011" else '0';

    Copy this code and write the necessary code to set the other 3 output bits.

  5. Select Project->Add current file to add the VHDL file to the current project. Then select File->Create symbol file so that you can include the project in other project files. This may require you to fix any bugs in the code.
  6. Create a new BDF file. Add 2 input pins and 4 output pins to the design. Name the two input pins clock and reset. Name the four output pins LEDR0, LEDR1, LEDR2, LEDR3. (Note that these are not the names given in the picture. Use the picture for the circuit layout -- not hte naming.)
  7. Add an lpm_counter device: megafunctions->arithmetic. Set up the clock to be 4-bits with a clock and asynchronous reset as the only inputs. After inserting it into your design, hook up the clock and reset signals from the input pins (which you should name something like "clock" and "reset".
  8. Add the boxdriver symbol to the graphic design file. Hook the counter outputs to the boxdriver inputs. Then hook the four boxdriver outputs to the four output pins. The circuit should look like the diagram below (again, ignoring the names).

    Save the file as flash.bdf, add the project to the file and then compile the project.

  9. Simulate the project.
    • Make the netlist
    • Send it to modelsim
    • vsim flash
    • View the wave window, then set up the clock and reset inputs.
    • Add the output pins to the wave window.
    • run 1000ps

  10. Back in Quartus, go to Assignments->Pin Planner. We need to make sure the input and output pins are connected intelligently when we download the design to hardware.

    You will want to have the DE1 User Manual handy when assigning pins.

    Use the popup menus (or just type the names) in the location field for each pin to set them to the desired values, or just type the pin name into the pin field. Connect the clock to the first push button. Connect the reset to the second push button. Connect the four outputs to four LEDs (use the pin names as an indicater for which LEDs I am refering to on the board).

  11. Use the Tools->Programmer to download your circuit to the board. If the programmer says 'No Hardware', then select Hardware Setup and in the popup menu select Byte blaster. Test out your circuit by holding down the reset push button (which is 0 when pressed) and then push the clock input. You should have one LED light up at a time. After every four clock cycles, a different LED should light up.

For more info on VDHL, see Stephanie's notes on VHDL.

When you have completed the lab assignment, go ahead and get started on the second project.