While using pulseIn to calculate the frequency of an AC audio wave which is converted into a square wave with an LM339 I get values that are much different while the wave stays constant.
int duration;
int setup()
{
pinMode(2, INPUT);
Serial.begin(9600);
}
int loop()
{
duration = pulseIn(2, LOW);
Serial.println(1000000 / (duration * 2));
delay(100);
}
I am using a 10K Ohm resistor to positive and a 4.7K Ohm resistor in series to the 10K to ground.
That sounds wrong.
Output of LM339 direct to the digital input and one end of the 10K, the other end of the 10K to +5V.
Those two extra resistors sound like they will limit the high voltage, it might just be on the limit of triggering the logic input.
And a 0.1uF across the LM339's power pins?
I am using a 10K Ohm resistor to positive and a 4.7K Ohm resistor in series to the 10K to ground.
I was wrong about the 4.7K Ohm resistor, it was 100K.
I took out the 100K out so now all I have is a 10K pull up resistor on the output of the LM339 and I still have the problem. However, I am still getting the full 5 volt output as well as a ground low from the LM339.
Yes it did it got rid of the spurious reading of 1.
Your main problem seems to be the spurious readings of 500000.
The other readings are not going to be rock steady you know.