`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    12:42:08 10/27/2020 
// Design Name: 
// Module Name:    decimBlock 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module decimBlock
#(	
	// parameter	R	=	2,
	parameter	inOutDataWidth	=	18,
	parameter	decimCntWidth	=	7
)
(
	input Clk_i,
	input Rst_i,
	input [2:0]	DecimFactor_i,
	input [inOutDataWidth-1:0] Data_i,
	input DataNd_i,
	output [inOutDataWidth-1:0] Data_o,
	output DataValid_o
);

reg	[decimCntWidth-1:0]	decimCnt;
reg	[inOutDataWidth-1:0]	dataReg;
reg	valReg;

always	@(posedge	Clk_i)	begin
	if	(!Rst_i)	begin
		if	(DataNd_i)	begin
			if	(decimCnt	==	DecimFactor_i-1)	begin
				decimCnt	<=	{decimCntWidth{1'b0}};
				valReg		<=	1'b1;
			end	else	begin
				decimCnt	<=	decimCnt+7'd1;
				valReg		<=	1'b0;
			end
		end	else	begin
			decimCnt	<=	{decimCntWidth{1'b0}};
			valReg		<=	1'b0;
		end
	end	else	begin
		decimCnt	<=	{decimCntWidth{1'b0}};
		valReg		<=	1'b0;
	end
end
	
always	@(posedge	Clk_i)	begin
	if	(!Rst_i)	begin
		if	(decimCnt	==	DecimFactor_i-1)	begin
			dataReg	<=	Data_i;
		end	
	end	else	begin
		dataReg	<=	0;
	end
end

assign	Data_o	=	dataReg;
assign	DataValid_o	=	valReg;
endmodule
