Timer1 ATMega16

Hallo,

ich versuche gerade mit GCC und ATmega16 eine 1ms Timer-Routine zu realisieren. Was dabei rauskommt ist aber etwa doppelt so schnell wie erwartet.

Der Quarz hat eine Frequenz von 11,0592 MHz, der Oszillator. Der Baudratengenerator läuft mit der erwarteten Geschwindigkeit

------------------- snip ----------------------------------

void init(void) { cli(); // znächst mal die INTs sperren .... OCR1A = 11059; TCCR1B = 0x09; // Set timerclock fosc / 1 TIMSK = 0x10; // Outputcomparematch A interrupt enabled.

sei(); //globale Ints aktivieren }

SIGNAL (SIG_OUTPUT_COMPARE1A) { ms1++; if (ms1++ > 9) { ms1 = 0; ms10++; if (ms10 > 99) {ms10 = 0; sec++; if (sec > 59) {sec = 0; min++; if (min > 59) { min = 0; hour++; } } } }

} // Ende der 1ms Timer Interrupt-Routine

int main( void ) { init(); // Initialisierung char c,b; for (;;) { b = sec; uart_putchar(c++); // sendet 1 Zeichen do {} while (b == sec); } // for (;;) }

Reply to
Stefan Brröring
Loading thread data ...

Hallo,

Stefan Brr=F6ring schrieb:

Der Fehler d=FCrfte hier liegen: ms1 wird zweimal inkrementiert.

hth,

Thomas

Reply to
Thomas.Mistelbauer

"Gernot Fink" schrieb im Newsbeitrag news: snipped-for-privacy@mid.individual.net...

Au ja, das wirds sein, danke

Stefan

Reply to
Stefan Brroering

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.