Digital Design Laboratory

Implementation of a 4-bit Adder with
7-segment HDL decoder

and the use of the
VHDL Hardware Description Language (HDL)


Purpose:

The purpose of this lab is:

Note: You will be using the Digilab board for the implementation and the VHDL Hardware description language for high level circuit descriptions.

Pre-lab assignments:

The pre-lab section consists of two parts, each having its own set of pre-lab questions.  This lab is more extensive than the previous lab. Make sure that  you do all the readings and answer all questions before coming to the lab or you will not be able to finish it on time.

DECODER

In the previous lab you designed a 4-bit adder (MY4ADD) using a full adder (MYFA) as a building block. In this lab you will be expanding the circuit to include a decoder (designed in HDL) so that you can display the results of the addition on a 7-segment display. The block diagram of the system is given in Figure 1. At the end of the lab, you will implement this adder in an actual PLD (FPGA or CPLD) and experimentally verify the performance.
 


Figure 1: Schematic block diagram of the 4-bit adder system. The 7-segment LED for
the tens digit is not available on the XS40 or XS95 board.

The project involves the design of a display decoder that decodes a 5-bit binary number coming from the 4-bit adder (four Sum bits and one Carry_out bit) and which displays the results on a 7-segment LED display. If you are using the Digilab board and FPGA demoboard, you  have two 7-segment displays available (one for the digits and one for the tens). However, the XS40 and XS95 boards have only one 7-segment display. In that case you won't be able to display numbers larger than 9, unless you add an additional external LED for the ten digits (more about this during the implementation and testing steps).  The decoder circuit is somewhat different from a regular 7-segment display decoder which decodes a BCD input (i.e. a 4-bit binary word) to display the results on a single 7-segment display.

The block diagram of the decoder is shown in Figure 2.
 


a.                                                                        b.
Figure 2: Block Diagram of the 5-bit decoder circuit: (a) detailed and (b) simplified block diagram.


The inputs to the decoder are Carry and X3, X2, X1, X0  (for short [X3..X0] or X[3:0]) and the outputs are a1, b1, ..., g1; and tens corresponding to seven signals for the units 7-segment display and the tens digit.

In order to design this circuit you will need to come up with the truth table. In doing so, remember that the two 4-bit input words that need to be added each represents a digit (from 0 to 9 as in a BCD code) and thus can have a  maximum value of 9 each (or 10012). The largest number that needs to be displayed is thus 18, which occurs when the two 4-bit inputs of the adder are both 9. As a result, the truth table has only 19 entries, starting from 00000 to 100102. This will simplify the design of the decoder considerably because any signal larger than 18 (or 100102) is not possible. If it were to occur, we know an error must have occurred during the operation, or that we added numbers larger than 9 (which is not allowed if we use a BCD representation). The digit of the tens can only be 0 or 1.


IMPLEMENTATION

You will  implement your design on a FPGA or CPLD which will complete the design cycle as explained in the introduction of the Foundation tutorial. Configuring and testing  your design will be done  using one of the prototyping boards. These boards contain the device (FPGA or CPLD) together with a series of switches, 7-segments displays, LEDs as well as power connections. It will be important for you to get familiar with the major features of the board your are using.

  1. Getting yourself familiar with the board

In-lab assignment:

A. Parts and Equipment:

B. Experiments
The lab consists of two parts. The first part is to design the decoder (as a macro). The second part is to add the decoder to the existing 4-bit adder (MY4ADD) schematic and simulate the overall system.
1. HDL Source file for the DECODER:

General Information.

Write the HDL  source file for the decoder circuit you designed as part of the pre-lab (Figure 2). In case you work with VHDL, you can use the "WITH-SELECT-WHEN" construct to specify a truth table (a truth table construct does not exist in VHDL - consult a VHDL tutorial or Language assistant for more information). When using ABEL you can  use the Truth Table option for the units digit, and use the equation option for the tens digit.

Name the inputs X3, X2, X1, X0 and Carry; for the outputs name them LEDONE6, LEDONE5, ..., LEDONE0,  TENS, and ERROR for the units display, tens and error signals, respectively. It will be convenient to define the inputs and outputs as buses X[3:0] and LEDONE[6:0], as schematically shown in Figure 2b.


