88.modelsim simulation do file related tips

Source: Internet
Author: User
Tags tcl code

On-line about do file writing as if the data is not much, more miscellaneous, so I summarize the commonly used simple grammar, convenient for everyone to view. In fact, I also just contact do file not long, there is a mistake is normal, welcome to criticize, learn from each other. PS: It's a little messy.

Another notable point is that when I read this article I was emulating a Verilog file that called a rom , But how do I simulate rom The output files have problems, after a QQ friend's guidance, I found unexpectedly is my QUARTUS next Exam library file There is a problem, Since this reminder has encountered this problem but has not resolved the classmate:

a . How do files are introduced and how they work

A do file is a script that executes more than one command at a time. This script can be as simple as a series of MODELSIM commands with related parameters, or a TCL program with variables, execution conditions, and so on. You can execute a do file in the GUI or at the system command prompt.

Because the TCL scripting language content a lot, I was just learning soon, rookie one. But for our course, some of the basic commonly used grammar is worth mentioning, convenient for everyone to learn to communicate, if the following is what is wrong, I hope you put forward and criticize, progress with each other.

First, how do we create a do file?

A lot of methods, one is can open Modelsim, execute file/new/source/do command, enter do file editing mode, in the edit window to enter the simulation batch file code, with. Do to save the file name extension. Of course, you can also create a new Notepad in your Windows system and write a. Do suffix when "save as" is also a method. The method of invocation is to use the instructions in the Modelsim Transcript window: Do filename.do, which completes the automatic simulation of the design.

The following is a brief talk about the steps of simulation. First we want to simulate a design, we usually need to do the following several steps:

Create a project and engineering library;

load the design files (including the testbench you have written. );

compile the source file;

Run the simulation and view the results;

Finally, the engineering debugging.

And do file, is to take the above steps ①---④ with the TCL scripting language to write out, let Modelsim to run the Do file Macro command, and automatically perform the steps of simulation. This benefit may not be much in the small design, but if in a large project, often need to be repeated debugging and simulation of a design unit, but the simulation settings are constant, then if the use of do files, the simulation used to save the command, you can save a lot of manpower, Increased productivity.

The following is a simple example of a counter.dothat tells us some of the basic instructions we use.

The comment for the Ps:do file starts with #, but cannot be added after the line of code, only another line.

The correct is:

Vlib work

#新建一个work库

The error is:

Vlib work #新建一个work库

