fixed timer initialization. timer works now.

This commit is contained in:
Stefan Rupp 2014-03-12 21:54:28 +01:00
parent 285732c1a0
commit bad75eb419

12
timer.c
View File

@ -17,10 +17,10 @@
/* timer_time gets increased on every interrupt /* timer_time gets increased on every interrupt
* those interrupts happen every 1ms * those interrupts happen every 1ms
*/ */
static volatile uint32_t timer_time; static volatile uint32_t _timer_time;
ISR(TIMER0_COMPA_vect) { ISR(TIMER0_COMPA_vect) {
++timer_time; ++_timer_time;
return; return;
} }
@ -38,7 +38,7 @@ void timer_init(void)
cli(); cli();
// Reset timer to zero // Reset timer to zero
timer_time = 0; _timer_time = 0;
// - Time accuracy: 1 millisecond (corresponding frequency: 1kHz) // - Time accuracy: 1 millisecond (corresponding frequency: 1kHz)
// ==> F_CPU = 20Mhz // ==> F_CPU = 20Mhz
@ -52,8 +52,8 @@ void timer_init(void)
// provided, we can't get any closer to the desired frequency of // provided, we can't get any closer to the desired frequency of
// 1kHz :( // 1kHz :(
OCR0A = 77; OCR0A = 77;
TCCR0B = (1<<WGM01); TCCR0A = (1<<WGM01);
TCCR0A = (1<<CS02); TCCR0B = (1<<CS02);
// Interrupts setzen // Interrupts setzen
TIMSK0 |= (1<<OCIE0A); TIMSK0 |= (1<<OCIE0A);
@ -72,7 +72,7 @@ inline uint32_t timer_get(void)
sreg = SREG; sreg = SREG;
cli(); cli();
t = timer_time; t = _timer_time;
SREG = sreg; SREG = sreg;
return t; return t;
} }