Quartus ii与Modelsim-altera 6.5b联调前仿真
生活随笔
收集整理的這篇文章主要介紹了
Quartus ii与Modelsim-altera 6.5b联调前仿真
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本實例使用的是Quartus ii9.1版本,Modelsim-altera版本是?
Quartus ii9.1版本
?對應的6.5b版本。
本實例使用的是格雷碼計數器(Gray)
=============================================================================
首先打開Quatus ii,File->New Project Wizard.操作如下。
之后出現如下界面,單擊Next按鈕. 出現如下對話框,輸入工程位置:G:\GrayCounter,工程名為:GrayCounter,設置頂層文件:GrayCounter,此次試驗比較簡單,頂層文件和工程名就命名為一樣的。之后單擊 Next, ? 有以下對話框:再單擊Next。 ? ? 在對話框中設置FPGA為Cyclone II家族的,EP2C8Q208C8,單擊Next. 對話框中都默認,然后單擊Next, ? 有以下對話框,單擊Finish。 ????
Quartus中有以下界面:可以看到工程文件為:GrayCounter
?之后要新建一個verilog文件,File->New
選擇以下:verilog HDL File,單擊OK按鈕。 在verilog 文件中輸入:以下代碼: `timescale 1ps/1ps
module GrayCounter ? #(parameter N=5 ) ( input clk, input rst_n, output reg [N-1:0] gray );
reg [N-1:0] cnt; reg [N-1:0] temp; integer i;
always @ (posedge clk ,negedge rst_n) begin if(!rst_n) cnt <= 1'b0; else cnt <= cnt +1'b1; end
always @(cnt) begin temp[N-1] = cnt[N-1]; for(i=1; i<=N-1;i=i+1) temp[i-1] = cnt[i-1]^cnt[i]; end
always @ (posedge clk, negedge rst_n) begin ? if(!rst_n) gray<=1'b0; else ? begin gray<=temp; $display("gray=%b",gray); ? ? ? ?end end? endmodule 窗口如下: ? 然后保存verilog文件:Ctrl+S快捷鍵:出現以下對話框,文件名為GrayCounter,類型選擇Verilog文件類型,單擊保存。 保存之后原來的verilog1文件變為: GrayCounter.v文件。 ? ???之后編譯工程,Processing->Start Compilation,編譯工程。 ? . 編譯成功出現如下界面:?
接下來設置Modelsim的設置。 Tools->Option. ? ?在General->EDA tool options->Modelsim-Altera,設置Modelsim-Altera?的安裝路徑:G:\altera\91\modelsim_ae\win32aloem(選你自己的安裝路徑)
? 開始設置testbench的相關設置項。Processing->start test bench template writer,
生成的文件位置在這里:G:\GrayCounter\simulation\modelsim\GrayCounter.vt GrayCounter.vt是testbench文件,在modelsim6.5中也可以使用.v文件作為testbench文件,都是可行的。 這里順便說一下:為什么使用Modelsim-altera呢,因為modelsim6.5每次都要寫實例化文件,要要自己建立modelsim的工程,相對來說麻煩,而Modelsim-altera每次打開Quartus工程,設置一次就可以使用Modelsim-altera,實例化等基本內容已經寫好,省去很多時間。
GrayCounter.vttestbench文件內容如下代碼: 這一步是建立一個仿真模板文件,模板文件提供了基本的寫法,具體的testbench文件內容還要自己寫。 =============================================================== // Copyright (C) 1991-2009 Altera Corporation // Your use of Altera Corporation's design tools, logic functions? // and other software and tools, and its AMPP partner logic? // functions, and any output files from any of the foregoing? // (including device programming or simulation files), and any? // associated documentation or information are expressly subject? // to the terms and conditions of the Altera Program License? // Subscription Agreement, Altera MegaCore Function License? // Agreement, or other applicable license agreement, including,? // without limitation, that your use is for the sole purpose of? // programming logic devices manufactured by Altera and sold by? // Altera or its authorized distributors. ?Please refer to the? // applicable agreement for further details.
// ***************************************************************************** // This file contains a Verilog test bench template that is freely editable to ? // suit user's needs .Comments are provided in each section to help the user ? ? // fill out necessary details. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // ***************************************************************************** // Generated on "05/29/2012 13:41:48" // Verilog Test Bench template for design : GrayCounter //? // Simulation tool : ModelSim-Altera (Verilog) //?
`timescale 1 ps/ 1 ps module GrayCounter_vlg_tst(); // constants ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? // general purpose registers reg eachvec; // test vector input registers reg clk; reg rst_n; // wires ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? wire [4:0] ?gray;
// assign statements (if any) ? ? ? ? ? ? ? ? ? ? ? ? ? GrayCounter i1 ( // port map - connection between master ports and signals/registers ?? .clk(clk), .gray(gray), .rst_n(rst_n) ); initial ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? begin ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // code that executes only once ? ? ? ? ? ? ? ? ? ? ? ? // insert code here --> begin ? ? ? ? ? ? ? ? ? ? ? ? ? // --> end ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? $display("Running testbench"); ? ? ? ? ? ? ? ? ? ? ?? end ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? always ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? // optional sensitivity list ? ? ? ? ? ? ? ? ? ? ? ? ?? // @(event1 or event2 or .... eventn) ? ? ? ? ? ? ? ? ? begin ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // code executes for every event on sensitivity list ?? // insert code here --> begin ? ? ? ? ? ? ? ? ? ? ? ? ? @eachvec; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // --> end ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? end ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? endmodule =================================================================================== 可以看出文件中提供了模塊的寫法和實例化調用,做以下修改,以適合我的工程。 修改GrayCounter.vt ? testbench文件之后,GrayCounter.vt ? testbench文件內容如下: =================================================================================== `timescale 1 ps/ 1 ps module GrayCounter_vlg_tst(); reg clk; reg rst_n; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? wire [4:0] ?gray; GrayCounter i1( .clk(clk), .gray(gray), .rst_n(rst_n) ); initial? begin? $display("Running testbench"); ? ? clk =0; rst_n = 0; #5 rst_n = 1; ? ? ? ? ? #500000 $stop; ?? end ? always#1 clk = ~clk; ? ? ? endmodule =================================================================================== 接下來設置工程 ?設置GrayCounter工程: 在 工程上右鍵settings
在EDA tool settings->simulation中設置tool name:modelsim-altera ? 輸出文件格式選擇為verilog HDL,NativeLink settings選擇Compile testbench。
? 再單擊Test Benches
?在這順便說一句,最好不要勾選Run gate-level simulation automatically after compilation,我的Modelsim破解的不是特別好,因此不勾選這個選項。 ? ?再單擊Test Benches 單擊Test benches按鈕之后出現如下對話框:選擇New... ? 設置文件名:GrayCounter_vlg_tst 模塊名:GrayCounter? 實例名:i1? 在File name中單擊按鈕:? 彈出以下對話框: 選擇:G:\GrayCounter\simulation\modelsim\GrayCounter.vt,類型選擇All files,否則看不到GrayCounter.vt。 單擊打開按鈕 對話框如下: 單擊Add按鈕。 ? 對話框變在File name中變為:?設置完成之后Compile test bench文件為:GrayCounter_vlg_tst文件。最后單擊OK。 ?編譯工程: 調用RTL仿真:Tools->Run EDA Simulation Tool -> EDA RTL Simulation ? 在modelsim窗口中有以下:常用的有Transcript:命令輸出,包括display等的輸出,wave是波形顯示窗口,library是文件的列表 ?標題如下: 對話框下面如下: 打開library標簽: 最下面的work目錄:有GrayCounter_vlg_tst文件 在文件上右鍵Simulate without Optimization操作。 ? 軟件跳轉到:sim頁面中 在GrayCounter_vlg_tst文件上右鍵,Add->To wave -> All items in region。 ?? 在wave標簽頁中有: 然后運行,執行run, 這時候波形看起來不是特清楚,需要調一下放大和縮小。 調節到合適位置波形如下: 可以看一下Transcript標簽頁中有:display的輸出。
module GrayCounter ? #(parameter N=5 ) ( input clk, input rst_n, output reg [N-1:0] gray );
reg [N-1:0] cnt; reg [N-1:0] temp; integer i;
always @ (posedge clk ,negedge rst_n) begin if(!rst_n) cnt <= 1'b0; else cnt <= cnt +1'b1; end
always @(cnt) begin temp[N-1] = cnt[N-1]; for(i=1; i<=N-1;i=i+1) temp[i-1] = cnt[i-1]^cnt[i]; end
always @ (posedge clk, negedge rst_n) begin ? if(!rst_n) gray<=1'b0; else ? begin gray<=temp; $display("gray=%b",gray); ? ? ? ?end end? endmodule 窗口如下: ? 然后保存verilog文件:Ctrl+S快捷鍵:出現以下對話框,文件名為GrayCounter,類型選擇Verilog文件類型,單擊保存。 保存之后原來的verilog1文件變為: GrayCounter.v文件。 ? ???之后編譯工程,Processing->Start Compilation,編譯工程。 ? . 編譯成功出現如下界面:?
接下來設置Modelsim的設置。 Tools->Option. ? ?在General->EDA tool options->Modelsim-Altera,設置Modelsim-Altera?的安裝路徑:G:\altera\91\modelsim_ae\win32aloem(選你自己的安裝路徑)
? 開始設置testbench的相關設置項。Processing->start test bench template writer,
生成的文件位置在這里:G:\GrayCounter\simulation\modelsim\GrayCounter.vt GrayCounter.vt是testbench文件,在modelsim6.5中也可以使用.v文件作為testbench文件,都是可行的。 這里順便說一下:為什么使用Modelsim-altera呢,因為modelsim6.5每次都要寫實例化文件,要要自己建立modelsim的工程,相對來說麻煩,而Modelsim-altera每次打開Quartus工程,設置一次就可以使用Modelsim-altera,實例化等基本內容已經寫好,省去很多時間。
GrayCounter.vttestbench文件內容如下代碼: 這一步是建立一個仿真模板文件,模板文件提供了基本的寫法,具體的testbench文件內容還要自己寫。 =============================================================== // Copyright (C) 1991-2009 Altera Corporation // Your use of Altera Corporation's design tools, logic functions? // and other software and tools, and its AMPP partner logic? // functions, and any output files from any of the foregoing? // (including device programming or simulation files), and any? // associated documentation or information are expressly subject? // to the terms and conditions of the Altera Program License? // Subscription Agreement, Altera MegaCore Function License? // Agreement, or other applicable license agreement, including,? // without limitation, that your use is for the sole purpose of? // programming logic devices manufactured by Altera and sold by? // Altera or its authorized distributors. ?Please refer to the? // applicable agreement for further details.
// ***************************************************************************** // This file contains a Verilog test bench template that is freely editable to ? // suit user's needs .Comments are provided in each section to help the user ? ? // fill out necessary details. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // ***************************************************************************** // Generated on "05/29/2012 13:41:48" // Verilog Test Bench template for design : GrayCounter //? // Simulation tool : ModelSim-Altera (Verilog) //?
`timescale 1 ps/ 1 ps module GrayCounter_vlg_tst(); // constants ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? // general purpose registers reg eachvec; // test vector input registers reg clk; reg rst_n; // wires ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? wire [4:0] ?gray;
// assign statements (if any) ? ? ? ? ? ? ? ? ? ? ? ? ? GrayCounter i1 ( // port map - connection between master ports and signals/registers ?? .clk(clk), .gray(gray), .rst_n(rst_n) ); initial ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? begin ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // code that executes only once ? ? ? ? ? ? ? ? ? ? ? ? // insert code here --> begin ? ? ? ? ? ? ? ? ? ? ? ? ? // --> end ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? $display("Running testbench"); ? ? ? ? ? ? ? ? ? ? ?? end ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? always ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? // optional sensitivity list ? ? ? ? ? ? ? ? ? ? ? ? ?? // @(event1 or event2 or .... eventn) ? ? ? ? ? ? ? ? ? begin ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // code executes for every event on sensitivity list ?? // insert code here --> begin ? ? ? ? ? ? ? ? ? ? ? ? ? @eachvec; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // --> end ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? end ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? endmodule =================================================================================== 可以看出文件中提供了模塊的寫法和實例化調用,做以下修改,以適合我的工程。 修改GrayCounter.vt ? testbench文件之后,GrayCounter.vt ? testbench文件內容如下: =================================================================================== `timescale 1 ps/ 1 ps module GrayCounter_vlg_tst(); reg clk; reg rst_n; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? wire [4:0] ?gray; GrayCounter i1( .clk(clk), .gray(gray), .rst_n(rst_n) ); initial? begin? $display("Running testbench"); ? ? clk =0; rst_n = 0; #5 rst_n = 1; ? ? ? ? ? #500000 $stop; ?? end ? always#1 clk = ~clk; ? ? ? endmodule =================================================================================== 接下來設置工程 ?設置GrayCounter工程: 在 工程上右鍵settings
在EDA tool settings->simulation中設置tool name:modelsim-altera ? 輸出文件格式選擇為verilog HDL,NativeLink settings選擇Compile testbench。
? 再單擊Test Benches
?在這順便說一句,最好不要勾選Run gate-level simulation automatically after compilation,我的Modelsim破解的不是特別好,因此不勾選這個選項。 ? ?再單擊Test Benches 單擊Test benches按鈕之后出現如下對話框:選擇New... ? 設置文件名:GrayCounter_vlg_tst 模塊名:GrayCounter? 實例名:i1? 在File name中單擊按鈕:? 彈出以下對話框: 選擇:G:\GrayCounter\simulation\modelsim\GrayCounter.vt,類型選擇All files,否則看不到GrayCounter.vt。 單擊打開按鈕 對話框如下: 單擊Add按鈕。 ? 對話框變在File name中變為:?設置完成之后Compile test bench文件為:GrayCounter_vlg_tst文件。最后單擊OK。 ?編譯工程: 調用RTL仿真:Tools->Run EDA Simulation Tool -> EDA RTL Simulation ? 在modelsim窗口中有以下:常用的有Transcript:命令輸出,包括display等的輸出,wave是波形顯示窗口,library是文件的列表 ?標題如下: 對話框下面如下: 打開library標簽: 最下面的work目錄:有GrayCounter_vlg_tst文件 在文件上右鍵Simulate without Optimization操作。 ? 軟件跳轉到:sim頁面中 在GrayCounter_vlg_tst文件上右鍵,Add->To wave -> All items in region。 ?? 在wave標簽頁中有: 然后運行,執行run, 這時候波形看起來不是特清楚,需要調一下放大和縮小。 調節到合適位置波形如下: 可以看一下Transcript標簽頁中有:display的輸出。
總結
以上是生活随笔為你收集整理的Quartus ii与Modelsim-altera 6.5b联调前仿真的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: modelsim与modelsim_al
- 下一篇: SDRAM工作的大体流程