PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Does oversampling a ADC to get more digits really work?

Started by TimB, Dec 23, 2021, 10:26 AM

Previous topic - Next topic


Hello all

I want to use a pic14/14k50 for its low cost, low pin count/size and USB. The issue is that it has a 10 bit ADC. I want to get the temperature from a device like this device the LMT70. In the data sheet it recommends as 12bit ADC. Now it will change temp in use very slowly and I do not need a high refresh rate so was thinking of using oversampling on the pics 10bit ADC  rather than a seperate 12bit ADC.

The question is, will it work? When I look up oversampling the first part is obvious you sample say 100 x and div by 50. But they also say that it relies on there being noise in the signal.

What do you people think? Will it work?

Thanks Tim


If you consider it as Carrier over Noise then oversampling is typically averaging of the noise floor which in theory improves the C/N.  Here is a paper on it


It looks like the output of the LMT70 is roughly 5mV/degC.
That's in the ballpark range of 1 lsb of the ADC, depending on the Vref.

Considering the K50 ADC specs, I would think you'd be lucky to get it accurate to within several degrees.


Hi tumbleweed

Thanks, that's made the decision for me.



I've done oversampling quite a few times in the past from A to D and from D to A, and they work extremely well. The actual noise of the ADC itself acts as the random noise sometimes needed for oversampling.


Quote from: TimB on Dec 23, 2021, 10:26 AMThe question is, will it work? When I look up oversampling the first part is obvious you sample say 100 x and div by 50. But they also say that it relies on there being noise in the signal.

Tim it works, the math theory behind it is impeccable, practically all sensors are using it to some extend. The extreme case are the Delta-sigma ADCs which use 1-bit modulation.

But slightly different - for each n-bits increase in resolution you need to accumulate (sum in a variable) 4^n samples and divide (right shift) by 2^n.

Thus increasing the resolution from 10bits to say 13bis will require summation of 4^3=64 samples and right shift by 3 of the sum which is the equivalent of division of 2^3=8.

The only requirement is that the noise of your system is above the ADC threshold (10bits in your case). This means that if your system is very stable and outputs only say value 789 -you can not use it to increase the resolution because there is no uncertainty to be "separated" between value "bins". 

As Les said the noise in the PIC ADC is sufficient - but if it is not I simply decrease the sampling time from say 40us to 20us to make the system more unstable and it works.

I used the oversampling technique before for analog barometric pressure sensors to achieve altitude (high) measurement with resolution of few centimeters by using 12bit ADC.



I think I need to buy a test board and see what results I get



I still remember creating a Delta-sigma ADC on my tiny ZX81 computer back in the early 1980s, via its mic in socket, used for the cassette input, and the output socket for a PWM DAC, so it would record/playback very short audio within its 16K RAM, and I created a digital echo and chorus. :-) At the time, I thought I had created magic because I had only read about it in theory, because it was used in CDROM players, then I got it working in Z80 assembler code after quite a few hours of play... Sorry... Work. :-) Back then ADC chips and DAC chips were crazy expensive and needed external clocks and negative voltages and all sorts of gubbins for them to work!

The fun of learning new things should never leave us.


not taking this thread off topic but Z81, I worked so hard to get this computer.  paper round, Milk round, bottling up in Pubs etc.  When it arrived OMG game changer.  Many yrs later we did the final design on the z88 but too late as IBM were growing fast.  Company dissolved and 3I investors took it over and we were working on set top boxes then for Amstrad (AS) so the z88 fell to wayside.  I saw the posts with Charlie and Les and it brought the old memories back, i joined at 21 and it was like walking into a ball of fire with engineering.  Happy days


Interesting topic.

@trastikata I used an MS5611 to get  measurement with resolution of few centimeters, but never managed, and gave up as I never had stable readings.

So it looks that oversampling could cure the problem. I would like to see a working math example of oversampling perhaps I try it.




Quote from: joesaliba on Dec 24, 2021, 09:21 AMSo it looks that oversampling could cure the problem. I would like to see a working math example of oversampling perhaps I try it.

MS5611 is a digital sensor and digital sensor tend to be noisy from the digital logic inside and by itself from the fact that most use D-S ADCs.

Thus for further noise reduction, the only option you have with digital sensors, is digital Low pass filtering - simplest is averaging, however you are limited by the sampling rate of the sensor itself.

That's why I used analog barometric pressure sensor, namely MPXHZ6116A. The sensor was powered by a 5v reference IC and the output was filtered with low-pass R-C filter with large time constant. Effectively reducing the noise but increasing the response time, which was not of importance in the case.

Oversampling by itself only slightly increases the SNR ratio by spreading the noise in different bins and won't help you much with noise in digital sensors.   

PIC ADC is 12 bit resolution
Approximately altitude resolution at sea level calculated in Excel spreadsheet for different resolutions (barometric formula is not linear function):
12b = 231 cm/bit
13b = 115 cm/bit
14b = 57 cm/bit
15b = 28 cm/bit
16b = 14 cm/bit
17b = 7 cm/bit

Ok, 7 cm/bit is good enough for me. So I need to increase the ADC resolution from 12 to 17 bits - thus 5 bits increase. Therefore I have to accumulate 4^5=1024 samples and then decimate by 2^5=32.

1024 samples at 30us each gives me about 30 ms total sampling time - plenty enough for extra, so I will average 8 such 17bit results to further noise reduction. How long it will take - 8*1024*30us = about 0.3 seconds.

Sounds complicated but it is not - all I need is to add 8*1024=8192 samples in a Dword variable. But then decimation by 32 and averaging by 8 - nothing simpler, remember n bit right shift equals division by 2^n. Thus all I need to do is shift my result 5 times to the right, which is division by 32 and another 3 bits right shift to divide by 8 - so my total number of bits I have to shift to the right is 8:

Device = 18F4553


Declare Xtal = 48
Declare Adin_Res = 12                                       '12 bit ADC
Declare Adin_Tad = 64_FOSC
Declare Adin_Stime = 30                                     '30us sampling time

Dim dw_ADC_accumulator As Dword
Dim dw_ADC_result As Dword
Dim i As Word
    ' Set ADC and analog inputs, VREF etc
    ' Analog sensor is connected at ADIn 0
    GoSub ADC


    dw_ADC_accumulator = 0                                  'reset accumulator
                                                            'Increase resolution to 17 bits and average 8x
    For i = 0 UpTo 8191                                     'Accumulate 8*(4^5)=8192 samples
        dw_ADC_accumulator = dw_ADC_accumulator + ADIn 0    'Time it takes is 8192*0.035ms = ~0.3 sec
    dw_ADC_result = dw_ADC_accumulator >> 8                 'Decimate 2^5 and divide by 8 same as 8 bits right shift



Thanks for your detailed answer, much appreciated.