This Exercise is based on the material covered in Real Digital Project 5, which can be found in the red tab to the right. A downloadable document for this exercise is available in the orange tab to the right. The mention of grading within the downloadable document is due to the exercise material being used as course work for an electrical engineering class at a university.
This exercise presents a brief tutorial (in Appendix 1) on the use of the Xilinx ISE/WebPACK VHDL design environment. After completing the tutorial, you should be able to design and implement the basic logic circuits presented in the problems below.
Use WebPACK tool to create a schematic for Y = A'BC + B'C' + AB'. Save the schematic, and then double-click on the “View VHDL Functional Model” entry in the “Sources in Project” panel of the Project Navigator. This creates a structural VHDL file from the schematic. Print and attach the schematic and VHDL file, and then label the gates and wires in the schematic with the labels generated in the VHDL file.
Use WebPACK to create a schematic for Y = AB + A'BC + A'C'. Save the schematic, double-click on the “View VHDL Functional Model” entry in the “Sources in Project” panel of the Project Navigator, and view the results. Print and attach the schematic and VHDL file, and sketch a circuit that corresponds to the VHDL listing. Comment below on the differences between the original schematic and the sketched circuit.
Use the Xilinx HDL tool to enter, simulate, and synthesize a 4-input, 2-output logic system that behaves according to the two logic equations shown. Simulate the source file by creating a stimulus file using the waveform editor in the same manner as you did with schematic-based circuits in previous projects. Print and submit your VHDL source file and simulation output.
Use the Xilinx HDL tool to enter, simulate, and synthesize the two logic circuits shown below. Simulate the source file by creating and running a VHDL test bench. Print and submit your VHDL source file, your VHDL test bench, and simulation output.
Use the Xilinx HDL tool to enter and simulate a three-input, two-output circuit that behaves according to the truth table shown. Create a macro symbol for the circuit, and add that symbol to a newly-created schematic page. Simulate the schematic using the waveform editor simulation interface. Print and submit your VHDL source file, your schematic, and your simulation output.
Hint: You can implement these truth-table functions in any way you choose—you can simply type non-minimized logic equations, or you can type minimized logic equations, or you can write VHDL code that uses a “selected assignment” statement to implement the truth table directly (see appendix 2 of this document for an example).
Use the Xilinx HDL tool to create a circuit that can perform the logical AND of two four-bit numbers represented as two four-bit busses. Implement the circuit on your Digilent board by connecting four switches to one 4-bit bus, four switches to a second 4-bit bus, and the outputs to 4 LED's.
Simulate your circuit for problem 6 using a VHDL test bench that includes the use of bus assignment statements.
A new VHDL project can be started following the methods used to start a new schematic project as discussed Project 3. When the new project is created, right-click on the target device and select “New Source” from the drown down menu. In the Select Source Type window that opens, select VHDL Module, enter an appropriate file name, choose an appropriate directory, and ensure the “Add to project” box is checked. Click Next to bring up the Define Module dialog box. The optional Define Module box is provided as a convenient way for you to generate part of the contents required in any VHDL source file. You can choose to enter information into this box, or proceed without entering anything and type the information directly into the VHDL editor at a later time. Here, we will enter information in the Define Module box to save time and effort. We will create a VHDL circuit defined by the equation “Y <= (A·B) + C”. This circuit uses three inputs labeled A, B, and C, and a single output Y, and this information can be entered into the dialog box as shown below (be sure to change the direction of Y to “out”). The entity name must be entered in the top-most field in the box using any alphanumeric text string. You can choose any name you like, but as always, it is a good idea to choose a name that will help you identify the file later. The architecture name can be any valid alphanumeric string. For now, accept the default name “Behavioral”. Click Next to bring up the summary window, and Finish to start the VHDL editor. When the VHDL editor opens, a file is automatically opened that contains the information you entered in the New Source Wizard, together with some additional items.
Comments in VHDL source files are shown in green, they always start with a double-dash, and they must be defined on a line-by-line basis. Anything between a double-dash and the end of a line is considered a comment, and will be ignored by all VHDL tools. Libraries and packages are always defined near the top of the source file. The “library” and “use” statements make vital information visible to your project—for now, simply leave them in the source file. Their functions will be explained in a later project.
The “entity” block defines the externally visible ports for the design. Every entity in a project must have a unique name, and once defined, every entity can be used as a component in another design. The “port” statement is the main statement of the entity block—the port statement defines all input and output signals, their direction (“in”, “out”, or “inout”), and their type. Types will be discussed in more detail at a later time. For now, and in fact for almost any design you encounter, the “std_logic” type is preferred (std_logic is the VHDL type that is meant to model a wire in a real circuit, and so it is the most generally applicable data type).
The window below shows an example of a VHDL source file. All of the code shown, except the code between the “begin” and “end” statements in the architecture block, was generated by the Define Module wizard. The “library” and “use” statements shown will appear at the top of virtually every source file. The entity block and port statement can also be seen in the code.
The “architecture” statement defines the behavior of the circuit—you must enter valid VHDL assignment statements between the “begin” and “end” statements in the architecture block to define your circuit. Note the area between the begin/end statements in the figure above is referred to as the “concurrent area”. This is because all assignment statements in this area are treated as concurrent by the VHDL simulator (“concurrent” means the statements are not executed by the simulator in sequence as they appear in the source file, but rather in parallel whenever the simulator detects that an input signal has changed). Concurrency is required when modeling physical circuits. This concept will be more fully explained later.
To complete this VHDL source file, you must type the VHDL assignment statement “Y<=(A and B) or C;” into the concurrent area to defines the circuit's behavior. The completed source file can now be simulated or synthesized, and then downloaded to the Digilent board.
To simulate the source file, a separate source file, called a “VHDL test bench” can be created as described below. Once a VHDL test bench is created, it is easy to execute in the simulator, and it is easy maintain, modify, and adapt for other VHDL designs.
To synthesize a VHDL source, highlight its name in the Sources window in the Project navigator, and then double-click the “Synthesize” process in the Processes window. If synthesis completes without errors, a green check mark will be displayed by the synthesize process, and a “process completed successfully” message will appear in the status window at the bottom of the Project Navigator window. If errors are present, error messages in the status window will guide you towards appropriate corrective action. Note that if error messages are related to problems in the source file, double-clicking the red “error” icon in the status window will automatically jump to the offending line in the source file.
It is possible (and sometimes desirable) to add VHDL modules into schematics. To create a schematic symbol for the VHDL module, select the VHDL source file name in the Sources window, and double-click on the “Create Schematic Symbol” process in the Design Utilities section of the Processes window. This will create a symbol that can be added to any schematic.
In future projects, we will discuss more VHDL language features, and show VHDL code examples for many new circuits. In addition to the material presented in these projects, you will find a wealth of reference material in the ISE/WebPACK tool (see for example the “language assistant” available from the lightbulb icon in the ISE VHDL editor toolbar), and in many websites.
A test bench can be created and added to a project in the same manner as any other source file (i.e., add a new source to the project, but select “VHDL test bench” as the source type). Once created, a test bench can be used to run a simulation by selecting the test bench source file, and then selecting the simulation process in the process window. Defining stimulus inputs in a test bench makes it easier to create a wider range of stimulus inputs, particularly with respect to the timing of input signals. In the exercises that accompany this module, you will need the ability to create specific input signal timings. An example of a test bench suitable for use in the exercises is presented on the following page.
A test bench is an entity-architecture pair that looks similar to any other VHDL source file, except that the entity statement is empty (see example below), and the VHDL source file that is to be simulated must be “instantiated” as a component. By following the example below, you can create a test bench suitable for simulating the exercise problems for this project. In later projects, more information will be presented about test benches, their use, and their capabilities.
library IEEE; use IEEE.std_logic_1164.all; -- Implement the following truth table in VHDL -- -- A B C X Y -- 0 0 0 1 0 -- 0 0 1 0 1 -- 0 1 0 0 0 -- 0 1 1 0 1 -- 1 0 0 1 0 -- 1 0 1 0 1 -- 1 1 0 1 1 -- 1 1 1 0 1 entity ttable is port (ABC: in STD_LOGIC_VECTOR(2 downto 0); X,Y: out STD_LOGIC); end ttable; architecture behavioral of ttable is signal OUTS : STD_LOGIC_VECTOR(1 downto 0) begin with ABC select OUTS <= "10" when "000", "01" when "001", "00" when "010", "01" when "011", "10" when "100", "01" when "101", "11" when "110", "01" when others; -- the “others” clause is used in place -- of “111” for reasons explained later X <= OUTS(1); Y<= OUTS(0); end behavioral;