/**************************************************************************************************
---------------------------------------------------------------------------------------------------
	Copyright (c) 2004, Jonathan Bagg
	All rights reserved.

	 Redistribution and use in source and binary forms, with or without modification, are permitted 
	 provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of 
	  conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of 
	  conditions and the following disclaimer in the documentation and/or other materials provided 
	  with the distribution.
    * Neither the name of Jonathan Bagg nor the names of its contributors may be used to 
	  endorse or promote products derived from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
  POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------------------------------
   Project name : Infidigm AVR Drivers
   Processor	: ATMega64, ATMega128
   File name    : timer1.h
---------------------------------------------------------------------------------------------------
   Modifications: 

   Revision 1.0  2004/06/11 	Bagg
   - Cleaned up for release
---------------------------------------------------------------------------------------------------
   Created      : 20 January 2004                Author(s) : Jonathan Bagg
---------------------------------------------------------------------------------------------------
   Timer/Counter1 Peripheral Driver, Input Capture 1 and PWM for Motors 1,2,3
---------------------------------------------------------------------------------------------------
**************************************************************************************************/

/**************************************************************************************************
*   Timer/Counter1 Prescaller Definitions (frequencies for 15.36 Mhz Clock)
	- TC1PRE Set to 1 = PWM Freq 14,976 Hz
	- TC1PRE Set to 2 = PWM Freq 1,872 Hz
	- TC1PRE Set to 3 = PWM Freq 234 Hz
**************************************************************************************************/
#define TC1PRE 1

#if TC1PRE==1
#define TC1DIV	64
#endif
#if TC1PRE==2
#define TC1DIV	8
#endif
#if TC1PRE==3
#define TC1DIV	1
#endif

/**************************************************************************************************
*   GLOBAL VARIABLES
**************************************************************************************************/
signed int width1;					//pulse width1 for tach1
signed int count1;					//pulse counter1 for tach1

/**************************************************************************************************
*
*   Signal	          : SIG_INPUT_CAPTURE1
*
*   Description       : Timer/Counter1 Input Capture Interrupt Service Routine.  Used to Capture
*						and build Pulse width and Pulse Counter measurement for IC1. Works with 
*						the Timer/Counter1 Overflow ISR.
*
*   Parameters        : None
*
*   Functions Called  : None
*
*   Returns           : None
*
**************************************************************************************************/

/**************************************************************************************************
*
*   Signal	          : SIG_OVERFLOW1
*
*   Description       : Timer/Counter1 Overflow Interrupt Service Routine.  Used to Capture
*						and build Pulse width for tach1. Works with the Timer/Counter1 Input 
*						Capture ISR.
*
*   Parameters        : None
*
*   Functions Called  : None
*
*   Returns           : None
*
**************************************************************************************************/

/**************************************************************************************************
*
*   Function          : startTC1
*
*   Description       : Sets up the Timer/Counter1 for 10-bit PWM, with settable clock rate 
*						(TC1PRE). Also enables the Input Capture Interrupt and the Overflow 
*						Interrupt. 
*
*   Parameters        : None
*
*   Functions Called  : None
*
*   Returns           : None
*
**************************************************************************************************/
void startTC1(void);
