Measurement of AVR ADC analog bandwidth + Equivalent Time Sampling >>>> WARNING: very poor translation!!! <<<<
Few weeks ago I was working on simple AVR PWM channel driven switch mode power supply that involved measurement of true-RMS current. Measured signal was steady and periodical with frequency around 40 kHz but it had very funky shape. At first I though about using some analog true-rms detector IC but than I said myself why not to use AVR ADC to sample the waveform directly? Although it has sampling rate limited to 15 kS/s for maximum resolution, its analog bandwidth is probably much higher because it contains no antialiasing filter. Normally, in real-time sampling mode, this ADC would be able to capture my waveform only with frequency less than some 500 Hz with reasonable time resolution for true-rms calculation. But fortunately there are several techniques how to sample signal with frequency components above Nyquist frequency. These techniques are often called Equivalent Time Sampling mode (ETS). Following text describes implementation of ETS with AVR ADC and measurement of its actual analog bandwidth which is not specified by ATMEL. 1. Equivalent Time Sampling
As mentioned the ETS is sampling technique that allows sampling of repetitive waveforms with frequency components above Nyquist frequency (fs/2).
It was very popular in older Digital Storage Oscilloscopes (DSO) because fast ADC's were very expensive back than.
Today it's mostly used only in toys like PicoScope and similars or in very fast DSO's where realtime sampling is simply impossible. Interesting fact is that
these methods are at least partially applicable for analog scopes too (sampling oscilloscopes).
Upper graph shows original waveform with fund. frequency f and the sampling intervals. The sampling rate fs is set exactly with ratio r = 20/(1+20) relative to f so every
new acquired sample is delayed by 1/20 of waveform period T more then the former one. After 20 samples the sample delay relative to the waveform period start is again exactly zero so I have one full period acquired.
The lower graph shows several periods composed of the acquired samples. The reconstructed signal has time magnification of 20 and equivalent sampling
rate (20+1) times higher than realtime sampling rate fs. In this particular case the ratio r was chosen so the samples comes already in order so it's not even necessary to reorder them. This ratio
also ensures that I have integer count of samples per period of the waveform so I don't even need synchronization because the alias will be static if it is captured continuously.
The last column in tab. 1.1 shows the position of the sample within waveform period. If reasonable ratio is chosen and enough samples are acquired this parameter can be used to reorder the samples within the reconstructed period. In case improper ratio is chosen (or it's not possible to set it) or small samples count is available then there might be "holes" in the reconstructed period for higher time magnifications and it will be necessary to use interpolation. Realization of this method is shown in fig. 1.2.
The waveform shown in the picture is export from my older experimental DSO. The realtime sampling rate is only 32 MS/s, sample memory depth is only 4 kS but even though it was possible to reconstruct the waveform with equivalent sampling rate 1.6 GS/s (which is 50x time magnification) and only few samples are missing (the steps in the waveform) so no interpolation was used. On the other hand the hardware wasn't designed for this mode of sampling so I have almost no control over sampling rate, only discrete steps 1-2-5 which is useless here. Result is that some signals with frequency close to some fractions of sampling rate can't be reconstructed as shown in fig 1.3.
Even if the ratio r wasn't exactly x.0000 the fractional part was too close to 0 so the 4 kS/s weren't enough to get samples with all needed delays to reconstruct full period. This is exactly the case where interpolation can help but it of course only smoothes the waveform without any details.
Fortunately in case of my AVR based switch mode PSU I have full control over the ratio. Although the 16-bit timer
offers only limited frequency resolution it is enough for the application and for some timer periods static aliases with integer sample count appears.
Sometimes simple reordering is needed but it is necessary only for displaying the waveform because true-rms calculation is not dependent on order of the samples. It is
only important to have as many evenly displaced samples as possible within the waveform period. To find possible ratios I've made a simple script for Matlab/GNU Octave (link below).
In the script it is necessary to setup AVR clock frequency, ADC setup (defaultly free-running mode) and desired range of
timer output frequencies. The script then scans all possible timer OCR register setups and displays values that will produce alias with integer sample count per waveform period.
Detailed description can be found in the script itself. 2. Measurement of AVR ADC analog bandwidth With debugged ETS I decided to measure actual ADC analog bandwidth. ATMEL claims 38.5 kHz in the datasheet but that looks like Nyquist frequency for highest ADC clock and that has of course nothing to do with analog bandwidth. Analog bandwidth is defined by three main parameters:
In another section of the datasheet there is simplified internal diagram of ADC input and Sample&Hold circuit. Capacity Ch is around 14 pF.
Series resistance R is anything between 1 and 100 kOhms. In case it is true it means 3 dB amplitude attenuation anywhere in range:
Circuit diagram for this experiment is shown in fig. 2.1. AVR generates rectangular waveform on PWM output OC1B. The signal
is then fed into rail-to-rail amplifier AD8041 via potentiometers for level control and slew rate contol. Output of the opamp is then connected via small
low-inductance resistor into ADC input ADC0 and high impedance DSO probe. The resistor is necessary because AD8041 is not able to drive the load directly without oscillations (around 30 MHz).
LabVIEW control program and "source codes" download, V1.00, 31.7.2013: AVR_ADC_bandwidth.zip (1.05 MB).
Fig. 2.2 shows screenshot of simple GUI for realtime displaying of the sampled waveform. The waveform in the figure has frequency around 24 kHz, realtime sampling
rate is set to 12.019 kS/s and ETS equivalent sampling freq is 20 MS/s (831 equivalent samples per waveform period). Right graph shows amplitudes of the odd harmonics of the waveform.
The program is made in LabVIEW 2011 so it requires NI's runtime engine and VISA drivers (at least version 2011). Both can be downloaded from
NI's webpage: The NI's runtime rubbish is "a bit" big to install but I was too lazy to draw the graphs in C/C++ by my self. The program tries to open COM port at certain baudrate and then periodically sends command for waveform readout. Received unsigned waveform is then converted to signed and normalized to ±1. Right graph shows amplitude spectrum of the signal. Unfortunately I don't have LabVIEW packages for signal analysis so I had to implement my own fourier transform. Although I used LV's matrix operations for the algorithm it is still a bit slow for higher sample counts. The program also allows export of waveform data into a csv file with selectable periods count.
Main calculation of the analog bandwidth is made by m-script for GNU Octave. Unfortunately I used function "leasqr()" for AVR vs DSO timebase deviation calculation
in the script so it won't work in Matlab. Simple description of the script: Loading reference (DSO) and AVR waveforms from CSV files,
preprocessing of the waveforms, correction of DSO timebase deviation from AVR, amplitude spectrums calculation, comparison of the spectrums => frequency transfer function.
I was also interested what is effect of the input waveforms and parameters uncertainties to the result so I also implemented simple measurement uncertainty analysis by means of Monte-Carlo method (MC).
It uses only few, mostly guessed, input uncertainties such as quantization noise, nonlinearity of the ADC and DSO input stage flatness.
Fig 2.3 shows result of the experiment. The reference signal was captured with low-end DSO Owon DS7102V with compensated Testec MF312 probe (250 MHz). Sample rate was 500 MS/s real-time. Although the DSO is really low-end its bandwidth is approx. 100 MHz so the flatness around 1 MHz should be good enough for the measurement. Measured bandwidth seems to be (543 ± 73) kHz for -3 dB. Distribution of the measurement uncertainty is shown in fig 2.4.
I repeated the experiment with different signal frequencies (both lower and higher) and slower ADC clocks but the results were almost identical (within uncertainty limits). So I assume the results are realistic. The waveform shape deformation compared to the DSO seems to be adequate to the bandwidth. So my conclusion is that AVR ADC is able do my measurement of the true-RMS value just fine for my signal. (c) 2013, Stanislav Maslan - All rights reserved.
|