Home

ModelSim Tutorial

image

Contents

1. Project test workspace No Design Loaded gt ModelSim Tutorial T 12 Lesson 1 Creating a Project 3 The next step is to add the files that contain your design units Click Add Existing File in the Add items to the Project dialog For this exercise we ll add two Verilog files Click the Browse button in the Add file to Project dialog and open the examples directory in your ModelSim installation Select tcounter v and counter v Select Reference from current location and then click OK Close the Add items to the Project dialog Add file to Project m File Name tcounter v counter w Browse m dd file as type Folder default T op Level 4 Click your right mouse button 2nd button in Windows 3rd button in UNIX in the Project page and select Compile gt Compile All fw Modelsim ia iol x File Edit view Compile Simulate Tools Window Help xj Orc i Loading project test S counter v z tcounter v P Verilc sa Edit Compile Compile Selected Simulate iai Add to Project gt Compile Out of D ate Remove from Project Compile Order ali Close Project Compile Report Project Library Properties Sores sae gt j i Compile Properties Project test lt No Design Loaded gt lt No OOPS DOEA ModelSim Tutorial Creating a project T 13 5 The two files are compiled Click on the Library tab and expand the work library by clic
2. Finding cursors in the Wave window 45 force command 20 H Hierarchy of a Verilog design 29 IEEE Std 1076 6 IEEE Std 1364 6 K Keyboard shortcuts Wave window 47 L Libraries creation and mapping 36 M Macros 8 Q quit VSIM command 22 34 R restart 33 Reusing commands 8 run VSIM command 20 S Shortcuts command history 7 Wave window 47 Signal transitions searching for 46 Signals applying stimulus to 20 ModelSim Tutorial T 58 Index display values with examine command 33 Simulation batch mode 51 executing commands at startup 55 saving results in log file 52 single stepping 22 Verilog 23 view switch 52 wlf switch 52 standards supported 6 System initialization file 56 T Transcript save 8 V Vera see Vera documentation Verilog interface checking between design units 26 standards 6 Verilog 2001 current implementation 6 Verilog simulation 23 VHDL standards 6 W Windows opening 38 Wave window changing display range zoom 46 cursor measurements 45 using time cursors 44 zoom options 46 zooming 46 Work library mapping 36 Z Zoom from Wave toolbar buttons 46 from Zoom menu 46 options 46 with the mouse 47 ModelSim Tutorial
3. Assumptions Before you begin T 6 T 6 T 6 T 7 ModelSim Tutorial T 6 Introduction Software versions This documentation was written to support ModelSim 5 7c for Microsoft Windows 98 Me NT 2000 XP If the ModelSim software you are using is a later release check the README file that accompanied the software Any supplemental information will be there Although this document covers both VHDL and Verilog simulation you will find it a useful reference even if your design work is limited to a single HDL Standards supported ModelSim VHDL supports both the IEEE 1076 1987 and 1076 1993 VHDL the 1164 1993 Standard Multivalue Logic System for VHDL Interoperability and the 1076 2 1996 Standard VHDL Mathematical Packages standards Any design developed with ModelSim will be compatible with any other VHDL system that is compliant with either IEEE Standard 1076 1987 or 1076 1993 ModelSim Verilog is based on IEEE Std 1364 1995 and a partial implementation of 1364 2001 see lt install_dir gt modeltech docs technotes vlog_2001 note for implementation details Standard Hardware Description Language The Open Verilog International Verilog LRM version 2 0 is also applicable to a large extent Both PLI Programming Language Interface and VCD Value Change Dump are supported for ModelSim PE and SE users In addition all products support SDF 1 0 through 3 0 VITAL 2 2b VITAL 95 IEEE 1076 4 1995 and VITAL 2000 IEEE 1076
4. Simulate gt Run gt Run 100ns Run All This causes the simulator to run forever To stop the run go on to the next step PROMPT run all Main MENU Simulate gt Run gt Run All Select the Break button on either the Main or Wave window toolbar to interrupt the run The simulator will stop running as soon as it gets to an acceptable stopping point Main MENU Simulate gt Break The arrow in the Source window points to the next HDL statement to be executed If the simulator is not evaluating a process at the time the Break occurs no arrow will be displayed in the Source window fi source counter vhd a Running the simulation T 21 Next you will set a breakpoint in the function on line 18 Scroll the Source window until line 18 is visible Click on or near line number 18 to set the breakpoint You should see a red dot next to the line number where the breakpoint is set The breakpoint can be toggled between enabled and disabled by clicking it When a breakpoint is disabled the dot appears open To delete the breakpoint click the line number with your right mouse button and select Remove Breakpoint 18 PROMPT bp counter vhd 18 lO x File Edit Yiew Tools Window SSHS4 BRBQOeMX BT WAH BPR x architecture only of counter is 8 9 10 ll 12 13 14 15 16 1 s 13 on 4 gt counter vhd B constant tpd_reset_to_count time l0 ns constant tpd_clk_to_count ti
5. enter the following at the command prompt vsim do yourfile wlf saved wlf counter c This is what you just did in Step 7 e invoked the VSIM simulator on a design unit called counter e instructed the simulator to save the simulation results in a log file named saved wif by using the wlf switch e used the contents of yourfile to specify that values are to be listed in decimal to execute a stimulus file called stim do and to write the results to a file named counter st Since you saved the simulation results in saved wif you can view the simulation results by starting up VSIM with its view switch vsim view saved wlf 10 11 T 53 Open these windows with the View menu in the Main window or the equivalent command at the ModelSim prompt view signals list wave Note If you open the Dataflow Process Source Structure or Variables windows they will be empty You are looking at a saved simulation not examining one interactively The logfile saved in saved wif was used to reconstruct the current windows Now that you have the windows open put the signals in them add wave add list Use the available windows to experiment with the saved simulation results and quit when you are ready quit f For additional information on the batch and command line modes please refer to the ModelSim User s Manual ModelSim Tutorial T 54 ModelSim Tutorial T 55 Lesson 7 Executing commands at load
6. entity to do different things when loading different designs Start the simulator and specify the top level design unit to be simulated by entering the following command at the DOS prompt vsim counter Notice that the simulator loads the design unit without displaying the Load Design dialog box This is handy if you are simulating the same design unit over and over Also notice that all the windows are open This is because the view command is included in the startup macro If you plan to continue with the following practice sessions keep ModelSim running If you would like to quit the simulator enter the following command at the VSIM prompt quit f You won t need the startup do file for any other examples so use your text editor to comment out the Startup line in modelsim ini Index T 57 Numerics 1076 IEEE Std 6 1364 IEEE Std 6 A Assertion errors 38 B Batch mode simulation 51 Breakpoints 21 continuing simulation after 21 C Command history 7 Compile compile order of Verilog modules 26 cursors finding 45 measuring time 45 naming 44 using in the Wave window 44 D Debugging a VHDL design 35 Design library creating 16 24 do command 8 DO files executing a DO file in batch mode 52 using a DO file at startup 56 using the transcript as a DO file 8 drag and drop 7 E Errors breaking on assertion 39 finding in VHDL designs 39 viewing in Source window 40 examine command 33 F
7. it is noted in a fashion similar to MENUS and PROMPTS with DRAG amp DROP Command history As you work on the lessons keep an eye on the Main transcript window The commands invoked by buttons and menu selections are echoed there You can scroll through the command history with the up and down arrow keys or the command history may be reviewed with several shortcuts at the ModelSim VSIM prompt Shortcut Description click on prompt left click once on a previous ModelSim or VSIM prompt in the transcript to copy the command typed at that prompt to the active cursor his or history shows the last few commands up to 50 are kept ModelSim Tutorial T 8 Introduction Reusing commands from the Main transcript ModelSim Tutorial ModelSim s Main transcript can be saved and the resulting file used as a DO macro file to replay the transcribed commands You can save the transcript at any time before or during simulation You have the option of clearing the transcript File gt Transcript gt Clear Transcript if you don t want to save the entire command history To save the contents of the transcript select File gt Transcript gt Save Transcript As from the Main menu Replay the saved transcript with the do command do lt do file name gt For example if you saved a series of compiler commands as mycompile do the do extension is optional you could recompile with one command do mycompile do gt Note
8. 4 2000 Assumptions ModelSim Tutorial We assume that you are familiar with the use of your operating system If you are not familiar with Microsoft Windows we recommend that you work through the tutorials provided with MS Windows before using ModelSim We also assume that you have a working knowledge of VHDL and Verilog Although ModelSim is an excellent tool to use while learning HDL concepts and practices this document is not written to support that goal Before you begin T 7 Before you begin Preparation for some of the lessons leaves certain details up to you You will decide the best way to create directories copy files and execute programs within your operating system When you are operating the simulator within ModelSim s GUI the interface is consistent for all platforms Additional details for VHDL and Verilog simulation can be found in the ModelSim User s Manual and Command Reference Command button and menu equivalents Drag and drop Many of the lesson steps are accomplished by a button or menu selection When appropriate VSIM command line PROMPT or menu MENU equivalents for these selections are shown in parentheses within the step This example shows three options to the run all command a button prompt command and a menu selection PROMPT run all MENU Simulate gt Run gt Run All Drag and drop allows you to copy and move signals among windows If drag and drop applies to a lesson step
9. Change the default run length e Set a breakpoint The project feature covered in Lesson executes several actions automatically such as creating and mapping work libraries In this lesson we will go through the entire process so you get a feel for how ModelSim really works ModelSim Tutorial T 24 Lesson 3 Basic Verilog simulation Compiling the design ModelSim Tutorial 1 Start by creating a new directory for this exercise in case other users will be working with these lessons Create the directory then copy all of the Verilog v files from lt install_dir gt modeltech examples to the new directory Make sure the new directory is the current directory Do this by invoking ModelSim from the new directory or by selecting File gt Change Directory Main window Start ModelSim with one of the following for Windows your option from a Windows shortcut icon from the Start menu or from a DOS prompt modelsim exe Note If you didn t add ModelSim to your search path during installation you will have to include the full path when you type this command at a DOS prompt Click Close if the Welcome dialog appears Before you compile any HDL code you ll need a design library to hold the compilation results To create a new design library make this menu selection in the Main window File gt New gt Library PROMPT vlib work vmap work work Make sure Create a new library and a logical mapping to it is select
10. Model Sim Xilinx Edition Il Tutorial Version 5 7c Published 11 Mar 03 The world s most popular HDL simulator ModelSim Tutorial ModelSim is produced by Model Technology a Mentor Graphics Corporation company Copying duplication or other reproduction is prohibited without the written consent of Model Technology The information in this manual is subject to change without notice and does not represent a commitment on the part of Model Technology The program described in this manual is furnished under a license agreement and may not be used or copied except in accordance with the terms of the agreement The online documentation provided with this product may be printed by the end user The number of copies that may be printed is limited to the number of licenses purchased ModelSim is a registered trademark and Signal Spy TraceX ChaseX and Model Technology are trademarks of Mentor Graphics Corporation PostScript is a registered trademark of Adobe Systems Incorporated UNIX is a registered trademark of AT amp T in the USA and other countries FLEXIm is a trademark of Globetrotter Software Inc IBM AT and PC are registered trademarks AIX and RISC System 6000 are trademarks of International Business Machines Corporation Windows Microsoft and MS DOS are registered trademarks of Microsoft Corporation OSF Motif is a trademark of the Open Software Foundation Inc in the USA and other countries SPARC is a registered trad
11. Neither the prompt nor the Return that ends a command line are shown in the examples T 9 Lesson 1 Creating a Project The goals for this lesson are e Create a project A project is a collection entity for an HDL design under specification or test Projects ease interaction with the tool and are useful for organizing files and specifying simulation settings At a minimum projects have a work library and a session state that is stored in a mpf file A project may also consist of e HDL source files or references to source files e other files such as READMEs or other project documentation e local libraries e references to global libraries For more information about using project files see the ModelSim User s Manual ModelSim Tutorial T 10 Lesson 1 Creating a Project Creating a project 1 Start ModelSim with one of the following for Windows your option from a Windows shortcut icon from the Start menu or from a DOS prompt modelsim exe gt Note If you didn t add ModelSim to your search path during installation you will have to include the full path when you type this command at a DOS prompt Upon opening ModelSim for the first time you will see the Welcome to ModelSim dialog If this screen is not available you can display it by selecting Help gt Welcome Menu from the Main window Welcome to ModelSim Welcome to ModelSim lt a amp menu Welcome to ModelSim Create a Pro
12. This is particularly useful when you need to run a simulation or a set of commands repeatedly A Important Batch mode simulations must be run from a DOS prompt Unless directed otherwise enter all commands in this lesson at a DOS prompt Additionally this lesson assumes you have added ModelSim to your PATH If you did not you ll need to specify full paths to the tools i e vlib vmap vcom and vsim that are used in the lesson ModelSim Tutorial T 52 Lesson 6 Running a batch mode simulation ModelSim Tutorial To set up for this lesson create a new directory and copy this file into it lt install_dir gt modeltech examples counter vhd Create a new design library again enter these commands at a DOS prompt in the new directory you created in step 1 vlib work Map the library vmap work work Then compile the source file lt install_dir gt modeltech lt platform gt vcom counter vhd You will use a macro file that provides stimulus for the counter For your convenience a macro file has been provided with ModelSim You need to copy this macro file from the installation directory to the current directory lt install_dir gt modeltech examples stim do Create a batch file using an editor name it yourfile With the editor put the following on separate lines in the file add list decimal do stim do write list counter lst git f and save to the current directory To run the batch mode simulation
13. braries SDF Options Library library_2 Entity C modeltech examples debug ad Entity C modeltech examples debug ad Entity C modeltech examples debug ga Entity C modeltech examples debug ga Contig C ial atta ai test_adder_struct Config Entity E Kmnodaliach sanpa Nabua Entity C modeltech examples debug ga ModelSim Tutorial T 38 Lesson 4 Debugging a VHDL design Running the simulation 1 Start by opening the Process Variables and Signals windows using the command below Note that you can abbreviate window names view p si v Main MENU View gt lt window name gt 2 Now run the simulation for 1000 ns run 1000 A message in the Main window will notify you that there was an assertion error VSIM 20 gt run 1000 I Error Sum is 00000111 Expected 00001000 Time 600 ns Iteration O Instance testbench Note There were ERRORS in the test Time 1 us Iteration 0 Instance testbench T IVSIM 219 estbench p ModelSim Tutorial Debugging the simulation T 39 Debugging the simulation Let s find out what is wrong Perform the following steps to track down the assertion message 1 First change the simulation assertion options Select Simulate gt Simulation Options from the Main window menu M Simulation Options m m m LI 2 Select the Assertions tab Change the selection for Break on Assertion to Error and click OK This will cause the simulator to s
14. ed Type work in the Library Name field and then select OK Create a New Library xj Create br ary and a logical mapping to it a map to an existing library m Library Name work m Library Physical Name work Cancel Compiling the design T 25 This creates a subdirectory named work your design library within the current directory ModelSim saves a special file named _info in the subdirectory Note Do not create a Library directory using Windows commands because the _info file will not be created Always use the File menu or the vlib command from either the ModelSim or DOS prompt In the next step you ll compile the Verilog design The example design consists of two Verilog source files each containing a unique module The file counter v contains a module called counter which implements a simple 8 bit binary up counter The other file tcounter v is a testbench module test_counter used to verify counter Under simulation you will see that these two files are configured hierarchically with a single instance instance name dut of module counter instantiated by the testbench You ll get a chance to look at the structure of this code later For now you need to compile both files into the work design library Compile the counter v and tcounter v files into the work library by selecting Compile gt Compile from the Main window menu PROMPT vlog counter v tcounter v This o
15. emark and SPARCstation is a trademark of SPARC International Inc Sun Microsystems is a registered trademark and Sun SunOS and OpenWindows are trademarks of Sun Microsystems Inc All other trademarks and registered trademarks are the properties of their respective holders Copyright 1990 2003 Model Technology a Mentor Graphics Corporation company All rights reserved Confidential Online documentation may be printed by licensed customers of Model Technology and Mentor Graphics for internal business purposes only ModelSim support Support for ModelSim is available from your FPGA vendor See the About ModelSim dialog box accessed via the Help menu for contact information Table of Contents I cece ese eae ee epee see enesse ee ceases T 5 Lesson 1 Creating a Project ove ewes t28e hh dee wees ees ee ee ee5 T 9 Lesson 2 Basic VHDL simulation 22000055 T 15 Lesson 3 Basic Verilog simulation 2 2 02 56s ee eee eee ee eee ee eee T 23 Lesson 4 Debugging a VHDL design 22 11 vieevee se eevaceees T 35 Lesson 5 Using the Wave window 00000e eee T 43 Lesson 6 Running a batch mode simulation T 51 Lesson 7 Executing commands at loadtime T 55 i Mose 6G corte ate und beeeee ee sear cease sees eeeaeeet bce T 57 T 3 ModelSim Tutorial T 4 ModelSim Tutorial Introduction T 5 Chapter contents Software versions Standards supported
16. ile the RTL version of the counter vlog cntr_rtl v Simulate the design vsim work cntr_rtl MENU Simulate gt Simulate Run the DO file to apply stimulus to the design do stimulus do Comparing the two designs ModelSim Tutorial To compare the two simulations we will create a second pane in the Wave window open the struct wif file and add the signals from the dataset to the new pane 1 Add a second pane to the Wave window Wave MENU Insert gt Window Pane Notice that a thick white vertical bar at the left edge of the window indicates that the new pane is active Open struct wlf dataset open struct wlf Wave MENU File gt Open gt Dataset Add signals for the struct dataset add wave Notice that the pathname prefix for the signals you just added is the dataset name struct The pathname prefix for the active simulation is sim The results for each simulation should be the same You can continue experimenting with the two simulations or quit the simulation quit sim Main MENU Simulate gt End Simulation T 51 Lesson 6 Running a batch mode simulation The goals for this lesson are e Runa batch mode VHDL simulation e Execute a macro DO file e View a saved simulation Batch mode allows you to execute several commands that are written in a text file You create a text file with the list of commands you wish to run and then specify that file when you start ModelSim
17. im Tutorial T 48 Lesson 5 Using the Wave window Combining items in the Wave window The Wave window allows you to combine signals into buses Select Tools gt Combine Signals to open the Combine Selected Signals dialog Combine Selected Signals m x Name Order of Indexes C Ascending Descending I Remove selected signals after combining Cancel A bus is a collection of signals concatenated in a specific order to create a new virtual signal with a specific value In the illustration below three data signals have been combined to form a new bus called pus Notice the new bus has a value that is made up of the values of its component signals arranged in a specific order Virtual objects are indicated by an orange diamond waye default Re 10 x File Edit view Insert Format Tools Window STS LBA RAT RK RIA ftop e clk top csrdy top c paddr top c bus p 2 top c prw 1 top c pstrb 0 top c prdy E H P ModelSim Tutorial Creating and viewing datasets Creating and viewing datasets Datasets allow you to view previous simulations or to compare simulations To view a dataset you must first save a ModelSim simulation to a WLF file using the vsim wlf option or File gt Save gt Dataset command Once you have saved a WLF file you can open it as a view mode dataset In this lesson you will compare two simple Verilog designs a struct
18. indow fw Modelsim File Edit view Compile Simulate Tools Window Help Function I x Xi Now Ons Delta 0 sim test_counter dut ZL Structure pane The Structure tab shows the hierarchical structure of the design By default only the top level of the hierarchy is expanded You can navigate within the hierarchy by clicking on any line with a expand or contract symbol The same navigation technique works anywhere you find these symbols within ModelSim By clicking the next to dut you can see all three hierarchical levels test_counter dut counter and a function called increment If test_counter is not displayed you simulated counter instead of test_counter Click on increment and notice how other ModelSim windows are automatically updated as appropriate Specifically the Source window displays the Verilog code at the hierarchical level you selected in the Structure tab and the Signals window displays the appropriate signals Using the Structure tab in this way is analogous to scoping commands in interpreted Verilog simulators For now make sure the test_counter module is showing in the Source window by clicking on the top line in the Structure tab ModelSim Tutorial T 30 Lesson 3 Basic Verilog simulation Running the simulation Now you will exercise different Run functions from the toolbar 1 ModelSim Tutorial Select the Run button on the Main window toolbar This causes the simula
19. ject ModelSim Projects contain simulation details like compile settings source files or libraries The Project Manager also lets you include references to shared global files Start here to create a new ModelSim ilodel Technology project Open a Project Your most recent project is opened when you start ModelSim Start here if you d like to open an older project Open Documentation Start here if you d like to open the ModelSim PDF bookcase The entire doc set is indexed for searching within Acrobat Reader Tl Don t show this dialog again Close 2 Select Create a Project from the Welcome dialog or File gt New gt Project Main window In the Create Project dialog enter test as the Project Name and select a ModelSim Tutorial Creating a project T 11 directory where the project file will be stored Leave the Default Library Name set to work Create Project xi Project Name ftes Project Location Ic fmodeltech win32 Browse Default Library Name work Upon selecting OK you will see a blank Project tab in the workspace area of the Main window and the Add Items to the Project dialog fw Modelsim File Edit view Compile Simulate Tools Window Help Add items to the Project x a Click on the icon to add items of that type Workspace xj D Name Status Type Ore Create New File Add Existing File M a Create Simulation Create New Folder
20. king the icon You ll see the compiled design units listed fw Modelsim File Edit view Compile Simulate Tools Window Help Loading project test Compile of tcounter v was successful Library Compile of counter v was successful counter Module 2 compiles 0 failed with no errors w test_counter Module ModelSim gt E MW vital2000 Library E i ieee Library m AD madalsi lib liran 6 The last step in this exercise is to load one of the design units Double click counter on the Library page You ll see a new page appear in the Workspace that displays the structure of the counter design unit jw Modelsim File Edit view Compile Simulate Tools Window Help Loading project test Compile of tcounter y was successful Compile of counter y was successful 2 compiles 0 failed with no errors counter counter Module increment Function counter vsim work counter vsim work counter Loading work counter VSIM 4 gt a test Now Ons Delta 0 sim counter gt At this point you would generally run the simulation and analyze or debug your design We ll do just that in the upcoming lessons For now let s wrap up by ending the simulation and closing the project Select Simulate gt End Simulation and confirm that you want to ModelSim Tutorial T 14 Lesson 1 Creating a Project quit simulating Next select File gt Close gt Project and confirm tha
21. me 5 ns function increment val bit vector return bit vector is normalize the indexing alias input bit _vector val length downto l is val variable result bit_vector input range input variable carry bit l for i in input low to input high loop result ii input i xor carry meer danut iii and navvrr zl Sots En 7 Col 0 read only 4 gt Note Breakpoints can be set only on lines with blue line numbers 5 Select the Continue Run button to resume the run that you interrupted ModelSim will hit the breakpoint as shown by an arrow in the Source window and by a Break message in the Main window i PROMPT run continue MENU Simulate gt Run gt Continue Bi ModelSim Tutorial T 22 Lesson 2 Basic VHDL simulation ModelSim Tutorial Click the Step button in the Main or Source window several times to single step through the simulation Notice that the values change in the Variables window you may need to expand the Variables window PROMPT step MENU Simulate gt Run gt Step 4 This concludes the basic VHDL simulation tutorial When you re done quit the simulator by entering the command quit force This command exits ModelSim without asking for confirmation T 23 Lesson 3 Basic Verilog simulation The goals for this lesson are e Compile a Verilog design e View signals in the design e Examine the hierarchy of the design e Simulate the design e
22. modules i ieee Lit counter a md ModelSim gt wm title ModelSim BES gt Library ModelSim gt se lt No Design Loaded gt WA 4 Double click test_counter to load the design unit PROMPT vsim test_counter El 2 Bring up the Signals Source and Wave windows by entering the following command at the VSIM prompt within the Main window view signals source wave Main MENU View gt lt window name gt ModelSim Tutorial T 28 Lesson 3 Basic Verilog simulation 3 Now let s add signals to the Wave window with ModelSim s drag and drop feature In the Signals window select Edit gt Select All to select the three signals Drag the signals to either the pathname or the values pane of the Wave window Ftsionals ox File Edit View Add Tools Window waa clk x wa rst X waa count HRKRERER waye default a 15 x File Edit view Insert Format Tools Window cH RAA KE RB QQOaE FF sim tes i EL i e test_counter clk test_counter rst test_counter count 4 x x RRRRARRR Cursor 1 21 iN Ons to 512 ns Rg HDL items can also be copied from one window to another or within the Wave and List windows with the Edit gt Copy and Edit gt Paste menu selections ModelSim Tutorial Loading the design T 29 You may have noticed when you loaded the design in Step 1 that a new tab appeared in the Workspace area of the Main w
23. n from the Start menu or from a DOS prompt modelsim exe Note If you didn t add ModelSim to your search path during installation you will have to include the full path when you type this command at a DOS prompt Click Close if the Welcome dialog appears Before you compile any HDL code you ll need a design library to hold the compilation results To create a new design library make this menu selection in the Main window File gt New gt Library PROMPT vlib work vmap work work Make sure Create a new library and a logical mapping to it is selected Type work in the Library Name field and then select OK Create a New Library J xj Create kaera a ara Te Teeter anA a map to an existing library m Library Name work m Library Physical Name work Compiling the design T 17 This creates a subdirectory named work your design library within the current directory ModelSim saves a special file named _info in the subdirectory Note Do not create a Library directory using Windows commands because the _info file will not be created Always use the File menu or the vlib command from either the ModelSim or DOS prompt Compile the file counter vhd into the new library by selecting Compile gt Compile PROMPT vcom counter vhd This opens the Compile HDL Source Files dialog You won t see this dialog if you invoke vcom from the command line Compile HDL S
24. n the Variables window Note that the sum of the inputs a b and cin should be equal to the output sum But there is an error in the test vectors To correct this error you need to restart the simulation and modify the initial value of the test vectors F signals zol xf It variables File Edit view Add Tools Window File Edit view Add Window adders n 8 EL test_patterns 00000000 00000001 0 01 1 00000000 00000001 0 00 2 00000001 00000001 0 00 3 00000001 00000001 1 00 4 00001 010 00000011 0 00 5 00000011 00001010 0 00 6 00000101 00000001 1 00 sim ftestbench 00000101 00000001 sim testbenchitest 8 Restart the simulation again restart f 9 Update the Variables window by selecting the test process in the Process window 10 In the Variables window expand test_patterns and test_pattern 6 again Then highlight the sum record by clicking on the variable name not the box before the name and select Edit gt Change from the menu Change Selected Variable ug Variable Name testbench test test_pattems 6 sum Value 00000111 enoe cos ModelSim Tutorial T 42 Lesson 4 Debugging a VHDL design 11 Change the value to 00000111 and then click Change Note that this is a temporary edit you must use your text editor to permanently change the source code 12 Run the simulation again for 1000 ns run 1000 At this point the simulation will ru
25. n without errors YSIM 30 gt run 1000 Note Test completed with no errors Time 1 us Iteration O Instance testbench 1VSIM 31 gt itbench Z This brings you to the end of this lesson but feel free to explore the system further When you are ready to end the simulation session quit ModelSim by entering the following command at the VSIM prompt quit f ModelSim Tutorial T 43 Lesson 5 Using the Wave window The goals for this lesson are Practice using the Wave window time cursors Practice zooming the waveform display Practice using Wave window keyboard shortcuts Practice combining items into a virtual object Practice creating and viewing datasets ModelSim Tutorial T 44 Lesson 5 Using the Wave window Using time cursors in the Wave window Any of the previous lesson simulations may be used with this part of the lesson or use your own simulation if you wish ioii Fie Edit view Insert Format Tools Window SHS BBA NIALARI RIAR top clk top prw top pstrb top prdy top paddr 00000100 i top pdata 0000000000000100 top srw top sstrb top srdy top saddr EL EM EY B i 3e 3140 ns to 4001 ns select name or value here interval measurement to jump to that cursor locked cursor is red selected cursor is bold When the Wave window is first drawn there is one cursor located at time zero Clicking anywhere in the wavefo
26. ndow The left mouse button lt Button 1 gt then offers 3 zoom options by clicking and dragging in different directions e Down Right Zoom Area In e Up Right Zoom Out e Up Left Zoom Fit The zoom amount is displayed at the mouse cursor A zoom operation must be more than 10 pixels to activate Keyboard shortcuts for zooming Using the following keys when the mouse cursor is within the Wave window will cause the indicated actions Key Action il or zoom in oOo zoom out for F zoom full lor L zoom last ror R zoom range lt arrow up gt scroll pathname values or waveform pane up lt arrow down gt scroll pathname values or waveform pane down lt arrow left gt scroll pathname values or waveform pane left lt arrow right gt scroll pathname values or waveform pane right lt page up gt scroll waveform display up by page lt page down gt scroll waveform display down by page lt Control arrow left gt scroll waveform display left one page lt Control arrow right gt scroll waveform display right one page lt tab gt searches forward right to the next transition on the selected signal lt shift tab gt searches backward left to the previous transition on the selected signal lt Control f gt opens the find dialog box searches within the specified field in the pathname pane for text strings ModelS
27. nter ModelSim gt lt No Design Loaded gt RO A Double click counter to load the design unit PROMPT vsim counter E 2 Next select View gt All Windows from the Main window menu to open all ModelSim windows PROMPT view For descriptions of the windows consult the ModelSim User s Manual Loading the design T 19 3 Next let s add top level signals to the Wave window by selecting Add gt Wave gt Signals in Region from the Signals window menu PROMPT add wave counter F signals File Edit view Add Tools Window count clk reset sim counter ModelSim Tutorial T 20 Lesson 2 Basic VHDL simulation Running the simulation ModelSim Tutorial We will start the simulation by applying stimulus to the clock input 1 Click in the Main window and enter the following command at the VSIM prompt force clk 1 50 0 100 repeat 100 Signals MENU Edit gt Clock ModelSim interprets this force command as follows e force clk to the value 1 at 50 ns after the current time e then to 0 at 100 ns after the current time e repeat this cycle every 100 ns Now you will exercise two different Run functions from the toolbar buttons on either the Main or Wave window The Run functions are identical in the Main and Wave windows Select the Run button first When the run is complete select Run All Run This causes the simulation to run and then stop after 100 ns PROMPT run 100 Main MENU
28. o reload the design elements and reset the simulation time to zero Main MENU Simulate gt Run gt Restart PROMPT restart ModelSim Tutorial Debugging T 33 Make sure all items in the Restart dialog box are selected then click Restart Restart OF Xx Keep IV List Format IV Wave Format IV Breakpoints MV Logged Signals IV Virtual Definitions Restart Cancel Select the Run All button to re start the simulation run PROMPT run all Main MENU Simulate gt Run gt Run All When the simulation hits the breakpoint it stops running highlights the line with an arrow in the Source window and issues a Break message in the Main window When a breakpoint is reached typically you will want to know one or more signal values You have several options for checking values e look at the values shown in the Signals window e hover your mouse pointer over the count variable in the Source window and a balloon will pop up with the value e select the count variable in the Source window right click it and select Examine from the context menu e use the examine command to output the value to the Main window transcript examine count ModelSim Tutorial T 34 Lesson 3 Basic Verilog simulation 5 Let s move through the Verilog source functions with ModelSim s Step command Click Step on the toolbar fH source counter y File Edit view Tools Window C modeltech vlog counte
29. ource Files Library work X Look in 3 vrd ce adder vhd bvadd vhd counter vhd testadder vhd gates vhd io_utils hd File name counter vhd Files of type HDL Files v2 vl2 vhd vhdl vho hdl v Done Default Options Edit Source Complete the compilation by selecting counter vhd from the file list and clicking Compile Select Done when you are finished You can compile multiple files in one session from the file list Individually select and compile the files in the order required by your design Note that you can have ModelSim determine the compile order See Auto generating compile order in the Project chapter of the ModelSim User s Manual for details ModelSim Tutorial T 18 Lesson 2 Basic VHDL simulation Loading the design ModelSim Tutorial 1 Inthe Library tab of the Main window Workspace click the sign next to the work library to see the counter design unit fw Modelsim Ol x xj File Edit view Compile Simulate Tools Window Help ModelSim gt ymap work work E EI work Modifying C modeltech win327 modelsim ini com reportprogress 300 work work C modelt E counter ech vhdl counter vhd i vital2000 i Model Technology ModelSim SE vcom 5 7 Bet ii ieee i a 2 Compiler 2002 11 Nov 22 2002 i delsi lib Loading package standard pes abel Compiling entity counter Compiling architecture only of cou
30. pens the Compile HDL Source Files dialog Compile HDL Source Files Library work T Look in vlog ck EE counter tcounter File name teounter v counter Files of type HDL Files w vl vhd vhdl vho hdl v Done Default Options Edit Source ModelSim Tutorial T 26 Lesson 3 Basic Verilog simulation ModelSim Tutorial Select counter v and tcounter v use Ctrl click and then choose Compile and then Done Note The order in which you compile the two Verilog modules is not important other than the source code dependencies created by compiler directives This may again seem strange to Verilog XL users who understand the possible problems of interface checking between design units or compiler directive inheritance ModelSim defers such checks until the design is loaded So it doesn t matter here if you choose to compile counter v before or after tcounter v Loading the design T 27 Loading the design 1 Inthe Library tab of the Main window Workspace click the sign next to the work library to see the counter and test_counter design units fw Modelsim File Edit view Compile Simulate Tools Window Help vlog reportprogress 300 work work C modelte l ch vlog counter v Model Technology ModelSim SE vlog 5 7 Beta INJ counter Mc 2 Compiler 2002 11 Nov 22 2002 M tas counter Me Compiling module counter i vital2000 Lit Top level
31. r v 23 carry val i carry Z4 end 2s end 26 endfunction 2 28 always posedge clk or posedge reset r 29 if ireset 30 count tpd_reset_to_ count ho 31 else 32 count lt tpdoclk to count increment count 33 34 35 To make module counter synthesizeable use the following 2e ale awwnt nm fawem naf tha Aleve hlan 4 gt counter teounter v 4 DSSS R Ln 29 Col 0 readony 5 This command single steps the debugger 6 Experiment by yourself for awhile Set and clear breakpoints and use the Step Step Over and Continue Run commands until you feel comfortable with their operation When yov re done quit the simulator by entering the command quit force ModelSim Tutorial T 35 Lesson 4 Debugging a VHDL design The goals for this lesson are Map a logical library name to an actual library Recognize assertion messages in the Main window transcript Change the assertion break level Restart the simulation run using the restart command Examine composite types displayed in the Variables window Change the value of a variable In this lesson we will debug an assertion message using the Source Signals and Variables windows ModelSim Tutorial T 36 Lesson 4 Debugging a VHDL design Compiling and loading the design ModelSim Tutorial 1 Create a new directory for this exercise and copy the following VHDL vhd files from lt install_dir gt modeltech e
32. rm display brings that cursor to the mouse location You can add cursors to the waveform pane by selecting Insert gt Cursor or the Add Cursor button shown below The selected cursor is drawn as a bold solid line all other cursors are drawn with thin lines Remove cursors by selecting them and selecting Edit gt Delete Cursor or the Delete Cursor button shown below Add Cursor Delete Cursor add a cursor to the Wave delete the selected cursor a window from the window Naming cursors By default cursors are named Cursor lt n gt To rename a cursor click the name in the left hand cursor pane with your right mouse button Type a new name and press the lt Enter gt key on your keyboard ModelSim Tutorial Using time cursors in the Wave window T 45 Locking cursors You can lock a cursor in position so it won t move Click a cursor with your right mouse button and select Lock lt cursor name gt The cursor turns red and you can no longer move it with the mouse As aconvenience you can hold down the lt shift gt key and click and drag the cursor Once you let go of the cursor it will be locked in the new position To unlock a cursor right click it and select Unlock lt cursor name gt Finding cursors The cursor value corresponds to the simulation time of that cursor Choose a specific cursor view by selecting View gt Cursors Wave window You can also select and scroll to a cursor by double clicking its value in the c
33. t you want to close the project Note that a test mpf file has been created in your working directory This file contains information about the project test that you just created You can open this project in future sessions by selecting File gt Open gt Project ModelSim Tutorial T 15 Lesson 2 Basic VHDL simulation The goals for this lesson are e Create a library and compile a VHDL file e Load a design e Learn about the basic ModelSim windows mouse and menu conventions e Force the value of a signal e Run ModelSim using the run command e Set a breakpoint e Single step through a simulation run The project feature covered in Lesson 1 executes several actions automatically such as creating and mapping work libraries In this lesson we will go through the entire process so you get a feel for how ModelSim really works ModelSim Tutorial T 16 Lesson 2 Basic VHDL simulation Compiling the design ModelSim Tutorial 1 Start by creating a new directory for this exercise in case other users will be working with these lessons Create the directory then copy all of the VHDL vhd files from lt install_dir gt modeltech examples to the new directory Make sure the new directory is the current directory Do this by invoking ModelSim from the new directory or by selecting File gt Change Directory Main window Start ModelSim with one of the following for Windows your option from a Windows shortcut ico
34. the waveform display range Zooming lets you change the simulation range in the waveform pane You can zoom using a context menu toolbar buttons mouse keyboard Using the Zoom menu You can access Zoom commands from the View menu on the toolbar or by clicking the right mouse button in the waveform pane The Zoom menu options include Zoom In Zooms in by a factor of two increasing the resolution and decreasing the visible range horizontally Zoom Out Zooms out by a factor of two decreasing the resolution and increasing the visible range horizontally Zoom Full Redraws the display to show the entire simulation from time 0 to the current simulation time Zoom Last Restores the display to where it was before the last zoom operation Zoom Range Brings up a dialog box that allows you to enter the beginning and ending times for a range of time units to be displayed Zooming with toolbar buttons These zoom buttons are available on the toolbar Zoom In 2x Zoom Out 2x zoom in by a factor of two zoom out by a factor of from the current view two from the current view ModelSim Tutorial Zoom Full Zoom Mode zoom out to view the full change the mouse pointer range of the simulation to zoom mode see below from time 0 to the current time Zooming changing the waveform display range T 47 Zooming with the mouse To zoom with the mouse first enter zoom mode by selecting View gt Mouse Mode gt Zoom Mode Wave wi
35. time The goals for this lesson are Specify the design unit to be simulated on the command line Edit the modelsim ini file Execute commands at load time with a DO file ModelSim Tutorial T 56 Lesson 7 Executing commands at load time ModelSim Tutorial A Important Start this lesson from the DOS prompt in the same directory in which you completed Lesson 6 Running a batch mode simulation For this lesson you will use a macro DO file that executes whenever you load a design For convenience a startup file has been provided with the ModelSim program You need to copy this DO file from the installation directory to your current directory lt install_dir gt modeltech examples startup do Next you will edit the modelsim ini file in the modeltech directory or the modelsim ini file in your current directory if one exists to point at this file To do this open lt install_dir gt modeltech modelsim ini using a text editor and uncomment the following line by deleting the leading in the vsim section of the file Startup do startup do Then save modelsim ini Note The modelsim ini file must be write enabled for this change to take place Using MS Explorer right click on lt install_dir gt modeltech modelsim ini then click Properties In the dialog box uncheck the Read only box and click OK You can also copy the file to your current directory Take a look at the DO file It uses the predefined variable
36. tion to run and then stop after 100 ns the default simulation length PROMPT run MENU Simulate gt Run gt Run 100 ns Next change the run length to 500 on the Run Length selector and select the Run button again jw Modelsim File Edit View Compile Simulate Tools Window Help Module increm counter Function sim Files Now 600 ns Delta 2 sim test_counter Z Now the simulation has run for a total of 600ns the default 100ns plus the 500 you just asked for The status bar at the bottom of the Main window displays this information The last command you executed run 500 caused the simulation to advance for 500ns You can also advance simulation to a specific time Type run 3000 This advances the simulation to time 3000ns Note that the simulation actually ran for an additional 2400ns 3000 600 Running the simulation T 31 4 Now select the Run All button from the Main window toolbar This causes the simulator to run until the stop statement in tcounter v PROMPT run all MENU Simulate gt Run gt Run All f source tcounter y 5 x File Edit view Tools Window 13 l4 initial Test stimulus 15 begin 16 rst 0 17 rst 18 i rst 19 20 end 21 22 initial 23 fmonitor stime rst clk count 24 25 endmodule re 4 gt tcounter v gt SS Ln 19 Col 0 read only 4 You can also use the Break button to interrupt a r
37. top at the HDL assertion statement 3 Restart the simulation using the following command restart f The f option causes ModelSim to restart without popping up the confirmation dialog 4 Run the simulation again for 1000 ns run 1000 ModelSim Tutorial T 40 Lesson 4 Debugging a VHDL design The Source window opens automatically to show the line where the break occurred Notice that the arrow in the Source window is pointing to the assertion statement P 108 amp _ Expected amp to_stringivector sun 109 found_error true 110 end if lll if cout vector cout then 112 assert false 113 report Cout is amp to_char cout 6 114 amp Expected value is amp to_char vectol 115 found error true 5 If you look at the Variables window now you can see that i 6 This indicates that the simulation stopped in the sixth iteration of the test pattern s loop adder8 n test_patterns 00000000 00000001 0 to_char Ux01Z2WLH test vector 00000101 00000001 1 0 found_error false a 1001 6 Expand the variable named test_patterns by clicking the You may need to resize the window for a better view 7 Also expand the sixth record in the array test_patterns 6 by clicking the The Variables window should be similar to the one below ModelSim Tutorial Debugging the simulation T 41 The assertion shows that the Signal sum does not equal the sum field i
38. un MENU Simulate gt Break ModelSim Tutorial T 32 Lesson 3 Basic Verilog simulation Debugging Next we ll take a brief look at an interactive debugging feature of the ModelSim environment 1 Let s set a breakpoint at line 29 in the counter v file which contains a call to the Verilog function increment To do this select dut in the Structure tab of the Workspace Move the cursor to the Source window and scroll the window to display line 29 Click on or to the left of the 29 to set a breakpoint You should see a red dot next to the line number where the breakpoint is set The breakpoint can be toggled between enabled and disabled by clicking it When a breakpoint is disabled the dot appears open To delete the breakpoint click the line number with your right mouse button and select Remove Breakpoint 29 gt Note Breakpoints can be set only on lines with blue line numbers source counter File Edit View Tools Window CAI sll seal AA ae B B E a E carry val i carry gt end 25 end 26 endfunction 2 28 always posedge clk or posedge reset 29 if reset 30 count tpd reset to count hu 31 else 32 count lt tpd clk to count increment count 33 34 35 To make module counter synthesizeable use the following 2c aleawenante an faem naf tha Aleve hlan gt 4 gt counter gt K Ln 1 Col 0 read only 4 2 Select the Restart button t
39. ural description and an RTL description of a 4 bit binary counter To begin you will simulate the structural description and save it to a WLF file Then you will simulate the RTL version Finally you will open the WLF file as a dataset and compare the two simulations in the Wave window Simulating the structural version 1 Start by creating a new working directory making it the current directory and copying the files from nodeltech examples datasets into it 2 Use the vlib command to create a work library in the current directory vlib work MENU File gt New gt Library 3 Use the vmap command to map the work library to a physical directory vmap work work Your modelsim ini file will be updated with this mapping 4 Compile the structural version of the counter vlog cntr_struct v MENU Compile gt Compile 5 Load the design and save the simulation to a WLF file named struct wif vsim wlf struct wlf work cntr_struct 6 Now you will run a DO file that applies stimulus to the design runs the simulation and adds waves to the Wave window Feel free to open the DO file and look at its contents do stimulus do MENU Tools gt Execute Macro The waves that appear in the Wave window are saved automatically into the struct wlf file 7 Quit the simulation quit sim MENU Simulate gt End Simulation T 49 ModelSim Tutorial T 50 Lesson 5 Using the Wave window Simulating the RTL version Comp
40. ursor value pane Alternatively you can click a value with your right mouse button type the value to which you want to scroll and press the Enter key Making cursor measurements Each cursor is displayed with a time box showing the precise simulation time at the bottom When you have more than one cursor each time box appears in a separate track at the bottom of the display ModelSim also adds a delta measurement showing the time difference between two adjacent cursor positions If you click in the waveform display the cursor closest to the mouse position is selected and then moved to the mouse position Another way to position multiple cursors is to use the mouse in the time box tracks at the bottom of the display Clicking anywhere in a track selects that cursor and brings it to the mouse position Cursors will snap to a waveform edge if you click or drag a cursor to within ten pixels of a waveform edge You can set the snap distance in the Window Preferences dialog select Tools gt Window Preferences You can position a cursor without snapping by dragging in the area below the waveforms You can also move cursors to the next transition of a signal with these toolbar buttons Find Previous Find Next Transition Transition locate the next signal locate the previous signal value change for the value change for the selected signal selected signal ModelSim Tutorial T 46 Lesson 5 Using the Wave window Zooming changing
41. xamples to the new directory e gates vhd e adder vhd e testadder vhd Make sure the new directory is the current directory Do this by invoking ModelSim from the new directory or by using the File gt Change Directory command from the ModelSim Main window Start ModelSim with one of the following for Windows your option from a Windows shortcut icon from the Start menu or from a DOS prompt modelsim exe Note If you didn t add ModelSim to your search path during installation you will have to include the full path when you type this command at a DOS prompt Enter the following command at the ModelSim prompt in the Main window to create a new library vlib library_2 Map the new library to the work library using the vmap command vmap work library_2 ModelSim adds this mapping to the modelsim ini file Compile the source files into the new library by entering this command at the ModelSim prompt vcom work library_2 gates vhd adder vhd testadder whd Compiling and loading the design T 37 Open the Simulate dialog by selecting Simulate gt Simulate Expand the work library and increase the width of the name column by clicking and dragging on the border between the Name and Type columns Make sure Simulator Resolution is set to nanoseconds select test_adder_structural and then click OK PROMPT vsim t ns work test_adder_structural E Simulate y iN oj x Design VHDL Verilog Li

Download Pdf Manuals

image

Related Search

Related Contents

SkylineGlobe Web Package v6.1 Release Notes  ESUS-B - Leroy Merlin  THM302M & 303M FRENCH OCT 8 (FINAL).CDR  ASUS X99-A F9644 User's Manual  取扱説明書  GE L250 User's Manual  Guide de dépannage du pain  「C02LCをご利用にあたってのご注意@」  INSTALLATION INSTRUCTIONS  FM-ONE - Fysic  

Copyright © All rights reserved.
Failed to retrieve file