5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LEDを1Hzで点滅させる回路を作成する

Last updated at Posted at 2025-01-12

verilogの基本的な回路を作成してみる

50MHzのクロックを入力として、LEDを1Hzで点滅させる回路を作成してみます。

入力

  • 50MHzのクロック
  • リセット信号

出力

  • 1Hzのクロック
  • LED1: 1Hzのクロックを使って点滅
  • LED2: リセット信号をそのまま出力
  • LED3: 1を出力

LED3は、回路が正常に動作しているか確認するたに追加しておきます。
LED3は、常に点灯となります。

作成した回路

blink.v
module blink(
    input wire clk_in,   // 50MHz
    input wire n_rst,      // reset
    output reg led1,   // 1Hzの出力
    output wire led2,
    output wire led3
);

    localparam DIVISOR = 25_000_000; 
    reg [24:0] counter;  // 2^25>25M

    always @(posedge clk_in) begin
        if (!n_rst) begin
            counter <= 0;
            led1 <= 0;
        end else begin
            if (counter == DIVISOR - 1) begin
                counter <= 0;
                led1 <= ~led1;  // 出力を反転してON/OFFを切り替え
            end else begin
                counter <= counter + 1;
            end
        end
    end
    assign led2 = !n_rst;
    assign led3 = 1;
    
endmodule

Sourcesに追加してSynthesisを実行します。

Synthesisが正常に終了したら、Open Synthesized Designをクリックして開きます。

I/O Portsの設定を行います。

image.png

Constraintsの制約としてIO Portの設定をしてもいいです。

constraints.tcl
set_property PACKAGE_PIN N18 [get_ports clk_in]
set_property IOSTANDARD LVCMOS33 [get_ports clk_in]

set_property PACKAGE_PIN K17 [get_ports led2]
set_property IOSTANDARD LVCMOS33 [get_ports led2]
set_property PACKAGE_PIN H18 [get_ports led3]
set_property IOSTANDARD LVCMOS33 [get_ports led3]

set_property PACKAGE_PIN E19 [get_ports led1]
set_property IOSTANDARD LVCMOS33 [get_ports led1]
set_property PACKAGE_PIN T19 [get_ports n_rst]
set_property IOSTANDARD LVCMOS33 [get_ports n_rst]

実行

Generate BitstreamをクリックしてBitstreamを生成します。

Open Hardware Managerをクリックして、Hardware Managerを開きます。

Program Deviceをクリックして、FPGAに書き込みます。

結果

まとめ

FPGAの回路を作成して、FPGAに書き込むまでの手順を確認しました。

EBAZ4205のIO基板のスイッチは負論理なので、LED2の出力が反転しているので、注意が必要でした。
最初、LEDが点滅しなくて、???となりましたが、LED2の出力が反転していることに気づきました。

5
2
1

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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?