ST AN2668 Application note

AN2668

Application note

Improving STM32F101xx and STM32F103xx

ADC resolution by oversampling

Introduction

The STMicroelectronics Mediumand High-density STM32F101xx and STM32F103xx Cortex™-M3 based microcontrollers come with 12-bit enhanced ADC sampling with a rate up to Msamples/s. In most applications, this resolution is sufficient, but in some cases where higher accuracy is required, the concept of oversampling and decimating the input signal can be implemented to save the use of an external ADC solution and to reduce the application consumption.

This application note gives two methods to improve ADC resolution. These techniques are based on the same principle: oversampling the input signal with the maximum 1 MHz ADC capability and decimating the input signal to enhance its resolution.

The method and the firmware given within this application note apply to both Mediumand High-density STM32F10xxx products. Some specific hints are given at the end of the application note to take advantage of the Mediumand High-density STM32F103xx performance line devices and of the High-density STM32F101xx access line devices.

This application note is split into two main parts: the first one describes how oversampling increases the ADC-specified resolution while the second describes the guidelines to implement the different methods available and gives the firmware flowchart of their implementation on the STM32F101xx and STM32F103xx devices.

July 2008

Rev 1

1/21

www.st.com

Contents

AN2668

 

 

Contents

1

Definition of ADC signal-to-noise ratio . . . . . . . . . . . . . . . . . . . . . . . . . .

4

2

Nyquist theorem and oversampling . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

3

Oversampling using white noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

 

3.1

SNR of oversampled signal with white input noise . . . . . . . . . . . . . . . . . . .

6

 

3.2

Decimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

 

3.3

When is this method efficient? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

 

3.4

Method implementation on the STM32F10xxx devices . . . . . . . . . . . . . . .

8

3.4.1 Oversampling using a white noise firmware flowchart . . . . . . . . . . . . . . . 9 3.4.2 Oversampling using white noise result evaluation . . . . . . . . . . . . . . . . . 10

4

Oversampling using triangular dither . . . . . . . . . . . . . . . . . . . . . . . . . .

12

 

4.1

When does this method work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

12

 

4.2

Method implementation on STM32F10xxx devices . . . . . . . . . . . . . . . . .

13

5

Comparing the first and second methods . . . . . . . . . . . . . . . . . . . . . .

15

6

Hints

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

16

 

6.1

What is the maximum number of bits that can be added to

 

 

 

the on-chip ADC resolution? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

16

 

6.2

Taking advantage of High-density STM32F10xxx devices . . . . . . . . . . . .

16

6.3Taking advantage of the Mediumand High-density performance line (STM32F103xx) devices 17

Appendix A Quantization error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

2/21

AN2668

List of figures

 

 

List of figures

Figure 1. Oversampling effect on the quantization noise. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Figure 2. Histogram analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Figure 3. Histogram analysis for DC = 1.65 V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Figure 4. Oversampling using a white noise flowchart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Figure 5. Ramp samples with 1 additional bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 6. Ramp samples with 2 additional bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 7. How to perform oversampling by adding a triangular signal . . . . . . . . . . . . . . . . . . . . . . . 12 Figure 8. Hardware requirements of oversampling by adding a triangular signal . . . . . . . . . . . . . . . 13 Figure 9. Oversampling using triangular dither flowchart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Figure 10. Oversampling effect on the quantization error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

3/21

Definition of ADC signal-to-noise ratio

AN2668

 

 

1 Definition of ADC signal-to-noise ratio

The ADC gives a representation of an analog signal among a finite number of digital words. Since the digital domain is represented by a finite number of words which have to present a continuous signal, the conversion step introduces the quantization error function of the ADC input range and resolution.

For an ideal ADC, the quantization error is between ±0.5 LSB. In the case where the input signal is varying through many levels between samples, and the sampling rate is not synchronized with the input frequency, the quantization error can be considered as a white noise whose energy is uniformly spread from the DC domain to half of the sampling frequency. Please refer to Appendix A for more details regarding the calculation of its density.

The SNR (signal-to-noise ratio) is the ratio of the ADC noise to the input signal power. For an ideal ADC, it is assumed that the SNR is equal to the quantization noise (no other noise source is considered) to the input signal. It is demonstrated that for a full-scale sinusoidal signal, the ADC SNR is maximum and given by the following formula:

SNRdB = 6.02N + 1.76 , where N is the ADC resolution.

It is can be easily noticed that when the SNR increases, the ADC effective number of bits increases.

For a real ADC, different error sources should be considered: offset, gain, INL (integral nonlinear) and DNL (differential nonlinear). A brief description of these errors can be found in the STM32F101xx and STM32F103xx datasheets. They degrade the ideal ADC resolution. In this case, we speak of real effective number of bits.

Improving the SNR involves an enhancement of the ADC effective number of bits.

