Hi all. I realise this question gets asked a lot, and I did read a number of answers... and I did implement the most prevalent answer, which was "add a capacitor". But I'm still struggling with those jittery analog reads.
It's a simple setup on my Due, where I'm in early debug/test mode. Pin A7 is connected to the wiper of a (fairly high quality) linear pot whose other 2 pins are connected to 3.3v and ground respectively. When I wind the pot knob back and forth I do indeed see a voltage on A7 that varies between 0 and 1023. So that's all nice and as it should be.
The problem is that even when I'm not touching that pot, the voltage on A7 jumps around a lot. I would say it jumped around randomly by 4% (40 units as read on A7) on first test (makes it kind of hard to use the pot for accurate input). So I did some googling and remembered, oh yeah, doh, I'm supposed to add a small cap between A7 and ground. So I added a .15uF ceramic cap between A7 and ground.
The noise diminished some, but it's not gone -- it's still around 2% (20 units). Ideally I was hoping to be able to dial-select values between 0 and 100 accurately, so I wanted noise lower than 10 units.
Some of my reading suggested that this problem is caused by using a wall-wart power supply for the Due; some say that these p/s introduce noise on all the vcc. I did put a (bigger) electrolytic cap between 5v and ground; should I do likewise for 3.3v, and how important is the cap value? is bigger better?
If you experienced people have a standard setup that you always start with for your breadboard -- caps on the power rails, caps on the analog pins -- I'd be very interested to know your "recipe" and whether it might get me a clean analog input from my pot.
As I (bonehead non EE) understand it, a capacitor can slow down the transitions on a signal line, so probably not a good idea to put them on any digital pins. Is that correct?
You can try using the internal reference.
Draw a cct. for how the pot is wired.
You can read the input multiple times and use the average value.
You can try reading the input twice in a row then use the second reading.
Make sure the supply connected to the voltage divider is stable.
The Due has only the 3.3 v reference from its own power supply, there is no internal reference to try.
If you have nothing else connected to the 3.3V supply, it could well be a very noisy power supply. Can you post a photo of any labels that are on the power supply? Is it’s a no-name Chinese special, it’s time for a real power supply.
I would consider a simple test; use 2 resistors maybe 10K each. Form a divider and replace the pot (using the same wires). If noise remains you can definitely rule out the pot.
Then I would move the same resistors to right at your analog inputs (with the 0.15 µF cap). If the noise still persists then you've narrowed it to the board / supply.
Is it possible to power the board temporarily with some AA batteries? If so you can narrow it to the power supply or grounding.
You didn't mention what else might be hooked to the board. If there are other circuits, disconnect them.
I try to use simple tests to eliminate possible causes. It probably took me longer to type this than to do these tests (maybe except the AA batteries )
What is the value of this pot? It should be about 10K, anything greater adds extra impedance to the input making it more susceptible to interference pickup.
Tazling:
The noise diminished some, but it's not gone -- it's still around 2% (20 units). Ideally I was hoping to be able to dial-select values between 0 and 100 accurately, so I wanted noise lower than 10 units.
I think there are two problems here.
Firstly the Due board has a noisy switch-mode 3.3V converter powering the 3.3V rail - bad choice for
anything analog.
Anyway after investigating (putting a high quality 3.3V regulated supply on AREF if I recall right), the
noise on the DAC didn't really get much better.
The DAC has sparkle codes by the look of it, its 12 bit nominal, but much less than this usable.
And it also only goes from 1/6th to 5/6th of the supply voltage, so its basically pointless in my
opinion. I think they tried to be clever and put a some sort of sigma-delta DAC on the process
designed for CMOS logic, and found out this isn't trivial...
Except for the surfmount packaging which is challenging for my oldskool soldering tools, this looks like a no-brainer to add to my project. I must have some basic surfmount breakout boards somewhere...
So, strategy 1 would be to get a clean reference voltage off a chip like this which (forgive my ignorance) I would then feed into AREF?
And strategy 2 would be to use a "real" ADC, external to the Due? I find that i2c ADCs are common as dirt (12 bit, 16 bit) so it looks like I could attach my pot to one of these and then read the digitised value over i2c bus (which I'm already pretty comfortable with).
I bought 50 TO92 TL431A 2.5V references for £0.99 from China on ebay. I was concerned that at 2p each they would be forgeries but I have setup 10 on soak test and they are all well within the 1% specification and do not change by more than 5 mV over a day. Maybe not the best voltage reference but at 2p each they are very good value and must be worth a punt.
One uses the TL431 like a zener with 1 resistor; it has a very very sharp knee.
BTW thanks MarkT for pointer to very informative thread.
I will read up about the option of cutting a trace to sever the noisy onboard 3.3vdc from the AREF.
Kind of scary to be mutilating my pricey genuine Due, but if it reduces the noise on the analog inputs it may be worth a tense moment or two with x-acto knife and elevated heart rate
I tried it, its not enough of a cure to be worth bothering with really - get an external DAC with much better
performance and clean analog ground and power...
Thanks MarkT I will invest in some DACs. Seems like it is always a case of "add one more part, add one more part" so my super simple Arduino projects get messier and messier. But worth it in this case to get a clean signal off my sensor.