Analog (In)Consistency

I am working on a project that is to have multiple analog sensors. Initial observations indicate that the readings were more inconsistent that hoped for. The spreads for a series of 24 reads was in the range of 10 to 14 counts.

No analog sensors were installed, just the potentiometers to provide an adjustable and steady input.

Some web pages state that the DUE has a 12 bit D/A and that the default mode is 10 bits. Ok, ten is sufficient. However, since the two LSBs are knocked off I expected rock solid measurements at ten bits. That is not the case.

I will upload a Excel workbook of the results. If I can I will also upload the code. Here is how the measurements were obtained.

I started with an Ethernet demo program found on line, left all the Ethernet stuff unchanged, then modified the code to make the measurements. It creates a two dimensional array and makes multiple measurements loading the results in the array. In the array I tracked the current/latest reading, min, the max, the sum, the average, and the spread (difference between min and max.)

I wired up three 20K pots. Pot 1 is wired to inputs 0, 3, 6, 9, Pot 2 is wired to 1, 4, 7, 10, Pot 3 is wired to 2, 5, 8, 11.
All three were set to zero volts, then pot 1 was set to max of 3.33. I ran the code and captured the data from the Chrome monitor and put in a text file. Then the pot was turned down to 3.0, 2.5, 2.0, etc, and the measurements taken. After some number of loops I used ctl-a and ctl-c to capture the data and put into Notebook. Then the data was imported into Excel. When the meter bobbled one digit I included that. My hands are not steady and I was unable to get the exact voltage desired but I think that matters little. Close enough should be good enough for this.

All the runs were repeated for Pots 2 and 3. The channels not being tested were kept a zero volts. I started putting in some statistics but decided that I would get little use from that. If anyone wants to massage the numbers any please feel free to do so.

Another post mentioned some pure digital temperatures sensors. I purchased three of those. As I get time I will connect them and see how they perform.

Edit: I see that only one attachment was accepted. And now I am not seeing a method to attach, upload, or link to the Excel workbook. If anyone is interested, please tell me how to add another attachment.

And since I cannot post that, here is one run at one voltage. This one is with an input of 3.01 volts on channels 0, 3, 6, and 9. They all had the same input.

meter = 3.01															
0	array_count	24	current	922	lowest	913	highest	927	sum	22106	average	921.08	spread	14	
1	array_count	24	current	0	lowest	0	highest	1	sum	1	average	0.04	spread	1	
2	array_count	24	current	0	lowest	0	highest	2	sum	3	average	0.13	spread	2	
3	array_count	24	current	920	lowest	916	highest	923	sum	22090	average	920.42	spread	7	
4	array_count	24	current	0	lowest	0	highest	0	sum	0	average	0	spread	0	
5	array_count	24	current	0	lowest	0	highest	2	sum	3	average	0.13	spread	2	
6	array_count	24	current	916	lowest	916	highest	924	sum	22083	average	920.12	spread	8	
7	array_count	24	current	0	lowest	0	highest	3	sum	3	average	0.13	spread	3	
8	array_count	24	current	0	lowest	0	highest	4	sum	6	average	0.25	spread	4	
9	array_count	24	current	923	lowest	916	highest	923	sum	22078	average	919.92	spread	7	
10	array_count	24	current	0	lowest	0	highest	0	sum	0	average	0	spread	0	
11	array_count	24	current	1	lowest	0	highest	1	sum	3	average	0.13	spread	1

analog_evaluations.ino (11.8 KB)

bkelly:
I wired up three 20K pots. Pot 1 is wired to inputs 0, 3, 6, 9, Pot 2 is wired to 1, 4, 7, 10, Pot 3 is wired to 2, 5, 8, 11.

Why are you wiring the output of a single pot to 4 analog inputs? Do you not trust a single reading of the same signal?

bkelly:
Some web pages state that the DUE has a 12 bit D/A and that the default mode is 10 bits. Ok, ten is sufficient. However, since the two LSBs are knocked off I expected rock solid measurements at ten bits. That is not the case.

I'm not sure I follow this - it sounds like you are reading a 16 bit integer and apparently disregarding the "two LSBs"? I'm guessing you mean two Least Significant Bits? Either way, unless you have any reason not to, use analogReadResolution(12); to get as much resolution as possible.

ALSO, if you are only interested in characterizing the ADC of the Due, I suggest getting rid of the Ethernet code entirely and go with a sketch that is as simple as possible for your purpose. You can add the Ethernet stuff once the characterization is done.

Power_Broker:
Why are you wiring the output of a single pot to 4 analog inputs? Do you not trust a single reading of the same signal?

Did not want to use 12 pots. Did not want to run the series 12 times, three will do. This provides four channels with exactly the same inputs for comparisons. It also puts some zero values between readings. That concept was mentioned in another thread where someone suggested that it might purge the circuits and provide a more accurate reading.

And no, I did not trust that all ports will read the same. But a cursory look indicates that they all bobble in about the same range. And not a good range at that.

LSB can mean Least Significant Byte or Bit. Read it as appropriate.

