Hi,
I have an arduino project that does analogue reads in the main loop. I am finding that the results are quite noisy with momentary jumps in values. All I am trying to read are 6 10k pots connected to each input. I am just using the standard analogread function.
I suspect this noise may be to do with the fact I have 2 timer interrupts which can't be stopped (as they're used to generate audio). Could these interrupts be interrupting the analogue conversion process and creating occasional inaccurate values? The values are generally OK, but maybe twice or three times a second I get a value that is clearly wrong.
I have Aref mode set to default, but have put a 100nF cap from Aref to ground pins, as I read that this can help with noise. I'm not totally convinced it is!
I have read that using an external voltage is good for more accurate readings, but my readings aren't out by a constant value (e.g. because my power is 5.2V not 5V (which it isn't anyway!)), so I'm not totally convinced this is the solution. I'm willing to be persuaded otherwise though!
Any solutions would be helpful. If it is the interrupts causing it, then I may have to put up with it.
Paul
(P.S. I don't have enough free mem to do smoothing of the incoming data)
I created a version of the software without the interrupts and you were correct - the interrupts weren't causing the spikes in the readings.
I then put a 100nF cap on each analog pin and yes this helped a lot! Spikes went from jumps of 10 or more down to just 2 or 3.
I hadn't tried that averaging idea. It's good, but doesn't actually seem to work to well in my case as the spikes last for too long, so you'd need to average a large number of readings. This would then make the pot not responsive enough.
Any other ideas on how to reduce noise would be welcome. I would love to irradiate the spikes completely!
Differential signals can reduce noise. Send the pot output to two op amps: one inverting op amp and one non-inverting. Measure both op amp outputs so that the signal is a difference between the two voltages and the noise is a common-mode noise that is subtracted out. The differential idea is that subtracting two common numbers results in zero, subtracting to different numbers is the value you want.
Maybe a clarification of these two statements would help.
but maybe twice or three times a second I get a value that is clearly wrong.
in my case as the spikes last for too long
How often are you sampling the analog signal?
How long does the spike last? Do you have an oscilloscope to view the signal?
How many analog inputs are you using?
Are these spikes at a consistent timing?
If the cap helped, did you also add the resistor (in series with the signal)? Maybe making the cap larger will reduce spikes more.
Hi,
I think I may have solved this just by dramatically reducing the cable length from the pots to the Arduino. Initially they were about 70cm and went around the houses via several solder joints. The output looked like this:
ms:reading
0:0
1:1
3:4
5:0
6:6
11:1
28:5
45:0
61:2
77:6
95:0
111:0
I've managed to shorten them to about 30cm and make the connection direct. The reading at 0 is this:
ms:reading
1:0
2:0
3:0
4:0
5:0
6:0
7:0
7:0
8:0
9:0
10:0
11:0
12:0
13:0
15:0
21:0
27:0
33:0
39:0
46:0
52:0
58:0
65:0
71:0
77:0
83:0
90:0
96:0
102:0
So a dramatic improvement. I had no idea the analogue inputs were so sensitive to cable length!
Thanks for your help.
Paul
P.S. The spikes turned out to be a red herring, due to an error in my programming. It wasn't spikes, just noise.
I think the analog inputs was not so sensitive to long cable lengths, it was long cable lengths pick up more emf/radio frequency than short ones do.
I am happy you have a solution. For others to learn from, can you modify your first post to include (SOLVED) in the subject.
Thanks, and have a great day.