You need to use an external voltage reference. I don't remember off the top of my head for sure, but I think the default is to use the AVcc pin as the voltage reference. (I could well be wrong -- it has been a while.) The ADC input will be compared to whatever the analog voltage on that pin happens to be at the time. In most projects I've seen, AVcc is just tied to Vcc, with nothing in particular to filter it, so it's going to be "about 5 volts," which means your ADC values will be "about" right.
To get accurate readings, you need to get a precision voltage reference and apply that to your AVref pin, then set the ADC to use that as a voltage reference. Again, if I remember correctly, there are a couple different voltage scales you can use, one of which being 1.0V I think. If that's the case, your ADC input can't exceed 1.0V or else it will clip, so you would need to scale the input accordingly. Or use a higher reference voltage setting.
The other thing you will want to do is determine how fast you can sample the ADC. That will be limited by either the ADC conversion time (if, for example, you set it to freewheeling mode and configure an interrupt to capture each measurement), or your code's ability to process the incoming samples. Either way, you need to estimate what you true max sample rate is, then filter the input voltage to lowpass to 1/2 that frequency. (See: Nyquist.) Otherwise you will get random point-in-time voltages that won't represent a human-friendly trend line. You'll have to accept that you can't observe, in real time, detail above the frequency you can hear.
386SX wrote:I have a PAM4803 amplifier board already built with 5V input and 3Wx2 output and for the DC problem I I already put a capacitor (0.47uF) in serie but maybe wrong..at the output of the amplifier, not the input. Do I need to put it at the input of the amplifier?
Typically, both. (* Caveat)
The input capacitor serves as a bias-removing function. You have an output signal that is (say) 0 to 2.5VDC and you need to shift that down to be -1.25 to +1.25 with 0V being silence. The cap removes the 1.25V positive offset around 0V. (This is something of a simplification, but it'll do.)
The output capacitor does the same thing from the amp's output to the speaker, to ensure that cone movement is centered around the rest position, instead of holding the cone partially out at all times -- which will likely damage the voice coil from excess heat. This is primarily an issue with single-supply amplifiers. If you have a +/- supply, then as long as your amp isn't misbehaving, and the input signal is high-passed to prevent DC offset, then you should be OK without an output cap. Certain amps usually require output caps -- like "Class D" amps -- while others are specifically designed to NOT require one -- like those with DC servo feedback to automatically correct any DC offset on the output terminals.
(* Caveat: Some amplifier "kits" will have an AC-coupled input already. That is, they already have an input capacitor installed. If you don't control both sides of an analog audio signal chain, then it is common to have a capacitor on the output of one device, as well as the input of the device it's connected to. E.g., the output of a CD player and the input of an amplifier. But, this means both caps will be in series, so the frequency response is dictated by the output circuit of the first component and the input circuit of the second. For that reason, the series caps tend to be oversized -- as large as practically possible -- to prevent loss of low frequencies. If you DO control both sides, then you can determine the exact response of the filter and size accordingly. You only need one cap in between. Possibly none, if you know the output and input criteria and they happen to align.
For that matter, since many low-power amplifiers -- and not-so-low-powered ones as well, in certain topologies -- are using a single supply rail, they will need to bias the input signal to 1/2 Vcc like we talked about in the earlier posts. In this case "silence" is actually at 50% voltage, with positive swings to 100%, and negative swings to 0%. But, unless you're designing the entire system, soup to nuts, the amp will probably still expect an AC input biased around 0V, which it will then bias to its own working reference point internally.)