Macro symbol and source file for the Decoder Circuit

    1. Start the Xilinx Foundation Tools. Open your project (MY4ADD) of the previous lab (4-bit adder). When you copy your project  from another computer or disk, make sure you copy both the project folder (MY4ADD) AND the .pdf file (my4add.pdf) into your folder c:\users\your_name\. The .pdf file is required and contains information about the project. Never place the project inside a folder whose name has more than 8 characters! This will give unexpected problems. The best method is to put the project in a folder with the same name (probably your name) as it was last week.
2. Complete theTOP LEVEL SCHEMATIC
  1. In the schematic editor you will need to add the decoder between the SBUS and the OBUF-OPADS. Disconnect the OPADS and OBUF from the SBUS.
  2. The SBUS needs to be connected to the X[3:0] input of the decoder.
  3. The outputs of the decoder will need an OBUF and OPAD because these signals will become the physical pins of the device (FPGA). Use a bus to connect the output  to the OBUF. When connecting the signals between the bus and the decoder be careful with the sequence in which you connect them (least significant bit of the bus should be connected to the least significant bit of the circuit, ...).
  4. Also label the output nets (i.e. the wires between the OBUF and OPAD) with the names A, B, ... G.
  5. Displaying  TENS  and ERROR signal. This depends on the type of board you are using.
  6. If  you are using the XS40 board and want to connect the input signals B3 and B4 to the parallel port D3 and D4, you will need to use the special purpose pads MD0 and MD2, respectively (D3 and D4 are connected to pins 32 and 34 on the XS40 board).
  7. The Carry-in (the Cin of the least significant bit FA) of the 4-bit adder is always "0". Thus, it is not necessary to connect the Carry-in to a pin (pins are expensive; devices are often pin limited). Rather than using a pin, lets connect the Cin internally to 0V or Ground. Remove the IPAD and IBUF for the Cin. Then place a Ground (GND) symbol in the schematic. This symbol is available from the SC Symbol windows (select GND). Place the GND symbol and connect it to the Cin of the FA of the least significant bit.
  8. Check your schematic, save it and create a netlist.
