You can use the analog compatorcomparator to detect an analog signal passing a threshold, like this:
You can use the analog compator to detect an analog signal passing a threshold, like this:
You can use the analog comparator to detect an analog signal passing a threshold, like this:
- 38.9k
- 13
- 69
- 125
Alternative method with analog comparator
Based on suggestions by Chris Stratton, there is another way of doing this.
You can use the analog compator to detect an analog signal passing a threshold, like this:
I have set up the voltage divider to trigger at 0.265V, so that a 500 mV signal should provide an acceptable triggering range.
As for the sketch, at these frequencies we can do something simpler than what I posted before:
volatile bool counting;
volatile unsigned long count;
ISR (ANALOG_COMP_vect)
{
if (counting)
count++;
}
void setup ()
{
Serial.begin (115200);
Serial.println ("Started.");
ADCSRB = 0; // (Disable) ACME: Analog Comparator Multiplexer Enable
ACSR = bit (ACI) // (Clear) Analog Comparator Interrupt Flag
| bit (ACIE) // Analog Comparator Interrupt Enable
| bit (ACIS1); // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on falling edge)
} // end of setup
unsigned long startTime;
void loop ()
{
if (!counting)
{
startTime = micros ();
count = 0;
counting = true;
}
else
{
// is a second up? (1000000 microseconds)
if (micros () - startTime >= 1000000)
{
counting = false;
Serial.print (count);
Serial.println (F(" Hz."));
} // end of a second being up
} // end of if
} // end of loop
Alternative method with analog comparator
Based on suggestions by Chris Stratton, there is another way of doing this.
You can use the analog compator to detect an analog signal passing a threshold, like this:
I have set up the voltage divider to trigger at 0.265V, so that a 500 mV signal should provide an acceptable triggering range.
As for the sketch, at these frequencies we can do something simpler than what I posted before:
volatile bool counting;
volatile unsigned long count;
ISR (ANALOG_COMP_vect)
{
if (counting)
count++;
}
void setup ()
{
Serial.begin (115200);
Serial.println ("Started.");
ADCSRB = 0; // (Disable) ACME: Analog Comparator Multiplexer Enable
ACSR = bit (ACI) // (Clear) Analog Comparator Interrupt Flag
| bit (ACIE) // Analog Comparator Interrupt Enable
| bit (ACIS1); // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on falling edge)
} // end of setup
unsigned long startTime;
void loop ()
{
if (!counting)
{
startTime = micros ();
count = 0;
counting = true;
}
else
{
// is a second up? (1000000 microseconds)
if (micros () - startTime >= 1000000)
{
counting = false;
Serial.print (count);
Serial.println (F(" Hz."));
} // end of a second being up
} // end of if
} // end of loop