自己工程中用到的一些testbench的代码,以后方便copy直接使用,节省开发时间。
一、做数据处理时,数据流的产生
有限数据流的产生。
integer i;
reg [15:0] st[1:100];
initial
begin
$readmemh("G:/zz/data.txt",st);
i=0;
s_axis_tdada1=0;
repeat(100)
begin
#10
i = i+1;
s_axis_tdada1 = st[i];
end
end
以上代码是产生宽度为2B,深度为100的ROM。
如上图所示。
2、无线数据流的产生
reg [39:0] st[1:100];
initial
begin
$readmemh("G:/zz/data1.txt",st);
end
reg [7:0]j;
always@(posedge clk_187 or negedge rst_n)
if(!rst_n)
begin
j = 8'b0;
end
else
if(j == 8'd100)
begin
j = 1'b0;
s_axis_tdada = 40'd0;
end
else
begin
j = j +1;
s_axis_tdada = st[j];
end
自己编写的一个简单的算法,从而实现宽度为5B,深度为100的ROM重复重复产生数据。