Das war ein sehr guter Tipp danke Besserwessi.
Wenn ich jetzt overflow0 Null setzte bekomme ich eine schöne Ausgabe zwischen den messzyklen. Ob sie stimmt muss ich morgen mal prüfen.
Mit dem "TCNT0 = 192" wird die Messung genauer, weiß aber noch nicht warum, bitte um Erklärung.
Hier nochmal der Quelltext so wie es geht:
Code:
volatile uint8_t count ;
volatile uint16_t overflow1 ;
volatile uint16_t overflow0 ;
volatile uint16_t low ;
volatile uint16_t high ;
volatile uint8_t newflag ;
uint32_t frequenz ;
/*-- Hauptprogramm ---------------------------------------------------------------------*/
int main(void)
{
char buffer[20] ;
count = 0 ;
overflow1 = 0 ; overflow0 = 0 ; // Variable für Overflow
lcd_init() ; // LCD aktivieren
//Timer0 auf Prescaler 8 stellen --> S.86
TCCR0 |= (1<<CS01) ;
// Overflow Interrupt Enable --> S.87
TIMSK |= (1<<TOIE0) ;
// Timer1 auf Externen Clock Source T1 mit Rising Edge setzen --> S.115
TCCR1B |= (1<<CS12) | (1<<CS11) | (1<<CS10) ;
// Overflow Interrupt Enable --> S.117
TIMSK |= (1<<TOIE1) ;
sei() ;
while(1)
{
if(newflag > 0)
{
set_cursor(0,1) ;
frequenz = (high*65536) + low;
snprintf(buffer, 20, "%u Hz", frequenz) ;
lcd_string(buffer) ;
newflag=0;
high = 0 ;
low = 0 ;
}
}
}
/*-- Timer0 Overflow Interrupt ---------------------------------------------------------*/
SIGNAL (SIG_OVERFLOW0)
{
overflow0 ++ ;
if(overflow0 > 3906)
{
sei() ;
low = TCNT1 ;
cli() ;
TCNT0 = 192 ;
TCNT1 = 0 ;
high = overflow1 ;
overflow1 = 0 ;
newflag = 1 ;
overflow0 = 0 ;
}
}
/*-- Timer1 Overflow Interrupt ---------------------------------------------------------*/
SIGNAL (SIG_OVERFLOW1)
{
overflow1 ++ ;
}
Lesezeichen