3. SIMULATION
Go to the simulator and do a functional simulation of the circuit. You can use the same inputs for the A and B signals as you did in the previous lab. You can load these waveforms, by going to the FILE->LOAD WAVEFORMS menu. Display the signals SBUS and the Carry_out signals in addition to the 7-segment display (A, B, etc.), the signals for the TENS digit and the ERROR signal. It may be helpful to check the results of the simulation on the schematic. In case the circuit does not give the right result, show the waveform of some of the intermediate signals and check where the circuit goes wrong. Debug the circuit in a systematic way. Check that your busses are connected right (most significant bit of the bus should be connected to the most significant bit of the circuit, etc...). Make sure that the macro's you designed are working properly. When the simulation gives the right result, take a screen catpure of part of the waveform. You will include this in your report.
4. IMPLEMENTATION
  1. Now you are ready for the implementation. Follow the tutorial on "Design Implementation" for your specific board. In the Project Manager window, click on the IMPLEMENTATION button. This will open the Implement Design window. The device should be S10PC84 if you are using the Digilab board, or 4010EPC84 for the FPGA demoboard, 4005XLPC84 for the XS40 board or 95108PC84 for the XS95 board.  Click on RUN. You will be notified when the implementation has completed successfully. In the Project Manager window, click on the Versions tab in the left window pane. You will notice that the project has been implemented. In case errors occurred you should check the Implementation Log file (Project Manager window: click on the Reports tab in the right window pane) and check what went wrong. You can also check the "Common Mistakes" section.
  1. The next step is to assign the input and output signals to the right pins of the FPGA or CPLD device. This can be done in two ways. In the first lab you placed pin numbers on the schematic using the Properties Attributes. An alternative method is  to use the Constraint Editor to specify pin locations. In the Project Manager window, select TOOLS ->IMPLEMENTATION -> CONSTRAINT EDITOR. This will open the GUI for the constraint editor. Click on the Ports tab and fill out the corresponding pin numbers for each signal in the Location column on the top of the window. Pin numbers start with a P followed by a number (ex. P19). Use the same numbers as you did in the pre-lab, depending on the board you are using. Double check the numbers and save the file. If you are using the XS40 board, you do not need to define the pin number P32 and P34 since these are special purpose pins and specified on the schematic with the special symbol pads MD0 and MD2, respectively.
  1. Note: In order for the system to use  the new constraint file you have to  re-run the translate operation.  This is done by going to the left window pane (versions tab) in the Project Manager and selecting the Revision and Version for which you have defined the constraints. Place the mouse over the revision/version name and click the right mouse button. Select "Invoke Interactive Flow Engine". This will open the Flow Engine window. Start the implementation including Translate, Map, etc.
  1. When the implementation has been successful, check the reports. In the Project Manager window click on the Reports tab and select Implementation Report files.
    1. The Map report. This report gives a design summary as well as information about errors, warnings, and removed or added logic. Open this report and check the the usage of the CLBs (Configurable Logic Block) and IOBs (IO Block). Write this information together with the equivalent gate count for your design down in your lab notebook. Check aalso the section 4 and 5 on removed logic.
    2. The Place&Route report tells also how much of the FPGA resources have been utilized (or the fitting report for a CPLD). It also  reports  if any connections could not be routed. You will also find information about the average connection delays. Open this report and check  that all connections are routed and that no errors were reported.
    3. The Pad report or Fitting report gives the pin locations.Check that the assigned pin numbers are the one you have specified. The constraint editor has been known to be unreliable. If the pins are not assigned right, you may edit the user constraint file directly instead of using the Constraint Editor. Edit the user constraint file using the HDL editor in the Project Manager; edit the file corresponding to the version and revision you want to implement (MY4ADD\xproj\ver\rev\my4add.ucf). Save the file and re-run the implementation. Check the pad report again.
    4. The Post Layout Timing Report gives you information about the delay between input and output signals. This is important to get an idea about the speed of your circuit. Open this report and check the delays. Note the maximum combinational path delay and the maximum net delay in your lab notebook. Between which input and output signal does the maximum delay occur?
    In case the compiler gives errors, go to the Report Browser and check the Implementation Log file. It is important that you get familiar with the error reports as a way to debug circuits. This is an essential part of each design (you should not have to bug the instructor every time you have an error; try to find the cause of it yourself first).

    If you are using a FPGA, you can  look at the internal structure of the FPGA and see which CLBs have been used and how they are interconnected. In the Project Manager window select TOOLS -> IMPLEMENTATION -> FPGA EDITOR. In case you are using a CPLD, go to TOOLS -> IMPLEMENTATION -> CPLD CHIP VIEWER in  the Project Manager window.
     

5. CONFIGURING

The next step is to download the configuration file into the FPGA.  Ask the lab manager for a FPGA or CPLD board. Be careful when handling these boards. Follow the tutorial in "Configuring the Device".

6. TESTING

You are now ready to test the design.

After you have convinced yourself that the circuit works properly, five a demo to the lab instructor and have him sign off in your lab notebook. The demo is due on the day the lab is scheduled.

Copy your project back to your persopnal computer account for future use. If you have created more than one version or revision during the Design Implementation, you should delete the version that you don't need and keep only the latest one. These files take up a lot of space. To delete an older revision, go to the Design Manager window, select the revision you want to delete and go to the PROJECT->DELETE revision menu (NOTE do not delete the project!!!). You can also easily zip the project: in the Project Manager window, go to FILE-> ARCHIVE Project. This will zip the entire project, including all the project libraries needed for the current project. You can now save the project in your directory. The archived project is also handy when you need to email it to somebody else.

 Put your name on the Schematic . Take a sreen capture of the top level schematic to include in your report.


Hand-in (at the start of next lab)

You must hand in a short lab report that contains the following:

The lab report is an important part of the laboratory. Write it carefully, be clear and well organized. It is the only way to convey that you did a great job in the lab. It is preferred (but not necessary) that you type the lab report. This report will count for 75 points and the pre-lab questions for 25 points.


Go to theVHDL Primer, ABEL Primer; go to Common Mistakes

Created by Jan Van der Spiegel; September 25, 1997; Updated October 1, 2001.
Copyright, Jan Van der Spiegel, 2001.

th visitor since 10/3/99