a four function arithmetic logic unit - clarkson …smithj/projects/files/... · web viewthe truth...

23
A Four Function Arithmetic Logic Unit EE 365 – Project 2 10-28-2004

Upload: others

Post on 28-Jan-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

A Four Function Arithmetic Logic Unit

EE 365 – Project 2

10-28-2004

Chris Ouellette

Joshua Smith

Page 2: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

Table of ContentsI. Objective..................................................................................................................................3

II. Approach..................................................................................................................................4III. Functional Design................................................................................................................4

A. Inverter.................................................................................................................................4B. AND.....................................................................................................................................5C. OR........................................................................................................................................5D. XOR.....................................................................................................................................6E. Multiplexer..........................................................................................................................7F. Arithmetic Logic Unit, 1-bit width......................................................................................9

IV. Timing Considerations.......................................................................................................11A. Timing Delay Research.....................................................................................................11B. Verification of Design.......................................................................................................12V. Further Design Timing Testing.........................................................................................12

VI. Conclusions........................................................................................................................14VII. Future Design.....................................................................................................................15

Table of Figures

Figure 1 - 1-bit ALU Design...........................................................................................................3Figure 2 - Inverter Timing Analysis................................................................................................5Figure 3 - AND Timing Analysis....................................................................................................6Figure 4 - OR Timing Analysis.......................................................................................................7Figure 5 - XOR Timing Analysis....................................................................................................8Figure 6 - MUX Timing Analysis (Dataflow).................................................................................9Figure 7 - MUX Timing Analysis (Behavioral)..............................................................................9Figure 8 - 1-bit ALU Architecture Design....................................................................................10Figure 9 - 1-bit ALU Timing Analysis..........................................................................................11Figure 10 - 1-bit ALU, with delay considerations.........................................................................13Figure 11 - 1-bit ALU output error................................................................................................13Figure 12 - 1-bit ALU, inputs constant..........................................................................................14Figure 13 - 1-bit ALU, select bits constant....................................................................................15

Table of TablesTable 1 - Inverter Truth Table.........................................................................................................4Table 2 - AND Truth Table.............................................................................................................5Table 3 - OR Truth Table................................................................................................................6Table 4 - XOR Truth Table.............................................................................................................7Table 5 - MUX Truth Table.............................................................................................................8Table 6 - 1-bit ALU Truth Table...................................................................................................11Table 7 - Timing Delay Summary.................................................................................................12

Page 3: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

I. ObjectiveThis paper outlines the design and testing procedures of a four function Arithmetic Logic

Unit (ALU) of 1-bit width. A design schematic is shown below:

Figure 1 - 1-bit ALU Design

The design has two inputs, A and B, and two select bits S1 and S0 to select between the

four functions (AND, OR, XOR, NOT(A)). A multiplexer is utilized in selecting the appropriate

output to pass through to the entity output, D.

This project will make use of various techniques of modeling circuits in VHDL including

dataflow, behavioral, and structural languages. In specific, the AND gate is created using a

concurrent conditional signal assignment, the OR is created with concurrent selected signal

assignments, the XOR uses a process statement (behavioral code), and the inverter is written in

dataflow. The 4:1 MUX was written in two ways, one using behavioral code, and the other using

dataflow. These two architecture definitions will be tested independently to verify that they get

the same results.

In addition to considering the functional accuracy of the design, timing delays will also

be considered for the circuit to see how propagation delay might effect the accuracy of the circuit

design. This analysis will be done as a “worst case” scenario, as the highest possibly timing

Page 4: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

delay for a given entity (i.e. AND) will be used, and will be used for both low to high and high to

low signal transitions.

II. ApproachThe design and test will be done in two parts. In the first part, each component of the

logic network will be designed and tested individually and as a whole, without considering

timing delays. After the ALU has been verified for accuracy by comparison between expected

values and truth tables, then timing delay will be added to the VHDL code and the design will be

re-tested to see the impact of the propagation delay on the output from the ALU.

Each component is tested in detail because of new design techniques being tested in this

paper. By verifying that each component works as expected, a greater certainty can be placed on

the conclusion that the ALU as a whole works after testing.

III. Functional Design

A. InverterThe inverter is a gate that simply negates the value of its input. Below is the truth table

for the inverter.

Input Output0 11 0

Table 1 - Inverter Truth Table

As you can see from the truth table the output is negated meaning that an input of 1

