`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    15:24:07 08/30/2009 
// Design Name: 
// Module Name:    GenericCounter 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module GenericCounter(CLK,
		      RESET,
 		      ENABLE_IN,
		      TRIG_OUT,
		      COUNT
);


parameter COUNTER_WIDTH = 4;
parameter COUNTER_MAX = 9;


input CLK;
input RESET;
input ENABLE_IN;
output TRIG_OUT;
output [COUNTER_WIDTH-1:0] COUNT;


reg [COUNTER_WIDTH-1 : 0]  Counter;
reg TriggerOut;


always@(posedge CLK) begin

	if(RESET)
		Counter <= 0;
	else begin
		if(ENABLE_IN) begin
			if(Counter == COUNTER_MAX)
				Counter <= 0;
			else
				Counter <= Counter + 1;			
		end
	end
end


always@(posedge CLK) begin
	if(RESET)
 		TriggerOut <= 0;
	else begin
		if(ENABLE_IN && Counter == COUNTER_MAX)
			TriggerOut <= 1;
		else
			TriggerOut <= 0;
	end
end


assign COUNT = Counter;
assign TRIG_OUT = TriggerOut;

endmodule 