The following section demonstrates that sampling the input signal with higher rates than the Nyquist frequency improves the SNR. The Nyquist frequency is introduced in the next paragraph.

4/21

AN2668

Nyquist theorem and oversampling

 

 

2 Nyquist theorem and oversampling

The Nyquist theorem states that in order to be able to reconstruct the analog input signal, the signal should be sampled at a rate fS (sampling frequency) that is greater than twice the maximum frequency component of the input signal.

Not respecting the Nyquist theorem causes aliasing effects and the analog signal cannot be fully reconstructed from the input samples. Therefore, in most applications, a low-pass filter is required at the ADC input to filter frequencies lower than half the sampling frequency. It is difficult to handle the filter constraints with low sampling frequencies.

Oversampling consists in sampling the input analog signal at rates higher than the Nyquist frequency limit, filtering the samples and reducing the sample rate by decimation. Using this method relaxes the anti-aliasing low-pass filter constraints.

5/21

ST AN2668 Application note

Oversampling using white noise

AN2668

 

 

3 Oversampling using white noise

3.1SNR of oversampled signal with white input noise

Let us assume that the quantization noise is assimilated to white noise. Then its power density is uniformly distributed between DC and half the Nyquist frequency. This power density is independent of the sampling frequency.

When sampling at higher rates, the quantization noise is spread over the bandwidth of the sampling frequency.

Figure 1. Oversampling effect on the quantization noise

PSD

PSD

 

 

 

Same area

-2.fm

- fm

fm

F

fS = 2.fm

Input signal

 

 

 

 

Quantization error

 

 

 

 

PSD = Power signal density

-2.N.f

m

- f

f

f = 2.N.f

F

 

m

m

S

m

ai14937

According to Figure 1, when sampling the input signal at higher rates, the same noise power, represented by the area of the green rectangle, is spread over a bandwidth equal to the sampling frequency which is much greater than the signal bandwidth fm. Only a relatively small fraction of the total noise power falls in the [–fm, fm] band, and the noise power outside the signal band can be greatly attenuated with a digital low-pass filter.

Reducing the quantization noise enhances the signal-to-noise ratio and, consequently, the ADC effective number of bits. Oversampling the input signal OSR times faster than the Nyquist frequency gives the following SNR

SNROVS = 6.02 N + 1.76 + 10log(OSR)

It can be concluded that each doubling of the sampling frequency will lower the in-band noise by 3 dB, and increase the measurement resolution by 1/2 bit. Therefore, 6dB SNR gain is required to add 1 resolution bit to the ADC.

In general, if p additional bits are required by the application then, the ADC sampling frequency should be at least:

FOVS = 4pFS , where FS is the current ADC sampling frequency used.

3.2Decimation

The conventional meaning of averaging is adding m samples and dividing the result by m. Averaging several data from an ADC measurement is equivalent to a low-pass filter which attenuates the signal fluctuation and noise. The average method is often used to smooth and remove speaks from the input signal.

Note that normal averaging does not increase the resolution of the conversion because the sum of m N-bit samples divided per m is an N-bit representation of the sample.

6/21

AN2668

Oversampling using white noise

 

 

Decimation is an averaging method. When combined with oversampling, decimation improves the ADC resolution.

In fact, adding 4p ADC N-bit samples, gives a representation of the signal on N+2p bits. In order to have p additional effective bits, the sum is shifted to the right by p bits.

This FIR filter with equal filter coefficients enables the user to filter the oversampling frequency by giving an output sample computed from the OSR input samples.

The oversampling method limits the maximum input frequency bandwidth. In fact, in the case of the STM32F10xxx, signals having components up to 500 kHz can be processed by the ADC. If for example, two additional resolution bits are required, then the maximum input frequency that can be entered is 500 kHz/16 = 31.25 kHz when oversampling using white noise.

3.3When is this method efficient?

For the oversampling and decimating method to work properly, the following requirements must be satisfied:

There should be some noise in the input signal. This noise must approximate white noise with a uniform power spectral density over the frequency band of interest.

The noise amplitude must be sufficient to toggle the input signal randomly from sample to sample by an amount of at least 1 LSB. Otherwise, the input samples would have the same representation and the sum and average operations would not give any extra resolution. In most applications, the internal ADC thermal noise and the input signal noise are sufficient to use this method. In the case where the thermal noise does not have a high-enough amplitude to toggle the input signal randomly, then artificial white noise should be injected into the input signal. This operation is referred to as “dithering”. Regarding this point, two questions can be raised. The first is “How to evaluate the ADC noise and test its Gaussian criteria?” and “How to generate white noise if needed?”

A practical way of detecting the Gaussian criteria of the input signal noise is to see the distribution of a clean DC signal over the ADC codes. The histogram method can be used to verify if the input noise follows a Gaussian distribution. The example in Figure 2 shows two possible situations.

7/21

Loading...
+ 14 hidden pages