Do you suspect that getting rid of the Ethernet would make the readings more accurate? I took advantage of some one else's code making my task as easy as possible. My project will have two Arduinos at separate locations and connected via Ethernet. As that is the end goal, use what I have.

bkelly:
Did not want to use 12 pots. Did not want to run the series 12 times, three will do.

I'm fairly certain an Arduino Due only has one ADC, which means all analog inputs are actually multiplexed into the single ADC input. Therefore, the reading of one voltage on one input pin will be exactly the same as a reading of the same voltage on any other pin. The only time you should care about having parallel sampling is if you think specific input pins are causing interference, but this is exremely unlikely.

bkelly:
Read it as appropriate.

yes-sir-memegenerator-net-yes-sir-obama-salute-meme-50128126.jpg

bkelly:
Do you suspect that getting rid of the Ethernet would make the readings more accurate?

No, but whenever you run into an issue with a project, it is always best to isolate the issue as much as possible. Simplifying the test case makes debugging much easier - speaking from personal experience.

Lastly, please post your (simplified) code and results in tags (just saw you edited your post with results). Then we can see exactly what's going on.

yes-sir-memegenerator-net-yes-sir-obama-salute-meme-50128126.jpg

However, since the two LSBs are knocked off I expected rock solid measurements at ten bits. That is not the case.

Of course not.

Some points that need to be taken into account on analog measurements:

  1. After switching channels, read the channel twice and discard the first reading.

  2. Obey the input impedance restrictions: on many ADCs, 10K Ohms maximum. If higher, add a 10 nF capacitor from analog input to ground.

  3. Basic counting statistics: expect +/- sqrt(N) statistical error in a measurement of expected value N.

  4. Pots are noisy.

Get a scope to verify the quality of every analog signal. Only if the signal is as stable as required it's worth to start coding.

Hi,
Have you only now at this stage encountered the analog read problem, after all that coding?

Did you develop your code in stages so that you got each input and output working separately before combining your code?

Go back to where you just had the analog inputs coded, without any of the other stuff in your code.
If you don't then, in the meantime forget the code you have and write some code JUST for the analog inputs and serially print it to the IDE monitor.
Don't do any data conversion, just output the raw ADC data.

I understand the connections, and your test conditions are valid.
Have you got 0.1uF capacitors on each of the pot outputs to gnd, to bypass any noise?

Thanks.. Tom... :slight_smile:

What are the steps to add an attachment to a reply?
I pasted in the final results of the last run in 12 bit mode, but not the other runs and no code.

Replying to several posts:
I do not have an o’scope available.

Writing the code is not the problem. This is my first foray into Arduino territory but I can write code.

I see no need to get rid of the Ethernet interface. That is the configuration of my project so I like it that way. If you really don’t like it, please state specifically why.

The raw data, yes, that is right there, along with the averages and spread. No corrections have been applied.

A cleansing read before the measurement? Sure. I added code to do three reads before taking the actual measurements. And while at it, saved those reads just to see what they look like. Still not good.

Use 12 bit mode? Sure. The spread jumped way up to as high as 32 between the highest and lowest. That is five bits of bobble. That means accuracy is only about seven bits. Not good.

Capacitors? Sure. Now there is 0.47 uF ceramic capacitor across the pot from ground to 3.3 volts and another from ground to the output. Yes, two of them on each pot. Not much better. The worst spread from the highest reading to the lowest on the first pass was 35 counts. Again, only 7 bits of accuracy out of a 12 bit A/D

The results are disappointing. The accuracy and reputability should be much better. Still, with all the parts purchased, the project will continue.

But first, connect the digital temp sensors that were suggested and see what they turn up. I work during the day so that may take a bit.

Add 0.47 uF across the pot from the 3.3 volt to ground.
Add 0.47 uF across the pot from the center tap to ground.
Yes, two of them

 
 0   count  31.00   current 4086   lowest 4079.00   highest 4095.00   sum  126672.00   average 4086.19  spread   16.00   DISCARDS  0 93.00   lowest 4064.00   highest 4095.00   sum  380184.00   average 4088.00  spread   31.00
 1   count  31.00   current    0   lowest    0.00   highest    6.00   sum       6.00   average    0.19  spread    6.00   DISCARDS  1 93.00   lowest    0.00   highest   12.00   sum      28.00   average    0.30  spread   12.00
 2   count  31.00   current    0   lowest    0.00   highest    6.00   sum       9.00   average    0.29  spread    6.00   DISCARDS  2 93.00   lowest    0.00   highest   11.00   sum      57.00   average    0.61  spread   11.00
 3   count  31.00   current 4083   lowest 4069.00   highest 4095.00   sum  126632.00   average 4084.90  spread   26.00   DISCARDS  3 93.00   lowest 4067.00   highest 4095.00   sum  380131.00   average 4087.43  spread   28.00
 4   count  31.00   current   15   lowest    0.00   highest   15.00   sum      23.00   average    0.74  spread   15.00   DISCARDS  4 93.00   lowest    0.00   highest    8.00   sum      48.00   average    0.52  spread    8.00
 5   count  31.00   current    2   lowest    0.00   highest   19.00   sum      41.00   average    1.32  spread   19.00   DISCARDS  5 93.00   lowest    0.00   highest   21.00   sum      95.00   average    1.02  spread   21.00
 6   count  31.00   current 4068   lowest 4060.00   highest 4095.00   sum  126676.00   average 4086.32  spread   35.00   DISCARDS  6 93.00   lowest 4043.00   highest 4095.00   sum  379992.00   average 4085.94  spread   52.00
 7   count  31.00   current    0   lowest    0.00   highest    8.00   sum      35.00   average    1.13  spread    8.00   DISCARDS  7 93.00   lowest    0.00   highest   19.00   sum     143.00   average    1.54  spread   19.00
 8   count  31.00   current    0   lowest    0.00   highest   19.00   sum      92.00   average    2.97  spread   19.00   DISCARDS  8 93.00   lowest    0.00   highest   18.00   sum     210.00   average    2.26  spread   18.00
 9   count  31.00   current 4074   lowest 4066.00   highest 4095.00   sum  126780.00   average 4089.68  spread   29.00   DISCARDS  9 93.00   lowest 4064.00   highest 4064.00   sum  380174.00   average 4087.89  spread    0.00
