VivadoとVerilogを用いたMinisysプラットフォームのデジタル回路開発入門

開発環境と目的

Vivadoの開発フロー(設計入力、シミュレーション、論理合成、配置配線、デバイス書き込み)を習得し、Minisys実験ボードの基本的な操作方法を理解することを目的とします。また、Verilog HDLを用いたテキスト入力による論理回路の記述方法を習得します。

実装する回路

  • 24ビットDIPスイッチの入力をそのまま24ビットLEDへ伝達するパススルー回路
  • ゲートレベルモデリングを用いた1ビットコンパレータ(大小比較および一致判定)

設計と実装:パススルー回路

Verilogソースコード

switch_to_led.v

`timescale 1ns / 1ps

module switch_to_led(
    input  [23:0] dip_sw,
    output [23:0] light_out
);
    // DIPスイッチの状態をLEDに直接接続
    assign light_out = dip_sw;
endmodule

テストベンチ

tb_switch_to_led.v

`timescale 1ns / 1ps

module tb_switch_to_led();
    // 入力信号
    reg  [23:0] dip_sw = 24'h0;
    // 出力信号
    wire [23:0] light_out;

    // テスト対象モジュールのインスタンス化
    switch_to_led uut (
        .dip_sw(dip_sw),
        .light_out(light_out)
    );

    // 10nsごとにスイッチの値をインクリメント
    always #10 dip_sw = dip_sw + 1;

endmodule

制約ファイル

pin_assign_sw.xdc

# I/O規格とスルーレートの設定
set_property IOSTANDARD LVCMOS33 [get_ports {light_out[*]}]
set_property IOSTANDARD LVCMOS33 [get_ports {dip_sw[*]}]
set_property SLEW SLOW [get_ports {light_out[*]}]

# LED出力のピン割り当て
set_property PACKAGE_PIN W14 [get_ports {light_out[23]}]
set_property PACKAGE_PIN Y14 [get_ports {light_out[22]}]
set_property PACKAGE_PIN AB11 [get_ports {light_out[21]}]
set_property PACKAGE_PIN AB12 [get_ports {light_out[20]}]
set_property PACKAGE_PIN AA9 [get_ports {light_out[19]}]
set_property PACKAGE_PIN AB10 [get_ports {light_out[18]}]
set_property PACKAGE_PIN AA10 [get_ports {light_out[17]}]
set_property PACKAGE_PIN AA11 [get_ports {light_out[16]}]
set_property PACKAGE_PIN V10 [get_ports {light_out[15]}]
set_property PACKAGE_PIN W10 [get_ports {light_out[14]}]
set_property PACKAGE_PIN Y11 [get_ports {light_out[13]}]
set_property PACKAGE_PIN Y12 [get_ports {light_out[12]}]
set_property PACKAGE_PIN W11 [get_ports {light_out[11]}]
set_property PACKAGE_PIN W12 [get_ports {light_out[10]}]
set_property PACKAGE_PIN V13 [get_ports {light_out[9]}]
set_property PACKAGE_PIN V14 [get_ports {light_out[8]}]
set_property PACKAGE_PIN U15 [get_ports {light_out[7]}]
set_property PACKAGE_PIN V15 [get_ports {light_out[6]}]
set_property PACKAGE_PIN T14 [get_ports {light_out[5]}]
set_property PACKAGE_PIN T15 [get_ports {light_out[4]}]
set_property PACKAGE_PIN W15 [get_ports {light_out[3]}]
set_property PACKAGE_PIN W16 [get_ports {light_out[2]}]
set_property PACKAGE_PIN T16 [get_ports {light_out[1]}]
set_property PACKAGE_PIN U16 [get_ports {light_out[0]}]

