SOLVED: Odd fluctuations in analog readings when using external power

SOLVED!

First: apologies if this is in the wrong category, there are just too many to choose from that this question may fit in...

I am building a midi controller and got everything working perfectly on the breadboard with the duemilanove, the 16 pots (being read through two 4051's) were stable at any position, fluctuating within 3 points (my smoothing value). I switched the duemilanove out for a breadboard arduino I made a few months ago and I tried powering it with (many different) wall warts (6.5v/200ma, 9v/150ma, 9v/800ma, 12v/1A). No matter what I used, I could not get the pots to hold their values any more... they would fluctuate by upwards of 15-20 points and therefore are pretty much useless...

After much searching, I figured out that the adc is fairly sensitive to changes in the reference voltage, so I began testing the voltages with various options I have available and noticed that the 7805 in the bb arduino was outputting about 4.95v steady. I switched it out with an LM2940 and it locked onto 4.99v and was steady... Using the bb arduino, but the duemilanove (atmega removed) for power (5v and gnd hooked up) I get 5.07v (and the pots are stable).

I guess my question would be: is the adc really THAT sensitive, in that .08v can cause an almost 10 fold increase in the jitter of the values?

What can I do to solve the problem?

I know you will want me to post a schematic, but I don't have one yet, and since everything works perfectly using the duemilenova on its on, AND when only using the power it provides (but using the bb arduino for everything else), I cannot see an issue with that part... I have a feeling my lack of basic electronics knowledge is hurting me here...

Thanks everyone!

Do you have a 0.1uF across +5 and GND as close to the processor's power pins as possible? Do you have any fast-switching digital pins close to AVCC, AREF, or the Analog Input pins? Did you try a capacitor on AREF? Have you checked Grumpy_Mike's website for de-coupling advice?

I have 100uF across the input and a 10uF across the output of the lm2940. (I have also played with a couple different ones i have on hand and none made a difference.

Not really... Its on a breadboard with a diy bb arduino... Picture attached. (remember, when I power it from the 5v from the duemilenove it works perfectly... the only change is the addition of the jumper wires and the lack of the dc plug being inserted.

AREF is not connected on the diy bb arduino (see previous response)

Yep, read every single page on his site... and nearly every post he as made since I joined :slight_smile:

AREF is not connected on the diy bb arduino (see previous response)

That's the problem, all the rest is a distraction. :slight_smile:

Ok, so why would it work when supplied with 5v from the duemilenove? and should just be connected to vcc? or should it also be decoupled?

I'm just curious as to why seemingly the only difference is where the power is coming from, and that the difference is a mere .08v....

Please explain, I am very interested in knowing the why behind this issue...

While you are reading the voltage on a meter you have no idea of the amount of ripple voltage siting on the top of it. So the source of the voltage can have an effect by being more noisy (having more ripple). Adding capacitors will make it smoother and it is the noise into your analogue circuitry and reference voltage that is giving you the variations you see. It also helps if the analogue side of the Atmega is decoupled from the digital side. In most circuits (mine included) these are simply connected together, but the data sheet recommends some LC circuits to isolate the two power rails.

Yeah I do have some sort of idea of the importance of decoupling, I am more interested in why not having aref connected is causing problems.. from what i read the adc defaults to vcc for its reference voltage, and since the pots are also hooked up to the same vcc, they should track with ahy ripple.... shouldn't they?

nickvd:
Yeah I do have some sort of idea of the importance of decoupling, I am more interested in why not having aref connected is causing problems.. from what i read the adc defaults to vcc for its reference voltage, and since the pots are also hooked up to the same vcc, they should track with ahy ripple.... shouldn't they?

Aref is the reference directly into the ADC circuitry - it needs to be held at a proper reference voltage. When its configured to be 5V it will be internally driven to the AVcc rail ON THE CHIP via a transistor. The transistor will have significant resistance and the power rail on the chip will be noisy (not the least because its connected to the digital Vcc on most boards!). Off the chip the noise on the supply rail is shorted out at the supply decoupling capacitors, but due to stray inductance and resistance this won't stop switching noise (which is really cross-talk) on the chip's rails. Even 10mV of noise will degrade the ADC performance, whereas the digital logic will survive hundreds of times more noise without complaining.

Adding the capacitor on Aref shorts out the noise (its acting as a low-pass filter together with the transistor). If it were economic to provide the decoupling on-chip it would be done, but there isn't room for large-value capacitance on the silicon. Besides the value of decoupling cap is a trade-off between performance and expense. For instance if you aren't using the ADC you don't need the cap.

Still a little confused, but I am getting there... So even if I need the internal reference of vcc, I should still have a cap from aref to gnd.. Is there a reason why it works fine off the duemilenove? Is it just that it provides a little more than 5v therefore any ripple would still keep it above 5v?

nickvd:
Still a little confused, but I am getting there... So even if I need the internal reference of vcc, I should still have a cap from aref to gnd.. Is there a reason why it works fine off the duemilenove? Is it just that it provides a little more than 5v therefore any ripple would still keep it above 5v?

The duemilenove has a capacitor on Aref. It probably has better decoupling on the rails too and a better groundplane.

Whichever voltage reference is being used (AVcc, external voltage applied to Aref pin, or internal bandgap voltage(s) ) it will be seen on and can be measured at the Aref pin when selected. That makes for a good common spot to add a .1ufd bypass cap. Not all boards include this cap. I have both a Seeeduino mega board and a clone RS-232 mega328 board which do not. If I run a continuous analogRead() with a good regulated clean voltage applied to the analog input pin and print the results to the serial monitor I see a +/- single count flicker at all times on the 328 board, but just a stable reading on the mega board. I soldered a .1ufd cap from the aref pin to ground on the serial board and then it to became flicker free.

As Grumpy said other things that can effect the A/D conversion noise. Such as filtering method on the Avcc pin, layout of the grounds between the analog and digital runs, source Vcc noise, etc. It all relates, however being only a 10 bit A/D conversion it's not too hard to tame it to be useful to the resolution possible with only a 10 bit conversion.

Lefty

Woo! :slight_smile:

Thanks guys, I now know why my previous tank gauge pcb kept giving me problems while the breadboard version worked perfectly... all my other pcb projects never used the adc so I never noticed the problem... I will update my standard atmega schematic to add a .1uF to aref from here on out..

I'll be making a thread about this project later on, it will be a work in progress, but it is very usable right now (in brief: I have an old Behringer DX-500 DJ mixer that sounds like crap now, so I am converting it into a midi dj controller... It has 18 pots, 15 on/off buttons, 3 toggle switches, and 3 momentary buttons... the software I use (Traktor) outputs midi for almost all of its functions, so my next step is to tap into the mixers VU meter and take it over for my own purposes :)) ... I'm giddy... lol