/*
 * $Id: timer.c 187 2005-09-30 18:04:41Z anders $
 * 
 * Copyright (C) 2005 Anders Dubgaard <anders@dubgaard.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "timer.h"

void start_timer0(void){
	/* timer0 in ATmega8 uses system freq. divided by 256.
	 * interrupt: SIG_OVERFLOW0
	 * freq. ex.: 7.3728MHz system clock / 256 = 28.8KHz
	 */
	TCCR0 |= (0<<CS02) | (0<<CS01) | (1<<CS00); /* CS02:00 = '001' => prescale = 1 */
}

void start_timer1(void){
	TCCR1B |= (0<<CS12) | (1<<CS11) | (0<<CS10);
}

void start_timer2(void){
	/* PWM on timer2 */
	setbit(DDRB, OC2PIN);  /* OC2 to output */

	TCCR2 |= (1<<WGM21) | (1<<WGM20);
	TCCR2 |= (0<<CS22) | (1<<CS21) | (1<<CS20);
	TCCR2 |= (1<<COM21) | (0<<COM20);
}

void start_pwm_timer(void){
	start_timer2();
}
