ELEN/COEN 21 - LOGIC DESIGN
Spring 2002
LABORATORY 6
:Arithmetic Logic Unit (ALU) with FPGA
Last update: May 8, 2002
Objectives:
Adder/Subtractor Circuit Specification:
The circuit that you will design will use a four-bit adder from the Xilinx library to do several possible operations on two three bit data inputs. A three-bit field will specify which of the operations will be performed. This can be interpreted as an operation code. Two three-bit data inputs will provide the values to be used in the operation. These are often called operands. The operations are specified in the table below. The output will be a four-bit value.|
INPUTS |
. |
OUTPUT |
|||
|
Operation Select |
Input A |
Input B |
OUTPUT X |
Notes |
|
|
s2 s1 s0 |
a2 a1 a0 |
b2 b1 b0 |
|
x3 x2 x1 x0 |
|
|
0 0 0 |
|
|
|
X=A |
transfer A |
|
0 0 1 |
|
|
|
X=A+B |
Add |
|
0 1 0 |
|
|
|
X=A-B |
Subtract |
|
0 1 1 |
|
|
|
X=A |
Transfer A |
|
1 0 0 |
|
|
|
X=A+1 |
Increment A |
|
1 0 1 |
|
|
|
X=A+B+1 |
Add and inc |
|
1 1 0 |
|
|
|
X=A-B-1 |
Sub. and dec. |
|
1 1 1 |
|
|
|
X=A-1 |
Decrement A |
PreLab:
2. Fill in the connection table below for your adder for each of the operations listed. (Note: The transfer can be implemented with two different combinations of B input and Carry input) This is similar to the ALU described in
Table 7-7 on page 361 of the text, but the selects are used in a different way. The first several operations have been done for you.|
Operation |
Select Inputs S2 S1 S0 |
4-bit A inputs |
4-bit B inputs |
Carry In |
Notes |
|
X=A |
0 0 0 |
0 a2 a1 a0 |
0 0 0 0 |
0 |
A+0 |
|
X=A+B |
0 0 1 |
0 a2 a1 a0 |
0 b2 b1 b0 |
0 |
A+B |
|
X=A-B |
0 1 0 |
0 a2 a1 a0 |
1 b2' b1' b0' |
1 |
A+B'+1 |
|
X=A |
0 1 1 |
|
|
|
|
|
X=A+1 |
1 0 0 |
|
|
|
|
|
X=A+B+1 |
1 0 1 |
|
|
|
|
|
X=A-B-1 |
1 1 0 |
|
|
|
|
|
X=A-1 |
1 1 1 |
0 a2 a1 a0 |
1 1 1 1 |
0 |
A + 1111 |
4. You can use MUXes and other logic gates along with the 4 bit adder to build this arithmetic unit. Write the logic equation for each of the adder inputs. Try to make a small efficient circuit.
5. Note that the adder expects four bits for each input and we are providing only three bit inputs. Make sure you connect the most significant bits of the inputs, a3 and b3, to the appropriate level according to the operation to be performed. For example: a3="0" and b3="0" when the operation is A+B and a3="0" and b3 ="1" when the operation is A-B.
6. Draw the schematic for your design using the Xilinx libraries. Be sure that all inputs to your components are controlled and are not left floating.
7. Connect the inputs to your circuit to the 8 switches on the board. Each input must come from an IPAD and have an IBUF connected to the IPAD. Refer to the
table for pad/pin numbers for switches of the demo board.8. In order to observe the inputs and outputs of your circuit you will connect them to LEDs and to seven segment displays. Remember that a signal which will be connected to an LED or a seven segment display must be connected to the OPAD through an OBUF. Refer to the
table for pad/pin numbers for LEDs and seven-segment display of the demo board.Information on how the seven segment display works is given in the
digilent board specifications under seven segment display.The sum output will be displayed using one of the seven segment displays and we will choose display 1. The displays all use the same cathode signals to turn individual segments on and off. Each has its own anode signal so that the whole display can be turned off. The anode for display 1 has to be on and so connect the pad A1 to logic 1. NOTE: this is a designation of the digilent board for a particular signal and it is NOT the same as our data input a1 which is connected to an input switch. The other anodes A2, A3, A4 need to be at logic 0, so that they will be turned off.
Create a seven segment display decoder to display the value of the sum using seven ROM16x1 components (each ROM is used for one segment of the seven segment display). Make a truth table for each segment for the
displayed images 0 to F as shown in the figure at the end of the prelab. Use these truth tables to determine the INIT value for each ROM. From your TT, determine the Hex Code for each of segment. For example, for segment G, the binary value from the TT table from bottom (F image) to top (0 image) is is 1110 1111 0111 1100 or EF7C in hexadecimal. You need to "click" on the ROM to change the parameter value INIT, which is initially set to 0000. Connect the output of the each ROM to the cathode of the segments of the display. For the display segment to turn on the cathode, it needs to be 0. Therefore you need to invert the ROM output before it goes to the OBUF and OPAD for the cathode of that segment. For example the output for the ROM for CG (with INIT value EF7C) will be inverted and go to Output Pad# 45 through an OBUF.9. Design a test plan to debug your circuit so that you detect a significant number of circuit faults. An example of the beginning of a plan is given here:
STEP 1
STEP 2
STEP 3 ???
10. Submit the circuit schematic and any necessary work such as truth tables as your prelab. Also submit your plan for steps 3 and 4 of the test procedure discussed above.

