Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

ADC successive reading wrong 1 out of 2

The Expander Pi is an Analogue, Digital and RTC development Interface for the Raspberry Pi

20/05/2020

Posted by:
spacinover

spacinover Avatar

Hi,

I am using the RPI3+expander Pi ADC to read 2 analog voltage coming from another RPI3+expander Pi DAC used as a simulator. To make sure that the analog signal is smooth I have a RC filter (470ohm + 22µF) on each line. All is written in Python3.7

In most conditions I have a stable readout of the voltage with

adc = ExpanderPi.ADC()

adc.set_adc_refvoltage(4.096)

VB = adc.read_adc_voltage(1,0)

VT = adc.read_adc_voltage(2,0)

But in part off the program I call VB and VT is succession to time stamp the values and evolution (it is a pseudo real time controller) and I get for example

VB=0.405V which is OK but next readout 4ms later gives: VB = 0.283V which is wrong . 4ms later another sample readout gives 0.438V again OK followed 4ms later by 0.318V wrong again!

Statitsics shows about 110 to 120mV difference between successive reading.

Any hint at what could cause such behaviour?

20/05/2020

Posted by:
andrew

andrew Avatar

Hi Robert
There are a few things you can try to improve the ADC performance.

First, check that there is a good ground connection between the two Expander Pis.

Have you checked the output from the DAC to make sure it is stable? If the power supply for the Raspberry Pi is noisy or the voltage is dropping for some reason that could create instability in the DAC output.

Similarly, if the power supply for the ADC is unstable that could cause errors in the measurements.

One other thing you could try is to reduce the SPI speed for the ADC chip which can improve its performance. In the Expander Pi python library on line 108, you can set the clock speed; it should be set at 200KHz. Try a speed of 100KHz and see if that makes any difference.

21/05/2020

Posted by:
spacinover

spacinover Avatar

Quote from andrew
Hi Robert There are a few things you can try to improve the ADC performance....

Thank you Andrew for the tips.

I already identified the ground issue between the 2 Pi Expanders, gained some 50mV.

I add on pin8 a readout of 5V at Expander header (through divider 1.2k-1.2k) and there I see some 0 +58mV fluctuation which is surprising as my RPI is fed via buck converters from 12V.

I will sniff voltage stability here with a scope and see to reducing clock speed.

22/05/2020

Posted by:
spacinover

spacinover Avatar

Andrew,

I looked in the ExpanderPi.py (no version date in file which I downloaded about 2 years ago) and in class ADC I found :

# Define SPI bus and init
__spiADC = spidev.SpiDev()
__spiADC.open(0, 0)
__spiADC.max_speed_hz = (1900000)
Looks to me that line 102 set the spi bus to 1.9MHz, a bit more than the 200kHz you mentionned.

For the DAC spi speed seems set to 20 MHz ! ( spiDAC.max_speed_hz = (20000000) )

IO class I could not find a spi speed ?

Is that normal? should I modify them to (200000) to start with?

22/05/2020

Posted by:
andrew

andrew Avatar

Hi Robert

Try changing the __spiADC.max_speed_hz = (1900000) to __spiADC.max_speed_hz = (200000)

The DAC should be ok at 20MHz.

I changed the speed of the ADC down to 200KHz as the ADC does sometimes give incorrect readings if the clock rate is too fast.

11/06/2020

Posted by:
spacinover

spacinover Avatar

Hi Andrew,

I changed the filtering on the supply of the voltage to be read together with cleaning my ground network and gained 100mV noise.

I tried ADC clock speed change, the 200 kHz is as good as 100 kHz: no difference. I still have some readout noise of the order of 20 mV. I guess I will have to live with that.

I also tried reading twice the ADC to average on 2 reading. It gained a bit but not as much as SQRT(2) as I would have expected.

I am not clear about is how long does it takes to get the data after a call to read the ADC?

11/06/2020

Posted by:
andrew

andrew Avatar

Hi Robert

The time it takes to get the data depends on the programming language you are using, the model of Raspberry Pi and any other running processes that are taking up CPU time.

To give you an example on my Raspberry Pi 3+ using a 200KHz clock rate and Python 2.7 I get a sample rate of around 4400 samples per second which means it will take 0.23 milliseconds to read a single sample. Using Python 3.7.3 the sample rate is slightly slower at 4200 samples per second so it will take 0.23 milliseconds per sample.

Using our C library with the clock rate set to 200KHz the sample rate increases to 5500 samples per second or 0.18 milliseconds per sample.

You can increase the sample rate by increasing the clock speed but then it becomes a compromise between ADC accuracy and sample rate.

In our Python library demos folder, there is a demo_adcspeed.py which you can use to test the sample rate on your Raspberry Pi. Most of the Expander Pi libraries in our GitHub repository, for the various languages that we support, will have similar ADC speed test demos which can be used to compare the performance of each language.

26/06/2020

Posted by:
spacinover

spacinover Avatar

Thanks Andrew for the informations.

I use Python 3.7 on a Rpi-3B, and 4000 sps is good enought for my application as the rest of the computations runs on few ms cycle.

I was interested in the sample rate mainly to determine what physical filter I can put in front of the ADC to limit the bandwidth in order to avoid spectrum folding and to reduce readout noise by averaging.

So far I had typically 1kohm+100nF filter close to ADC input, I can increase the capacitor to 470nF and read more samples to average out the noise.

Sign in to post your reply


Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.

Home

Shop

Learn

Forum

FAQ

Contact

0 item

Your cart is empty

Please browse our shop to order from the wide range of Raspberry Pi boards and accessories.

Subtotal:£0.00
View Basket Continue to Checkout