`timescale 1ns / 1ps
module InternalDspTb;

	parameter	AdcDataWidth	=	14;
	parameter	ChNum			=	4;
	parameter	ResultWidth		=	32;
	parameter	CmdDataRegWith	=	24;
	
	reg	rst;
	reg	clk_50;

	reg	[31:0]	tb_cnt;
	
	reg	StartCalcCmdReg	;
								
	wire	[AdcDataWidth-1:0]	adcData;				
	wire	measDataRdy;			

	reg	startMeas;
	reg	[CmdDataRegWith-1:0]	measCtrl;
	reg	calModeEn;
	reg	[8-1:0]	ifFtw0;
	reg	[CmdDataRegWith-1:0]	ifFtw1;
//==========================================================================================
//clocks gen
	always	#10 clk_50	=	~clk_50;
//==========================================================================================
	initial begin
		clk_50	=	1'b1;
		rst		=	1'b1;
	#10;
		rst		=	1'b0;
	end		

	always	@(posedge	clk_50)	begin
		if	(!rst)		begin
			tb_cnt	<=	tb_cnt+1;
		end	else	begin
			tb_cnt	<=	0;
		end
	end

	always	@(posedge	clk_50)	begin
		if	(tb_cnt	== 10)	begin
			measCtrl	<=	{8'h0,8'h55,8'b0};
			calModeEn	<=	1'b0;
			ifFtw0		<=	8'h89;
			ifFtw1		<=	24'h256041;
		end
	end
	
	always	@(posedge	clk_50)	begin
		if	(rst)	begin
			startMeas	<=	1'b0;
		end	else	begin
			if	(tb_cnt	== 20)	begin
				startMeas	<=	1'b1;
			end	else	if	(measDataRdy)	begin
				startMeas	<=	1'b0;
			end
		end
	end
	
CordicNco		
#(	.ODatWidth	(14),
	.PhIncWidth	(32),
	.IterNum	(10),
	.EnSinN		(0))
ncoInst
(
	.Clk_i				(clk_50),
	.Rst_i				(rst),
	.Val_i				(1'b1),
	.PhaseInc_i			(32'h25604189),
	.WindVal_i			(1'b1),
	.WinType_i			(),
	.Wind_o				(),
	.Sin_o				(adcData),
	.Cos_o				(),
	.Val_o				()
);

InternalDsp	
#(	
	.AdcDataWidth		(AdcDataWidth),
	.ChNum				(ChNum),
	.ResultWidth		(ResultWidth),
	.CmdDataRegWith		(CmdDataRegWith)
)
InternalDsp
(
	.Clk_i				(clk_50),
	.Rst_i				(rst),
	
	.adc1ChAData_i		(adcData),	//A
	.adc1ChR1Data_i		(adcData),	//R1
	.adc2ChR2Data_i		(adcData),	//R2
	.adc2ChBData_i		(adcData),	//B
	
	.StartMeas_i		(startMeas),	
	
	.MeasCtrl_i			(measCtrl),
	
	.CalModeEn_i		(calModeEn),

	.IfFtw_i			({ifFtw1,ifFtw0}),
	
	.Adc1ImAData_o		(),
	.Adc1ReAData_o		(),
	.Adc1ImR1Data_o		(),
	.Adc1ReR1Data_o		(),
	
	.Adc2ImR2Data_o		(),
	.Adc2ReR2Data_o		(),
	.Adc2ImBData_o		(),
	.Adc2ReBData_o		(),
	
	.MeasDataRdy_o		(measDataRdy)
); 

endmodule






























