首页 > 代码库 > RGB Resampler IP核的测试

RGB Resampler IP核的测试

关于RGB Resampler IP核的测试

1.RGB Resampler功能描述

    将输入的RGB数据流转换成其它格式的RGB数据流。

技术分享 

技术分享

 2.功能验证

    设置源图像像素数据为:3X4格式。

 技术分享

    设置RGB Resampler参数如下图所示,将24-bit RGB格式转换为40-bit RGBA格式。

技术分享 

    顶层文件的编写:

 1 module top(
 2     clk_clk,
 3     reset_reset_n,
 4     video_rgb_resampler_avalon_rgb_source_ready,
 5     video_rgb_resampler_avalon_rgb_source_startofpacket,
 6     video_rgb_resampler_avalon_rgb_source_endofpacket,
 7     video_rgb_resampler_avalon_rgb_source_valid,
 8     video_rgb_resampler_avalon_rgb_source_data,
 9 );
10 
11     input clk_clk;
12     input reset_reset_n;
13     input video_rgb_resampler_avalon_rgb_source_ready;
14     output video_rgb_resampler_avalon_rgb_source_startofpacket;
15     output video_rgb_resampler_avalon_rgb_source_endofpacket;
16     output video_rgb_resampler_avalon_rgb_source_valid;
17     output [39:0]video_rgb_resampler_avalon_rgb_source_data;
18 
19  RGB_format u1 (
20   .clk_clk                                             (clk_clk),                                            
21   .reset_reset_n                                       (reset_reset_n),                                       
22   .video_rgb_resampler_avalon_rgb_source_ready         (video_rgb_resampler_avalon_rgb_source_ready),         
23   .video_rgb_resampler_avalon_rgb_source_startofpacket (video_rgb_resampler_avalon_rgb_source_startofpacket), 
24   .video_rgb_resampler_avalon_rgb_source_endofpacket   (video_rgb_resampler_avalon_rgb_source_endofpacket),   
25   .video_rgb_resampler_avalon_rgb_source_valid         (video_rgb_resampler_avalon_rgb_source_valid),         
26   .video_rgb_resampler_avalon_rgb_source_data          (video_rgb_resampler_avalon_rgb_source_data)          
27  );
28 
29 endmodule 

    Testbench的编写:

initial                                                
begin                                                  
   reset_reset_n = 0; #10; reset_reset_n = 1;
    clk_clk = 1; forever #10 clk_clk = ~clk_clk;                 
end

always@(posedge clk_clk or negedge reset_reset_n)
    if(!reset_reset_n)
        video_rgb_resampler_avalon_rgb_source_ready = 1b0;
    else
        video_rgb_resampler_avalon_rgb_source_ready = 1b1;

    ModelSIM仿真波形:

技术分享

波形分析: 输出source_data为40-bit,在start---end之间输出12个数据。

3.224X224 24-bit RGB图像转换为40-bit RGBA 图像

参数配置:

技术分享 

modelsim仿真并导出modelsim中生成的图像像素数据:

技术分享

integer w_file;
initial w_file = $fopen("video_rgb_resampler_avalon_rgb_source_data.txt");
always@(posedge clk_clk)
    $fdisplay(w_file, "%d", video_rgb_resampler_avalon_rgb_source_data); 

技术分享

40-bit RGBA数据格式:

 技术分享

Matlab中进行数据处理:

fd = fopen(‘video_rgb_resampler_avalon_rgb_source_data.txt‘);
A =uint64(fscanf(fd,‘%f‘));
fclose(fd);
B = uint64(zeros(224,224));

A1 = uint64(zeros(50176,1));
A2 = uint64(zeros(50176,1));
A3 = uint64(zeros(224,224));

R1 = uint64(zeros(50176,1));
R2 = uint64(zeros(50176,1));
R3 = uint64(zeros(224,224));

G1 = uint64(zeros(50176,1));
G2 = uint64(zeros(50176,1));
G3 = uint64(zeros(224,224));

B1 = uint64(zeros(50176,1));
B2 = uint64(zeros(224,224));

for j = 1:224
    for i = 1:224
        B(j,i) = A((j-1)*224+i);
    end
end

% A---1111 1111 11 --- 0000 0000 00 --- 0000 0000 00 --- 0000 0000 00 
% R---0000 0000 00 --- 1111 1111 11 --- 0000 0000 00 --- 0000 0000 00 
% G---0000 0000 00 --- 0000 0000 00 --- 1111 1111 11 --- 0000 0000 00  
% B---0000 0000 00 --- 0000 0000 00 --- 0000 0000 00 --- 1111 1111 11  

a = uint64(bin2dec(‘1111111111000000000000000000000000000000‘));
r = uint64(bin2dec(‘0000000000111111111100000000000000000000‘));
g = uint64(bin2dec(‘0000000000000000000011111111110000000000‘));
b = uint64(bin2dec(‘0000000000000000000000000000001111111111‘));

%---A
for i = 1:50176
    A1(i) = bitand(A(i),a);
end

for i = 1:50176
    A2(i) = bitshift(A1(i),-30);
end

for j = 1:224
    for i = 1:224
        A3(j,i) = A2((j-1)*224+i);
    end
end

%---R
for i = 1:50176
    R1(i) = bitand(A(i),r);
end

for i = 1:50176
    R2(i) = bitshift(R1(i),-20);
end

for j = 1:224
    for i = 1:224
        R3(j,i) = R2((j-1)*224+i);
    end
end

%---G
for i = 1:50176
    G1(i) = bitand(A(i),g);
end

for i = 1:50176
    G2(i) = bitshift(G1(i),-10);
end

for j = 1:224
    for i = 1:224
        G3(j,i) = G2((j-1)*224+i);
    end
end

%---B
for i = 1:50176
    B1(i) = bitand(A(i),b);
end

for j = 1:224
    for i = 1:224
        B2(j,i) = B1((j-1)*224+i);
    end
end

需要注意的问题:

    源文件中的数据值比较大,如果以十进制的方式读入数据,会出现如下问题:

技术分享

技术分享

    如果以16进制的形式读入,则不会出现此问题:

技术分享

技术分享

 

 

RGB Resampler IP核的测试