/**************************************************************************** Title : C file for Interrupt intilialization (interrupt.c) Author: Gorang Gandhi (gorang@ufl.edu) Date: July/24/2006 Software: AVR-GCC Target: Atmega 128 Comments: *****************************************************************************/ #include #include #include #include "interrupt.h" /* void INIT_TIMER3(void) // Used to read in sensors every 0.1 ms { ETIFR |= _BV(OCF3A); // clears output compare flag 1 TCCR3B |= _BV(CS31)|_BV(WGM32); // CTC (clear time on compare match), prescale = 8 TCNT3 = 0; ETIMSK |= _BV(OCIE3A); // enable output compare interrupt OCR3A = 200; // match in approx 0.1ms. 1/(16 MHz/8)*200 = 0.1ms } void INIT_TIMER2(void) // Used to update motor drivers every 8 ms { TIFR |= _BV(OCF2); TCCR2 |= _BV(WGM21)|_BV(CS22)|_BV(CS20); // CTC, prescale = 1024 TCNT2 = 0; TIMSK |= _BV(OCIE2); // enable output compare interrupt OCR2 = 125; // match in approx 8ms. 1/(16 MHz/1024)*125 = 8ms } void INIT_TIMER0(void) // Used to execute PID loop { TIFR |= _BV(OCF0); TCCR0 |= _BV(WGM01)|_BV(CS02)|_BV(CS01)|_BV(CS00); //CTC, prescale by 1024 TCNT0 = 0; TIMSK |= _BV(OCIE0); OCR0 = 156; // match in 0.01 sec . 1/(16 MHz/1024)*156 = 0.01 s } */ void INIT_TIMER2(void) // Used to execute PID loop. Interrupts every 10 ms. { TIFR |= _BV(OCF2); TCCR2 |= _BV(WGM21)|_BV(CS22)|_BV(CS20); // CTC, prescale = 1024 TCNT2 = 0; TIMSK |= _BV(OCIE2); // enable output compare interrupt OCR2 = 156; // match in approx 10ms. 1/(16 MHz/1024)*156 = 10ms } void INIT_TIMER1(void) // Used for ms_sleep. Interrupts every 1 ms. { TIFR |= _BV(OCF1A); // clears output compare flag 1 TCCR1B |= _BV(CS11)|_BV(CS10)|_BV(WGM12); // CTC (clear time on compare match), prescale = 64 TCNT1 = 0; TIMSK |= _BV(OCIE1A); // enable output compare interrupt OCR1A = 250; // match in approx 1ms. 1/(16 MHz/64)*250 = 1ms }