PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33
Started by TimB, Dec 23, 2021, 10:26 AM
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.
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.
Device = 18F4553Config_Start 'Config_End Declare Xtal = 48 Declare Adin_Res = 12 '12 bit ADCDeclare Adin_Tad = 64_FOSCDeclare Adin_Stime = 30 '30us sampling timeDim dw_ADC_accumulator As DwordDim dw_ADC_result As DwordDim i As Word Main: ' Set ADC and analog inputs, VREF etc ' Analog sensor is connected at ADIn 0 GoSub ADC EndADC: 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 Next dw_ADC_result = dw_ADC_accumulator >> 8 'Decimate 2^5 and divide by 8 same as 8 bits right shiftReturn