阶段目标:建立可靠的视频时序基准,排除物理显示器和 VGA 接口的干扰,验证视频时序和信号完整性

输出结果:VGA 显示器显示标准彩色测试条纹

设备:NEXYS A7开发板

架构梳理

  • 手写axis_colorbar替代真实视频源,生成标准 AXI-Stream 像素流。
  • Video Timing Controller (VTC) 提供精确的 HSYNC、VSYNC 和 VDE 时序信号。
  • AXI4-Stream to Video Out 模块完成握手,将流数据与时序强绑定。

系统总体架构

1.png

硬件模块配置

1. Video Timing Controller (VTC)

作用:生成 VGA 640×480 @ 60Hz 标准时序信号

取消勾选Include AXI4-Lite Interface,暂不需要总线参与;取消勾选Enable Detection

然后记得Video Mode 调到自己预期的分辨率,如果为了适配OV5640这里设置成480p。其他保持默认就行

2. AXI4-Stream to Video Out

作用:将 AXI Stream 视频数据转换为标准并行 VGA 接口

Clock Mode调成independent方便像素时钟接入。可选适当调大FIFO Depth,避免缓冲深度不足而卡顿。其他可保持默认

3. ColorBar 彩条生成器

作用:实时生成标准测试条纹

为什么不用TPG IP?,,用这个可能在综合时报错module 'design_1_v_tpg_0_0_v_tpg' not found,可能和底层不是verilog而是C实现有关,比较麻烦。既然只是做个测试图像,直接手写一个或许更简单一点。

`timescale 1ns / 1ps

module axis_colorbar #(
    parameter integer H_ACTIVE = 640,
    parameter integer V_ACTIVE = 480
) (
    input  wire        ap_clk,
    input  wire        ap_rst_n,
    output wire        m_axis_video_tvalid,
    input  wire        m_axis_video_tready,
    output wire [23:0] m_axis_video_tdata,
    output wire [0:0]  m_axis_video_tuser,
    output wire [0:0]  m_axis_video_tlast
)

    localparam integer X_BITS = 16;
    localparam integer Y_BITS = 16;

    reg [X_BITS-1:0] x_cnt;
    reg [Y_BITS-1:0] y_cnt;

    wire axis_fire  = m_axis_video_tvalid && m_axis_video_tready;
    wire line_last  = (x_cnt == H_ACTIVE - 1);
    wire frame_last = line_last && (y_cnt == V_ACTIVE - 1);

    always @(posedge ap_clk) begin
        if (!ap_rst_n) begin
            x_cnt <= {X_BITS{1'b0}};
            y_cnt <= {Y_BITS{1'b0}};
        end else if (axis_fire) begin
            if (line_last) begin
                x_cnt <= {X_BITS{1'b0}};
                if (frame_last) begin
                    y_cnt <= {Y_BITS{1'b0}};
                end else begin
                    y_cnt <= y_cnt + 1'b1;
                end
            end else begin
                x_cnt <= x_cnt + 1'b1;
            end
        end
    end

    function [23:0] color_bar;
        input [X_BITS-1:0] xpos;
        begin
            if (xpos < (H_ACTIVE * 1 / 8)) begin
                color_bar = 24'hffffff;
            end else if (xpos < (H_ACTIVE * 2 / 8)) begin
                color_bar = 24'hffff00;
            end else if (xpos < (H_ACTIVE * 3 / 8)) begin
                color_bar = 24'h00ffff;
            end else if (xpos < (H_ACTIVE * 4 / 8)) begin
                color_bar = 24'h00ff00;
            end else if (xpos < (H_ACTIVE * 5 / 8)) begin
                color_bar = 24'hff00ff;
            end else if (xpos < (H_ACTIVE * 6 / 8)) begin
                color_bar = 24'hff0000;
            end else if (xpos < (H_ACTIVE * 7 / 8)) begin
                color_bar = 24'h0000ff;
            end else begin
                color_bar = 24'h000000;
            end
        end
    endfunction

    assign m_axis_video_tvalid = ap_rst_n;
    assign m_axis_video_tdata  = color_bar(x_cnt);
    assign m_axis_video_tuser  = (x_cnt == 0) && (y_cnt == 0);
    assign m_axis_video_tlast  = line_last;

endmodule

4.rgb888_to_rgb444_vga

作用:如名所示,转换到支持vga的rgb444格式

`timescale 1ns / 1ps

module rgb888_to_rgb444_vga #(
    parameter integer HSYNC_ACTIVE_LOW = 1,
    parameter integer VSYNC_ACTIVE_LOW = 1
) (
    
    input  wire        vid_vsync,

    output wire [3:0]  vga_r,
    output wire [3:0]  vga_g,
    output wire [3:0]  vga_b,
    output wire        vga_hsync,
    output wire        vga_vsync
);

    wire video_de = vid_active_video && !vid_hblank && !vid_vblank;

    assign vga_r     = video_de ? vid_data[23:20] : 4'h0;
    assign vga_g     = video_de ? vid_data[15:12] : 4'h0;
    assign vga_b     = video_de ? vid_data[7:4]   : 4'h0;
    assign vga_hsync = HSYNC_ACTIVE_LOW ? ~vid_hsync : vid_hsync;
    assign vga_vsync = VSYNC_ACTIVE_LOW ? ~vid_vsync : vid_vsync;

    wire unused_vid_field = vid_field;

endmodule

时钟方案

Clocking Wizard 配置

输入板载时钟(一般100M),为以上模块提供100M和25.175M或者粗略一点25M的时钟

接出Processor System Reset,给对应时钟域的ip复位信号

100M时钟域:axis_colorbar_0

25M时钟域:v_tc_0,v_axi4s_vid_out_0(aclk和vid_io_out_dk都是)

接线

最有操作的一集:使用Run Connection Automation 麻麻再也不用担心手残把时钟和复位接错了

尤其要注意一点,AXI4-Stream to Video Out的vtg_ce接回Video Timing Controller的gen_clken,目的是让 AXI4-Stream to Video Out 这个 IP 核能够主动控制 Video Timing Controller (VTC) 内部时序生成器的启停,从而实现两者精确的同步和错误恢复。

数据通路:axis_colorbar_v1_0->AXI4-Stream to Video Out->rgb888_to_rgb444_vga_v1_0->make external

时序信号通路:Video Timing Controller->AXI4-Stream to Video Out

尾声

Generate Output Products

Create HDL Wrapper

分配引脚生成.xdc

综合实现生成比特流