0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

FPGAプログラミング大全Xilinx編第2版 クロック利用 #4

Posted at

FPGAに再入門しようと思いたちFPGAプログラミング大全Xilinx編第2版を頭からやっていく4日目

時期的にも良いので一人Advent Calendarで25日続ける

今日からは実際のCPU作りのためのことを始める

25日終了時の目標

4004等の実CPUの実装

目次

# タイトル
01 ツール導入
02 実機テスト下準備
03 実機テスト
04 クロック利用
05 未定

環境

【実装ボード】 Digilent Artix-7 35T Arty FPGA 評価キット
【OS】 Windows10
【IDE】 Vivado 2022.2

今日のゴール

クロックを利用できるようになる

今日も写経が多め

クロックを利用したLEDチカ

  1. 分周機能の追加
    今回使用した制約ファイルによると元クロックが100MHzなのでわかりやすいように分周して使用する
    本では26bitカウンタを利用してフルビットのときだけ色々しているがもうちょっとちゃんと作るようにする
LED_Test.v
~~~~~ここから
reg [25:0] cnt26;
wire ledcnten = (cnt26==26'h2faf080);

always @(posedge CLK100MHZ ) begin
    if(ledcnten)
        cnt26 <= 26'h0;
    else
        cnt26 <= cnt26 + 1'h1;
end 
~~~~~ここまで

2. LED表示用カウンタ

LED_Test.v
~~~~~ここから
reg [3:0] ledcnt;
always @(posedge CLK100MHZ) begin
    if(ledcnten)
        if(ledcnt == 4'b1111)
            ledcnt <= 4'b0000;
        else
            ledcnt <= ledcnt + 4'b0001;
end
~~~~~ここまで

3. 全体像

LED_Test.v
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date: 2022/12/02 22:34:10
// Design Name: 
// Module Name: LED_Test
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//////////////////////////////////////////////////////////////////////////////////


module LED_Test(
   input   CLK100MHZ,
   output  reg [3:0]   led
   );
   
reg [25:0] cnt26;
wire ledcnten = (cnt26==26'h2faf080);

always @(posedge CLK100MHZ ) begin
   if(ledcnten)
       cnt26 <= 26'h0;
   else
       cnt26 <= cnt26 + 1'h1;
end 

reg [3:0] ledcnt;
always @(posedge CLK100MHZ) begin
   if(ledcnten)
       if(ledcnt == 4'b1111)
           ledcnt <= 4'b0000;
       else
           ledcnt <= ledcnt + 4'b0001;
end
always @* begin
   led = ledcnt;
end
endmodule

3. 結果
result

今日はここまで

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?