Differential ADC (ADC1-ADC2)

What could be included in further releases, or for the forum.
User avatar
Pito
Posts: 1529
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Differential ADC (ADC1-ADC2)

Post by Pito » Sat Sep 16, 2017 10:25 am

Based on the topic on simultaneous conversion from ADC1 and ADC2 by jeremy777:
I've been thinking on using simultaneous ADC conversion from ADC1 and ADC2 to form a differential measurement - hoping to cancel the common mode noise (which is huge on MapleMini clones and BluePills). Perhaps the above code could be modified (or there is a library already) to work that way..
For example one shot measurement from ADC1 & ADC2 simultaneously and then do ADC1 - ADC2..
Something like this - ie. (maybe a core enhancement?)

Code: Select all

int32_t readAnalog(PIN_U1, PIN_U2); 
returns the U1 - U2 difference. With simultaneous ADC conversion (the ADC1 samples in exactly same time as the ADC2 does) the common noise voltage cancels (because we do u1 - u2).
.
Diff 2xADC simult.JPG
Diff 2xADC simult.JPG (22.55 KiB) Viewed 296 times
Last edited by Pito on Sun Sep 17, 2017 11:34 am, edited 2 times in total.
Pukao Hats Cleaning Services Ltd.

stevestrong
Posts: 1609
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Differential ADC (ADC1-ADC2)

Post by stevestrong » Sat Sep 16, 2017 4:22 pm

Pito wrote:
Sat Sep 16, 2017 10:25 am
With simultaneous ADC conversion (the ADC1 samples in the exactly same time as the ADC2 does) the common noise voltage cancels (because we do u1 - u2).
... theoretically. But it did not work for me, I tried that a half a year ago, still got sporadically some differential noise.
Maybe due to unequal noise on GND or Vcc between ADC1 and 2.

User avatar
Pito
Posts: 1529
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Differential ADC (ADC1-ADC2)

Post by Pito » Sat Sep 16, 2017 6:15 pm

How was the difference noise?
Pukao Hats Cleaning Services Ltd.

User avatar
ahull
Posts: 1597
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Differential ADC (ADC1-ADC2)

Post by ahull » Sat Sep 16, 2017 7:53 pm

I wonder how "white/pink" the noise is. Given that most of it is likely to originate from the digital domain I suspect it pretty non-linear, and it may be possible to suppress it to some degree if we know what sort of spectrum it has.
- Andy Hull -

User avatar
Pito
Posts: 1529
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Differential ADC (ADC1-ADC2)

Post by Pito » Sat Sep 16, 2017 8:37 pm

I've spent a night reading posts (various forums) on STM32F1/2/4 ADCs problems.

There are 2 groups of people up there:
A. they say the STM32 silicon re ADC is sub-optimal, and the worse among others
B. they say the STM32 silicon is ok, but the PCB layouts used are mostly a crap (including commercial dev boards like discovery/nucleo etc).

A guy with a serious project - UPDATE the link https://community.st.com/thread/19850 and the pictures https://electronics.stackexchange.com/q ... dc-noise-2 - elaborated pcbs (2 layers) with all the tricks with no success. The people involved into the discussion indicated both A and B positions. Then he finally accepted the B position and draw a 4 layer one (with separate gnds for analog and digital, dgnds and agnds connected together in a single point - at the agnd pin, no crossing of digital and analog tracks, etc). And he concluded at the end "the noise is gone" (unfortunately without any numbers, so take it or leave it..).

I tend currently to be in the group B, therefore my current naive understanding is it could be the ADC silicon works as advertised, therefore the differential scheme could work.

The noise coming from the ADC on our boards is not white/pink but it is a "digital" noise coming from poor grounding and pcb layout.
Noise suppression via averaging/digital filtering etc. is a workaround only..
Pukao Hats Cleaning Services Ltd.

User avatar
mrburnette
Posts: 1803
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Differential ADC (ADC1-ADC2)

Post by mrburnette » Sun Sep 17, 2017 10:02 pm

Recall that the official Maple mini had separate analog and digital ground planes.
Baite (&others) went cloning with a dual-sided board ... hence the increased analog noise.

Ray

