RGB转HDMI方案——FPGA学习笔记20
一、简介
见HDMI彩条显示——FPGA学习笔记12-CSDN博客
二、TMDS编码原理
HDMI 采用 TMDS (Time Minimized Differential Signal) 最小化传输差分信号传输技术, 是美国 Silicon Image 公司开发的一项高速数据传输技术, 将视频、 音频、 控制信号进行编码并串转换后发送。 TMDS 是一种微分信号机制,采用的是差分传动方式。 利用 2 个引脚间电压差来传送信号, 由两脚间电压正负极性和大小决定传送“0” 还是“1”。采用 2 根线来传输信号, 一根线上传输原来的信号, 另一根线上传输与原来信号相反的信号, 接收端就可以通过让一根线上的信号减去另一根线上的信号的方式来屏蔽电磁干扰, 从而得到正确的信号。
(1) 使用 channel0 的 D[1:0]传输 HSYNC, VSYNC, 占用 2bit, 控制信号被编码成 10 位传输, 00、 01、 10、 11 编码后分别是 10'b1101010100, 10'b0010101011, 10'b0101010100, 和 10'b1010101011。
( 2) Preamble 控制信息, 图中的 CTLx, 可用来表示后面传输的是 data island 还是 video data。 通过 channel1 和 2的 D[1:0]传输, 占用 4bit, 控制信号被编码成 10 位传输。
三、代码实现
`timescale 1ns / 1psmodule HDMI_top(input I_sysclk ,input I_rst_n ,output O_hdmi_clk_p ,output O_hdmi_clk_n ,output [2:0] O_hdmi_tx_p ,output [2:0] O_hdmi_tx_n
);wire [7:0] rgb_r ;
wire [7:0] rgb_g ;
wire [7:0] rgb_b ;
wire lcd_hs ;
wire lcd_vs ;
wire lcd_de ;//LCD驱动时钟
clk_wiz_0 u_clk_wiz_0
(.clk_75M (clk_40M ) , .clk_375M (clk_200M ) , .clk_in1 (I_sysclk )
); video_lcd u_video_lcd(.I_vid_clk (clk_40M ) , //系统时钟.I_vid_rstn (I_rst_n ) , //系统复位输入.O_vid_hs (lcd_hs ) , //hs信号.O_vid_vs (lcd_vs ) , //vs信号.O_vid_de (lcd_de ) , //视频数据有效信号.O_rgb_r (rgb_r ) , // RGB-红.O_rgb_g (rgb_g ) , // RGB-绿.O_rgb_b (rgb_b ) // RGB-蓝
);hdmitx#
(.FAMILY ("7FAMILY")
)
u_hdmitx
(
.I_rstn (I_rst_n ) , //复位
.I_hs (lcd_hs ) , //hs信号
.I_vs (lcd_vs ) , //vs信号
.I_de (lcd_de ) , //de信号
.I_rgb ({rgb_r,rgb_g,rgb_b}) , //RGB数据
.I_pclkx1 (clk_40M ) , //像素时钟
.I_pclkx2_5 (1'b0 ) , //2.5倍像素时钟,只有UFAMILY需要
.I_pclkx5 (clk_200M ) , //5倍像素时钟
.O_hdmi_tx_clk_p (O_hdmi_clk_p ) , //HDMI时钟输出P端
.O_hdmi_tx_clk_n (O_hdmi_clk_n ) , //HDMI时钟输出N端
.O_hdmi_tx_p (O_hdmi_tx_p ) , //HDMI输出数据P端
.O_hdmi_tx_n (O_hdmi_tx_n ) //HDMI输出数据N端
);endmodule
module hdmitx#
(
parameter FAMILY = "ULTRASCALE"
)
(input I_rstn,input I_vs,input I_hs,input I_de,input [23:0] I_rgb,input I_pclkx1,input I_pclkx2_5,input I_pclkx5,output O_hdmi_tx_clk_p,output O_hdmi_tx_clk_n,output [2:0]O_hdmi_tx_p,output [2:0]O_hdmi_tx_n
);wire [7:0] RED = I_rgb[23:16];
wire [7:0] GREEN = I_rgb[15:8];
wire [7:0] BLUE = I_rgb[7:0];
wire [9:0] intTmdsRed;
wire [9:0] intTmdsGreen;
wire [9:0] intTmdsBlue;wire intRst = !I_rstn;//----------------------------------------------------------------------------------//-- DVI Encoder; DVI 1.0 Specifications//-- This component encodes 24-bit RGB video frames with sync signals into 10-bit//-- TMDS characters.//----------------------------------------------------------------------------------
TMDSEncoder Inst_TMDSEncoder_red(.D_I(RED),.C0_I(1'b0),.C1_I(1'b0),.DE_I(I_de),.CLK_I(I_pclkx1),.D_O(intTmdsRed));
TMDSEncoder Inst_TMDSEncoder_green(.D_I(GREEN),.C0_I(1'b0),.C1_I(1'b0),.DE_I(I_de),.CLK_I(I_pclkx1),.D_O(intTmdsGreen));
TMDSEncoder Inst_TMDSEncoder_blue(.D_I(BLUE),.C0_I(I_hs),.C1_I(I_vs),.DE_I(I_de),.CLK_I(I_pclkx1),.D_O(intTmdsBlue));
//----------------------------------------------------------------------------------
//-- TMDS serializer; ratio of 10:1; 3 data & 1 clock channel
// -- Since the TMDS clock's period is character-long (10-bit periods), the
// -- serialization of "1111100000" will result in a 10-bit long clock period.
//----------------------------------------------------------------------------------
generate if(FAMILY == "ULTRASCALE" || FAMILY == "ULTRASCALE_PLUS")begin : ULTRASCALE_FAMILY oserdese3_10to1 #(.FAMILY(FAMILY))Inst_clk_oserdese3_10to1(.txdata("1111100000"),.txrst(intRst),.pclk(I_pclkx1),.clkdiv2(I_pclkx5),.clkdiv4(I_pclkx2_5),.tx_p(O_hdmi_tx_clk_p),.tx_n(O_hdmi_tx_clk_n));oserdese3_10to1#(.FAMILY(FAMILY))Inst_d2_serializer_10_1(.txdata(intTmdsRed),.txrst(intRst),.pclk(I_pclkx1),.clkdiv2(I_pclkx5),.clkdiv4(I_pclkx2_5),.tx_p(O_hdmi_tx_p[2]),.tx_n(O_hdmi_tx_n[2]));oserdese3_10to1#(.FAMILY(FAMILY))Inst_d1_serializer_10_1(.txdata(intTmdsGreen),.txrst(intRst),.pclk(I_pclkx1),.clkdiv2(I_pclkx5),.clkdiv4(I_pclkx2_5),.tx_p(O_hdmi_tx_p[1]),.tx_n(O_hdmi_tx_n[1]));oserdese3_10to1#(.FAMILY(FAMILY))Inst_d0_serializer_10_1(.txdata(intTmdsBlue),.txrst(intRst),.pclk(I_pclkx1),.clkdiv2(I_pclkx5),.clkdiv4(I_pclkx2_5),.tx_p(O_hdmi_tx_p[0]),.tx_n(O_hdmi_tx_n[0]));
endelse if(FAMILY == "7FAMILY")begin : family_7 oserdese2_10to1 Inst_clk_oserdese2_10to1(.txdata("1111100000"),.txrst(intRst),.pclk(I_pclkx1),.clkdiv2(I_pclkx5),.tx_p(O_hdmi_tx_clk_p),.tx_n(O_hdmi_tx_clk_n)); oserdese2_10to1 Inst_d2_serializer_10_1(.txdata(intTmdsRed),.txrst(intRst),.pclk(I_pclkx1),.clkdiv2(I_pclkx5),.tx_p(O_hdmi_tx_p[2]),.tx_n(O_hdmi_tx_n[2]));oserdese2_10to1 Inst_d1_serializer_10_1(.txdata(intTmdsGreen),.txrst(intRst),.pclk(I_pclkx1),.clkdiv2(I_pclkx5),.tx_p(O_hdmi_tx_p[1]),.tx_n(O_hdmi_tx_n[1]));oserdese2_10to1 Inst_d0_serializer_10_1(.txdata(intTmdsBlue),.txrst(intRst),.pclk(I_pclkx1),.clkdiv2(I_pclkx5),.tx_p(O_hdmi_tx_p[0]),.tx_n(O_hdmi_tx_n[0]));end
endgenerate
endmodule
四、上板验证