EECS 270: Lab 5

Designing combinational circuits II

See the lab schedule for due dates.
Value: 150 points

  1. Overview
  2. In this experiment you will learn more about modular design of combinational circuits. The type of circuit you'll be designing lends itself very naturally to this style of design: it is a datapath whose structure, or architecture, is typically determined by the types of operations it is required to perform. In addition, datapath circuit signals come in two distinct varieties: data and control. Control signals determine where to send, or route, the data signals and what operations to perform on them. Data signals, on the other hand, are the primary carriers of information in the circuit, and are typically bundled as multi-bit words. Datapath circuits tend to be quite regular, allowing the use of a structured design approach that simplifies the design process and leads to easily testable implementations.

  3. Preparation

  4. Figure 1: Top-level view of the CALCULATOR circuit.

  5. Design Specification
  6. The top-level schematic of the CALCULATOR circuit is shown in Figure 1. It has a 2-bit opcode C and two 4-bit operands A and B that represent two's complement integers. The output F must be generated according to the following function table:
    Key3 (C1)Key2 (C0)Operation
    PressedPressedDisplay A+B
    PressedUnpressedDisplay A-B
    UnpressedPressedDisplay the absolute value of B
    UnpressedUnpressedDisplay the absolute value of A
    Table 1: Calculator operations

    The A and B operands should be connected, respectively, to DIP switches 3-0 and 7-4 (the higher number being the MSB). The opcode bits (C[1:0]) should be controlled by the two leftmost buttons. The CALCULATOR output (F) should be displayed in decimal signed-magnitude notation using three 7-segment LEDs: The two rightmost to display the 2-digit decimal magnitude, and the next one (on the left) to display a negative sign for negative results (the middle horizontal bar).

    Verilog and schematic restrictions
    Your top-level module must be a schematic. You are welcome to use Verilog as much as you want, but the top-level schematic will hopefully aid you in visualizing your solution.

    In this lab you are restricted to the same set of Verilog you used in lab 3 with two exceptions. First, you may now use the "?:" operator, which acts like a MUX (see Appendix A of this document for details.) You may also use the "==" operator to check for equality. You specifically may not use operations like '+' and '-'.

    On the schematic side you may freely use gates, MUXes, encoders and decoders.

    In all cases, you are to use only one adder.

  7. Design Notes and Hints
  8. Deliverables
  9. Pre-Lab (55 Points)
    1. Answer the following questions:
      1. What is the range of positive and negative input values? Give your answer in decimal. (5 points)
      2. What is the range of possible positive and negative output values given the above input values? Give your answer in decimal. (5 points)
      3. Using both 4-bit and 5-bit two's complement representation, express the numbers 3, -3, 7 and -7. (5 points)
    2. Design a ripple carry adder macro using the full 1 bit adder from lab 2 to perform the following operations in a functional simulation:
      1. 3+4 with Cin=1
      2. 3+(-4) with Cin=0
      3. -8+-8 with Cin=0
      Turn a single printout showing these three operations in functional simulation. Explain any issues with the answers gotten. Clearly label which part of the simulation is doing which operation (a, b, c). (20 points)

    3. For this problem, say you have an adder with inputs labeled X[4:0], Y[4:0] and Cin, with outputs R[4:0] and Cout. Assume the inputs to your calculator are labeled A[3:0] and B[3:0] and that your output is called H[4:0]. H[4:0] is the 2's complement binary representation of the answer, not the encoding sent to the 7-segment displays. You may use conditionals to express your answer (so "if A[2]==1 then..." is okay). (20 points)
      1. If you are to compute A+B, what should be passed to X, Y and Cin in the general case? In addition provide specific (binary) values for the case when A=-3 and B=3.
      2. If you are to compute A-B, what should be passed to X, Y and Cin in the general case? In addition provide specific (binary) values for the case when A=-3 and B=3.
      3. If you are to compute |A|, what should be passed to X, Y and Cin in the general case? In addition provide specific (binary) values for the case when A=-3 and B=3.
      4. If you are to compute |B|, what should be passed to X, Y and Cin in the general case? In addition provide specific (binary) values for the case when A=-3 and B=3.

    In-lab (55 points)
    Demonstrate the operation of your final calculator design to the lab GSI. Be sure that the following cases work before demonstrating.

     1 + (-7)   = -6
     0 - 7      = -7
     -1 + 1     = 0
     7 - (-8)   = 15
     -8 + (- 8) = -16
     |7|        = 7
     |-8|       = 8
     
    Post-Lab (40 Points)
    1. Simulate your calculator design for the following scenarios. You are to:
      • Provide hardcopy of each simulation on its own print-out.
      • Include A, B, C inputs and express each as buses in hex.
      • Use the binary outputs, NOT the 7 segment outputs. Express as buses in hex.
      • Clearly label each time period was corresponding to a given scenario (a, b, etc.)
      • Clearly label each printout by scenario name.
      • Use the "Count value" icon () in the simulator to generate all possible values.
      • Scenarios: (10 points each)
        1. 5+(all possible values)
        2. abs(all possible values) (on B)
        3. 4-(all possible values)
    2. Submit a top-level design, all Macro contents, and qsf files (15 points)

  10. Appendix A: Using ?: to display values to the 7-segment display
  11. A very useful Verilog operation is the ternary (also called "conditional") operator "?:". It works as follows:
    assign bob=(mary==1'b1) ? 2'b01 : 2'b10);
    
    This is basically the same as saying
    if(mary==1'b1)
      bob=2'b01;
    else
      bob=2'b10;
    
    This operator can be thought of as a MUX.

    Consider the following coding example (parameter is a way to declare a constant).

    module display(letter,seven);
      input [1:0] letter;
      output [6:0] seven;
      parameter F=7'b1000111;
      parameter S=7'b1011011;
      parameter r=7'b0000101;
      parameter L=7'b0001110;
     
    
      assign seven= (letter==2'b00 ? F:
                    (letter==2'b01 ? S:
                    (letter==2'b10 ? r:
                     L)));
    endmodule
    
    This uses the ?: operator to assign values to the seven-segment display depending upon the value of "letter".

    Important: Quartus appears to occasionally be very sensitive to a lack of spaces around the ? operator.