10   count  31.00   current    0   lowest    0.00   highest   10.00   sum      20.00   average    0.65  spread   10.00   DISCARDS 10 93.00   lowest    0.00   highest   13.00   sum      90.00   average    0.97  spread   13.00
11   count  31.00   current   10   lowest    0.00   highest   12.00   sum      27.00   average    0.87  spread   12.00   DISCARDS 11 93.00   lowest    0.00   highest   13.00   sum     200.00   average    2.15  spread   13.00

This blog might help you:

One good trick with this kind of ADC is to have one input dedicated as a purging input. Connect it to ground through a small resistor (say 100 ohms) and sample that channel in between each channel you are interested in. This ensures that the S&H capacitor is purged of residual charge between readings. The resistor is important to reduce current flow, but you want it small enough that the capacitor discharges in a reasonable time.

Don't forget the reference voltage for a 12-bit DAC (maybe the hardest part). The reference voltage has to be stable to 0.0008volt (powering the board thru a USB cable is not a good idea because it's very unstable).

For a better reading, I wouldn't use analogRead() function. You can find example sketches for ADC conversions with ADC registers in the DUE sub forum.

How long are the wires to your pots and what might interfere with them?

You've been told that pots are noisy, maybe see if a resistor gives the same results?

Is anything affecting your reference voltage?

bkelly:
Writing the code is not the problem. This is my first foray into Arduino territory but I can write code.

If you supply code just to read the analog inputs and display your results, and the problem persists, then we can concentrate on the problem better.
Any modifications to your code will be easy as there will be less of it to work through.
At the moment your code is about 340 line long, we are only concerned with the analog input readings at the moment.
Thanks.. Tom.. :slight_smile:

bkelly:
I am working on a project that is to have multiple analog sensors. Initial observations indicate that the readings were more inconsistent that hoped for. The spreads for a series of 24 reads was in the range of 10 to 14 counts.

No analog sensors were installed, just the potentiometers to provide an adjustable and steady input.

Some web pages state that the DUE has a 12 bit D/A and that the default mode is 10 bits. Ok, ten is sufficient. However, since the two LSBs are knocked off I expected rock solid measurements at ten bits. That is not the case.

Yes, the analog sections of the Due chip are pretty awful, sparkle codes, much noise. And the DACs don't even
go rail-to-rail (and the DAC pins are extremely sensitive to damage).

Use an external SPI ADC if you want any kind of performance on the Due.

Power_Broker:
I... Yes Sir

How did you add the attachment in your reply?
I don't see anything in Chrome, and now in Edge to do that.

I re-wrote the code to use the console output. Because of the primitive print() statement it takes more code to print the output than to create it.

There is much to show. Ctl-S does not stop the scrolling. Is there any way to stop the output so I can look at it and maybe capture it with ctl-C?

Is there a print output that will put the cursor in a specified location so I can write all the outputs in a stationary place? Without any scrolling?

With the Ethernet interface, provided in the example program, that is referenced in the original code, that was already part of the scheme. Look back in post #7. That screen stays in one place and the numbers are updated. They don't move around. That is the effect I want.

GoForSmoke:
How long are the wires to your pots and what might interfere with them?

You've been told that pots are noisy, maybe see if a resistor gives the same results?

Is anything affecting your reference voltage?

The wires to the pots are about six inches long. Nothing in the circuit is longer than that. Everything is mounted on a metal plate for installation in an outside box. A ground plane that shields the hardware from the bottom.

There is a 0.47 ceramic cap across each pot from ground to 3.3 volts, and another from ground to the pot center connection. They are right next to the pots. I strongly suspect that is sufficient.

There is no explicit control of the reference voltage with the Arduino DUE.

The DUE is powered by a commercial power supply, not the USB connection. A voltmeter shows no bobble at all.

A Mega screw down board is plugged into the DUE and the Ethernet board plugged into that. This provides screw down connections to all the analog inputs.