Professional Documents
Culture Documents
vsdt_Lab_Tute_02
Designs can be entered in two basic modes: Schematic and HDL (Hardware Description Language) mode. A hardware description language allows you to describe the behaviour of a system rather than as individual gates. There are several popular hardware description languages such as VHDL, Verilog and ABEL. The schematic flow mode allows you to create a design that consists of either a top-level schematic or top-level ABEL file. It can contain underlying schematic diagrams, state machine macros, instantiated HDL (ABEL, VHDL or Verilog) macros, LogiBLOX, CORE Generator modules. The HDL flow mode can contain a VHDL (or Verilog) or a schematic top-level design with underlying VHDL, Verilog, schematic modules, as well as LogiBLOX, CORE Generator and Finite State Machine modules. Notice that for a top level ABEL-based design, you will need to use the Schematic mode. In order to create VHDL or Verilog designs you will need the Synopsis FPGA Express package which comes with the Foundation Base Express and Foundation Express tools. Figures 2 and 3 show a more detailed view of the different steps involved in the creation of a design in the schematic flow mode and HDL flow mode, respectively. Notice the extra Synthesis step that is required in case of a HDL flow design. Also, the target device and the top-level module is specified during the synthesis step in the HDL flow mode. The implementation tools fit the entered design into the target device architecture. The tools compile a design file into a configuration file that is optimized in terms of use of logic gates and interconnections for the targeted device. Downloading of the bitstream can be done easily from a PC into a FPGA (using the Xilinx demoboard, the XS40 or XSV boards) or into a CPLD (on the XS95 board). Both devices can also be programmed in-the-system (ISP) by connecting a JTAG or XChecker cable to the device's programming pins. Design verification includes functional simulation, in-circuit testing, and timing simulation. Functional simulation can be done after the design entry to verify the proper operation of the circuit. However, functional simulation does not provide timing information, such as delays, race condition, set-up and hold-time violations. This information is obtained from the static timing simulator and is done after the design has been compiled for the target device. Figure 2 shows the design flow for a Schematic Flow project.
vsdt_Lab_Tute_02
Figure 3 shows the design flow for a HDL Flow project. The top-level module and the target device aren't specified until the Synthesis step as shown in the figure below.
vsdt_Lab_Tute_02
Figure 3: Overview of the design and implementation sequence of a HDL Flow project. [2]. 1.2 Types of Devices: FPGA and CPLD
There are two types of programmable logic devices. One is called a field programmable gate array (FPGA) and the other a complex logic device (CPLD). The CPLD XC9500 device has a PAL-like architecture and is non-volatile. It gives relatively good performance (up to 250 MHz) and is well suited for combinational logic circuits and control logic of medium complexity (up to about 10,000 logic gates). The FPGA device (ex. XC4000 series) has an array-like architecture and is volatile (SRAM based). It makes use of lookup tables (stored in the SRAM memory) to implement logic functions. It is good to realize complex logic functions that contain both combinational and sequential circuits. Its capacity is usually limited by the number of input/output pins and not by its complexity. FPGAs can currently implement up to 1 million logic gates and operate up to 150 MHz. The XC4000XL and XC9500XL are 3.3V devices with a 3.3V Vcc but with 5V tolerant I/Os. The devices come in a variety of packages. The ones used on the FPGA demoboard or the XS40 and XS95 boards are packaged in an 84 pin PLCC and have the following part names: XC4010EPC84, XC4005XLPC84 and XC95108PC84 . To find out which device you will be using, check the board you have available in the lab. Detailed information on these devices is given in the Xilinx
vsdt_Lab_Tute_02
When you launch the Foundation tools, the Project Manager window will open as is shown in Figure 4 for a Schematic Flow project. The Project Manager gives you access to all the tools that are needed to design, simulate and implement a project. From the Manager you can also create a new project, open an existing project or delete projects. You can launch the Xilinx Project Manager by going to the START/PROGRAMS/Xilinx Foundation Series 2.1i menu. You can also click on the Project Manager icon at the bottom toolbar.
When you create a new project e.g. MyProj, the Foundation tools will create the following files: a project configuration file (PDF), called Project Description File (myproj.pdf), and three library files, the project library file (myproj), the simulation library file (simprims) and the device library (xc4000x) files. The libraries are shown in the left window pane (called the Hierarchy browser) of the Project Manager. A project must always have one or more top level design files. In case the top-level cell is a schematic, the file will be shown in the hierarchy browser with an extension .sch (e.g. myproj.sch) as can be seen in Figure 4 above. The foundation tools will create additional folders and files during different stages of the project design/implementation.
vsdt_Lab_Tute_02
If the required library does not show up in the left side window, you need to attach the library first. Click the Lib Manager button to open the Library Manager. Go to the LIBRARY -> ATTACH menu to open the Attach Library. You can now select the required library and click the OK button. The systems' libraries are usually found in the c:\fndtn\active\syslib directory. The newly selected library will appear in Attached Library list. You can now add the library to your project. Notice that libraries which are already attached will not be displayed in the Libraries list. 1.4 Creating a new project: Schematic Entry
The design entry is the first step in the process of creating a new design. Design can be entered either as a schematic or as a text-based entry (ABEL, VHDL or Verilog). An overview of the overall process of creating a design in the Schematic Flow mode is shown in Figure 2 of the introduction section. In this tutorial you will learn how to create a new project and enter a design using the Schematic Editor in the Schematic Flow mode. In later sections you will learn how to create more complicated projects using macros and hierarchies. For now let us assume you want to build a really simple circuit, as shown in Figure 1, using the Schematic Editor. This circuit will be used in a car to generate a warning signal when "The Ignition key is in the lock AND the door is open OR the seatbelt is not used". The corresponding Boolean expression is: F = IGNITION.(DOOR' + SBELT')
vsdt_Lab_Tute_02
1.4.1
To start the Xilinx Foundation tools (click on the icon on the desktop or go to the window's START menu -> Programs -> Xilinx Foundation Series F2.1i-> Project Manager). First, a small window will pop up asking to open an existing project or to create a new one. Select "New Project". This will bring up the new project window
Fill out the name of the project, the directory where you want to store the project, and the Type. Let's give it the project Name: EasyProj . The project name is not case sensitive. Do not use more than 8 characters in the project name. Directory: Select the proper directory (folder) where you want to save your project. Use the Browse button to change the directory. For the type select F2.1i. Under Flow, select Schematic flow since we will use the Schematic editor to create our design. The three pulldown boxes at the bottom of the New Project window refer to the device family, the part and the speed grade. The family refers to the device family. If you are using a FPGA, select XC4000E (for the FPGA demoboard) or XC4000XL (for the XS40 board); if you are using a CPLD, select XC9500 (for the XS95 board).
vsdt_Lab_Tute_02
The Project Manager window will open as shown inFigure 3. This window shows the design flow as well as the associated tools.
Figure 3: Xilinx Foundation Project Manager window (Schematic Design Entry) (Screen clip from Xilinx (TM) Foundation software) The project will have a .PDF extension. Other project files such as schematics, netlists, macros, etc., will be stored in a subdirectory with the project name. A project can have only one top schematic (or HDL source file). Sub-schematics can be added to the project as macros. For more information about the Project Manager, use the online help function by selecting HELP -> PROJECT MANAGER FOUNDATION HELP CONTENTS in the Project Manager window. To access the Foundation 2.1i User Guide, go to the HELP ->ONLINE DOCUMENTATION menu. Next, click on the WEB BOOKS button and on Foundation Series 2.1i Software link. 1.4.2 b. Schematic Entry
To create the circuit of Figure 3.1 using the Schematic editor, click on the Schematic editor icon in the Project Manager window or select the TOOLS menu -> DESIGN ENTRY -> SCHEMATIC EDITOR. A Schematic Capture window will appear as in Figure 4.
vsdt_Lab_Tute_02
Figure.4: Xilinx Foundation Schematic Capture window with blank schematic (Screen clip from Xilinx (TM) Foundation software) i. Placing symbols You can add the logic symbols by clicking on the Symbol Toolbox (Symbols icon) on the toolbar on the left. An SC Symbols Toolbox will pop up. You can scroll down the list and select AND2 or type the symbol name at the bottom box of the list. Notice that a brief description of the selected symbol appears at the bottom. You can now place the gate with your cursor on the schematic by clicking the mouse. To place another AND gate just click on the previous one and a second gate will be attached to the cursor. Every time you click another gate of the same type will be placed in the schematic until you press the Escape (ESC) key.. Place two 2-input NAND gates. Next, select OR2 from the SC Symbol Toolbox and drop one OR gate. Figure 5 shows the schematic with the symbols added.
vsdt_Lab_Tute_02
Figure 5: Xilinx Foundation Schematic Capture window with Symbols added (Screen clip from Xilinx (TM) Foundation software). You can mirror a symbol by pressing Ctrl+M keys or rotate it by pressing the Ctrl+L keys. To redraw the screen press the F10 function key.
Side note: The FPGA (not the CPLD) comes with an on-chip oscillator of 8 MHz. This can be used by placing the symbol OSC4 in the schematic (or HDL code). An internal divider makes the following signals available: 8MHz, 500 kHz, 16 kHz, 490 Hz and 15 Hz. The frequencies are not very well defined and can vary between -50% and +25%. ii. Adding I/O buffers, pads and I/O terminals FPGAs and CPLDs have input/output blocks that act as an interface between the internal circuitry and the pins which connect to the external world. The I/O block can be configured by the user. It consists of input and output buffers (designated by the library symbols IBUF and OBUF), tri-state output buffer (OBUFT) and flip-flops (edge-trigger D flip flop (IFD) or a latch (ILD)). Buffers: Buffers are needed for input and output signals which go to a pin of your device (FPGA or CPLD). Place the buffers on the schematic in a similar fashion as you did for the other symbols. For the input buffers select the IBUF symbol and for the output buffer select OBUF from the SC Symbol list. In case you would like to add a tri-state buffer, you can select OBUFT. Do not forget to add buffers or your schematic will not compile later on! Pads: You will also need to add I/O pads to the input and output buffers. These pads represent the actual pins on the XILINX device. A pad is a physical component in the Xilinx Unified Library and is placed like any other component (ex. AND, NAND, etc.). The names of pads are IPAD (input), OPAD (for output), IOPAD (bi-directional), IPAD4 and OPAD4, etc. All device pins MUST be represented with one of these I/O pads! Pads should be given a name and possibly a pin number (pin location). This can be done by double clicking on the pad to bring up the Symbol Properties window (see Adding pin locations below). Output pads are pulled-high or pulled-low through a pull-up or pulldown resistor of about 10 kOhm, respectively, when not in use to prevent floating outputs. During normal operation, the pull-up/down is deactivated.
10
vsdt_Lab_Tute_02
11
vsdt_Lab_Tute_02
Figure 6: Symbol Properties window to assign pin locations (Screen clip from Xilinx (TM) software window) An alternative way is to not assign pins on the schematic, but specify the pin numbers later, before compiling the design. This can done by creating a User Constraint File (see constraint editor section). The advantage of the latter method is that the schematic is more generic and you can easily change pins without having to modify the schematic (or the HDL code). When using the Demoboard, the XS40, or the XS95 boards, certain pins have been pre-assigned and some are connected to LEDs and switches for ease of testing (consult the descriptions of the Demoboard, XS40 or the XS95 boards). Assign the pin numbers so that you can make use of these devices. The pinouts of the 84 pin PLCC XC4000 and XC9500 devices are available on the web. In case you are using the XS40 board, you can connect the inputs "DOOR", "IGNITION" and "SBELT" to the pins of the parallel port connector (e.g. pins 44, 45 and 46, respectively - see Table 1 of the XS40 board description) and the output to one of the LED segments (e.g. segment "a" or pin 19). Figure 7 shows the finished schematic.
12
vsdt_Lab_Tute_02
Figure 7: Schematic of the finished circuit including pin numbers locations (Screen clip from Xilinx (TM) Foundation software. v. Add your name, title of project and date It is good practice to label the schematics clearly. There is a standard way of doing so. Go to the bottom of the page and fill out the small rectangle. If the box has a predefined name, you can change this by going to the FILE->TABLE SETUP. You can now change the address, Name, Description, Date, etc. vi. Netlist and Integrity Test You will need to generate a netlist which is in a format that is readable by the compiler. This is done by going to the OPTIONS menu-> CREATE NETLIST. When finished, it is always a good idea to check that the schematic has no electrical design rule errors. This is done from the OPTIONS menu > INTEGRITY TEST. You can now also generate a EDIF netlist by going to the OPTIONS menu -> EXPORT NETLIST. If you don't do this, do not worry - the system will prompt you later to do so. vii. Save your schematic Go to the FILE menu -> SAVE or click the floppy disk icon on the top toolbar. Give your schematic a name with the extension .SCH (ex. EASYPROJ.sch). When finished with the schematic, exit the Schematic capture program which will bring you back to the Foundation Program Manager window (Figure 3.3). viii. Adding the schematic to the project If the created schematic is not listed in the Project Manager window under the Project you created (ex. easyproj1.sch), you have to go to the DOCUMENT menu -> ADD in the Project Manager window. A window with a list of files will appear. To show only the type "Schematic" display *.SCH in the dialog window. Then select the schematic (EASYPROJ.sch) you would like to add to your project (EasyProj). ix. Copy your project to another disk. If you want to save your project on another disk (e.g. floppy disk) you can to do this from within Xilinx. Go to the Project Manager. Open the FILE->COPY PROJECT menu. Give the name of the Drive and directory to which you would like to copy your project.
13
vsdt_Lab_Tute_02
The implementation tools will translate the netlist (schematic, HDL), place and route (or fit for CPLDs) the design in the target device and generate a bitstream that can be downloaded into the device. The implementation is typically done, after the design has been verified by the functional simulator, as shown in Figure 1 below. Implemenation needs to be done prior to doing a timing simulation, since timing information depends on a specific target device and the way the design has been placed and routed on the device (See Figures 2 and 3 of the introduction).
Figure 1: Overview of the Design Flow. a. Implementation Go back to the Project Flowchart in the Project Manager window. If this is the first time you implement the design, click on the Implementation icon in the flow section of the Project Manager window. This will open the Implement Design window, shown in Fig. 2 below. If you have implemented earlier an earlier version and would like to create a new revision or new version, go to the PROJECT -> CREATE REVISION or CREATE VERSION menu. This will open the Create Revision or Version window, similar to the Implement Design window shown in Fig. 2. The Implement Design Window lets you specify the target device and speed grade. In case you get a message saying "Schematic Netlist is older than the Schematic. Update netlist from Schematic Editor?", click the YES button. The target device is already specified as 4005XLPC84 as this is the one we selected when the project was created. If needed, you can change the target device. The Revision and Version name is automatically filled in with rev1 and ver1. You can change the name if you want to. The implementation options allow you to specify how the design is optimized, mapped, placed, routed and configured. In general, the default settings should be good enough for introductory lab exercises. When you click on the SET button, the Settings dialog box will open. This allows you to specify control files such as a specific Constraint, Guide or Floorplan files. The default settings are usually fine. In case you are using the HDL Flow mode for your project, the Implementation Settings window will open. Click on the RUN button to start the implementation process.
14
vsdt_Lab_Tute_02
Figure 2: Implement Design Window (Screen clip from Xilinx (TM) Foundation software) Note: If you need to switch to another device family, you can do so by going to the FILE -> DEVICE TYPE menu in the Project Manager window. The change Project Type window will pop up. Under Flow, select the new device type (ex. XC9500 in case want to switch to a CPLD device). When you click on the RUN button in the Implement Design window, the Flow Engine window will open and display the progress through the different steps in the implementation process. Figure 3 shows the Flow Engine window in case the target device is a FPGA.
15
vsdt_Lab_Tute_02
Figure 4: Project Manager showing the status of the implemented version and the reports. (Screen clip from Xilinx (TM) Foundation software) In case you are targeting the design for a CPLD device, the Flow Engine looks like the one in Figure 5. The bitstream generates a .jed file..
16
vsdt_Lab_Tute_02
Figure 5: Flow Engine window for a CPLD device. (Screen clip from Xilinx (TM) Foundation software) For a CPLD the .jed (bitstream) needs to be first tranlsated into a format that is compatible with the CPLD device before it can be downloaded. This is done as follows. In the Poject Manager, click on the Programming Icon in the Flow section, or go to TOOLS -> DEVICE PROGRAMMING -> JTAG PROGRAMMER. The JTAG Programmer window will open, shown in Fig. 6.
17
vsdt_Lab_Tute_02
Figure 6: JTAG Programmer Window (Screen clip from Xilinx (TM) Foundation software) In the JTAG Programmer window, go to OUTPUT -> CREATE SVF FILE. In the SVF Options window, select the " Through Test-Logic-Reset" radio button and click OK. Save the my_proj.svf file. You can save it in any directory, but the easiest is to save it in the directory corresponding to the revision and version of the current project. You will need to remember later where you saved the .svf file for programming the CPLD. Next, go to OPERATIONS -> PROGRAM in the JTAG Programmer window. Select "Erase Before Programming" and click the OK button. When the operation is successfully you will get the following message "All operations were completed successfully". Click OK. button Close the JTAG Programmer window. The .svf file can be used to configure the CPLD.
b. Viewing the Implementation Results You can also view the reports from the Project Manager (Fig. 4). Reports are associated with each version. In the Project Manager, click on the Versions tab in the left-hand pane. Select the version and revision for which you would like to see the reports. You can then click on the Report Browser icon on the top toolbar. Or you can also click on the Reports tab in the right-hand window pane. Next, double click on the Implementation Report Files. This will open the report browser window. In case you are using a FPGA target device, you will see the Translation, Map, Place&Route, Pad reports and others. Click on the Pad report to see the assignments of the I/O pins. You will recognize the same names as the ones you specified on the schematic (Door, Ignition, Sbelt and Buzzer). Check the pin locations. Another interesting report is the Map report which will tell you if logic has been removed (as part of the optimization) or added. The Place&Route report indicates how much of the device has been utilized. It gives also a rough estimate of the average interconnection delay.
18
vsdt_Lab_Tute_02
19
vsdt_Lab_Tute_02
Figure 7: Constraint Editor window (Screen clip from Xilinx (TM) Foundation software) In order for the system to use the new constraint file you have to re-run the tranlate operation. This is done by going back to the left window pane (versions tab) in the Project Manager and selecting the same Revision and Version for which you have defined the contraints. 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. You may have to back up to make sure that you redo the translation step (in order to use the modified constraint file). Start the implementation including Translate, Map, etc. When the implementation is successful check the Pad report or Fitting report (corresponding to the version you just implemented) to make sure the pads have been properly placed as specified in the new user constraint file, in case of a FPGA or CPLD, respectively.
When you create a new version or revision a window like the one in Figure 2 will pop up. To make sure you are using the right user constraint file, click on the SET button. When the Settings window opens, you can select the desired user constraint file (ucf) by using the pull-down box for the "Use contraint file from" menu (see Figure 8). Use "custom" to browse the directory. If you do not specify a ucf file, the one corresponding to the last revision will be used.
20
vsdt_Lab_Tute_02
Figure 8: Setting window that allows you (Screen clip from Xilinx (TM) Foundation software)
to
specify
specific
user
constraint
file.
You can also use the Constraint Editor to specify whether an output should have a Pullup or Pulldown resistor, and have a Slow or Fast slew rate. You can specify these by clicking on the I/O Configuration Option box. This will add a few columns to the Ports window. You can now specify the Slew Rate and Pullup/Pulldown option using the pull down menus in the corresponding colums. Edit the User Constraint File An alternative way to specify constraints is to edit the user constraint file directly after you have run the translate program once. This file has the same name as the project with a .ucf extension. The easiest way to edit the .ucf file is by using the HDL editor, by clicking on the HDL Editor icon in the Project Manager, or by going to TOOLS -> DESIGN ENTRY -> HDL EDITOR menu. Select "Open Existing Document". The user constraint file is located in the xproj folder, inside the corresponding version/revision folder. You will notice that the existing .ucf file contains a lot of comments explaining how to create a constraint file. Right now we are interested in defining pin locations. Scroll to the bottom of the file and add the pin locations as follows. NET "BUZZER" LOC = "P19"; # output: DOOR NET "DOOR" LOC = "P44"; # input NET "IGNITION" LOC = "P45"; # input NET "SBELT" LOC = "P46"; # input Be careful - the constraint file is case sensitive. Make sure you use exactly the same name in the constraint file as the one you have defined in your schematic or in the HDL file. The "#" is used for comments. When done, save the file. You can now re-run the implementation tools by selecting the version in the left window pane (versions tab) of the Project Manager. Click on the version with the right mouse button and select "Invoke Interactive Flow Engine". Start the Flow Engine. When finished successful, check the Pad or Fitting report to make sure that the right pin locations have been assigned. d. Create Design Version and Implementation version
21
vsdt_Lab_Tute_02
Figure 9: FPGA Editor window with view of the floorplan for the logic circuit of Fig.1 (Schematic Entry section). (Screen clip from Xilinx (TM) Foundation software)
22
vsdt_Lab_Tute_02
23
vsdt_Lab_Tute_02
An alternative way to using the Schematic or the ABEL editor is to enter a VHDL/Verilog-based design . In this section you will learn how to enter a VHDL-based design using the HDL-flow mode. If you are not familiar with VHDL, consult the VHDL Reference Guide (on the Xilinx web site) or a textbook on VHDL. Figure 1 shows schematically the different steps involved in the creation of a HDL-based project.
Figure 1: Overview of the design and implementation sequence of a HDL Flow project. In this tutorial you will learn how to enter and synthesize a VHDL based design. Once you have synthesized the VHDL file, the remaining steps of implementation and downloading will be identical as the ones for the Schematic Flow mode. i. Open a Project in the Foundation Project Manager If you are not in the Foundation Project Manager, open it now and create a new project called EasyVHDL. We will create the same logic function as was done before in the Schematic Entry section (circuit of Figure 2). Go to the FILE -> NEW PROJECT menu. In the pop up window, select for flow
24
vsdt_Lab_Tute_02
Figure 2: Logic circuit to be implemented as a VHDL file. ii. Create a VHDL Design and assign port names with the HDL Wizard In the Foundation Project Manager, click on the HDL Editor icon or go to the TOOLS -> DESIGN ENTRY ->HDL EDITOR menu. Select HDL Design Wizard. In the Design Wizard window click NEXT and go to the Design Wizard Language window. Select VHDL as the design language. Click on NEXT button which will open the Design Wizard Name window. Enter the name of your design. Lets call it EasyVHDL. You can give it another name, but the name should not be larger than 8 characters. Then click NEXT. The Design Wizard Ports window will appear showing a symbol on the left. Follow the instructions in this window. You can create here the input and output pins (ports). Use the same names as you did for the schematic of Figure 2 (DOOR, IGNITION, SBELT and BUZZER). Click on the NEW button and enter the Name, select as Direction Input or Output, depending on the type of port. For output pins you go to the ADVANCED button which will open the Advanced Port Setting windows. Select STD_LOGIC. When done, click on the FINISH button. The HDL Editor window will open at this point. iii. Create the Source with the VHDL Editor The HDL editor window will open a template which contains the Entity and Architecture section. The Entity section contains the input and output Port declarations made in the previous step. You should verify that all the inputs and outputs are present. The Architecture section contains the logic description of the circuit. Logic descriptions can be entered in a variety of ways: Equations, Truth Tables, and State Description (for sequential circuits). We will be using an equation to define the logic function of Figure 2. Under the Architecture section (<<enter your statements here>> ) type the following equation: BUZZER <= IGNITION and (not DOOR or not SBELT); Figure 3 gives the VHDL source file for the circuit of Figure 2.
25
vsdt_Lab_Tute_02
Figure 3: VHDL Editor window for the circuit if Figure 1 (Screen clip from Xilinx (TM) Foundation software) To find out more about the VHDL syntax click on the Language Assistant icon on the top right the toolbar, or select TOOLS -> LANGUAGE ASSISTANT. This will bring up a window with language and synthesis templates. The language templates shows basic language constructs while the synthesis templates give the code of functional blocks such as counters, multiplexers, adders, flip-flops and architectures features such as Boundary Scan and RAM blocks. Figure 4 shows the Language Assistant window.
Figure 4: VHDL Language Assistant window showing the template for a multiplexer. (Screen clip from Xilinx (TM) Foundation software)
26
vsdt_Lab_Tute_02
Figure 5: Project Manager for the HDL flow mode. (Screen clip from Xilinx (TM) Foundation software) vi. Analyzing and Synthesizing the Design First you will analyze the syntax by going to SYNTHESIS -> ANALYZE ALL SOURCES menu in the Project Manager window. To view warnings or errors click on the HDL Errors, Warnings of Messages Tab at the bottom of the Project Manager. When the files have been successfully analyzed you can translate the design into gates, optimized for the target device.
27
vsdt_Lab_Tute_02
Figure 6: Synthesis Settings/Implementation window. (Screen clip from Xilinx (TM) Foundation software) Click on the SET button. In the Setting window you can ask to optimize the synthesis for Area or Speed. You can also specify the target clock frequency. Select Insert I/O pads. This will add input and output pads to the top-level module. When done, click OK.
28
vsdt_Lab_Tute_02
Figure 7: Synthesis settings window. (Screen clip from Xilinx (TM) Foundation software) Click RUN to start the synthesis of the design. You can now proceed with a functional simulation by clicking on the Simulation Icon in the Project Manager. Alternatively, you can implement your design. 1.7 Macros and Hierarchical Designs
It is always a good practice to keep a design modular and hierarchical. This is important for designs of moderate and high complexity. Often, you will use a circuit (consisting of different logic gates or HDL code) over and over again. Instead of drawing these logic gates every time you need them, it would be more efficient to make a module or macro out of them with its own symbol. You can then use this macro every time you need it by adding the macro to your schematic. Also, the use of macros keeps the schematic neater and easier to read. A macro does not have to be a schematic, but can be defined by an ABEL, VHDL description, LogiBLOX, CORE Generator module or Finite State Machine module. Macros can be created in both the Schematic and HDL Flow modes. In the schematic flow, macros are added after the creation of the top level schematic, as illustrated in Figure 1a. In case of the DHL flow, the top-level module will be defined at a later stage, during the synthesis step as can be seen in Figure 1b.
29
vsdt_Lab_Tute_02
Figure 1: Design and Implementation sequence of a Schematic (a) and HDL flow (b) projet. In this section we will briefly discuss how to create macros in the Schematic Flow mode. You will learn how to create a macro from a schematic, an ABEL and VHDL file, and how to instantiate these macros in a top level schematic. The procedure for creating macros in the HDL Flow mode is very similar. The main difference is the synthesis step as illustrated in Figure 1 above. We will illustrate the creation of macros using a simiple example of a 4-bit comparator that compares two 4-bit words and outputs a logic "1" if the two words are identical, otherwise a logic "0". However, to keep the comparator more general, the X inputs can be selected from two different words (A or B) using a 2:1 multiplexer. If the X (i.e. A or B) and Y signals are the same, the comparator generates a logic "1", otherwise a logic "0". Figure 2 shows the overall schematic. Each comparator compares one bit of each word. If the four comparators outputs Zi are equal to "1", the AND gate will give a "1".
Figure 2: Two 4-bit word comparator We will build this circuit in a modular way, using macros. First, we will create a macro for a 1-bit comparator using the schematic entry tool. We will call this macro "COMP1ME". Then, we will build a
30
vsdt_Lab_Tute_02
The Boolean expression for a 1-bit comparator is given by, Z = X.Y + X'.Y' The corresponding schematic is shown in Figure 3. Notice that the 1-bit comparator is actually an XNOR gate. In principle, we can use the XNOR gate to build our 4-bit comparator. However, for the purpose of illustrating the use of macros, we will recreate this 1-bit comparator by using AND gates and inverters as shown in Figure 3.
Figure 3: 1-bit comparator schematic and symbol a1. Using the Symbol Wizard i. Create a Symbol Open the Schematic Entry tool by clicking on the Schematic Entry icon in the Project Manager Window. Lets use the Symbol Wizard tool. In the Schematic Entry window, go to the TOOLS menu -> SYMBOL WIZARD. A Wizard will guide you through by asking several questions. For the Symbol Name, type in the name you want to give to the 1-bit comparator. Lets call it "COMP1ME". Select the Schematic for Contents. Then push the NEXT button. Fill out the name of the input and output port names. When all input and output ports have been defined, push the NEXT button. Follow the instructions. When finished push the FINISH button.
The symbol will now be created and added to the project library. An underlying design file will also be created that has the defined port names. The schematic editor will open showing an empty schematic page for the comparator macro, except for the input and output pins.
31
vsdt_Lab_Tute_02
Figure 4: 1-bit comparator schematic used as a macro (Screen clip from Xilinx Foundation Foundation software). When finished save the schematic. To check if the macro has been created, in the schematic editor go to FILE->OPEN->MACRO. The macro COMP1ME should appear. At this point you can simulate the macro. To simulate the macro, go to the TOOLS -> SIMULATE CURRENT MACRO in the Schematic Editor window of the macro COMP1ME. This will open the simulator. You can now add the signals and stimuli. You can do a functional simulation and verify the operation of the 1-bit comparator. Alternatively, you can first place the macro on the main schematic. You will find the macro in the Symbol Toolbox of the Schematic Editor under the name COMP1ME. Next, go to the simulator by clicking on the SIM icon on the top toolbar. In the Waveform viewer, click on the Add Signals icon (or go to SIGNALS -> ADD SIGNALS). In the middle panel of the Component Selection window, called Chip Selection you will see the name of the macro, COMP1ME. Double click on it. In the right panel, Scan Hierarchy, all the input and output pins will be displayed. Select these pins by double clicking. When done, click the Close button.
32
vsdt_Lab_Tute_02
a2. Using an existing schematic as a macro In case you created a schematic as part of another project and would like to use this schematic as a macro in a new project you can do so. First you will have to add the old schematic to the current (new) project. In the Project Manager window, go to the FILE->ADD DOCUMENT menu. Use the browser to locate the schematic of interest. When done, you will see that the schematic has been added to the project in the left window page (Files tab). Lets assume that the schematic is named TEST1.sch. You may want to modify this schematic, e.g. to change the pin names, replace input PADS (IPADS) by I/O terminals and remove buffers (BUF). Remember that for macros you do not use IPADs or OPADS (these indicate the physical pins of the device) but I/O terminals (see section "Schematic Entry" on I/O pins, Buffers and Pads). Next you need to create a macro from the schematic. This is done as follows: go to HIERARCHY menu -> CREATE MACRO SYMBOL FROM CURRENT SHEET. A window will pop up. You can change the name of the macro, and add a brief description in the comment line. Lets call the macro MACRO1. You can also check the input and output signals. Click OK. When you convert the schematic TEST1.sch into the macro MACRO1, there is no longer any relationship between the schematic TEST1.sch and the project COMP4ME, even though you can still open the schematic TEST1.sch. You can remove the schematic from the project directory using the Windows Explorer.
a3. Creating a Schematic first An alternative way to create the macro, is to create the schematic first and then the symbol. In that case you will open a new sheet and draw the schematic. For the input and output ports you need to use I/O terminals and not IPAD, OPAD, IBUF and OBUF as explained above. When finished with the schematic of the macro, you need to create a symbol. This is done in the same way as above. Go to the HIERARCHY ->CREATE MACRO SYMBOL FROM CURRENT SHEET menu. The Create Symbol window will appear. For the Symbol Name, type in the name you want to give to the 1-bit comparator. Lets call it "COMP1ME2". Make sure that all input and output pins appear in the Pin section of the Create Symbol window. In the comment field, type any comment you like. Click OK. The symbol will be added to the SC Symbols toolbox list. You can now use the newly created macro (symbol) as you would do with any other symbol. You can complete your top level schematic at this point, or create another macro. 1.7.2 b. Create an ABEL macro
Here we will demonstrate how to create a new symbol (or macro) for a 2:1 multiplexer (Figure 2) with ABEL. The symbol for the multiplexer is shown in Figure 5. The MUX selects between two 4-bit words: when S1 is 0, word A will appear at the output; when S1 is 1, word B is connected to the output. We can consider this multiplexer a quad 2:1 MUX. We will now create an ABEL macro for this quad multiplexer. Lets call this macro "MUX4X2ME".
33
vsdt_Lab_Tute_02
You can now place the MUX4X2ME on the new schematic page (COMP4ME1.sch). You will notice that the inputs A[3:0], B[3:0] and output C[3:0] are shown as buses, rather than as individual inputs. This makes the schematic easier to read and less complicated. We will see later how to use buses. (Note: if you created the symbol using the HDL Editor from the Project Manager window, the signals will not be represented as buses but as individual signals A0, A1, A2, etc. This is an annoying feature, particularly when working with wide buses. To prevent this, use the Symbol Wizard in the Schematic Editor window, as outlined above, to create the symbol). In case you want to modify the symbol, such as changing the shape of the symbol, adding, renaming, or removing I/O pins, you can do so. In the Schematic Editor window, select TOOLS -> SYMBOL EDITOR. Or you can also click on the macro symbol on the schematic. The Symbol Properties window will open. Click on Symbol Editor. This will open the HDL Editor window. You can now define the ABEL file in the HDL Editor window as explained next. iii. Create an ABEL macro You still need to define the new macro for which you have created the MUX4X2ME symbol. After placing the symbol on the schematic click the "H" icon (Hierarchy). Next, double click on the MUX4X2ME symbol. The ABEL editor will open its Editor window. You will notice that the pins have already been declared in the HDL Editor window. Make sure that the output pin C3..C0 has been specified as an istype 'com' and not 'reg' because the C is the output of a combinational circuit. In the equation section, type the expression for the 2:1 multiplexer. The expression for the multiplexer output is as follows, according to the Truth Table I. Be careful, input and output names are case sensitive! C = !S1 & A # S1 & B; TABLE I: Truth Table of the 2:1 MUX
S1
34
vsdt_Lab_Tute_02
In order to simplify the expression we made use of sets in the ABEL description (A = [A3..A0], etc.). Each member of the set will undergo the same logic operations (see ABEL Primer - section 5b on Sets). Thus the above expression is equivalent to four individual expressions: C0 =!S1 & A0 # S1 & B0; : C3 =!S1 & A3 # S1 & B3; Figure 6 shows the ABEL editor window. Notice that the sets for A, B and C are already defined. Enter in the equation section the expression for C.
Figure 6: ABEL editor window for the quad 2:1 multiplexer (Screen clip from Xilinx Foundation (TM) Foundation software). When finished, check the syntax (go to the SYNTHESIS->CHECK SYNTAX menu). Exit. When prompted to update the macro, select YES. The synthesis of the macro will now proceed. In the Project Manager window, click on the HDL icon or select TOOLS -> DESIGN ENTRY > HDL Editor. In the HDL Editor window select "Use HDL Design Wizard". Next, click the NEXT button. In the Design Language window, select the ABEL radio button. Then click NEXT. Follow the instructions as outlined above. When the symbol has been created, the HDL Editor will open. Enter the ABEL code.
An alternative way to create an ABEL macro is to open the HDL Editor from the Project Manager:
35
vsdt_Lab_Tute_02
In the previous section we demonstrated how to create an ABEL macro. An alternative way is to define the macro as a VHDL module. In this section we will define the 2:1 MUX as a VHDL file. The procedure is similar to the one for an ABEL macro. i. Open the Project: COMP4ME and open the Schematic Editor window. ii. Create new symbol In the Schematic Editor window select TOOLS -> SYMBOL WIZARD. Click NEXT. In the Design Wizard Contents window enter the name of the Symbol: MUX4X2VH. Note: the name of the VHDL macro should not have more than 8 characters. Click NEXT. In the Design Wizard Ports window, click on the NEW button to enter the name of the inputs and outputs. Enter S1 in the name field and select Input in the Direction field. Click NEW and enter A[3:0] in the Name field; select Input in the Direction section. Do the same for the B[3:0] input. Next, click on NEW again and enter C[3:0] in the Name field and select Output for the Direction. Go to the ADVANCED button and select the 'STD_LOGIC_VECTOR' port. Create also the input S1. When finished defining input and outputs, click on NEXT. In the Attribute window fill out short comments (ex. VHDL code) and long comments (4-bit 2:1 MUX in VHDL). Click the NEXT and FINISH buttons.
You can now place the MUX4X2VH on the new schematic page (COMP4ME1.sch). You will notice that inputs A[3:0], B[3:0] and output C[3:0] are shown as buses rather than as individual inputs. This makes the schematic easier to read and less complicated. We will see later on how to use buses. In case you want to modify the symbol, such as changing the shape of the symbol, adding, renaming, or removing I/O pins, you can do so. In the Schematic Editor window, select TOOLS -> SYMBOL EDITOR. Or you can also click on the macro symbol on the schematic. The Symbol Properties window will open. Click on Symbol Editor. This will open the HDL Editor window. You can now define the ABEL file in the HDL Editor window as explained next. iii. Create a VHDL macro You still need to define the new macro for which you have created the MUX4X2VH symbol. After placing the symbol on the schematic click the "H" icon (Hierarchy). Next, double click on the MUX4X2VH symbol. The VHDL editor will open its Editor window. You will notice that the pins have already been declared in the HDL Editor window. In the architecture section, type the expression for the 2:1 multiplexer. The expression for the multiplexer output is as follows, according to the Truth Table I. Be careful, input and output names are case sensitive! C(0)<= ((not S1) and A(0)) or (S1 and B(0)); C(1)<= ((not S1) and A(1)) or (S1 and B(1)); C(2)<= ((not S1) and A(2)) or (S1 and B(2));
36
vsdt_Lab_Tute_02
Figure 7: VHDL Editor window for the 2:1 MUX of Figure 8.4. (Screen clip from Xilinx Foundation (TM) Foundation software). In the HDL Editor window, go to SYNTHESIS -> Check Syntax Select PROJECT -> UPDATE MACRO. Save and exit the editor. In the Project Manager window, click on the HDL icon or select TOOLS -> DESIGN ENTRY > HDL Editor. In the HDL Editor window select "Use HDL Design Wizard". Then click the NEXT button. In the Design Language window, select the VHDL radio button. Then click NEXT. Follow the instructions as outlined above. When the symbol has been created, the HDL Editor will open. Enter the VHDL code. When finished with entering the VHDL code, check the synthesis. To create the macro, go to PROEJCT menu -> CREATE MACRO. Give the macro a name. When finished the macro symbol will be added to the project library. d. Create a top level schematic: 4-bit comparator
An alternative way to create an ABEL macro is to open the HDL Editor from the Project Manager:
1.7.4
A top-level module can be a schematic or an ABEL file. However, it is not recommended to have an ABEL top-level module for a FPGA design. The top-level module can have underlying schematic, ABEL, VHDL or Verilog, LogiBLOXs, Finite State Machine and CORE Generator Modules. In this example we will limit ourselves to a schematic and ABEL or VHDL macro, defined above. We are now ready to design our 4-bit comparator of Figure 2 using the macros for the 1-bit comparator and the quad 2:1 MUX. Go to the Schematic Editor window. The sheet COMP4ME.sch will open.
37
vsdt_Lab_Tute_02
Figure 8: Top level schematic of the 4-bit comparator (Screen clip from Xilinx Foundation (TM) Foundation software). ii. Adding wires and net names Connect the IPADS to the IBUF and the OBUF to the OPAD using the Draw Wire command. Also, connect the output of the AND gate to the input of the OBUF and the output of the four 1-bit comparators to the input of the 4-input NAND gate. Next, we want to label the input, output nets and the compartor outputs. Select the Add Net Names icon on the left toolbar. The Net Name window will pop up. Enter the Net Name A0. To speed up the net naming, select the REPEAT button. Every time you click on a net, a new name will be placed and the name index will be incremented by one. Press the ESC key to finish the command. Do the same
38
vsdt_Lab_Tute_02
Figure 9: Edit Bus window (Screen clip from Xilinx Foundation (TM) Foundation software). Bus Taps Now we can connect the inputs of the 1-bit comparators to the buses. This is done by clicking on the Draw Bus Taps icon or going to the MODE menu ->DRAW BUS TAPS. Click first on the bus name ABUS to select the bus you want to tap into. The status line will show that the first bus tap ABUS0 (usually the member with the lowest index) has been selected for placement. Next click the cursor on the A0 output of the first input buffer (IBUF4) (least significant bit). Then, click on A1 outputs of the 2nd, 3rd and 4th buffer. When finished click on the ESC key twice. Repeat the process for the BBUS and CBUS as shown in Figure 8. Make sure that the tap numbers correspond to the numbers of the input signal (A0 connected to ABUS0, A1 to ABUS1, etc.). Note: The default start number for the tap is 0. You can use the up and down arrow keys to select which bus bit will be tapped. If the down arrow key was pressed last, the bus tap numbers will decrease. If you want to connect a single wire to a bus, you need to draw a wire that starts or ends at the bus. Next you will need to label the wire with the name of a bus member to which you want to connect. For instance, you want to access the most significant bit in the carry-cout bus (CBUS). You need to name the wire CBUS3. If you do not name the wire, there will be no connection (a warning will be generated) or if you give it different name from the bus, there will be an error. Complex buses
39
vsdt_Lab_Tute_02
40
vsdt_Lab_Tute_02
Finite state machines can be specified in a variety of ways. One way is to use HDL, such as ABEL or VHDL. The ABEL tutorial explains how the STATE_DIAGRAM, IF-THEN-ELSE or the TRUTH_TABLE construct in ABEL can be used to fine state machines. Examples of both a Mealy and a Moore machine have been discussed. The Xilinx Foundation tools provide an alternative method to specify a state machine. In order to use the State Editor, one must have XABEL or X-VHDL installed. The State Editor allows you to define a state diagram using a graphical description and to convert the graphical description in either ABEL or VHDL. In order to show the use of the State Editor, we will implement the same sequence detector that we used to illustrate the use of ABEL to define a state machine. We will implement two variations of the same sequence detector - one implemented as a Mealy machine and another as a Moore machine. The sequence detector recognizes the following input bit sequence X: "1011". The machine will keep checking for the proper bit sequence and does not reset to the initial state after it has recognized the string. In case we are implementing a Mealy machine, the output is associated with the transitions as indicated on the following state diagram.
Figure 1: A Mealy machine for a non-resetting sequence detector for the input sequence 1011. In the following sections we will explain how to define the above state diagram using the State Editor. First one has to create a new project (or use an existing project). For help with the State Editor go to HELP -> FOUNDATION HELP CONTENTS -> STATE EDITOR. 1. Creating a State Machine Macro a. In the Project Manager Flowchart, click on the State Editor button or go to TOOLS -> DESIGN ENTRY -> STATE EDITOR. This will open the State Editor window. b. Select "Use the HDL Design Wizard" and click OK. c. In the Design Wizard Language window, select either ABEL or VHDL. We will be using the ABEL language. This implies that the State Editor will convert the graphical description into an ABEL code (or VHDL).
d. Specify the file name. Do not use names which are longer than 8 characters. Click NEXT. e. In the Ports window, define the inputs: X, RST (for reset) and CLK (clock). Define also the output port Z. Click on the ADVANCED button and select the "Combinational" for the output direction in case you are using ABEL or select "STD_LOGIC" when using VHDL. We will assume that the output of the sequence detector is coming from a combinational circuit. We could make the state machine synchronous by selecting "registered" for the output port Z (for ABEL). Notice that one needs to define a clock as one of the input ports. By naming one of the input ports CLK, the state machine determines that CLK is the clock input. We will also provide a reset signal, RST, that will allow us to reset the sequence detector to a known state. When all input and output ports have been defined click on the NEXT button. f. In the "Machines" window, select "One" and click FINISH. The default name for the state register is Sreg0. This will open the State Editor window in which we can
41
vsdt_Lab_Tute_02
Figure 2: State Editor window used to define the state diagram (Screen clip from XilinxXACTstep(TM) Foundation software) 2. Defining the States a. In the State Editor window, click on the State "S" icon on the left side vertical toolbar or select FSM-> STATE from the menu. This will place a state bubble in the window. You can reshape the bubble by selecting it and dragging the small squares. To rename the state click on the state name in the middle of the bubble and type the new name. Add the three other states as shown in Figure 3.
42
vsdt_Lab_Tute_02
Figure 3: The four states of the sequence detector. (Screen clip from XilinxXACTstep(TM) Foundation software) b. A state machine should have a reset so that it powers up in the correct state. This reset will not appear on the schematic but the presence of the reset in the state diagram will direct the HDL compiler to define the state encoding such that the machine starts in the correct state. To add the reset to the state diagram, click on the Reset icon (small triangle) on the left side toolbar or select FSM ->RESET. Place the reset symbol on the diagram. We want the machine to reset to the state S0. This is done by clicking inside the S0 state bubble. The reset can be synchronous or asynchronous. We will make the reset asynchronous. This can be done by right-clicking on the reset symbol and selecting "Asynchronous". 3. Defining the transitions: A state diagram is defined by specifying under what conditions the input signal the machine goes from one state to another. These transitions are indicated by arrows between the state and by labeling the input conditions that causes the transition to occur as is shown in Figure 1 for our sequence detector. We will first define the transitions and then the conditions. c. Click on the Transition icon (icon with the arrow) on the left side toolbar (or select FSM -> Transition).
d. Next, place the cursoor in the state S0 to start the transition. To create a bend in the arrow, place the cursor and click where you want the bend to occur. Then, click inside the state S1 to complete the transition. Do the same for all the transitions shown in Figure 1. 4. Defining the conditions The next step is to define the conditions associated with each transition (arrow). a. Click on the Condition icon (=?) or select FSM -> CONDITION. b. Click on the transition arrow, e.g. the transition between State S0 and S1. A small text box appears
43
vsdt_Lab_Tute_02
d. Do the same for all the other transitions. For instance, the transition between the Reset symbol and State S1 occurs under the condition: RST. Similarly, one stays in State S0 under the condition: !X#RST (i.e. when X=0 or the RST signal has been asserted). Notice that strictly speaking we dont have to include the RST input in all the state transitions because we have included a Reset symbol. We have included it here to illustrate how to specify conditions with more than one input. Figure 4 shows the state diagram with labeled transitions. You can select the conditions and move them around on the diagram.
Figure 4: State diagram of the sequence detector with transitions and conditions using the ABEL syntax. (Screen clip from XilinxXACTstep(TM) Foundation software) 5. Defining the Actions Actions (i.e. output signals) are either associated with transitions as is the case for a Mealy machine, or with a state as is the case for a Moore machine. In the example of our sequence detector (Mealy machine) we will associate actions with a transition. a. Click on the Transition Action icon on the vertical toolbar or select FSM -> ACTIONS > TRANSITIONS. b. Click on the transition arrow. A text box will appear c. Type in the desired action. For the transition from S0 to S1, the output Z should go low. This is specified by typing: ^b0 in the text box, in case you use ABEL (for a VHDL based FSM, type Z<='0';). Do the same for all other transitions except for the transition from S3 to S1 which causes the output to go high: ^b1. In case multiple outputs are present you need to define each output. For intance: OUT1=0; SUM=0; or in case of a bus: OUTPUT_BUS=^b10.
44
vsdt_Lab_Tute_02
Figure 5a: Completed State Diagram of the sequence detector implemented as a Mealy machine using ABEL. (Screen clip from XilinxXACTstep(TM) Foundation software) In the previous example, it is not necessary to add the Reset signal at each transition. The same results would be obtained by only including the Reset signal at the transistion between the Reset icon and the S0 state, as shown in Figure 5b below.
Figure 5b: State Diagram of the (1011) sequence detector implemented as a Mealy machine using ABEL. The signal X is the input string.
45
vsdt_Lab_Tute_02
Figure 5c: State Diagram of the (1011) sequence detector implemented as a Mealy machine with VHDL. An example of a Moore machine that implements the same sequence detector is given further on. 6. Generating the HDL code and compiling the state diagram. a. Save the state diagram b. Specify the type of encoding to use for the states. Go to FSM -> MACHINE -> Sreg0. The Machine Properties window will open; select Binary encoding. c. In case you would like to see the ABEL or VHDL code, go to SYNTHESIS -> HDL CODE GENERATION. A window will open showing the HDL Code. The ABEL code of the State Diagram of Figure 5b synthesized with Binary Encoding or Symbolic Encoding can be seen by clicking on the above links. The VHDL code for the state diagram with symbolic encoding can be seen by clicking here.
d. At this point you can create a macro from the state diagram by going to the PROJECT -> CREATE MACRO menu. This will synthesize the state diagram and add it to the symbol libraries. e. When you open the schematic editor you will be able to place the macro from the SC Symbol window. After placing the macro you can simulate it to verify the proper operation. f. In case there are errors, you can view the report by going to SYNTHESIS -> VIEW REPORT. It can also be instructive to check the HDL Code (if you are familiar with specifying a state diagram in ABEL or VHDL).
7. Simulation and Implementation Once you have created a macro or synthesized the state diagram you can do a simulation. The functional simulation of the Mealy machine of the sequence detector is shown in Figure
46
vsdt_Lab_Tute_02
Figure 6: Functional simulation of the Mealy sequence detector (sequence 1011). (Screen clip from XilinxXACTstep(TM) Foundation software) Graphical Simulation When you use for the encoding "Encoded (e.g. binary) " instead of Symbolic encoding you can follow the state transitions on the State Diagram during simulation. This is a good feature when debugging your state diagram. Start the simulator and define the signals. Next, open the state diagram; this can be done by using the Push Hierarchy button in the schematic editor. Once the State Editor window is open, go to TOOLS -> SIMULATION. This will activate the graphical simulation feature. The best is to have both the Waveform viewer and the State Editor window open so you can follow the state of simulation. The graphical simulation feature does not work for Mealy machines. An example is given below for a Moore Machine sequence detector. When the circuit works properly you can implement it. Go to the Project Manager and click on the Implementation Icon. For more information about implementation consult the tutorial section in implementation. Example of a Moore machine If one wants to eliminate the glitches in the output in the Mealy machine, one can implement the sequence detector as a Moore machine. The state diagram is given in Figure 7 below. One has to add one state, S4, as compared to the Mealy machine.
Figure 7: State diagram of a sequence detector for the sequence 1011, implemented as a Moore machine.
47
vsdt_Lab_Tute_02
Figure 8: Completed State Diagram of the sequence detector implemented as a Moore machine using ABEL (Screen clip from XilinxXACTstep(TM) Foundation software) In order to do a graphical simulation we will use Binary state encoding instead of symbolic encoding. Select FSM -> MACHINE ->Sreg0. In the Machine Properties window select Encode: binary. Click OK. To see the ABEL code, select SYNTHESIS -> HDL CODE GENERATION. To see the ABEL code click here. We will do a functional simulation together with the graphical simulation of the State Machine. Start the simulator from the Project Manager window and select the signals and define the stimulators. Next, open the State Diagram by using the Push Hierarchy (H) button in the Schematic Editor window. From the State Diagram window, select TOOLS -> SIMULATION. The functional simulation of the Moore machine together with the state diagram is shown in Figure 9. The output goes high after the sequence 1011. No glitches are present in the output as compared to the Mealy machine (see Figure 6). Notice that the graphical editor can only be used when the State Editor is opened from the Project Manager or by using the Push Hierarchy in the schematic.
48
vsdt_Lab_Tute_02
Figure 9: Functional simulation of the Moore Sequence detector (1011). The top window shows the functional simulation and the bottom one, the state diagram. The State S4 is highlighted after the sequence (1011). (Screen clip from XilinxXACTstep(TM) Foundation software) In the above example we created a Finite State Machine macro as part of a top-level schematic. However, a schematic project can have a top-level ABEL design created with the FSM editor (toplevel ABEL designs are not recommended for FPGA projects). To add a top-level ABEL design to the project, do the following: in the State Editor, select FILE - SAVE; then select PROJECT -> ADD to PROJECT. Next, select SYNTHESIS -> SYNTHESIZE. For more information about the State Editor, go to HELP -> STATE EDITOR HELP CONTENT in the State Editor Window.
Examples: 1.How-to Easily Design an Adder Using VHDL We are going to take a look at designing a simple unsigned adder circuit in VHDL through different coding styles. By doing so, this will get you familiar with designing by different methods and, hopefully, show you to look for the easy solution before attempting to code anything. The specific circuit we are going to model in this how-to is a 4-bit unsigned adder. In the first pass of the design, we will build a 1-bit full adder (or (3,2) counter) slice that will be used to build the full 4-bit
49
vsdt_Lab_Tute_02
The VHDL code for the above component is as follows: library IEEE; use IEEE.std_logic_1164.all; entity add_1_bit is port ( x: in std_logic; y: in std_logic; cin: in std_logic; sum: out std_logic; cout: out std_logic ); end add_1_bit; architecture rtl of add_1_bit is begin sum <= x xor y xor cin; cout <= (x and y) or (x and cin) or (y and cin); end rtl; As you can see, we are using the standard IEEE libraries, which include std_logic, in order to create components that can be synthesized easily to hardware. Using signal types such as bit may not synthesize or produce unpredictable results. Always use the std_logic_1164 library! This is a pretty standard component. In the entity declaration, x, y, and cin are declared as inputs of type std_logic. The outputs are sum and cout of type std_logic. In the architecture section, we define the outputs sum and cout to be concurrent statements based directly off the inputs. Nothing special about this component, I'm sure you have already seen a version of this model. 4-Bit Unsigned Adder using 1-Bit Full Adder Component
50
vsdt_Lab_Tute_02
The inputs to the component are the 4-bit unsigned numbers, x and y, and the carry in that includes cin and the internal ripple carries between each 1-bit block. The 4-bit output sum and cout are shown as outputs of the systems. Listed below is the VHDL code for the component. library IEEE; use IEEE.std_logic_1164.all; entity add_4_bits is port ( x: in std_logic_vector(3 downto 0); y: in std_logic_vector(3 downto 0); cin: in std_logic; sum: out std_logic_vector(3 downto 0); cout: out std_logic ); end add_4_bits; architecture rtl of add_4_bits is component add_1_bit port ( x: in std_logic; y: in std_logic; cin: in std_logic; sum: out std_logic; cout: out std_logic ); end component; signal i_carry: std_logic_vector(2 downto 0); begin cell_1: add_1_bit port map (x(0), y(0), cin, sum(0), i_carry(0)); cell_2: add_1_bit port map (x(1), y(1), i_carry(0), sum(1), i_carry(1)); cell_3: add_1_bit port map (x(2), y(2), i_carry(1), sum(2), i_carry(2));
51
vsdt_Lab_Tute_02
52
vsdt_Lab_Tute_02
Thus, for a basic mux, the VHDL coding would be the following : library IEEE; use IEEE.std_logic_1164.all; entity mux_4ops_8bits is port ( sel: in std_logic_vector(1 downto 0); op_0: in std_logic_vector(7 downto 0); op_1: in std_logic_vector(7 downto 0); op_2: in std_logic_vector(7 downto 0); op_3: in std_logic_vector(7 downto 0); output: out std_logic_vector(7 downto 0) ); end mux_4ops_8bits;
53
vsdt_Lab_Tute_02
54
vsdt_Lab_Tute_02
55
vsdt_Lab_Tute_02
Here is where I will take the novice who can turn on the computer and find the mouse (nine out of ten times) through a simple VHDL Xilinx project. Below is the schematic I wish to implement. By this time you should be able to identify all of the parts and understand what they do.
VHDL has three styles of implementing designs. You can choose data flow, structural or behavioral. Any decent VHDL book can give you an in-depth study of the differences between them. I have chosen behavioral for this implementation since I believe it will be the easiest for you to interpret into what you are now learning. Below is the code for this project. You should be able to recognize items like: in, out, and the signals (A, B, C, Y) from the picture above. Highlight and copy this code. Copy only the words in RED FEW GATES CODE library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end FEWGATES; architecture behavioral of FEWGATES is begin fcn: process (A, B, C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral;
56
vsdt_Lab_Tute_02
Select "Create a new project" and click ok. Click on the "HDL" option since we are going to code this project in VHDL versus a schematic. For name, pick a name you like and that will be easy for you to identify with this project. I would suggest getting a zip disk to store your work on. For the early labs, it should fit on a 3.5 diskette.
57
vsdt_Lab_Tute_02
When you click OK, watch the lower half of the screen. If you see red lines of text, you have a problem with the Xilinx software. Anything you do beyond this point will be in vain. Notify me of the broken machine so I can get it fixed. After a few seconds your project has been created. In the design entry area of the top center section of the screen, click on the HDL paper looking symbol.
58
vsdt_Lab_Tute_02
It will bring up the "HDL Editor." Click on the "create empty" section and then "OK." You are now looking at line 1 of the VHDL text editor section where you will type your code. For simplicity, just paste in the sample code listed above entitled "FEW GATES."
You can now see how VHDL and Xilinx treat certain key words like "in and out." The key words are shown in red and this will keep you from using restricted words like "and" in your code. If you have errors in your code you will see red lines under the suspected errors or problem areas. Let's check and see if the code is any good. Go to the Synthesis drop down menu and select "check syntax."
59
vsdt_Lab_Tute_02
You will be reminded to save first. Click "OK" and title your code whatever name you like. Once again you should try to use a name that will identify what the code is doing. Click save.
60
vsdt_Lab_Tute_02
This adds the newly compiled code to our project. Click "X" on the HDL Editor screen to close it. You now see a green check on the Design Entry section which means you are done with that section and are ready to move on.
61
vsdt_Lab_Tute_02
Look at all the options you have. Again for simplicity, we will use the defaults. Click "Run." The software is now deciding how to best take your design and put it into a logic schematic. When it is done you will see a green check in the section. Scanning down you will see you can now choose between Simulation or Implementation.
Let's do the implementation first. Click Implementation once. You will be brought to the "Synthesis/Implementation" menu. Click Run. The software is now taking your project and deciding how to burn it into a chip. This may take a few minutes. Project manager rewards you eventually by telling you that it completed the process successfully. Click "OK".
62
vsdt_Lab_Tute_02
A neat thing to now look at is some of the reports that have been generated. On the top of the screen you will see a reports tab. Double click on some of the reports. Most of it will make very little sense to you at this point but it is kind of neat to see the wealth of information that has been generated by this project. Let's see if the circuit performs as we designed it to.
Go back to the flow tab and click on "Simulation." This will take you to the "logic simulation" section.
63
vsdt_Lab_Tute_02
You need to put the inputs and outputs into the page. At the top of the screen click on the "signal" drop down menu. Click on add signals.
64
vsdt_Lab_Tute_02
We only care about A, B, C, and Y since we are concerned at this point with our inputs and outputs. The other signals relate to signals within the created chip. Double click on each of them (A, B, C, Y), one at a time. They should have red checks on them meaning that they have been selected. At the bottom left of the screen, click "close". You now see your signals on the left yellow side of the screen. Now we want to make A, B, and C change states (shift from 1 to 0 and back to 1 quickly) and see what our output Y does in response. Select A by clicking once on it. It should turn blue.
65
vsdt_Lab_Tute_02
Go up to the signal drop down menu and select "add stimulators." There are many options for you here. I have included an entire page on this web site strictly to simulation. You can refer to it later by clicking here. For now, let's keep it simple
Look for the "Bc" row and select the far right little round yellow dots. You should see a red "B0" appear next to A. For B, select the next yellow dot to the right, which will assign "B1" to B. Select the B2 for C. Click "close" on the stimulation selection screen. This places three clocks of different
66
vsdt_Lab_Tute_02
Go to the top of the screen and select the options drop down menu. Select "start long simulation." Accept the default of 00:00:10 and click start.
67
vsdt_Lab_Tute_02
2.
The only new item of Xilinx that we need to show you for this lab is how to give specific inputs in Xilinx simulation. The benefit of simulation is that it allows you to test your designs before you create your first chip. In all your previous labs, we were only concerned with having enough inputs to allow for a complete collection of all possible combinations of inputs. You did this by selecting the little dots from the stimulator section. For this lab, we will specify our inputs. Input your code just like you did in simple project. Once you have done your syntax check, added your code to your project, and done the synthesis, come here. I will start out with the point where you click on the simulation button. Just like in simple project, click on Simulation and add your input and output signals. Put them in the correct order (inputs go on the top, outputs go on the bottom). Click on add stimulators and you should be looking at a screen like this.
68
vsdt_Lab_Tute_02
The difference between clocks and formulas is that clocks continue forever to repeat the sequence you put in. Formulas only continue as long as you tell them. Click on "formula" and then double click on "C1". We are now going to write specific clock function. It is similar to writing a script file. Click on Wizard.
This is where we are going to specify our input for CLK_H. If you look at your required waveform you will see that what is needed is an input that switches between high and low every 25
69
vsdt_Lab_Tute_02
J_H has a more unique waveform. Let's do it this way. Choose C2 for your J_H formula. Use the same steps as before but with different repeat values for this new formula. Now that you have the general idea, look at what waveform you need for K_H (C3) and program it in.
When you get done, it should look something like this. When it does, push Close.
70
vsdt_Lab_Tute_02
You can now see that C1-C3 are a different color than C4 indicating that they have been programmed.
Select CLK_H and click on C1. Repeat the process with C2 and C3 until you have the same picture as mine then close the Stimulator Selection area.
71
vsdt_Lab_Tute_02
Click on the Simulation Step (looks like footprints to the left of the 200ns window) several times and you should have an output that looks like mine. If you have straight lines or grey boxes, you should click on the upside down rakes to "scrunch" or expand your display.
Below is the code I developed to perform this action. Take a few minutes to look at the code and you will be able to see the subtle way that it steps through each of the states. --recognizes sequence 10010 library ieee; use ieee.std_logic_1164.all; entity seq_rec is port(CLK, RESET, X: in std_logic; Z: out std_logic); end seq_rec;
72
vsdt_Lab_Tute_02
73
vsdt_Lab_Tute_02
Chose the following signals once you are in simulation. It is common practice to put inputs on the top (choose first) and outputs on the bottom (choose last). Choose (STATE4, STATE0) to be on the bottom by choosing it last.
74
vsdt_Lab_Tute_02
Now go into choose stimulators. I want you to program in the following stimulators. For clock 1 (C1) and formula 0 (F0) put in the values from above. Here is the test bench part. For F1, paste in the following test sequence: L150nsH50nsL100nsH50nsL100nsH50nsL100nsH50nsL50nsH50nsL50nsH50nsL 50nsH150nsL100nsH50nsL50nsH238nsL338nsH314nsL203ns When yours looks like mine above, choose close. Assign FO, F1 and C1 as shown below.
Click on the feet enough times for you to get a good simulation like mine above This is a good way to watch your project actually stepping through the different states. Compare this to your state diagram to make sure you are stepping through the states as you predicted in your state diagram.
4.
75
vsdt_Lab_Tute_02
Synthesis should be performed in the same way you did with the sequence recognizer.
Go to simulation and select the following signals for simulation. When you have selected the signals, go back to the main simulation window. Do not flatten the bus like you did in the first project.
76
vsdt_Lab_Tute_02
Code in the following formula for F0. It is going to be used for your reset. Once you have coded in F0, choose Bc (binary counter - little yellow/green dot) zero (far right dot) for your clock.
Now you can see what happens. Your counter is turned off until the reset goes low. Once the reset goes low, your counter starts counting from 1-16(F) in hex. Once it gets to 16, you get an output on CO.
77