becomes and output of 0 and visa versa. The VHDL was written in dataflow language. This can

be seen in the appendix. Below is the timing diagram of this gate. Since there are only two

possible states for this gate (input high or input low), all possible states are tested:

Page 5: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

Figure 2 - Inverter Timing Analysis

This figure has a 1-to-1 correspondence with the truth table. When the input is low, the

output is high, and vice versa. This leads us to believe that the inverter is functioning correctly

and can be incorporated into higher level designs.

B. ANDThe AND gate is a little more complex then the inverter in that it compares two bits

together and based on the bits outputs a 1 or a 0. Below is the truth table of an AND gate.

Input(1) Input(0) Output0 0 00 1 01 0 01 1 1Table 2 - AND Truth Table

From the truth table we can see that the output is only 1 when the inputs are both 1. The

AND gate was written using concurrent conditional signal assignment statements within the

architecture. Conditional signal assignment is similar to the “if” statement in C++. In the case of

the and gate, if both of the inputs are “1” then the output is “1”, otherwise the output is “0”.

Below is the timing diagram for the AND gate.

Page 6: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

Figure 3 - AND Timing Analysis

The timing diagram shows a 1-to-1 correspondence between the signal high and low

logic levels and the truth table presented. This leads us to believe that the conditional signal

assignment code was properly constructed to model an AND gate.

C. ORThe OR gate works such that when either input is “1” the output is “1.” This gate was

written using concurrent selected signal assignment statements. The selected signal assignments

are similar to a switch in C++. That is one signal is chosen as a switch and then outputs are

assigned for each input. Usually the inputs of interest are listed and assigned output values and a

different value is assigned when “others.” The truth table and timing diagram for an OR gate are

given below.

Input(1) Input(0) Output0 0 00 1 11 0 11 1 1Table 3 - OR Truth Table

The timing diagram follows displaying high and low logic levels for the OR gate

designed using selected signal assignments.

Page 7: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

Figure 4 - OR Timing Analysis

By comparing the logic levels displayed in the timing diagram and the OR gate truth

table we can see that there is a 1-to-1 correspondence between the two. This leads us to believe

that the OR gate was correctly represented using the selected-signal assignment statement.

D. XORThe XOR gate is an inequality tester. If the input values are not equal than it outputs a

“1.” This component was written using a process statement. The process statement can be used

anywhere a concurrent statement can be used. It has two states. One is when the process is

running where it is evaluating the expressions within it or it can be suspended. That is, when the

signals listed in the sensitivity list change their value, the process wakes up and re-evaluates its

outputs. In the case of the XOR gate both inputs must be in the sensitivity list because one case

will be left out if only one input is listed. For example, using the table below, if input(1) were

listed and not input(0), if input(1) was held “high” as input(0) changed from “high” to “low”, the

output would remain zero because the process would not “wake-up” during this change.

However, if input(1) change from “high” to “low” while input(0) was held high, this design (as

stated) would accurately reflect the change. Thus, to account for all cases, both inputs must be

listed in the sensitivity list. Below is the truth table for the XOR gate.

Input(1) Input(0) Output0 0 00 1 11 0 11 1 0

Table 4 - XOR Truth Table

Page 8: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

The timing diagram for the XOR gate is shown below:

Figure 5 - XOR Timing Analysis

The timing diagram shows a 1-to-1 correspondence of cases between the truth table and

its logic levels. This leads us to believe that the XOR was properly designed using the process

statement.

E. MultiplexerA mux works like a routing device. If a particular input is desired to be passed through to

the output the 4:1 mux in this design uses two select bits (S) to choose that input. The mux has

been written in two different ways. One is using a data flow technique, case-select (similar to a

switch). This lists a series of possible cases that the select bits can be, and assigns an output

based on the select bits. This assignment can be arbitrary. The way we chose to order assignment

for this project is shown in the truth table below.

S(1) S(0) Input to Select

0 0 C(0) - AND

0 1 C(1) -OR

1 0 C(2) - XOR

1 1 C(3) -NOT

Table 5 - MUX Truth Table

Page 9: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

The second way that it was written in was using a case statement within a process

statement. The case statement just works like it sounds. It will make the output be a specified

value when a certain case is met. Again if the select bits are “00” then make the output A.

Testing the design of the 4:1 mux is more difficult than testing the design of simple 2-

input gates because there is a greater number of possibilities for inputs: two select bits and four

input bits create a large amount of possible combinations. However, a few representative cases

