LoginSignup
30
22

More than 3 years have passed since last update.

Icarus Verilogの導入とAND回路のシミュレーション

Posted at

概要

マイコンばっか触ってきたけど唐突にFPGAに手を出したくなったのでVerilogHDLを学ぼうと思い、コンパイラと波形シミュレータの環境を整えたのでその備忘録

開発環境の導入

Windows版もあるようだが、情報が少なかったのでUbuntu 18.04LTSに導入する。
ターミナルを開いてaptから"iverilog"と"gtkwave"をインストールする。

sudo apt install iverilog
sudo apt install gtkwave 

AND回路の実装

適当なディレクトリに移動してVimを用いて以下のファイルを作成する

and.v
module AND(
        input wire in0,
        input wire in1,
        output wire out0
        );
        assign out0 = in0 & in1;
endmodule

テストベンチファイルの作成

今回はFPGAには書き込まず、シミュレータ上で動作確認を行うため、以下のようなテストベンチファイルも用意する

and_test.v
module ANDTEST;

reg a, b;
wire c;

AND and_instance(a, b, c); //オブジェクト指向感

initial begin
        $dumpfile("and_test.vcd");
        $dumpvars(1, ANDTEST);

        a = 0; b = 0;
        #10 a = 1;
        #10 a = 0; b = 1;
        #10 a = 1;
        #10 a = 0; b = 0;
        #10 $finish;
end

endmodule

コンパイル

以下のコマンドを入力する
iverilog -o [出力ファイル名] -s [トップモジュール名] [.vファイルの羅列]
-oオプションを省略すると出力ファイルはa.outになる。-sオプションは省略可能だが、省略せずにトップモジュールを明示したほうが良さげである。

iverilog -o andtest -s ANDTEST and_test.v and.v

vcdファイルの作成

以下のコマンドを実行し、and_test.v内で指定したファイル名であるand_test.vcdが出力されたか確認する。

vvp andtest.out

波形の確認

ターミナルに以下のコマンドを入力する。得られた波形を確認するとc = a & bという回路を実装できていることがわかる。

twinwave + and_test.vcd

Screenshot from 2019-08-02 19-24-44.png

参考にしたサイト

  1. http://cellspe.matrix.jp/zerofpga/icarus.html
  2. http://altmo.html.xdomain.jp/src_00/2015_0110/verilog-hdl_base_04.html
  3. http://cas.eedept.kobe-u.ac.jp/~arai/Verilog/
30
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
22