First, go to the Add Bus button on the toolbar, , and click the arrow just to the right. Select the Bus with Port option. Now make sure the Add Bus button is highlighted, or selected, if not left-click on it to do so. Now when you move the mouse over the design area you will see the pointer is now a crosshair. Left-click once with the left button near the left hand side of the design area to begin drawing a bus. If you move the pointer you will see the outline of an input port with a bus extending out of it to the point where the pointer currently is. Move the pointer to the right six or seven grid spaces and double-click with the left button to terminate the bus with a dangling net connector, which will be represented by an open circle at the end of the bus. The left hand side of the bus should have an input port attached to it and the right hand side should end in an open circle, meaning it is not yet connected to anything. Also a default name, dbus0, has been assigned to the bus with a default type unsigned(15 DOWNTO 0) and this has been added to the Declarations list.
By default, the Add Bus button will remain active until you press the Escape key or click with the right mouse button or on another button on the toolbar. While it remains active, add three more busses to the diagram below the first one so that it looks something like Figure 2. Space your ports and busses at least two to three grid spaces apart.
You may move the bus around on the block diagram by making sure that the selection tool, , is active and then pressing and holding the left mouse button over a point in the middle of the bus and dragging it to the new position. You should see the outline of the bus as you drag and reposition it. You may make the bus longer or shorter at this point by pressing and holding the left mouse button over the dangling net connector circle and dragging it to the new location.
Add an input signal in the same way you added buses. Click on the Add Signal button on the toolbar, , and click the arrow just to the right. Select the Add Signal with a port option. Add the signal input so that your design looks something like Figure 3. This input signal will be used for SHAMT_HIGH.
The Add Bus button, unfortunately, cannot be used to add an output port in the manner described above. Before adding the output ports, resize the design area so that it extends almost the width of the screen. This way we can add output ports at the far right and have plenty of room in between to place the blocks which will give the ALU its functionality.
In order to add an output port click on the Add Port Out button: . Now move the pointer to the right hand side of the design area and place an output port in the design. While the tool is still active, place two more output ports, making sure to leave at least two vertical grid dots between each port.
Now change the Add Bus button back to Bus Without Port. Move the pointer to the design area and left-click on the hanging end of output port. Move the mouse about six or seven grid spaces to the left and double-left-click to terminate the bus with a dangling net connector. For the other two output ports, follow the same procedure, except using the Add Signal button, , set to Signal Without Port. The Add Signal button is used because two of the outputs, Zero and Overflow, are single bit signals instead of multi-bit busses. Your Design should now look like Figure 4.
Since we do not want to use the default names for the signals and busses, we need to assign our own. To do this, first make sure that the selection tool, , is active and then double-left-click on the bus dbus0. This will bring up the Object Properties window opened to the signals tab with the dbus0 signal selected. In the name field replace dbus0 with ALUOp. In the declaration section, set the bounds as 3 DOWNTO 0. Finally click OK. These changes should be reflected on the signal name and the Declarations.
Change the rest of the signals and busses as shown in the following table. The design should now resemble Figure 5.
Original Name | New Name | New Type | New Range |
dbus0 | ALUOp | std_logic_vector | 3 DOWNTO 0 |
dbus1 | A | std_logic_vector | 63 DOWNTO 0 |
dbus2 | B | std_logic_vector | 63 DOWNTO 0 |
dbus3 | SHAMT | std_logic_vector | 4 DOWNTO 0 |
dbus4 | R | std_logic_vector | 63 DOWNTO 0 |
sig0 | SHAMT_HIGH | std_logic | NONE |
sig1 | Zero | std_logic | NONE |
sig2 | Overflow | std_logic | NONE |
Once you have finished making all of the changes, you need to save the Block Diagram by selecting Save from the File menu. Select ALU as the library to save the design in, enter ALU as the design unit name, and struct as the view name. This will save the block diagram source data and also create a symbol for the design unit with ports matching those in the block diagram.
To see what effect our work thus far has had, go back to the Design Manager menu and double-click the ALU symbol.
A window similar to Figure 7 should appear. You should see input ports for A, B, ALUOp, SHAMT, and SHAMT_HIGH and output ports for Zero, Overflow, and R. We will modify the symbol later to make it more readable. Once you have examined it, you may close the window containing the symbol.
Now that we have examined the symbol, lets generate the VHDL code for this file and see what is produced. First, back on the Design Manager, highlight the ALU component. Then, click the Generate Through Components button:
Note that this button can also be used from a design editor window, such as the block diagram editor. In other words, you could have also clicked this button from the ALU block diagram editor. This will generate HDL for the current design unit. A Log Window will appear. If the log window reports any errors, ask the professor or TA for help.
If the HDL generation completes with no errors, activate the Design Manager window again. Make sure you have the ALU library window open. Put the Design Manager in HDL mode by clicking the HDL mode button: . Left-click on the plus sign to expand the tree under ALU and you should see an entry for ALU_struct.vhd as in Figure 8. Double-left-click on this file to open it up in a VHDL editor.
The generated HDL code should be similar to the following:
-- VHDL Entity ALU.ALU.symbol -- -- Created: -- by - ajnoyola.UNKNOWN (TWEETY) -- at - 12:16:05 08/30/2005 -- -- Generated by Mentor Graphics' HDL Designer(TM) 2004.1 (Build 41) -- LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.std_logic_arith.all; ENTITY ALU IS PORT( A : IN std_logic_vector (63 DOWNTO 0); ALUOp : IN std_logic_vector (3 DOWNTO 0); B : IN std_logic_vector (63 DOWNTO 0); SHAMT : IN std_logic_vector (4 DOWNTO 0); SHAMT_HIGH : IN std_logic; Overflow : OUT std_logic; R : OUT std_logic_vector (63 DOWNTO 0); Zero : OUT std_logic ); -- Declarations END ALU ; -- -- VHDL Architecture ALU.ALU.struct -- -- Created: -- by - ajnoyola.UNKNOWN (TWEETY) -- at - 12:16:05 08/30/2005 -- -- Generated by Mentor Graphics' HDL Designer(TM) 2004.1 (Build 41) -- LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.std_logic_arith.all; ARCHITECTURE struct OF ALU IS -- Architecture declarations -- Internal signal declarations BEGIN -- Instance port mappings. END struct; |
Examine the generated HDL. The first section is the Entity Declaration which describes I/O for our black box design unit. The ports with connected and named busses and signals which we placed on the block diagram have been translated into ports in the entity declaration.
The second section of the generated HDL is the Architecture Declaration for our struct architecture of the ALU entity. So far, we have only placed ports and signals or busses directly connected to those ports onto the block diagram. Since the signals for these ports are inherently declared in the architecture by their presence in the entity declaration, there is nothing left to do. Hence, the architecture is empty except for a few comments.
Now that we have placed the ports on the block diagram and looked at the simple VHDL generated by it, it is time to Add Subblocks to the Block Diagram.