have been developed. We hope these cases show possible situations where the MUX design

could fail, and show its correct representation of output. The same inputs were given to both

designs to cross check the output, since they should be functionally the same.

Figure 6 - MUX Timing Analysis (Dataflow)

Figure 7 - MUX Timing Analysis (Behavioral)

Comparing these timing diagrams we can see that there is a 1-to-1 correspondence

between the two, meaning that for the cases listed they are functionally the same. Consider one

of the timing diagrams. In the first case, the select bits are “00” meaning to pass through input

C(0). This input is “1” in this case, therefore output d is “1.” Note that the order of the bits is

C(3) is the MSB and C(0) is the LSB. The second and fifth cases confirm this order of

significance. The other cases confirm that the output of the 4:1 mux is the selected input bit of C

Page 10: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

passed through to D. This leads us to believe that the mux is functioning correctly, for both

architectures.

F. Arithmetic Logic Unit, 1-bit widthThe goal of this part of the project is to develop and test a functional ALU as described in

Part I. Thus far, we have shown the process we have used for developing parts to be used in the

ALU. In this part, the parts are integrated through structural language in VHDL by instantiating

each part and then mapping the ports together with appropriate wires needed for connections.

Slightly modifying the original schematic, the following diagram shows how the ALU was wired

together, including new signal names:

Figure 8 - 1-bit ALU Architecture Design

Since there are only 4 inputs to this logic network, it is relatively easy to do a “brute

force” test of the logic network, testing and verifying every combination (16 combinations).

Below is a summary truth table of the possible inputs and outputs of the logic network.

Page 11: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

A B S1 S0 D0 0 0 0 00 0 0 1 00 0 1 0 00 0 1 1 11 0 0 0 01 0 0 1 11 0 1 0 11 0 1 1 00 1 0 0 00 1 0 1 10 1 1 0 10 1 1 1 11 1 0 0 11 1 0 1 11 1 1 0 01 1 1 1 0

Table 6 - 1-bit ALU Truth Table

The outputs in this table were determined by considering the logic network, and the input

being selected for pass through by the mux. The input values for A, B, S1, and S0 were used in

the testbench. The timing diagram for the testbench is shown below.

Figure 9 - 1-bit ALU Timing Analysis

Comparing the expected output values for each of the inputs in the table and the timing

diagram, we see a 1-to-1 correspondence. Since each component that the ALU consists of was

tested and verified individually before being incorporated into the ALU, we believe that the

correct outputs from the ALU are proof that the design of the ALU is correct as described in the

project description.

Page 12: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

IV. Timing ConsiderationsIn the last section of this report we considered only the functional design and test of a 1-

bit wide ALU. However, this design did not account for timing delays inherent in real-world

circuits. In this section we will add timing consideration to our logic design and re-test the ALU

to see the impact of the timing propagation delay, if any.

A. Timing Delay ResearchIn order to add timing delays to our logic network, assumptions needed to be made

regarding each of the circuit’s logic networks/gates. We have assumed for simplicity a “worst-

case” scenario where the propagation delay for each of the gates and the mux is

tpd=max(tpHL,tpLH). Information for each of the components was found at www.ti.com.

Device: Use timing for: tpd (ns)AND gate 74F08 6.6OR gate 74ALS32 14

XOR gate 74LS86 30Inverter 74LS04 154:1 Mux 74ALS153 21

Table 7 - Timing Delay Summary

B. Verification of DesignUsing the timings from the above section and applying them to the components of the

ALU we will be able to verify that the design is also correct with timing considerations included.

This means that the design takes into account the propagation delays from the components such

that there is no overlapping of signal changes. Below is a timing diagram showing the errors that

occur when the timing delays are taken into account. In this case, the wait period of the

ModelSim test bench was 10ns, causing the inputs to change every 10ns. Since it takes

significantly longer for the outputs to change because of propagation delay, the wait period needs

to be set to a longer length. Below is a timing plot example of the errors encountered when the

wait period is 10ns.

Page 13: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

Figure 10 - 1-bit ALU, with delay considerations

As has been highlighted in the timing diagram, there was an error with the circuit. No

output was displayed until after over 110ns because of the timing delay. We will need to

consider the worst case scenario for the wait period time so that the output will correctly reflect

the inputs as the inputs and select bits change. However, it is still possible that if inputs and

select bits are changing simultaneously that an error can occur, as described below.

