本來打算搞VHDL的,但是怎么都沒有找到個好的小巧的編譯器+模擬器.Verilog跟VHDL差不多就試試它啦o(∩_∩)o .直接看的是http://www.asic-world.com/verilog/veritut.html這里的教程.
Icarus Verilog官方地址在http://iverilog.icarus.com/,windows版的在http://bleyer.org/icarus/一共就7M.
安裝后有主要的三個工具iverilog.exe--編譯工具 vvp.exe模擬運行的 gtkwave.exe顯示模擬結果的.
以一個簡單的編碼程序說明下.輸入是 0x0002輸出就是1,輸入是0x0004輸出是2具體可以看http://www.asic-world.com/examples/verilog/encoder.html#Encoder_-_Using_if-else_Statement這里.
同時我也把代碼貼出來.
module encoder(binary_out,encoder_in,enable);
output [3:0] binary_out;
input enable;
input [15:0] encoder_in;
reg [3:0] binary_out;
always @ (enable or encoder_in)
begin
binary_out = 0;
if(enable) begin
if(encoder_in == 16'h0002) begin
binary_out = 1;
end if(encoder_in == 16'h0004) begin
binary_out = 2;
end if(encoder_in == 16'h0008) begin
binary_out = 3;
end if(encoder_in == 16'h0010) begin
binary_out = 4;
end if(encoder_in == 16'h0020) begin
binary_out = 5;
end if(encoder_in == 16'h0040) begin
binary_out = 6;
end if(encoder_in == 16'h0080) begin
binary_out = 7;
end if(encoder_in == 16'h0100) begin
binary_out = 8;
end if(encoder_in == 16'h0200) begin
binary_out = 9;
end if(encoder_in == 16'h0400) begin
binary_out = 10;
end if(encoder_in == 16'h0800) begin
binary_out = 11;
end if(encoder_in == 16'h1000) begin
binary_out = 12;
end if(encoder_in == 16'h2000) begin
binary_out = 13;
end if(encoder_in == 16'h4000) begin
binary_out = 14;
end if(encoder_in == 16'h8000) begin
binary_out = 15;
end
end
end
endmodule
編譯方法很簡單 只要使用 iverilog encoder.v 就可以了.
單獨的這一個模塊是不能夠運行的,得寫個測試程序如下.
module encoder_te();
reg enable;
reg [15:0] encoder_in;
wire [3:0] binary_out;
initial begin
$dumpfile("test.vcd"); //這兩行主要是給gtkwave這個工具使用的...
$dumpvars(0,encoder_te);
$monitor("%g\t %b %b %b",
$time,enable,encoder_in,binary_out);
enable = 0;
#5 enable = 1;
#5 encoder_in = 16'h0004;
#6 encoder_in = 16'h0040;
#7 encoder_in = 16'h0400;
#8 encoder_in = 16'h1000;
#10 $finish;
end
encoder en(binary_out,encoder_in,enable);
endmodule
編譯下iverilog -o dsn encoder.v encoder_te.v 得到文件dsn.使用 vvp運行下 vvp dsn
結果如下.
運行后會有文件test.vcd得出 這個文件之間傳給gtkwave就可以可. 運行gtkwave test.vcd
結果如下
很好.耶.
當然為了簡化中間過程寫了個簡單的Python腳本
import os
import sys
srcs = "encoder.v encoder_te.v"
out = 'dsn'
verilog = 'iverilog'
vvp = 'vvp'
gtkwave = 'gtkwave'
dumpvcd = 'test.vcd'
(CL,RUN,SIM) = (True,True,True)
if CL:
command = verilog+" -o "+out+" "+srcs
print command
res = os.system(command)
if res != 0: #這句其實不太頂用編譯時有誤也會返回0 ~>_<~+
sys.exit()
if RUN:
command = vvp + " "+out
print command
res = os.system(command)
if res != 0:
sys.exit()
if SIM:
command = gtkwave+" "+dumpvcd
print command
res = os.system(command)
if res != 0:
sys.exit()
iverilog 還可以將verilog文件轉換為VHDL文件 具體看http://iverilog.wikia.com/wiki/User_Guide
每次改變幾個變量就可以了.等我把Scons搞定后.試試寫用scons擴展.o(∩_∩)o
PS.昨晚下載了個Quartus® II的Web Edition (free) 這版本.搞得有好幾個G.可是里面什么亂七八糟的都有
cygwin,tcl,perl.....我找了半天也沒找到怎么模擬運行程序,太菜了.o(︶︿︶)o .