Write a file named counter.do with the following :
vlib  work   (corresponding to the simulation step ①: Create a new work library.) The purpose of this command is to create a work directory under the current directory, and be careful not to create a new work folder directly in Windows because the Works folder created with the operating system does not have an Modelsim se automatically generated _info file.
vmap work  work (corresponding to the emulation step ①: The purpose of this command is to map the current logical working-Library works to the actual work-Library works mapping. You can also directly use the instruction "Vmap work" to indicate that you are mapping to the current working directory.
vlog counter.v  counter_tb.v   (corresponding to the simulation step ②③: Compiling counter.v and COUNTER_TB.V files, which are compiled by default into the work library. The purpose of this command is to compile these files, note that the files can be compiled separately, but be sure to compile the called files first. If it is VHDL file, only need to change the instruction Vlog vcom can be.
vsim  work.counter_tb  -t 1ns   (corresponding to the simulation step ④: Simulate a module named COUNTER_TB in the work library with a minimum time unit of 1ns.
Add  wave/counter_tb/*  , which is the role of the Testbench file camera_tb.v in the module Camera_ TB all the signal variables are added to the waveform file, note that before the "*" to add a space. You can also see the wave file being opened. Of course, you can add a single signal, such as adding a clock: Add Wave CLK, and so on.
Run 2000   (This command functions as a simulation that runs a unit of time of up to three hours.) You can also use the run–all command to continue emulation. )

You can see your simulation results in the Wave window file. Of course, you can also observe the results of other windows, displayed with the view * command. View * commands can be viewed including signals, wave, dataflow and other window files, can also be opened separately. For example, use the view signals to observe the signal variables.

The above is the use of some of the basic TCL scripting language of Do file, writing is relatively simple, but in fact, the complex is to add the signal line there is more than the addition wave parameter settings, the main guidance of the simulation process instructions are still these few.

After you have written the Do file, in Modelsim, switch the working directory to the same directory as the COUNTER.V, COUNTER_TB.V, and counter.do three files, and then enter do transcript in the command line in the Counter.do window. To switch to a working directory, such as 1, click Change Directory:

Figure 1


PS: If you want to modify the. do file when simulating, you need to run Quit-sim in Modelsim now, exit emulation, then modify the. do file, save it, and then re-execute the Do filename.do command.

Tip tips:

In order to distinguish the various signal lines in the Simulation waveform window, the signal waveform needs to be set up, such as the color of different signal lines, display base, display method and so on to have a difference, at this time need to be in the simulation waveform window separately for each signal line manually set, which for constantly modified source code and then continue to simulate, very troublesome.

Here, let me just say that there is a simple way to automatically generate this type of personalization do file. First of all, we need to do a simulation first, in the waveform window when the need to manually set the required signal line, as shown in 2:

Figure 2

Then, click on the Save icon in the top left corner of the wave window, and a window with a do file will appear, 3:

Figure 3

Its path pathname means that Modelsim automatically creates a new wave.do do file in the current default directory, and we can modify the saved path and do file name ourselves.

Let's take a look at the saved wave.do file above and open it as shown in 4:

Figure 4

from the wave.do file, we can see the different colors, different display methods used in the TCL scripting language, such as the add Wave-color yellow/freq_meter_tb/i1/freq_data means that the freq _data signal shows yellow ... For example, add Wave-noupdate-radix decimal/freq_meter_tb/i1/div_coef means to have the DIV_COEF signal displayed in decimal decimals ... Other information can be compared to their waveform settings one by one corresponding to the other, and so on.

Careful classmates will find this do file is not complete, basically are some add wave, that is, the various settings for each signal TCL code. Yes, because it lacks the simulation step ①②③④ we talked about earlier, we can fill it up with the Tcl language we've learned above.

As in the preceding statement, so that the do file includes the complete instructions for the simulation process, including the new working library, compiled source files, simulation testbench files, etc.:

Vlib work

Vmap work

Vlog FREQ_METER.V

Vlog FREQ_METER_DIRECT.V

Vlog FREQ_METER_TB.V

The new do file looks like this:

Figure 5

At this point, the Do file can be used to achieve a more complete automation simulation.

two . Interactive Commands

Through the command window in the main window to implement, with better debugging and interactive functions, provide a variety of instructions, can be a single-step instruction, can also constitute a batch file, to control the editing, compiling and simulation process;
Common interactive commands are as follows:
1.force-repeat directive
Instruction format: Force start time level value, end level value ignore time (i.e. 0 level hold time)-repeat cycle
The Force CLK 0 0,1 30-repeat 100 indicates that the mandatory CLK starts at 0 time unit, the starting level is 0, the end level is 1,0 level hold time is 30 default time unit, the period is 100 default time units, and the duty cycle is 70%.
Command function: Repeat a certain force command for every interval of time, used to generate clock signal, also can produce the period of input signal, such as 01010101,00110011.
2.force instruction
Instruction format: Force Item_name value Time,value Time;item_name is a port signal or internal signal, supporting wildcard symbols, but only one match; value cannot be defaulted, time, optional, and the unit is supported;
Force DIN 16#40900000 from the current moment to the DIN value 16 40900000;
Force bus 16#f @100ns to the bus at 100ns time to assign a value of 16 F;
Force CLR 1 100 undergoes 100 default time unit delay after assigning a value of 1 to the CLR;
Force CLR 1,0 100 indicates that the CLR assigns a value of 1 after 100 default time cell delays and assigns a value of 0 to the CLR;
3.run instruction
Instruction format: Run Timesteps time_unit,timesteps time step, time_unit time unit, can be FS, PS, NS, US, MS, SEC;
Command function: Run (simulate) and specify the time and unit;
Run 100, which indicates running 100 default time units;
Run 2500ns, indicating running 2500ns;
Run-all, indicating the whole process of operation;
Run-continue, indicating continued operation
4.FORCE-CANCEL directive
Instruction format: Force-cancel period
Command function: Cancel force command after executing period cycle time;
Force CLK 0 0,1 30-repeat 60-cancel 1000, indicating mandatory CLK starting from 0 time unit until 1000 time unit ends;
5.view instruction
Instruction format: View window name
Command function: Open the Modelsim window
View Souce, open the Source code window;
View wave, open the waveform window;
View list, open the listing window;
View Varibles, open the variable window;
View signals, open the signal window;
View all, open all windows;

88.modelsim simulation do file related tips

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.