Tutorial #3
The objectives of this tutorial are for you to:
- Learn how to create macros and use them to create a hierarchial structure for designs.s
- Learn how to create buses to simplify your design and your design's schematics.
This tutorial has the following sections:
- A Brief Introduction to Full Adders and Adders.
- Creating and Using Macros.
- Creating and Using Buses.
- Navigating Up and Down in the Design Hierarchy.
- Simulating a Design with Input and Output Buses.
- Complete and Demonstrate Your 4-bit Adder Design.
A Brief Introduction to Full Adders and Adders.
The implementation of a binary adder can be divided into the addition of pairs of bits from each binary number using a ripple-carry structure shown below in the block diagram of an 8-bit adder. In a ripple-carry adder, full adders are used to create the sum and carry out for each bit position and the carry-out signals from the low-order positions are passed to the carry-in signals for the full adder for the next higher bit position.
This tutorial uses full adders and a ripple-carry adder to demonstrate how to use macros and buses to create a hiearchial structure for your designs. This tutorial also demonstrates how to use buses in simulations and UCF files.
Creating and Using Macros.
Open the Xilinx project navigator and start a new schematic-entry project as outlined in Tutorial #1. Call the project "my_adder".
Add a new schematic-entry source file to your project named "full_adder" (via the {Project}{New Source...} menu item) place the XOR2, AND2 and OR3 gates roughly as shown below.
Use the wiring tool () to connect the gates as shown below. To use this tool, click on the input or output of a gate, and then move (with the button held down) the cursor to the other terminal and release. Ctrl-Z is your friend: it erases the last addition. To connect to an existing wire, simple put the cursor on the wire where the connection is to be made. Note the difference between wires that merely cross each other and are not connected and wires that cross each other and are connected. The wires that cross and are connected have a small (very small) white circle on top of their intersection to indicate that they are connected. Note also that the outputs of the right-most gates have been extended for aesthetical reasons.
Now add inputs and outputs as shown below:
Once you have entered the full-adder schematic as shown above, check your schematic for errors by using the {Tools}{Check Schematic} menu option from the project navigator window and fix any errors reported. Next, click on the save icon () to save your "full_adder.sch" schematic file.
You now want to use your full-adder schematic as a "macro" so you can easily replicate it in the design of a multi-bit, ripple-carry adder. Once you have created a full-adder macro, a full-adder symbol will be created for you that you can select and drop into your schematic using the schematic editor.
To create a full-adder macro and symbol from your full-adder schematic, adjust the "Sources" and "Processes" panes on the left side of the project navigator window to appear as shown below. Now, double-click upon the "Create Schematic Symbol" option highlighted below.
The symbol will be created, but the green check doesn't appear (a bug in the Xilinx software, presumably. However, the transcript will say:
Started : "Create Schematic Symbol".
Process "Create Schematic Symbol" completed successfully
Add a new schematic-entry source file to your project named "adder_4bit" (via the {Project}{New Source...} menu item). You will use this schematic to create a macro and symbol for a 4-bit adder using the full_adder macro and symbol you just created. Select the "Symbols" tab in the pane on the left side of the project navigator window and adjust it as shown below on the left. Highlight the first entry in the "Categories" pane ("<C:/student_name/tutorial_3/my_adder") and then click once on the "full_adder" entry in the "Symbols" pane to select the full_adder symbol. Drop one full_adder symbol into the empty "adder_4bit" schematic. Your project navigator window should now be similar to the one shown below.
When a schematic symbol is created, the Xilinx tools make a guess as to how the inputs and outputs to the symbol should be arranged. However, sometimes these guesses are not aesthetically pleasing. Sometimes they are; it seems to depend on the order you add the labels. The first time this tutorial was tested, the symbol appeared as above.I would prefer a full adder that had its outpus listed on the right in this order: SUM COUT. To change the way a symbol appears, you can right-click on the symbol and select the {Symbol}{Edit Symbol} menu option to bring up the symbol editor. Using the mouse to select both the wire, the wire's name, and the terminal box (hold Ctrl down to make multiple selection), move the wires and names to the preferred arrangement. Next, click on the save icon () to save your new symbol for the full adder and then click on the "X" on the top-right of the symbol editor window to close the symbol editor. Click anywhere in the schmatic. An "Obsolete Symbols" window should pop up as shown below.
Click on the "Update" and then on "OK" to update the full_adder symbols in your schematics. Your full_adder symbol should now be similar to the one shown below.
Place three other full_adder symbolx in your "adder_4bit" schematic as shown below.
Proceed to the next section of this tutorial to learn how to create and use buses.
Creating and Using Buses.
Buses are used to reduce the number of wires drawn in schematics, making the schematics more compact and easier to read. For your 4-bit adder, you want to create three 4-bit buses: "A(3:0)" and "B(3:0)" for the adder's 4-bit inputs and "SUM(3:0)" for the adder's sum output. The 4-bit adder will also have a "CIN" (carry-in) input and a "COUT" (carry-out) output.
First, create the "A(3:0)" and "B(3:0)" as follows. Click on the add-wire icon () and draw two vertical wires on the left side of your schematic along the four full adders. Next, click on the add-net-name icon () and name one of the vertical wires "A(3:0)" and the other vertical wire "B(3:0)". You'll notice that once these wires are named using parenthesis to indicate a collection of wires, the wire drawn on the schematic is thicker indicating that the wire is now a bus (a collection of similarly-named wires). Use the same procedure to create a vertical wire on the right side of the full adders and name it "SUM(3:0)". Your vertical wires (now buses) should be similar to the ones shown below.
Now, you need to connect these busses to the inputs and outputs of the four full adders. To do this, click on the add-bus-tap icon () and select the "Left" bus-tap orientation as shown below.
Now, add four bus taps each to the "A(3:0)" and "B(3:0)" buses as shown below. Next, choose the "Right" orientation for the bus taps and add four bus taps to the "SUM(3:0)" bus.
Now, click the add wire icon () and add wires from the bus taps to the inputs and outputs of the full adders as shown below.
Now, use add-net-name icon () to name the wires connecting the bus taps and the full adders. By selecting the appropriate name and the "Increment the name" option in the "Add Net Name Options" pane shown below, naming these wires is much easier as the wire's name will be incremented after each wire (net) is named. Name all the bus taps as shown above.
Now, complete the design of the 4-bit adder macro by connecting the COUTs to the CINs of the full adders and adding I/O markers for the "A(3:0)", "B(3:0)", and "SUM(3:0)" buses as well as the low-order CIN input and the high-order COUT output as shown below. ISE sometimes guesses wrong on the direction of buses. If this occures, double-click on the I/O marker, and select the proper orientation.
Check your schematic for errors and save it. Now, as you did for the full_adder macro, create a macro and symbol for the 4-bit adder using the "Create Schematic Symbol" option from the "Sources" and "Processes" panes. Confirm that you have created the macro successfully by placing a "adder_4bit" symbol in your top-level schematic, "my_adder_top". Your "adder_4bit" symbol should be similar to the one shown below.
Now, finish your 4-bit adder design as shown in the "my_adder_top" schematic below. Be sure to check the schematic for errors and to save it.
Proceed to the next section of this tutorial to learn how to navigate up and down your design hierarchy.
Navigating Up and Down in the Design Heirarchy.
Often when creating a design with multiple levels of hierarchy (i.e., a design containing macros that contain other macros and so on...), it is helpful to be able to pop up or drop down a level in the heirarchy quickly. You can do this using the schematic editor's push () and pop () icons.
For example, bring up your "my_adder_top" schematic and click once on the adder_4bit symbol to select it (once selected, it should be highlighted in red). When you select a symbol, the push () icon becomes availble. Click once on the push () icon to "push down" in the design hierarchy and see the schematic for the "adder_4bit" macro. You can push further down into the design hiearchy by selecting one of the "full_adder" macros and clicking the push () icon again to bring up the schematic for the "full_adder" macro.
To pop up a level in the design hierarchy from within the schematic of a macro, make sure no symbol is currently selected on the current schematic and click once on the pop () icon. Doing this from the "full_adder" macro should take you back up to the "adder_4bit" macro. Then, clicking once more on the pop () icon should take you back to your top-level schematic, "my_adder_top".
Simulating a Design with Input and Output Buses.
In this section, you will learn how to simulate a design that has buses for inputs and outputs, displaying the buses in hexadecimal format. For this task, you will simulate your "adder_4bit" macro. So, select the "adder_4bit" macro schematic and add a new test bench waveform source file named "adder_test" to your project using the steps outlined in Tutorial #1.
In the waveform editor, click on the "CIN" signal at 500ns to make "CIN" 0 from 0 - 500ns and 1 from 500 - 1000ns. Next, bring up the pattern wizard for the "A(3:0)" and "B(3:0)" buses (as you did in Tutorial #1. Use the selections below for "A(3:0)" and "B(3:0)":
Once the patterns are defined for "A(3:0)" and "B(3:0)", you can right click on the signal values and select "Hexadecimal" to display the signals in hexadecimal as shown below.
Now, as in Tutorial #1, start up the ModelSim simulator by double-clicking upon "Simulate Behavior Model" in the proceses pane. Manipulate the ModelSim window until you can view the whole waveform simulation results as shown below. To get the values for the "A(3:0)", "B(3:0)", and "SUM(3:0)" signals to display in hexadecimal, double-click upon the value field (immediately to the left of the waveform pane on the right side of the Modelsim window) and select "Hexadecimal" format and click "OK".
From the above window, you can verify that your adder is functioning correctly. For example, in the left of the waveform pane (near time=0), you can see that when A=0, B=4, and CIN=0 the outputs are SUM=4 and COUT=0. As another example, when A=0x6, B=0xA, and CIN=1 (here, 0x denotes hexadecimal format) the outputs are SUM=1 and COUT=1 (indicating a decimal value of 17 = 1 + 6 + 10).
Demonstrate your simulation results to the lab instructor.
Obtain a printout of the simulations results for your lab report.
Proceed to the next section to complete and demonstrate your 4-bit adder design using the Spartan-3 board.
Complete and Demonstrate Your 4-bit Adder Design.
Add a user constraints file (as you did in Tutorial #2) to your design and use the following for the input and output pin connections for the Digilent Spartan-3 Board:
- Slider switches SW3 - SW0 for the SWA(3:0) I/O markers.
- Slider switches SW7 - SW4 for the SWB(3:0) I/O markers.
- Push button BTN0 for the SWCIN I/O marker.
- LEDs LD3 - LD0 for the SUMLED(3:0) I/O markers.
- LED LD4 for the COUTLED I/O marker.
The UCF file will look like:
NET "ASW<0>" LOC = "F12" ;
NET "ASW<1>" LOC = "G12" ;
NET "ASW<2>" LOC = "H14" ;
NET "ASW<3>" LOC = "H13" ;
NET "BSW<0>" LOC = "J14" ;
NET "BSW<1>" LOC = "J13" ;
NET "BSW<2>" LOC = "K14" ;
NET "BSW<3>" LOC = "K13" ;
NET "COUTLED" LOC = "P13" ;
NET "SUMLED<0>" LOC = "K12" ;
NET "SUMLED<1>" LOC = "P14" ;
NET "SUMLED<2>" LOC = "L12" ;
NET "SUMLED<3>" LOC = "N14" ;
NET "SWCIN" LOC = "M13" ;
Synthesize, implement, download, and test your design with the Spartan-3 board.
Demonstrate the operation of your 4-bit adder on the Spartan-3 board to the lab instructor.
Obtain printouts of all of your schematics and the UCF file for your lab report.
You will use this project as the starting point for Tutorial #4.