QuartusII-Testbench-Tutorial (1162597)
Текст из файла
Quartus II Testbench TutorialThis tutorial will walk you through the steps of creating Verilog modules in Quartus II andsimulating them using Altera-Modelsim.1) Create a new Quartus Project & configure it for Altera-ModelsimTo configure Quartus to use Altera-Modelsim as the simulator, first create a new project (oropen an existing one) and go to Assignments > Settings > EDA Tool Settings > Simulation.Make sure “Modelsim-Altera” is selected as the tool as shown below (make sure to clickApply then OK if you made any changes).Next go to Tools > Options > General > EDA Tools sure that the path next to ModelsimAltera is configured correctly.
If you installed Quartus II with Altera-Modelsim the pathshould be similar to the one shown in the figure below (i.e. on Windows:“C:\altera\13.0sp1\mode-sim_ase\win32aloem”), otherwise you will need to browse towhere you installed Altera Modelsim and point it to the win32aloem directory.2) Create your Top-Level ModuleIn Quartus, the top level module must have the same name as your project name and mustbe in a file with the same name and a “.v” extension. To create the top level module goback to the main Quartus window and select File > New… > Design Files > Verilog HDL Fileand click OK. An example template of a top-level module can be seen below.
Notice howthe project is called “testbench_example” which is the same name as the top level module,“testbench_example” which exists in the file “testbench_example.v”.3) Create your Unit Under Test & TestbenchNext we will write the Verilog code that we want to test. This code can go in the same fileas the top-level, but it is good practice for separate modules to have their own files, so wewill do that in this example.For this tutorial the code that we want to test will be a simple 2 to 1 multiplexor circuit.Create a new file by going File > New… etc. and save it as “mux.v”. Next write the code thatwe want to test as shown below (Note: the example code can all be found in the appendix)Next we will write the testbench for our multiplexor circuit.
While it is not necessary, it isgood practice to keep the testbench for a module in the same file as the module itself, soagain that is what we will do here. Below is a simple testbench for testing this circuit (again,the code can be found in the appendix).Note: The testbench module does not contain any inputs or outputs, and it instantiates aninstance of our mux module that we want to test calling it “DUT”.Once you have finished writing everything, including your testbench, and everythingcompiles correctly you can move on to part 4. (Note: you might need to put some dummyinputs and outputs in your top-level module to get Quartus to stop complaining, but don’tworry these can be changed later).4) Open Altera-ModelsimTo open altera-modelsim go to Tools > Simulation Tool > RTL Simulation.
This should openup Altera-Modelsim.Modelsim creates a WORK library and puts your compiled Verilog modules from Quartus init. It also sets the working directory to be the modelsim directory of your project (this canbe changed in the settings in step one, but is not recommended).5) Compile the UUT & TestbenchTo compile your Testbench go to Compile > Compile..
and select the file that contains yourVerilog code that you want to test and its testbench. If you left the default settings formodelsim’s working directory you will probably have to browse up a few folders to find thefile you want (in this case mux.v). Once you have selected the file click Compile, then afterit has finished compiling click Done.Notice two new modules have been added to your WORK library.
This process can also bedone by declaring an instance of your UUT module in your top-level module in Quartus.However, if you have a module that you do not plan to use directly in your top-level moduleyou can still use the above instructions to compile it in Modelsim. (Note: You can in factopen Modelsim on its own, browse to the where the file that contains the code you want totest and its testbench lives, and compile it there.
In some cases this may make a bit moresense than going through Quartus.)6) SimulateTo run the simulation right click on the testbench module that you want to simulate, in thiscase “mux_testbench”, i.e. right click mux_testbench > simulate, or simply double click onit. (Note: you can have multiple testbenches compiled at the same time under your WORKlibrary and you can then select which one you want to simulate).Next, add the waves by selecting the signals you want and right click > add wave (or simplyuse the hot key CTRL + W).
This can also be done by selecting the signals you want andclicking the icon of a green circle with a + in it at the top.To run the simulation click the click the icon that looks like a white page with a down-arrowdirectly to the right of the box that says 100 ps.To adjust the simulation time simply edit the time in this box (for this multiplexor example100 ps is more than enough time, but for more complex circuits you may need to simulatelonger). This can also be achieved by typing: run 100 ps in the command prompt at thebottom.Observe your simulation waveforms (you may have to adjust the window zoom/scrolllocation to see your waveforms)*Note if you make a change to either your Unit Under Test or your testbench, you must firstrecompile whatever you changed before re-running the simulation.
Also make sure thatyou click the Restart button directly to the right of the simulation time window (or simplytype “restart” in the command prompt at the bottom) otherwise you will not see yourchanges.Appendix: Source Code/**************************************************** File: testbench_example.v* Author: Benjamin Morgan* Class: EE 271* Module: testbench_example* Description: The top level module for the*testbench tutorial*****************************************************/module testbench_example(LEDR, SW);output [0:0] LEDR;input [2:0] SW;//mux my_mux(.f(LEDR[0]), .in0(SW[0]), .in1(SW[1]), .sel(SW[2]));endmodule/**************************************************** File: mux.v* Author: Benjamin Morgan* Class: EE 271* Module: mux* Description: A simple 2 to 1 multiplexor circuit****************************************************/module mux(f, in0, in1, sel);output f;input in0, in1, sel;assign f = (in0 & ~sel) | (in1 & sel);endmodule/**************************************************** File: mux.v* Author: Benjamin Morgan* Class: EE 271* Module: mux_testbench* Description: A simple 2 to 1 multiplexor circuit****************************************************/module mux_testbench;reg in0, in1, sel;wire f;parameter stimDelay = 10;mux DUT(f, in0, in1, sel);initialbeginin0 = 0; in1 = 0; sel=0;#(stimDelay) in0 = 1;#(stimDelay) in0 = 0; in1 = 1;#(stimDelay) in0 = 1;#(stimDelay) in0 = 0; in1 = 0; sel = 1;#(stimDelay) in0 = 1;#(stimDelay) in0 = 0; in1 = 1;#(stimDelay) in0 = 1;#(stimDelay) sel = 0;#100; //Let simulation finishendendmodule.
Характеристики
Тип файла PDF
PDF-формат наиболее широко используется для просмотра любого типа файлов на любом устройстве. В него можно сохранить документ, таблицы, презентацию, текст, чертежи, вычисления, графики и всё остальное, что можно показать на экране любого устройства. Именно его лучше всего использовать для печати.
Например, если Вам нужно распечатать чертёж из автокада, Вы сохраните чертёж на флешку, но будет ли автокад в пункте печати? А если будет, то нужная версия с нужными библиотеками? Именно для этого и нужен формат PDF - в нём точно будет показано верно вне зависимости от того, в какой программе создали PDF-файл и есть ли нужная программа для его просмотра.















