|
楼主 |
发表于 2019-10-17 13:14:06
|
显示全部楼层
`timescale 1ns / 1ps
`define sys_clk 20
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2019/10/11 08:34:25
// Design Name:
// Module Name: Time difference location_tb
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module Time_difference_location_tb;
reg aclk;
reg aresetn;
reg cnt_en=0;
wire [7:0] fft_real;
wire [7:0] fft_imag;
reg [5:0] addr;
reg [7:0] cfg_cnt;
wire [7:0] dout;
parameter MCNT = 120;
parameter MCNT1 = 7;
reg s_axis_config_tdata=8'd1;
reg s_axis_config_tvalid=0;
wire s_axis_config_tready;
wire [15 : 0] s_axis_data_tdata;
reg [7 : 0]sink_ctl_cnt;
reg s_axis_data_tvalid=0;
wire s_axis_data_tready;
reg s_axis_data_tlast=0;
wire [31 : 0] m_axis_data_tdata;
wire [7 : 0] m_axis_data_tuser;
wire m_axis_data_tvalid;
reg m_axis_data_tready=1;
wire m_axis_data_tlast;
wire event_frame_started;
wire event_tlast_unexpected;
wire event_tlast_missing;
wire event_status_channel_halt;
wire event_data_in_channel_halt;
wire event_data_out_channel_halt;
ip_rom rom0(
.a(addr),
.clk(aclk),
.spo(dout)
);
xfft_0 fft0(
.aclk(aclk),
.aresetn(aresetn),
.s_axis_config_tdata(s_axis_config_tdata),
.s_axis_config_tvalid(s_axis_config_tvalid),
.s_axis_config_tready(s_axis_config_tready),
.s_axis_data_tdata(s_axis_data_tdata),
.s_axis_data_tvalid(s_axis_data_tvalid),
.s_axis_data_tready(s_axis_data_tready),
.s_axis_data_tlast(s_axis_data_tlast),
.m_axis_data_tdata(m_axis_data_tdata),
.m_axis_data_tuser(m_axis_data_tuser),
.m_axis_data_tvalid(m_axis_data_tvalid),
.m_axis_data_tready(m_axis_data_tready),
.m_axis_data_tlast(m_axis_data_tlast),
.event_frame_started(event_frame_started),
.event_tlast_unexpected(event_tlast_unexpected),
.event_tlast_missing(event_tlast_missing),
.event_status_channel_halt(event_status_channel_halt),
.event_data_in_channel_halt(event_data_in_channel_halt),
.event_data_out_channel_halt(event_data_out_channel_halt)
);
initial aclk=1;
always#(`sys_clk/2)aclk=~aclk;
initial
begin
aresetn = 0;//低有效
#(`sys_clk*3) aresetn = 1;
end
// always@(posedge aclk or negedge aresetn)
// if(!aresetn)
// cfg_cnt<=8'd0;
// else if(m_axis_data_tlast)
// cfg_cnt<=8'd0;
// else
// cfg_cnt<=cfg_cnt+1'b1;
// always@(posedge aclk or negedge aresetn)
// if(!aresetn)
// addr=6'd0;
// else if((cfg_cnt<8'd10)&&(cfg_cnt>8'd2))
// addr=addr+1'b1;
// else
// addr=6'd0;
// / //s_axis_config_tvalid驱动
always@(posedge aclk )
begin
if(s_axis_config_tready)
s_axis_config_tvalid<=1'b1;
else
s_axis_config_tvalid<=1'b0;
end
// // assign s_axis_config_tdata = 8'd1;
//............上升沿捕捉。。。。。。。。。。。。。。。。//
wire data_tready_pose; //tready信号上升沿
reg data_tready_r0 = 0;
reg data_tready_r1 = 0;
always @(posedge aclk) begin
data_tready_r0 <= s_axis_data_tready;
data_tready_r1 <= data_tready_r0;
end
assign data_tready_pose = data_tready_r0 & ~data_tready_r1;
//--------------------设置tvalid信号------------------------//
always @(posedge aclk) begin
if(data_tready_pose == 1) begin
s_axis_data_tvalid <= 1; //检测到上升沿,信号拉高,数据有效
end
else begin
s_axis_data_tvalid <= s_axis_data_tvalid;
end
end
//---------------检测到上升沿,计数器开始工作----------------//
always @(posedge aclk) begin
if(data_tready_pose == 1) begin
cnt_en <= 1;
end
else if(addr == 6'd6) begin /*需要改动*/
cnt_en <= 0;
end
end
always @(posedge aclk) begin
if(cnt_en == 1) begin
addr <= addr + 1;
end
else begin
addr <= 0;
end
end
//----------------------设置tlast信号-----------------------//
always @(posedge aclk) begin
if(addr == 6'd6) begin /*需要改动*/
s_axis_data_tlast <= 1; //输入最后一个数据时,tlast信号产生一个脉冲
end
else begin
s_axis_data_tlast <= 0;
end
end
assign s_axis_data_tdata=dout;
// always@(posedge aclk or negedge aresetn)
// begin
// if(!aresetn)
// s_axis_data_tdata <=16'd0;
// else if(s_axis_data_tready)
// s_axis_data_tdata<=dout;
// end
// always@(posedge aclk or negedge aresetn)
// begin
// if(!aresetn)
// m_axis_data_tready <=1'd0;
// else
// m_axis_data_tready<=1'b1;
// end
// always@(posedge aclk or negedge aresetn)
// begin
// if(!aresetn)
// sink_ctl_cnt <= 8'd0;
// else if(addr==8'd0)
// sink_ctl_cnt <= 8'd0;
// else if(sink_ctl_cnt == 8'd7)
// sink_ctl_cnt <= 8'd0;
// else
// sink_ctl_cnt <= sink_ctl_cnt+1'b1 ;
// end
// //s_axis_data_tvalid
// always@(posedge aclk or negedge aresetn)
// begin
// if(!aresetn)
// s_axis_data_tvalid <= 1'b0;
// // else if(sink_ctl_cnt<8'd8&&cfg_cnt<8'd9)
// else if(cfg_cnt<8'd12)
// s_axis_data_tvalid <= 1'b1;
// else
// s_axis_data_tvalid <= 1'b0;
// end
// //s_axis_data_tlast
// always@(posedge aclk or negedge aresetn)
// begin
// if(!aresetn)
// s_axis_data_tlast <= 1'b0;
// else
// begin
// if(addr == 8'd7)
// s_axis_data_tlast <= 1'b1;
// else
// s_axis_data_tlast <= 1'b0;
// end
// end
assign fft_real = m_axis_data_tdata[11:0];
assign fft_imag = m_axis_data_tdata[27:16];
endmodule |
|