Vivado 中使用 ILA 进行在线调试实战
在 FPGA 开发中,ILA(Integrated Logic Analyzer)是 Vivado 自带的集成逻辑分析仪。它允许我们在芯片内部实时抓取数字信号的波形,直接定位硬件逻辑错误。相比传统的 Testbench 仿真,ILA 无需编写复杂的仿真文件,支持上板后直接观察信号变化,效率更高。
设计准备与例化
假设我们需要调试一个通过状态机控制 4 个 LED 循环点亮的工程,时间间隔为 0.5 秒。首先准备好基础的设计模块 LED_ILA。
`timescale 1ns / 1ps
module LED_ILA(
input wire clk, // 100MHz 时钟
input wire rst_n,
output reg [3:0] led
);
reg [25:0] count = 26'd1;
reg [2:0] state = 3'b000;
reg [2:0] next_state = 3'b000;
parameter count_max = 26'd50_000_000; // 约 0.5 秒计数值
parameter IDLE = 3'b000;
parameter s1 = 3'b001;
parameter s2 = 3'b010;
parameter s3 = 3'b011;
parameter s4 = 3'b100;
always@(posedge clk or negedge rst_n) begin
if(!rst_n)
count <= 26'd1;
else if(count == count_max)
count <= 26'd1;
else
count <= count + 26'd1;
end
always@(posedge clk or negedge rst_n) begin
if(!rst_n)
state <= 3'b000;
else if(count == count_max)
state <= next_state;
end
always@(*) begin
if(!rst_n)
next_state <= 3'b000;
else begin
case(state)
IDLE: next_state <= s1;
s1: next_state <= s2;
s2: next_state <= s3;
s3: next_state <= s4;
s4: next_state <= s1;
default: next_state <= IDLE;
endcase
end
end
always@(*) begin
if(!rst_n)
led <= 4'b0000;
else begin
case(state)
IDLE: led <= 4'b0000;
s1: led <= 4'b0001;
s2: led <= 4'b0010;
s3: led <= 4'b0100;
s4: led <= 4'b1000;
default: led <= 4'b0000;
endcase
end
end
endmodule
接下来在顶层模块中例化该设计,并调用 ILA IP 核。ILA 可以读取模块内部的寄存器信号,因此连接时直接使用层级路径即可。
`timescale 1ns / 1ps
module TOP(
input wire clk,
input wire rst_n,
output wire [3:0] led
);
LED_ILA u_LED_ILA(
.clk(clk),
.rst_n(rst_n),
.led(led)
);
ila_0 u_ila_0(
.clk(clk),
.probe0(rst_n),
.probe1(led),
.probe2(u_LED_ILA.count),
.probe3(u_LED_ILA.state)
);
endmodule
注意:不同探针的位宽必须与待检测信号严格匹配。如果不确定,可以双击生成的 IP 核查看配置详情。
配置与生成 IP 核
在 Vivado 的 IP Catalog 中搜索 "ILA",双击打开配置界面。这里主要关注三个参数:名称、探针数量(Probe Count)和样本数据深度(Sample Depth)。
以本例为例,我们需要监控复位信号、LED 输出、计数器和状态机,共 4 个探针。样本深度默认 1024 通常足够,表示每个有效时钟采样一次,记录 1024 个点。设置完成后点击 OK,选择默认选项生成 IP 核。生成完毕后,工程中会多出一个 ila_0 模块,将其加入顶层连接即可。


