CS 232: Project 1

Title image Fall 2021

Project 1: Combinational Circuits

Due Monday 20 September 2021

Purpose: to give you experience with basic digital design components.


Tasks

  1. Prime-finder. Using Quartus, create a new project (call this one prime). Create a circuit with 4 inputs, treated as a 4-bit positive binary integer. The circuit should output a 1 if the input is a prime number and 0 otherwise. Note, the numbers 0 and 1 are not prime numbers.

    Simulate your circuit with ghdl by exporting the circuit to vhd and then adapting the testbench code from lab. It should test all possible combinations of inputs, similar to the way we tested the circuit in the lab exercise. Take a screen shot of both your final circuit design and your simulation. Include the screen shots in your report. Note, demonstrating that your circuit works is a required part of the project report. Be sure to test your circuit and document that testing in your writeup.

  2. Traffic lights. This project simulates two stoplights - one controlling north/south traffic and one controlling east/west traffic. The red, green, and yellow lights change as expected when the lights are timed (no need to include any car-sensors here!). The simulation has 16 "time steps" (we use a counter to counter from 0 to 15). At each step, the lights have a prescribed configuration (shown below). To tell the counter when to increment, we need an input. When you are using the board, that input can be a button - every time you press and release the button, the counter will increment and the lights will adjust accordingly. When we test the circuit with ghdl, we will have the counter increment at regular intervals - like clockwork. I.e. we will use a "clock" to generate that input (a clock is a signal that repeats a pattern of off and on with the same amount of time between each transition).

    Using Quartus, create a new project (call this one traffic). Create a circuit that has two components.

    1. One component should be a counter.
      • If you are using the board and don't want to simulate, you can use the lmp_counter avialable in Quartus.

        + (more detail)

        The important inputs to the counter are a clock and a reset or clear button. In the counter wizard process, set the counter to be four bits and check the box for the asynchronous clear option.
      • If you are off-campus or want to simulate, then you should use a counter written in VHDL.

        + (more detail)

        Download this VHDL counter. With your traffic project open, open the counter.vhd file. Then select Project:Add current file to project. Then select File:create/update:make symbol files from current file. The new counter symbol should appear in the symbol browser under the Project (i.e. press the button you use to add gates to the circuit and look under the tree for the project). Note that the counter I'm providing has an enable input, which should always be 1 (you can use the symbol vcc to create a 1) and a reset signal, which should start at 1 to reset the counter and then go to 0 a short time later to let the counter run. Make the reset signal be an input to your traffic circuit.

      The output of the counter will be a bus with four values. To access individual bits from the bus, add small wires for each input/output and assign labels to them. If you label the bus as q[3..0], then you can access the leftmost bit as q[3] and the other bits as q[2], q[1], and q[0]. If you have labeled your circuit inputs as A, B, C, D, you can use a wire gate and label the input to the wire gate as q[3] and the output as A.

    2. The second component should be a combinational circuit that controls the six lights of a 4-way traffic light. The output signals are NS-red, NS-green, and NS-yellow, EW-red, EW-green, and EW-yellow. They should follow the timings below, given the 4-bit input from the counter.

      Input ValuesLight setting
      0N/S Red, E/W Red
      1-5N/S Green, E/W Red
      6-7N/S Yellow, E/W Red
      8N/S Red, E/W Red
      9-13N/S Red, E/W Green
      14-15N/S Red, E/W Yellow

      Test your circuit by driving a 4-bit counter with a clock. (You should connect it to a button so that you can control when the counter adds 1. The counter is looking for each rising edge - each transition from off to on.) Demonstrate your six output signals for all possible inputs. You can take a video (if using the board or the board animation) or a snapshot of gtkwave to demonstrate your circuit is working properly.

      • If you have are campus and working with a board, you can test it directly with the board.

        + (more detail)

        The easiest way to test it is using the board and having a push-button as the clock input.
          Note that the buttons on the board are 0 when you push them down and 1 otherwise. Therefore, if you want to use a push button as a reset signal, run the signal through a NOT gate before feeding it into the counter. Then it will reset the counter when you push down the button.

        To use the board, you will need to do the following.

        • Select the device Assignments::Device to a Cyclone II FPGA with device number EP2C20F484C7.
        • Recompile your circuit.
        • Select the output pins using Assignments::Pin Planner. You can get the pin IDs from the DE1 user manual. Use the toggle switches as inputs and the LEDs as outputs.
        • Recompile your circuit.
        • Get a board from the grey cabinet and plug it into the USB port on the computer body. If the board does not light up, push the big red button on the board.
        • Use the Tools::Programmer to program your board. You may have to go to Hardware setup and choose USB-Blaster. You may also have to delete the current file and select the .sof file for your circuit in the output_files subdirectory. If everything is properly set, the Start button will be enabled.
        • Click the start button and your board should react. When the lights come back on, your circuit is ready to test.
      • If there aren't any boards available, then you can test it using ghdl.

        + (more detail)

        Download testbench for the traffic circuit. Be sure to read the code before compiling it. In particular, it makes an assumption about the order of the signals in the "port" definition in traffic.vhd. Also, note that I include both signals for the lights (such that 1 is lit), but also their inverses (so that 0 is lit). I do this in case you want to use segments from the 7-segment display in a board animation (7-segment displays are on when the signal is 0).

        Compile and run the code using ghdl.

        ghdl -a trafficbench.vhd counter.vhd traffic.vhd
        ghdl -e trafficbench
        ghdl -r trafficbench --vcd=trafficbench.vcd    
        						
        View the simulation using gtkwave or animate it using vcd_movie.py. If you make the animation, remember to make the mapping file first.

        Take a screen capture of your final circuit and your simulation. Include them in your project report.


    Extensions

    The following are some suggested extensions for the project. You are free to develop your own ideas as well.

    • Sometimes, it is more efficient to design the inverse circuit (it outputs 1 for all zeros and 0 for all ones) and invert the output. Explore whether this is the case for one or more of the circuits in this lab.
    • Extend the prime numbers circuit to 5 or even 6 bits.
    • Do something interesting with the traffic light circuit, like add a walk button that makes the light leave the opposite green early (this is challenging).
    • Pick a different (but simple) function, then go through the design process and implement the circuit.

    Writeup

    Create a wiki page with your report. For each task, write a short description of the task, in your own words.

    + (more detail)

    Colby Wiki - a Wiki is a convenient way to put content up on the web quickly and easily. If you have not used the wiki before, thenyou will need to create your space. Log in to the wiki, and click on "Create your personal space" For each project, you will create a new page in your wiki space. You can create a new page in your space by pressing the "Create Child Page" link in the lower left of the side bar. You can edit any existing page in your space by going to that page and then pressing the Edit link in the upper right.
    1. Make a page for Project 1. Press the "Create Child Page" link, press the Next button, then Replace the "New Page" title with something meaningful, like "Milo's CS232 Project 1" so that the page content is clear from the title.
    2. Now save your page. Even though it has no content, let's save it -- it is a good idea to save often. After saving your page, it will show up in the list of child pages in the side bar. To make it easier to find this page again, it is probably a good idea to make a link to it in your home page in your space. To do so, find the home page for your space (you can just select Personal Space from that under-the-person menu) , press the Edit link, then press the link button (it looks like a chain) and search your space for it. But it is also perfectly acceptable to simply leave it as a child page.
    3. In all of you project wiki pages, you will need to include pictures of the images you created with your program. To edit the content of the project 1 wiki page, click on the link to it, then press Edit. Write text and include images as indicated in the project and write-up instructions.
    4. Label the page. The label field is a text field at the bottom of the page, and is different from the title of your page. Each assignment will specify a label, which we will use to find your pages so we can show off your work and so we can grade it. For this project, add the label cs232f21project1.

    The primary purpose of your report for this class is to demonstrate that you did the assignment and that your circuits work properly. Therefore, your report needs to include pictures of required design documents, a description of your testing procedure, and a description of the results of the testing procedure.

    For a simple circuit with a small number of inputs and outputs, your testing procedure might be an exhaustive evaluation of all possible input/output combinations and a visual inspection that they were all correct. For more complex circuits that generate complicated patterns or processes -which we do later in the semester--the demonstration might be a video of the circuit working. Screen captures of the ghdl waveform output is often the best evidence that your circuit is working properly.

    • Include a description of the task, in your own words.
    • Include a picture of your final design.
    • Include a picture of your ghdl waveform simulation.
    • Describe why the simulation proves your circuit works.
    • If you tested your circuit using hardware, describe your procedure and explain why it is sufficient.
    • Include a description, and pictures, of any extensions.

    Handin

    Give your wiki page the label cs232f21project1.

    Put your bdf and vhd files in a folder called project1 in your private subdirectory on the Courses server in /CS232. Please put only the bdf and vhd files into your handin directory, not the whole project.

    Here are links to two videos describing how to turn in code.

    1. Video on how to mount the Personal and Courses fileserver volumes (for on-campus computers and computers running the VPN Pulse client)
    2. Video on how to use the web interface.