How Oversampling Demo Application Works

In the example source code provided, ADC conversion is done in the functions ‘process_single_sampled()’ and ‘process_oversampled()’. For comparison, both oversampled and normal ADC results are sent through USART to the serial terminal. Measured analog input voltage (in volt) is displayed.

In the function ‘process_single_sampled()’, the ADC sample accumulator has been configured to 1. The ADC result of only one sample is read. No oversampling is done here.

The function ‘process_oversampled()’ demonstrates how the oversampling is done and resolution has been increased from 10 to 12 bits. In the function ‘process_oversampled()’, to get a 12-bit resolution from the 10-bit ADC it is required to read 16 ADC samples and then right shift the sum of the ADC results by 2 (i.e. divide by 4).

To increase the resolution, for each additional bit of ADC resolution, n, the signal must be oversampled 4n. To achieve 12-bit ADC, you need an additional 2-bit resolution. Hence, the signal has to be sampled 42, i.e. 16 times more samples. The ADC has a configurable accumulator setting. This accumulator is configured to do 16 samples. The result in the ADC result register will then be the sum of the 16 samples. The scale factor, sf, is given by sf = 2n. The scale factor is the number the result may be divided by to scale the result to the desired bit width. In this example, the result is increased by two bits. Hence, the scale factor is 22 = 4. So the result may be divided by 4 or a right shift of 2 can be performed.

In both the ‘process_single_sampled()’ and ‘process_oversampled()’ functions, the ADC result is read and the measured voltage has been converted to a string using the standard library function ‘dtostrf’ and this measured analog input voltage (in volt) has been sent through USART to the serial terminal of the PC every 1 second.