V. Further Design Timing TestingIn the project specification, the output of the circuit for the following conditions were

asked to run the timing simulation of our circuit for the following conditions: At t = 0 ns: S1 = 0,

S0 = 0, A = 0, B = 1 and At t = 100 ns: S1 = 1, S0 = 0, A = 0, B = 0. This was done by setting

the PERIOD in the testbench for the ALU to 100ns, and then having the inputs change as

specified. Below is a timing diagram of the output of this test.

Figure 11 - 1-bit ALU output error

There is a couple interesting features to this timing diagram. First, notice the “U” value

for the output for t=0 to t=28ns. This delay in the output is caused by the fact that for the signal

to go through the AND gate (6.6ns) and then through the MUX (21ns) it takes approximately

28ns from the time the signals were first asserted. The second part of interest is the errornous

Page 14: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

“blip” after the w_s goes to “10” from “00” and B=“1”. During this time interval, the output

should be “0” because 0 XOR 0 is “0”. This blip is caused by propagation delay. This blip occurs

because of the differences in timing delays of the different inputs to the MUX, and the delay of

the MUX itself. At t=100ns, both inputs and select bits are changed. This becomes “time zero”

for the transition of the MUX inputs, and for the MUX to change which input it is selecting. The

input that the MUX is changing to select is the XOR, the delay from the time that the select bits

change to when that input becomes the output is 21ns. This coincides with the time that the

output signal goes high (when it shouldn’t). Since the signal from the XOR is still 0 XOR 1, the

output is high. After another 9ns, the XOR has finished “evaluating” the new input and its output

of “0” is passed to the now currently selected input of the MUX (a total of 30ns has elapsed since

the inputs and select bits changed). Now there is another delay period because it takes the MUX

21ns to transition its current “high” state to a “low” state as dictated by the XOR. This occurs at

time 151ns, or 51ns after the initial transition took place. After this time has passed, the correct

logic output (“0”) is output from the circuit.

This is the hazard of the circuit design as it is: when both the input and select bits are

changed at the same time there exists a possibility for the output of the circuit to change to a

value that was not intended while all of the internal components reach their new logic state.

It is interesting also to look at the timing diagrams for cycling through all the possible

values for the input bits. This is shown below in two different scenarios. In the first scenario, the

select bits cycle through 4 possible values while the inputs remain constant and the select bits

remain constant while the input values are varied.

Figure 12 - 1-bit ALU, inputs constant

The diagram shows that if the select bits and the input bits are not changed at the same

time the correct values for the circuit can be obtained. For example, with A=0 and B=1, S=00

Page 15: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

(AND) is “0”, S=01 (OR) is “1”, S=10 (XOR) is 1, and S=11 (NOT A) is “0.” Note that while

the outputs are as expected, they are still slightly delayed from when the select bits changed.

Below is the second scenario where the inputs are varied and the select bits are held

constant.

Figure 13 - 1-bit ALU, select bits constant

This diagram shows that the circuit can also handle the changing of the inputs without

running into any errors. Note again the delay that exists when the output needs to change.

Observing the fact that there were problems with extraneous output in the circuit, extra

caution would need to be taken with the design if input and select bits were to change at the same

time. If this were the case, the situation should be analyzed functionally (as it was described in

this section) and also should be simulated for verification.

VI. ConclusionsIn this project we have used various modeling techniques in VHDL to create a 1-bit wide

four function Arithmetic Logic Unit. We developed and tested the design functionally first and

then tested the design with consideration to timing (propagation of delay). The functionality of

the circuit encountered no errors during simulation. Timing delays were considered which

resulted in some erratic behavior. However, this behavior was easily analyzed and as the circuit

is designed this output is expected. This was due to inputs switching too late or the mux

switching too early, meaning that the correct values could not be output/evaluated within the

time allotted. This fact is the most significant part of the design of this circuit. Knowing that the

delay of the circuit will cause problems we can design ways to fix the problems that occur

because of the inherent delays of each of the components.

Page 16: A Four Function Arithmetic Logic Unit - Clarkson …smithj/projects/files/... · Web viewThe truth table and timing diagram for an OR gate are given below. Input(1) Input(0) Output

VII. Future DesignThe functionality and issues associated with the design proposed have been analyzed.

Since there are issues with inputs and the ALU function changing simultaneously, adding a

synchronous element to the circuit in order to control the flow of input signals could prevent

some of the problems associated with the design.