5
\$\begingroup\$

I was trying to use the ATMega328 ADC port A0 to read a signal. The hardware I used was:

The signal I got seems to be only the positive part of a sine wave. Is it possible that this setup isn't suited for audio recording? What I have to change?

\$\endgroup\$
7
3
\$\begingroup\$

Without having ever used any of those parts, let me see if I can take a stab. Do you happen to have access to an oscope? If so you might want to check your signal before you start building anything.

Most likely your microphone/amp is outputting a wave that is centered around 0v, meaning you have + and - voltages. Think of a sin wave that fluctuates between -1v and 1v. In order for your micro to use this, you will need to add a DC offset such that you most negative voltage becomes slightly above 0v and your most positive voltage is slightly below the max that your micro can read (probably around 5v).

With out looking into your components in more, it is hard to tell you specifically what you need to do in order to get your DC offset, but maybe this will put you in the right direction.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Without is written without spaces \$\endgroup\$
    – Jader Dias
    Oct 17 '10 at 23:45
  • \$\begingroup\$ Corrected for you. \$\endgroup\$
    – Kellenjb
    Oct 18 '10 at 0:08
3
\$\begingroup\$

Do you have a DC-blocking/biasing capacitor at the input?

Analog input with DC-blocking capacitor

The combination of the C with the R sets the lowest frequency that can pass through to the ADC. DC (the ultimate low frequency) is blocked, while AC passes through. In this case, the cutoff frequency would be 1 Hz, which is plenty low for audio.

The DC bias is provided by something in the middle of the ADC range, with low noise. For example:

DC bias source

This would produce 2.5 V at DC, but the AC is closely coupled to ground by the capacitor, so it filters out any fluctuations in the supply. A larger capacitor would improve the noise at lower frequencies.

(Originally I linked to this image, but that would only work if your 5 V supply is noise-free.)

\$\endgroup\$
13
  • \$\begingroup\$ Good schematic... I'll check it. \$\endgroup\$
    – Jader Dias
    Oct 18 '10 at 1:41
  • 3
    \$\begingroup\$ @blalor strictly speaking 0V doesn't become 2.5V. The general rule is that the DC component of the signal becomes 2.5V \$\endgroup\$
    – Jader Dias
    Oct 18 '10 at 1:54
  • 3
    \$\begingroup\$ @blalor if you were able to put an infinitely large capacitor in there, you would see that your entire signal is shifted to be centered around 0v. Hence, removing the DC offset. This is a common method to make sure that there isn't any circuit adding an unwanted offset. R1 and R2 then just add back a known dc offset for ADC purposes in this case. Since we can't have infinitely large caps we settle for smaller caps that cause some of the low frequencies to get cut off. \$\endgroup\$
    – Kellenjb
    Oct 18 '10 at 2:22
  • 1
    \$\begingroup\$ Infinitely large caps would take forever to charge up to the bias voltage anyway. \$\endgroup\$
    – endolith
    Oct 18 '10 at 13:48
  • 1
    \$\begingroup\$ @Jader: It was from here sites.google.com/site/ki4mcw/Home/arduino-tnc , but it's actually not a good circuit. I'll redraw it. \$\endgroup\$
    – endolith
    Oct 19 '10 at 15:44
2
\$\begingroup\$

The solution is to use an Amp-Op

Pins

In a circuit like this:

Circuit

You can simulate it using the Java Circuit Simulator where you can import the following code:

$ 1 5.0E-6 10.20027730826997 57 5.0 50
g 240 240 240 288 0
r 240 112 240 160 0 47000.0
r 240 192 240 240 0 47000.0
R 240 112 240 80 0 0 40.0 5.0 0.0 0.0 0.5
r 272 384 336 384 0 1000.0
R 176 384 144 384 0 1 40.0 0.5 0.0 0.0 0.5
w 176 384 192 384 0
c 192 384 256 384 0 1.0000000000000001E-7 -2.9572014071857935
c 192 176 192 240 0 1.0000000000000001E-7 2.5000000000001608
w 192 240 240 240 0
w 256 384 272 384 0
w 336 384 336 192 0
r 416 240 512 240 0 100000.0
w 512 240 512 176 0
w 192 176 240 192 0
w 416 240 416 192 0
w 240 192 240 160 0
a 416 176 512 176 1 5.0 0.0 1000000.0
w 416 160 240 160 0
w 336 192 416 192 0
o 13 64 0 35 20.0 9.765625E-5 0 -1

The gain will be proportional to the ratio between the resistance of the 100k resistor and the 1k one.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.