Gast
#168990
Hallo, ich versuche einen ATMega8 mit dem internen Oszillator zu betreiben. Fuses: CKSEL2 und SUT0 (Das geht problemlos) Zusätzlich möchte ich eine RTC mit Timer2 implementieren. Zu diesem Zweck habe ich an XTAL1 und XTAL2 einen 32kHz Quarz und zwei 39pF Kond. angeschlossen. (die internen Kond. Fuse CKOPT funktionieren ja irgendwie nicht, siehe http://www.mikrocontroller.net/forum/read-1-179766.html#new ) Das programm läuft bis zur Abfrage: while(ASSR & 0x07); Kommentiere ich diese Zeile aus läuft das programm, aber TIM2_OVF wird nie ausgeführt. Source: interrupt [TIM1_CAPT] void timer1_capt_isr(void){ e2events++; } interrupt [TIM2_OVF] void timer2_overflow_isr(void){ isrCnt++; } void main(void){ //RTC Init TIMSK &= ~((1<<TOIE2)|(1<<OCIE2)); // Select the external clock source (Asyncronous Status Register) ASSR |= (1<<AS2); // Set timer to be asynchronous // as the setting of the assr to asyncronus clock // might corrupt other registers they have to be reset // Reset the timer counter register TCNT2 = RESET; // 32768Hz / 256 = 128 -> prescaler 128 for 1 sec interr. // no prescaler for exactly 1/128 second interrupt => every 7.8125 ms TCCR2 |= ((1<<CS22)|(1<<CS20)); // wait for the ASSR flags to be cleared, the registers are updated while(ASSR & 0x07); // clear the timer2 isr flags TIFR |= (1<<TOV2); // enable overflow interrupt TIMSK |= (1<<TOIE2); // external isr init PORTB.0 = 1; //Pullup on TCCR1B |= (1<<NOISE_CANCEL);// Noise Canceler On, Timer1 Prescaler 1 CAPTURE_FALLING_EDGE; // Edge Select falling // Timer1 InputCapture Interrupt Enable for PWM Duty Cycle measuring TIMSK |= (1<<INPUT_CAPT_ISR); // Global enable interrupts #asm("sei") while(1){ sprintf(line1, "Events: %u %u",e2events); sprintf(line2, "Timer2ISR: %u",isrCnt); RedrawDisplay(); delay_ms(200); }; }
