






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







September 18th^ , 2007 CSC Fall 2007 Prepared by: Steven Medina
The purpose of this lab is to show you how to implement an adder using Quartus. As the name implies, adders are used to add two sets of values together. Adders are a very common design in digital design. For example, a CPU will use an adder to have its program counter point to its next instruction. This is done by adding a constant value of 4 to the current instructions memory address. You will be using adders both here, and in future labs. You will be shown three different kinds of adders. They are the half-adder, the full-adder. And the ripple carry adder. The purpose is to show you not only what each is, but why they are important. You will learn why each is important as you go through this lab. After creating our adder designs in Quartus, you will test your design on Altera’s DE2 programmable board. The DE2 board will be explained later in this lab.
A half-adder (HA) is an adder that accepts two inputs and gives two outputs. The two inputs are the two single bit binary values that will be added to each other. The two outputs represent the sum. We need two outputs (rather than one output) because the sum may have a carry bit. For example, in binary, 1+0 = 1. This situation has no carry bit in the output. In other words, the output itself is 1 bit. However, if we add 1+1, we get 10. This output is 2 bits long. This is a case where the carry-bit for the output is needed. A half adder consists of two logic gates. These are an AND gate, and an Exclusive OR gate. A diagram of a half adder is shown below.
. Figure 1: Half Adder using XOR and AND gate.
For the design of the half adder, do the following.
Create a new project in Quartus. Where it asks for the family or device you wish to target for compilation, select the Cyclone II board. Under the list of available devices, click EP2C35F672C6.
Design the half-adder shown in figure 1 in a block diagram file (bdf). Remember that the XOR and AND gates are available by clicking the “Symbol Tool” icon.
Compile your design.
ENTITY dec_7seg IS PORT( hex_digit : IN STD_LOGIC; segment_a, segment_b, segment_c, segment_d, segment_e, segment_f, segment_g : OUT std_logic); END dec_7seg;
ARCHITECTURE a OF dec_7seg IS SIGNAL segment_data : STD_LOGIC_VECTOR(6 DOWNTO 0);
BEGIN PROCESS (Hex_digit) -- HEX to 7 Segment Decoder for LED Display BEGIN -- Hex-digit is the four bit binary value to display in hexadecimal CASE Hex_digit IS WHEN '0' => segment_data <= "1111110"; WHEN '1' => segment_data <= "0110000"; WHEN OTHERS => segment_data <= "0111110"; END CASE; END PROCESS;
-- extract segment data bits and invert -- LED driver circuit is inverted
segment_a <= NOT segment_data(6); segment_b <= NOT segment_data(5); segment_c <= NOT segment_data(4); segment_d <= NOT segment_data(3); segment_e <= NOT segment_data(2); segment_f <= NOT segment_data(1); segment_g <= NOT segment_data(0); END a;
Figure 3: Image of dec_7seg block.
Add one of the dec_7seg blocks to both the carry output and the sum output.
Add a dec_7seg block to each wire coming out of the input pins. You have three input pins going into three inputs. Simply split the wire coming out of each input pin between your original design and the dec_7seg blocks.
Create output pins for each of the seven outputs of both dec_7seg blocks. Naming them something such as “a1, b1, c1…g1” and “a2, b2, c2…g2” from top to bottom would be a good naming convention.
Simulate your design using a vector waveform file. Just as in the half-adder, set your inputs to have every possible combination of adding before simulating. Of course, since this is a full-adder, you will have more possible combinations of inputs. Do your outputs show that the inputs are being added together?
In your simulation output, you will have outputs for each of the pins from the dec_7seg outputs. These represent a seven-segment display like the one shown below.
Figure 4: Seven-Segment Display
Each of the 7 lines is labeled according to the labels you would have on your dec_7seg block if you used the naming convention I suggested.
Now that you have created a full-adder, you can begin adding numbers that are larger than 1-bit in length. In this case, you will design a circuit that will add two 4-bit numbers together. This will be done by cascading four full-adders together. For example, if we wanted to add the numbers 1011 and 1110 together, we should get the proper result of 11001 by using nothing but full adders. In other words we need to implement a design that can add numbers such as:
Figure 6: Black box of hexadecimal-to-binary converter.
Create a symbol block for the VHDL code you just wrote. Connect an input pin into your hex-to-binary converter (remember, it is a 4-bit input). One of each output should connect to the first input for each full-adder in your design.
Add another hex-to-binary converter in your diagram. Connect an input pin into the block. Connect one of each output into the other input for each of the full-adders in your design.
Split both input pins that go into your hex-to-binary converter into a dec_7seg_hex block. You should have already created this block in step 4.
The input pin that goes into the “carry” input can remain the same, with no need for converting it into hexadecimal. However, split the wire coming out of this input pin into a regular dec_7seg block. You must import this block into your design if you have not done so already. To import a file:
a) Click project=>Add/remove files in project. The screen that appears is shown below.
Figure 7: Add/Remove project screen.
b) Click on the box with the three dots. A screen will appear asking which file you wish to add.
c) Add the “dec_7seg” file. If it is not in the same directory as your Ripple-Carry Adder project, you must copy and paste it there first, and redo this process.
Figure 8: Binary-to-hexadecimal converter.
Connect one data outputs from each full-adder into one of the inputs of the binary-to- hex converter.
Connect a wire from the carry output of the last full adder into a regular dec_7seg block. Create output pins for all seven outputs.
Output the binary-to-hex converter into a dec_7seg_hex block. Create output pins for all seven outputs.
Compile your design.
Simulate your design in a vector waveform file.
See if you can trace a combination of inputs to see if the two dec_7seg_hex blocks have the right logic values. Remember; invert the logic values to see what the ACTUAL seven-segment decoder on the DE2 board would display.
Shown below in figure 9 is a sample of what the final design might look like.
Create a symbol block out of your two’s compliment VHDL code.
Connect all the inputs and outputs to either a dec_7seg or a dec_7seg_hex block; whichever is appropriate for that input or output.
Compile your design.
Simulate your design in a vector waveform file to see if your design adds and/or subtracts, depending on the value of the input pin going into the two’s compliment block.
A final design of your Adder/Subtractor will look something like the image below.
Figure 11: Image of an Adder/Subtractor using a Ripple-Carry Adder.
The block that is highlighted in red is the symbol block for the ripple-carry adder. The block highlighted in green is the symbol block for the two’s complimentor. All the rest of the blocks are either dec_7seg blocks or input/out pins.