Electronic – arduino – Does the arduino (ATMEGA328P) ADC really only sample periodically

adcarduino

I have been experimenting with the Arduino's ADC, and I have noticed some bizarre behaviour. I am wondering if it is normal, or if this is something specific (and bad) about the Atmel ATMEGA328P that the Uno is based around.

Basically, it would appear that the input value on the ADC is sampled at a lower rate than the ADC is actually returning values for:

enter image description here

In this image you can see the sampled input running at full speed connected to a simple pot. As the pot is swept from full to minimum the input voltage drops. As you can see the returned values from the ADC come in steps, where it returns the same (or similar) value for multiple calls to analogRead(), before then dropping down sharply.

What is actually going on here? Is the ADC input running at a different speed to the data output? Is the Arduino code reading the ADC wrong?

I have tried playing with the ADC pre-scaler, and no matter what I set it to (apart from 1:2 or 1:4, where it dies completely) it reads in steps like this.

Edit

It takes about 32 successive ADC reads for the steps to completely disappear.

Best Answer

DAC error? : You say the scope trace is displaying the Arduino's ADC input values BUT you are apparently displaying an analog signal. I assume there is a DAC of some sort in the process to convert the ADC readings back to analog.
The trace gives the appearance of a DAC with a massive error in a mid level bit. eg address bit A2 of the DAC may have a resistor value that is say 10 times too small.

Test: Turn the pot VERY slowly, do the gross steps vanish?
ie do you get a smoothly descending level.
If the level steps down like that at any sweep speed you probably have a bit based error post ADC.
Or, just possibly a microcontroller with a bit error in the IC's DAC hardware (less likely) .


ADC speed: Failing the above -

General web feel is that you can do better than what you are seeing.
If that pot sweep is in say 0.1 second then your gross step rate is about 10 mS.
HOWEVER- there seem to be small declining steps on your waveform - perhaops 10 per gross step, for a ministep of say 1 mS.
Even that is longer than you'd reasonably expect.

This discussion suggests 10's f kHz. - 77 kHz is mentioned.

Arduino based scope gives an idea of speed expected.

Energy monitor using ADC again, a guide.

Useful