ag123
Posts: 740
Joined: Thu Jul 21, 2016 4:24 pm

Re: Differential ADC (ADC1-ADC2)

Post by ag123 » Thu Sep 21, 2017 1:40 pm

oh well, i actually messed with this:
https://www.sparkfun.com/products/12650
and of course there are cheaper 'knock offs' from here:
https://www.ebay.com/sch/i.html?_from=R ... 32&_sop=15
(think the 'cheap' ones may not be as safe it's good to measure the resistances of the smd resistors and measure voltages, currents esp the probes)
that design supposedly does 'right leg drive' with an intent of removing common mode noise, i'd guess part of that may be that 50/60 hz hum
https://en.wikipedia.org/wiki/Driven_right_leg_circuit
but simply sitting near an ac source e.g. a switch mode usb charger, pc, etc is adequate to induce visible 50/60 hz noise mixing up with ECG signals (1mv average) the sparkfun's breakout actually use the ad8232 for a low pass filter set at 40 hz cutoff, nevertheless hum is visible.
then i simply have do a software FIR filter to remove the rest of that hum.

my thoughts are that different resistances from the lead wires is sufficient to cause differences that they couldn't be simply removed as 'common mode noise'

an oh btw that sparkfun ad8232 breakout is pretty good as an analog front end for ecg paired with MM/BP
http://www.analog.com/en/products/appli ... d8232.html
it removes a dc bias common in ecg meaaurements, removes baseline drift to an extent and centers the ecg around 1.5v out of 3v, amplifies that 1100 times based on sparkfun's breakout and analog's sample design,
then use an op amp in there to do an analog 40 hz cutoff low pass filter
that output can be simply plotted on an ili9341 with hardly any additional processing

that result is somewhat like this
https://github.com/sylvainf/stm32-ecg
but interfacing is a lot simplified with the ad8232 breakout, it is simply analogread and just plot that
however, i noted various artefacts which seem to be caused by the ad8232 itself, sometimes there are periodic spikes which i'm not too certain if it is introduced by the ad8232 or true ecg signals

just 2 c

ag123
Posts: 740
Joined: Thu Jul 21, 2016 4:24 pm

Re: Differential ADC (ADC1-ADC2)

Post by ag123 » Thu Sep 21, 2017 2:25 pm

thinking through this it would seem this differential adc could help remove some of that common mode noise, i could feed that ad8232 output into 2 ADCs and perhaps it may remove some of that artefact spikes :?

User avatar
Pito
Posts: 1529
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Differential ADC (ADC1-ADC2)

Post by Pito » Thu Sep 21, 2017 2:25 pm

I run an ADS1110 (not in differential mode, -Vin at GND) on the same breadboard as the BPill + all the other stuff.
When I connect +Vin to a resistor divider 3k6/3k6 (divider from Vcc to GND, not blocked) to get 1.65V as the ADS1110 is max 2.048V, with 12cm long wire, and -Vin to GND (12cm wire and gnd) the ADS shows +/-1 reading (on 15bit resolution). The BPill's 12bit ADC reads +/-30.
Yes, I know the ADS is fully different ADC (16bit, sigma-delta, 15meas/sec - sloow) but..
Pukao Hats Cleaning Services Ltd.

ag123
Posts: 740
Joined: Thu Jul 21, 2016 4:24 pm

Re: Differential ADC (ADC1-ADC2)

Post by ag123 » Fri Sep 22, 2017 12:17 am

on this topic about noise, in part as i use low pass filtering, i've inherently 'escaped' some of the noise issues.
ecg signals are in the low orders of 5 hz - 40 hz (accordingly the range do extend upwards to say 50hz or somewhat more but of low amplitude), nevertheless low pass filtering set at 40 hz cut off removed some of the ecg signals and the ecg is less accurate.
however, as my aim is to capture between 5hz - 60hz range, i sampled at 150 sampl per secs and digitally low pass (FIR) filtered that with a 40 hz cutoff, my guess is that the low sampling rates and low pass filter removed quite a fraction of common mode or differential high frequency noises

but if you have to sample in the mhz (msps) ranges i'd think it would be difficult to remove noise this way and other means such as differential filtering or differential adc would likely matter significantly

Post Reply