# DIPスイッチ入力のピン割り当て
set_property PACKAGE_PIN Y19 [get_ports {dip_sw[23]}]
set_property PACKAGE_PIN V18 [get_ports {dip_sw[22]}]
set_property PACKAGE_PIN V19 [get_ports {dip_sw[21]}]
set_property PACKAGE_PIN AA19 [get_ports {dip_sw[20]}]
set_property PACKAGE_PIN AB20 [get_ports {dip_sw[19]}]
set_property PACKAGE_PIN V17 [get_ports {dip_sw[18]}]
set_property PACKAGE_PIN W17 [get_ports {dip_sw[17]}]
set_property PACKAGE_PIN AA18 [get_ports {dip_sw[16]}]
set_property PACKAGE_PIN AB18 [get_ports {dip_sw[15]}]
set_property PACKAGE_PIN U17 [get_ports {dip_sw[14]}]
set_property PACKAGE_PIN U18 [get_ports {dip_sw[13]}]
set_property PACKAGE_PIN P14 [get_ports {dip_sw[12]}]
set_property PACKAGE_PIN R14 [get_ports {dip_sw[11]}]
set_property PACKAGE_PIN R18 [get_ports {dip_sw[10]}]
set_property PACKAGE_PIN T18 [get_ports {dip_sw[9]}]
set_property PACKAGE_PIN N17 [get_ports {dip_sw[8]}]
set_property PACKAGE_PIN P17 [get_ports {dip_sw[7]}]
set_property PACKAGE_PIN P15 [get_ports {dip_sw[6]}]
set_property PACKAGE_PIN R16 [get_ports {dip_sw[5]}]
set_property PACKAGE_PIN N13 [get_ports {dip_sw[4]}]
set_property PACKAGE_PIN N14 [get_ports {dip_sw[3]}]
set_property PACKAGE_PIN P16 [get_ports {dip_sw[2]}]
set_property PACKAGE_PIN R17 [get_ports {dip_sw[1]}]
set_property PACKAGE_PIN N15 [get_ports {dip_sw[0]}]

設計と実装:1ビットコンパレータ

Verilogソースコード

comparator_1bit.v

`timescale 1ns / 1ps

module comparator_1bit(
    input  val_x,
    input  val_y,
    output x_greater,
    output x_equal,
    output x_less
);
    // ゲートレベル記述による等価ロジック
    wire not_y, not_x;
    
    not (not_y, val_y);
    not (not_x, val_x);
    
    and (x_greater, val_x, not_y); // val_x > val_y
    and (x_less, val_y, not_x);    // val_x < val_y
    nor  (x_equal, x_greater, x_less); // val_x == val_y
endmodule

テストベンチ

tb_comparator_1bit.v

`timescale 1ns / 1ps

module tb_comparator_1bit();
    reg val_x, val_y;
    wire x_greater, x_equal, x_less;

    comparator_1bit uut (
        .val_x(val_x),
        .val_y(val_y),
        .x_greater(x_greater),
        .x_equal(x_equal),
        .x_less(x_less)
    );

    initial begin
        val_x = 0; val_y = 0;
        #10;
        val_x = 1; val_y = 0;
        #10;
        val_x = 0; val_y = 1;
        #10;
        val_x = 1; val_y = 1;
        #10;
        $finish;
    end
endmodule

制約ファイル

pin_assign_comp.xdc

set_property IOSTANDARD LVCMOS33 [get_ports {val_x val_y x_greater x_equal x_less}]

set_property PACKAGE_PIN Y9 [get_ports val_x]
set_property PACKAGE_PIN W9 [get_ports val_y]
set_property PACKAGE_PIN L13 [get_ports x_greater]
set_property PACKAGE_PIN K17 [get_ports x_equal]
set_property PACKAGE_PIN M13 [get_ports x_less]

実機動作確認

生成したビットストリームをMinisysボードへ書き込んだ後、DIPスイッチを操作すると、対応するLEDが連動して点灯および消灯することを確認できます。1ビットコンパレータの回路においては、入力スイッチの切り替えに伴い、大小関係や一致を示す出力LEDが真理値表通りに変化することが検証できます。

タグ: Vivado Verilog FPGA Minisys XDC

7月6日 18:40 投稿