//--------------------------------------------------------------------------------------------------
//
// Title       : Counter
// Design      : quaddecode
// Author      : mbari585
// Company     : MBARI
//
//-------------------------------------------------------------------------------------------------
//
// File        : C:\projects\genosensor\ESP 2003\quaddecode\quaddecode\src\Counter.v
// Generated   : Tue Oct 15 14:20:57 2002
// From        : interface description file
// By          : Itf2Vhdl ver. 1.20
//
//-------------------------------------------------------------------------------------------------
//
// Description : 
//
//-------------------------------------------------------------------------------------------------
`timescale 1ps / 1ps

//{{ Section below this comment is automatically maintained
//   and may be overwritten
//{module {Counter}}
module Counter ( Zero ,ce ,count ,Reset ,updown ,Sclk ,sense );

input Zero ;
wire Zero ;
input ce ;
wire ce ;
input Reset ;
wire Reset ;
input updown ;
wire updown ;
input Sclk ;
wire Sclk ;
input sense ;
wire sense ;

output [23:0] count ;
wire [23:0] count ;

//}} End of automatically maintained section

// -- Enter your statements here -- //
//sense is used to case the counter to count up or down based on the sense of
//updown.  This will invert count direction to compensate for the encoder phase.
reg [23:0] location;
assign count = location;

always @ (posedge Sclk)
	begin  
		if (Reset || Zero)location <= 24'h000000;
		else if (ce)
				begin
					if ((updown & !sense) || (!updown & sense))
						begin
							location <= location + {23'b0,1'b1};
						end
					else 
						begin
							location <= location - {23'b0,1'b1};
						end	 
				end	
		else location <= location;
	end
endmodule
