`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    10:02:35 04/20/2020 
// Design Name: 
// Module Name:    PulseGen 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module	RefSequenceGen	
#(	
	parameter	CmdRegWidth	=	32
)
(
	input	Rst_i,
	input	Clk_i,
	input	StartMeasEvent_i,
	
	input	OpMode_i,
	input	[CmdRegWidth-1:0]	PulsePeriod_i,
	
	output	Pulse_o
);	

//================================================================================
//  LOCALPARAM

//================================================================================
	reg		[CmdRegWidth-1:0]	periodCnt;
	reg		pulsePreset;
//================================================================================
//  ASSIGNMENTS
	assign	Pulse_o	=	pulsePreset;
//================================================================================
//  CODING
	
	always	@(*)	begin
		if	(OpMode_i)	begin
			if	(!Rst_i)	begin
				if	(StartMeasEvent_i)	begin
					if	(periodCnt	==	0)	begin
						pulsePreset	=	1;
					end	else	begin
						pulsePreset	=	0;
					end
				end	else	begin
					pulsePreset	=	0;
				end
			end	else	begin
				pulsePreset	=	0;
			end
		end	else	begin
			pulsePreset	=	0;
		end
	end
	
	always	@(posedge	Clk_i)	begin
		if	(!Rst_i)	begin
			if	(OpMode_i)	begin	
				if	(StartMeasEvent_i)	begin
					if	(periodCnt	!=	PulsePeriod_i-1)	begin
						periodCnt	<=	periodCnt+32'd1;
					end	else	begin
						periodCnt	<=	32'd0;
					end
				end	else	begin
					periodCnt	<=	32'd0;
				end
			end		else	begin
				periodCnt	<=	32'd0;
			end
		end	else	begin
			periodCnt	<=	32'd0;
		end
	end
	
endmodule











