Overview

This assignment is to implement a four-bit up/down counter on the UP2. When PB1 is pressed, the counter increments once per second, and when PB2 is pressed, the counter decrements once per second. When neither button is pressed and when both buttons are pressed, the counter does not change state.

Procedure

  1. Set up the project directory for the assignment.

    Create a subdirectory named Assignment_03 under your My Projects directory and copy the following files into it:

    • hex2sevenseg.v This is the same file I provided for Assignment 2.
    • divideBy25.175M.v I am providing this file for converting the 25.175 MHz clock on the UP2 board to a 1 Hz clock so that you can see the behavior of your counter.
    • Your 4x1 multiplexer BDF file from Assignment 2.
  2. Create the project and create the initial set of symbols.

    Create a project in your Assignment_03 directory named Assignment_03, and with the top-level design entity is named UpDownCounter. Add the three files already in the Assignment_03 directory to the project. Open each one and convert it to a symbol.

  3. Create the top-level design, and assign the pin numbers.

    The top level design has three input pins, named Up, Down, and Clock, and seven output pins, one for each segment of one seven segment display. Connect an instance of the hex2sevenseg symbol to the output pins, and connect the Clock input pin to the ClockIn pin of an instance of divideBy25175000. Build the project once now so the assignment editor will know the names of your pins.

    Assign PB1 (Pin 28) to Up, PB2 to Down (Pin 29), and assign Clock to Pin 91. Rembember that the pushbuttons need to be inverted in order to generate a 1 when pressed. Assign the outputs of hex2sevenseg to the appropriate pins of the right seven segment display on the UP2. Optional: Connect output pins to the segments of the left display and the two decimal points, and connect the inputs to those pins to Vcc (Logic 1) so they will remain dark.

  4. Create a symbol for one counter bit.

    There are five inputs and one output for a counter bit. The inputs are named Up, Down, ToggleUp, ToggleDown, and Clock. Connect Up and Down to the selector inputs of a 4x1 mux, and connect the output of the mux to the D input of a D Flip-Flop. You will find a D flip-flop under primitives→storage. It has two extra inputs named prn and clrn that you will need to connect to Vcc. (When they are negative, they preset and clear the flip-flop independently of the clock.)

    Connect the inputs to the mux so that the flip-flop does nothing if neither Up nor Down is true or if both are true. Use mux input number 1 to cause the flip-flop to toggle if ToggleUp is true, and use mux input number 2 to cause the flip-flop to toggle if ToggleDown is true.

    Connect the output of the flip-flop to an output pin named Q.

    Name the schematic counterBit and save it as a symbol.

  5. Create a four-bit up/down counter.

    Use four instances of counterBit to build a 4-bit up/down counter. Input pins should be named Clock, Up, and Down. There should be four output pins named Out_8, Out_4, Out_2, and Out_2 connected to the Q outputs of the counterBit instances. Save as a symbol

  6. Complete the top-level design and test

    Insert an instance of the four-bit counter in the top level design. Compile the design and test it to make sure it counts up and down correctly and does nothing when neither button is pressed and when both buttons are pressed.

Submit the Assignment

When you have completed the circuit and tested to be sure it works correctly, send me an email message telling me the project is ready for grading. Be sure to put CS-343 Assignment 3 in the subject line to avoid the wrath of my spam filters! I will get a copy of your assignment from maple and test it.

If you worked on the assignment with someone else, be sure to list the names of both contributers in the email message so you both get full credit. Be sure to tell me which account has the final version of the project for me to look at.

Remember, it is perfectly all right to help each other to do the assignment. Just don’t exchange design files with each other; nobody learns anything if you do that.

Due Date The assignment is due by midnight, September 28. Do not submit the assignment unless you have verified that it works correctly using an actual UP2 in the lab. Having said that, you can get partial (half) credit for “trying.” Just say in your email that the assignment is incomplete, and I will look at your project, but not try to run it.