Note that in this is similar to the BCD to seven-segment decoder described
on page 109 of the text. However, in this lab we will want to be able to identify all 16 possible output bit patterns so 16 different patterns will be needed and there will not be any "don't care" input conditions.Lab:
2. When your test plan has been successful, demonstrate the operation to your laboratory assistant, who will test several input combinations. Test the circuit for these combinations and write the values observed for the 4 output bits of the Adder and the carry and overflow. Be prepared to explain to the lab assistant why the carry and overflow are 1 for the examples you have recorded.
|
. |
. |
A+B |
A-B |
A |
A+1 |
||||||||||||||||||||
|
A |
B |
C |
V |
X3 |
X2 |
X1 |
X0 |
C |
V |
X3 |
X2 |
X1 |
X0 |
C |
V |
X3 |
X2 |
X1 |
X0 |
C |
V |
X3 |
X2 |
X1 |
X0 |
|
2 |
3 |
0 |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
1 |
1 |
1 |
1 |
? |
0 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
1 |
1 |
|
1 |
7 |
|
|
|
|
||||||||||||||||||||
|
3 |
1 |
|
|
|
|
||||||||||||||||||||
|
3 |
4 |
|
|
|
|
||||||||||||||||||||
|
7 |
0 |
|
|
|
|
||||||||||||||||||||
|
0 |
7 |
|
|
|
|
||||||||||||||||||||
|
7 |
4 |
|
|
|
|
||||||||||||||||||||
|
7 |
7 |
|
|
|
|
||||||||||||||||||||
|
|
|
|
|
|
|
||||||||||||||||||||
Lab report:
1. For each of the operations, what is the full range of the outputs if the inputs are interpreted as unsigned three-bit integers? (i.e., what is the minimum and maximum values can your outputs display?)
2. Estimate how many CLBs are needed for each component of your circuit. Assume that each 4-bit adder is created from four bit slice adders which each accept three inputs (Ak, Bk, Cin) and create two outputs (Sk, Cout). Remember that each CLB can create 2 outputs that are functions of up to four inputs. Compare your estimate to the actual number of CLBs used in your circuit.
3. The circuit created in this lab used three bit unsigned inputs and created a four-bit output and a carry. Consider the carry as a fifth bit and interpret the results you recorded in your table as follows.
4. How would you modify your circuit to handle four bit inputs in 2's complement form? (i.e., inputs representing values from -8 to +7). Indicate what circuitry you would add to detect overflow conditions.
5. If you connected your four adder outputs directly to the cathodes CA, CB, CC, and CD instead of using your seven segment display decoder, what would you expect to see for the 16 outputs?
6. Consider the following conditions for testing your circuit: