Forum: Compiler & IDEs Frequenzmessung


von FaB (Gast)


Lesenswert?

hallo,

habe hier ein script für frequenzmessung zusammengebastelt,
jedoch funktioniert es noch nicht so recht. ich habe eine 
flipflop-schaltung an PD3 mit einer frequenz von ca. 285Hz angehängt. 
die ausgegebene frequenz beträgt jedoch etwa -17400 Hz. irgendwas muss 
da wohl falsch sein. hatt jemand von euch vielleicht eine idee????

danke!

fab

====================================

#include <io.h>
#include <sig-avr.h>
#include <stdlib.h>
#include "lcd.c"

unsigned int iOverload;
unsigned char sLedout[10];
unsigned int iCount;
unsigned long lFreq;
unsigned int x;

SIGNAL (SIG_OVERFLOW0)
{
   iCount++;
}

int main (void)
{
   outp(0xFF, DDRB);
   outp(0x00, DDRD);

   sbi(TIMSK,TOIE0);
   outp(3, TCCR0);
   asm volatile ("sei");

   lcd_init();
   lcd_print("WELCOME");
   delay_ms(2000);
   lcd_cls();

   while(1)
   {
      iOverload = 0;
      loop_until_bit_is_clear(PIND, 3);
      loop_until_bit_is_set(PIND,3);
      outp(0,TCNT0);
      iCount = 0;

      for (x = 0; x < 10; x++)
      {
         while (bit_is_set(PIND,3))
         {
            if (iCount > 2000)
            {
               iOverload = 1;
               break;
            }
         }

         while (bit_is_clear(PIND,3))
         {
            if (iCount > 2000)
            {
               iOverload = 1;
               break;
            }
         }
      }

      if (iOverload != 1)
      {
         lcd_cls();
         lFreq = 40000000/(64*iCount);
         itoa(lFreq, sLedout, 10);
         lcd_print(sLedout);
      }


   }
}

======================================

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.