Electronic – Reading frequency of an audio signal from Android device

audiofrequencysignal

I am doing a project that reads frequency of audio signals generated from Android device through the headset jack. The audio jack is connected to Atmega microcontroller as shown in the figure.!

I am using the analog comparator to compare between a reference voltage 2.61v and the audio signal (DC biased; AC + 2.5v).
The audio signal range is 200mv p-p so after DC biasing it will be from 2.3 to 2.7.
When the comparator input 1 passes 2.61 (reference volt), a timer starts to measure the frequency.
But the problem is I am not getting a stable reading of frequency. For example, if the signal is 1000Hz, I read it between 4000 and 5000 Hz. The values always change. Sometimes the comparator outputs one for few microseconds even there is no audio signal (the output should be zero).!!

I think the problem is one of these:

  1. The power supply has a high ripple so I cannot read low-level signals properly.
  2. I should use a higher blocking capacitor C2 like 10uF instead of 100nF.
  3. The 200 mv is in the range of noise signals, I should amplify it before read.
  4. The voltage divider should use high values of resistors like 3MOhm as in the Hijack project below.

What do you think.

This is similar to the hijack project proposed by UMICH. Their schematic is shown below.
enter image description here

Best Answer

There a few things missing here. Maybe too many questions for a comment, but maybe enough to help you see where it's going wrong.

First of all, a 200mV peak to peak signal on 2.5V will give a range of 2.4V-2.6V, not 2.3V to 2.7V. Unless you mean it's 400mV p-p or 200mV amplitude. We'll assume you are dealing with a 400mV p-p 1kHz sine wave, since the other wouldn't work except to measure noise.

When you say a timer starts to measure the frequency, are you just seeing how long the signal is above your 2.61V reference? What are you expecting to find? A 314ns pulse from the comparator? Or are you just waiting for next rising edge of the comparator? What time resolution are you measuring at? What's your calculation?

Does the comparator have any hysteresis? If so, are you accounting for it?

Do you have any code for this project? Can you show it to us?

You should know that your method will only work for pure tone signals and it is very susceptible to noise. We don't know your ultimate application, so it's difficult to suggest alternatives.