一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

ModelSim Library Tutorial

 tallergao 2011-03-20
TR>

ModelSim Tutorial

[ModelSim EE software on SPL's HPs]

1. Introduction

ModelSim is quick and handy VHDL/Verilog simulator. From this document you can find short introduction how to use ModelSim without design manager or other Mentor applications (i.e., as a stand alone tool).

2. Introduction

Before using ModelSim you have to initialize few variables etc. Refer to section Getting Started with ModelSim.

3. Beginners' Guide

Your VHDL code must be compiled into a VHDL library before it can be simulated. Simulator itself can't read VHDL source code, it can only simulate a compiled database (think it as a compiled program).

In the compilation phase all syntactical bugs/typos will be pointed out. After you have succesfully managed to compile the design, actual simulation/debugging of semantical mistakes (= design errors) may begin. (In fact ModelSim may point out some possible design pitfalls already in compilation phase.)

You can manage your VHDL libraries with following shell commands. Study them carefully:

vlib      Create a new library
            vmap      Map physical and logical library
            vdir      List currently compiled design units
            vdel      Delete a design unit
            vmake     Automatically generate Makefile
            
Compilation and simulation commands:
vcom      Compile VHDL source code
            vsim      Simulate compiled design
            

4. Exercises and demos

In the following example we will design simple traffic lights control circuit with behavioral vhdl. We will compile and simulate vhdl with ModelSim and study how to create and manage VHDL libraries in practice. Then we will improve the functionality of our traffic lights editing the source code and verifying our changes with second simulation.

First we need a VHDL library where we can compile our source code.

    Create two libraries (codelib and traffic_lib)
       % vlib codelib
                    % vlib traffic_lib
                    
As you can see vlib created two directories (codeliband traffic_lib) and one file into each of the directories (_index or _info). That file contains information about compiled VHDL sources and the state of the library (of cource at this moment both of these files are empty). You should never edit these files yourself 'by hand'. Let the ModelSim itself handle its own bookcounting. In order to change the state of the library use only appropriate library commands.

Now we must tell ModelSim where our newly created libraries are located in physical media (= path on the disk we are using).

    Map the physical and logical library
       % vmap codelib $PWD/codelib
                    % vmap traffic_lib $PWD/traffic_lib
                    
    $PWD here represents full path to the physical library.
vmap writes an initialization file called modelsim.ini into your working directory which contains information about your working environment (like which libraries you are using etc.).

Hint: If you use only vmap without parameters you will get a list of currently mapped libraries, which ModelSim.ini you are currently using and physical location of every library.

Compile the source code:
    Compile the vhdl package into the traffic_lib:
       % vcom package.vhdl -work traffic_lib -source
                        
The following command-line options can be used with vcom:
    -work path
    Specify library WORK

    -nowarn #
    Do not flag warnings for the warning number specified.

    -line #
    Specify starting line number

    -source
    Print the VHDL source line with error messages

    -just e,a,p,b,c
    Compiles only the specified units (entities, architectures, package headers, package bodies, configurations)

    -skip e,a,p,b,c
    Compiles everything except the specified units (entities, architectures, package headers, package bodies, configurations)

     

Note that vcom always compiles sources to the library work. The only way to compile designs other libraries than work is to rename the work. This can be done with -work switch in vcom like we did in the package's case or remapping the work into another library with vmap.
% vmap destination_library work (This command is not ment to be performed)
                
Now work points to the destination_library and -work -switch may be omitted. Remember that you can always check your current mapping just typing vmap without any parameters.

Map the work to codelib and compile the architecture and entity into it.

    Map the work into codelib:
       % vmap work $PWD/codelib
                        
    Try now vmap...
       % vmap
                        Reading /home/user/.ModelSim.ini
                        "work" maps to directory /home/user/codelib/.
                        "codelib" maps to directory /home/user/codelib/.
                        ...
                        
    Verify that you mappings are something like above. After that you can compile the source code into codelib...
       % vcom top_level_entity.vhdl -source
                        % vcom behavioral.vhdl -source
                        
Soon you will notice that VHDL design cycle is something like edit-compile-simulate-edit-compile... It is quite annoying always write same compilation commands every design cycle. One can always write a shell script, but if your design is large enough compilation times may be quite long. Those who are familiar with make knows that it is answer to all these problems. Fortunately in ModelSim there is a command which automatically generates a Makefile for your design hierarchy.
    Generate a Makefile from the codelib's sources:
       % vmake codelib > Makefile
                        
In order to keep your library up-to-date, you have to only give a command make. Make knows which files have been edited and automatically compiles only needed designs.

More information about make and Makefile from UNIX manuals (% man make) See also: man touch.

Now you are ready to simulate out traffic lights!

    Start ModelSim
       % vsim &
                        
First ModelSim prompts you to choose the entity-architecture pair you want to simulate. Select the traffic_lights entity and just press Load. Soon a window (like following picture) should open.

Then expand the library codelib on library list window. (After that the view is like below)

Then load the traffic_lights. (double click the text traffic_lights or first select it by clicking it once and then take from menu Simulate - Simulate)



There are two ways to give commands to ModelSim. You can either choose commands with mouse from simulator's GUI or write them directly to the command line. Try for example writing:

VSIM> view signals
                
Or try to choose from ModelSim (ModelSim : View - Signals).

You can also write scripts and then execute them by choosing (ModelSim : Macro - Execute Macro...)

Simulation

    View the wave -window by choosing (ModelSim : View - Signals) and (Signals : Add - Wave - Signals in Region) or by writing to the command line:
       VSIM> add wave *
                        

    You can force signals from (Signals : Edit - Force...) or clock signal (Signals: Edit - Clock) or by writing commands to the command line:

       VSIM> force -deposit /clk 1 5 -repeat 20
                        VSIM> force -deposit /clk 0 10 -repeat 10
                        VSIM> force -deposit /reset 0 0
                        VSIM> force -deposit /reset 1 15
                        
    Now press run button couple of times or (Modelsim : Simulate - Run):
    You should see simulation results in the wave-window.
Configuring environment
    You can move signals up and down in the Wave-window with the mouse. You can add signals from different entities to the same wave window by first pointing right entity from structure windown, choosing signal(s) from signal window and then giving command (Signals : Add - Wave - Selected signals). Of cource, that is not possible in our trafficlight example (we only have one entity).
Saving the configuration
    After your simulation environment is ready, you can save it in the script file as a configuration for future use by choosing (Wave : File - Save Format...). Saved configuration can be read by choosing (ModelSim : File - Load Format...) and choosing the file you have saved.
Debugging VHDL with trace
    You can trace your vhdl source code: First view Source (ModelSim : View - Source) or VSIM> view source and then press (ModelSim : Step) or (ModelSim : Step Over) buttons.
Our traffic lights has no output for actual light bulbs. It is only a state machine at the moment. That is why we are now going to improve our design by adding output signals wires to every bulb (reg, yellow and green).
    Choose your favorite editor (like emacs) and edit the top level entity (top_level_entity.vhdl):
       ENTITY traffic_lights IS
                                            PORT ( clk,
                                            reset             : IN std_logic;
                                            red_light,
                                            orange_light,
                                            green_light       : OUT std_logic);
                                            END traffic_lights;
                                            
    And then edit the architecture (behavioral.vhdl):
       CASE current_state IS
                                            WHEN red  =>
                                            IF (count = 20) THEN
                                            next_state <= orange;
                                            count := 0;
                                            red_light <= '1';
                                            orange_light <= '0';
                                            green_light <= '0';
                                            END IF;
                                            WHEN orange =>
                                            IF (count = 5) THEN
                                            next_state <= green;
                                            count := 0;
                                            red_light <= '1';
                                            orange_light <= '1';
                                            green_light <= '0';
                                            END IF;
                                            WHEN green =>
                                            IF (count = 20) THEN
                                            next_state <= red;
                                            count := 0;
                                            red_light <= '0';
                                            orange_light <= '0';
                                            green_light <= '1';
                                            END IF;
                                            WHEN OTHERS =>
                                            next_state <= current_state;
                                            END CASE;
                                            
    Now we have to recompile edited VHDL sources before we can simulate our enhanced design. Make will do that for us automatically.

    Save changes and goto to the shell prompt and give command:

       % make
                                            
    (Note that if you took a new shell you must first execute your Mentor initialization script unless you have edited your .cshrc file to include the source commands and goto the directory where your libraries, codes and Makefile are.)

    After compilation you must load new design to the simulator. If you did not Quit the simulator just give the command:

       VSIM> restart -force
                                            
    Otherwise you must start the simulator again:
       % vsim &
                                            
    Now you can simulate and verify our new design. Try to view all signals (including those we just added).

5. More Information

For more information refer to the OnLine Manuals.

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多

    麻豆视传媒短视频在线看| 亚洲国产综合久久天堂| 亚洲精品中文字幕一二三| 亚洲一区二区久久观看| 欧美日韩少妇精品专区性色| 偷拍美女洗澡免费视频| 99免费人成看国产片| 老司机激情五月天在线不卡| 亚洲精品福利视频在线观看| 六月丁香六月综合缴情| 亚洲中文字幕在线观看黑人| 中文字幕乱码免费人妻av| 一区二区三区免费公开| 十八禁日本一区二区三区| 少妇高潮呻吟浪语91| 在线观看那种视频你懂的| 人妻一区二区三区多毛女| 亚洲综合香蕉在线视频| 国产亚洲精品香蕉视频播放| 在线观看视频国产你懂的| 国产精品香蕉免费手机视频| 欧美日韩一区二区综合| 91久久国产福利自产拍| 99国产一区在线播放| 可以在线看的欧美黄片| 五月情婷婷综合激情综合狠狠| 国产一区二区三区口爆在线| 欧美日韩亚洲国产综合网| 成人区人妻精品一区二区三区| 亚洲二区欧美一区二区| 熟女少妇一区二区三区蜜桃| 开心久久综合激情五月天| 国产精品成人一区二区在线 | 正在播放玩弄漂亮少妇高潮| 日本加勒比中文在线观看| 黑人巨大精品欧美一区二区区| 精品人妻精品一区二区三区| 久久精品福利在线观看| 国产麻豆一区二区三区在| 国产又粗又猛又大爽又黄| 日韩成人高清免费在线|