Vivado 在線調試之 ILA 核

對於已經通過了功能仿真的 Verilog HDL 電路,Download 到板端後,可以通過 Vivado 的 ILA 核進行在線調試,觀察波形。ILA 核相當於在線的邏輯分析儀,ISE 上叫做 Chipscope,Vivado 下叫 ILA;

添加 ILA 核的方式比較簡單,首先在 Vivado 集成環境中添加 ILA IP Core:

1、點擊 IP Catalog,搜索 ila 核,雙擊 ILA 的 IP

這裏,Verilog 源文件用一個簡單的 LED 燈作爲例子,源文件如下:

module pl_led(
    input sys_clk,
    input rst_n,
    output reg [3:0] led
    );
    parameter max_cnt = 32'd49999999;
    reg [31:0] timer_cnt;

    always @ (posedge sys_clk or negedge rst_n)
    begin
        if(!rst_n)
        begin
            timer_cnt <= 32'd0;
        end
        else
        begin
            if (timer_cnt < max_cnt) timer_cnt <= timer_cnt + 32'd1;
            else timer_cnt <= 32'd0;
        end
    end

    always @ (posedge sys_clk or negedge rst_n)
    begin
        if(!rst_n)
        begin
            led <= 4'b0000;
        end
        else
        begin
            if(timer_cnt == max_cnt) led <= ~led;
            else led <= led;
        end
    end

endmodule

一個 32bit 的 counter 計數器,50MHz 的外部時鐘,LED 一秒鐘亮,滅;

比如我們需要觀察兩個信號,一個是 counter 信號,另一個是 led 信號(led[3:0]),所以在雙擊 ILA IP Core 後,做如下配置:

使用兩個 probe (即,探針),一個 probe 0 爲查看 counter 計數器的值,另一個 probe 1 爲 4bit 位寬的 led 的值;

點擊 OK 後,在點擊生成:

此刻在資源地方就可以看到這個 IP 了:

然後打開這個 ila 裏面的 template 例化的例子:

直接拷貝下來到 Verilog 源碼下面去,並將信號對應上:

module pl_led(
    input sys_clk,
    input rst_n,
    output reg [3:0] led
    );
    parameter max_cnt = 32'd49999999;
    reg [31:0] timer_cnt;

    always @ (posedge sys_clk or negedge rst_n)
    begin
        if(!rst_n)
        begin
            timer_cnt <= 32'd0;
        end
        else
        begin
            if (timer_cnt < max_cnt) timer_cnt <= timer_cnt + 32'd1;
            else timer_cnt <= 32'd0;
        end
    end

    always @ (posedge sys_clk or negedge rst_n)
    begin
        if(!rst_n)
        begin
            led <= 4'b0000;
        end
        else
        begin
            if(timer_cnt == max_cnt) led <= ~led;
            else led <= led;
        end
    end

// Add ILA Here
// Instant ila in source code
ila ila_inst(
    .clk(sys_clk),
    .probe0(timer_cnt),
    .probe1(led)
);

endmodule

OK,搞定,重新 Generate 生成 Bit Stream;

單板上電,打開 Open Hardware Manager 然後掃描 Target:

這裏我用的是 ZYNQ-7000 的 7020 ;選擇 xc7z020_1,右鍵 Program Device:

點擊 Program 下載完畢後,出現在線調試的窗口:

點擊左上的三角形,便開始採集波形,當然可以在右下角的窗口設置 Trigger ,這裏我將 Trigger 設置成爲 timer_cnt 等於 49999999 即,LED 翻轉的時刻,設置好後,點擊左上角的 RUN:

紅色的 T,代表 Trigger ,即,timer_cnt 滿足設置的條件

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章