Electronic – Measuring VPP and DC offset of a 1Hz – 1MHz signal using MCU

achigh frequencymeasurementmicrocontrollervoltage measurement

I need to measure the peak to peak voltage and DC offset of a 1Hz to 1MHz sine/triangle wave. The signals amplitude varies between 0 and 2Vpp and the offset can vary between -2v and +5v. I will be using an Atmega16 to do the A/D. The Atmega16 has an 8 channel 10-Bit ADC with 50-200KHz sample rate @10-Bit resolution. Taking multiple samples for cycle is obviously out of the question.

What I was thinking of doing was to sample two different versions of the signal eg connect the signal to both a negative peak detector and a precision rectifier and connect those circuits outputs to two different ADC channels and then from result of these conversions (ie the negative and positive peaks) calculate the the vpp and DC offset. Obviously the signals will need to scaled and level shifted before being applied to the controller.

Im not really sure if this will work at all, there must be a far simpler and more sophisticated way to do this that I haven't thought of.

Best Answer

Several ways to measure peak-to-peak voltage with a MCU:

  • undersampling: Directly sample with an ADC, even though you know you are getting less than once sample per cycle of the signal. This requires (a) the signal repeats over and over the same waveform, and any changes to that pattern occur relatively slowly, and (b) the actual sample-and-hold part of the ADC has a high enough bandwidth, even though you only get one sample once every few cycles of the signal, and (c) the exact sampling instant of the sample-and-hold doesn't always hit the same point on the repeating signal, but drifts along it, eventually hitting the highest peak and later the lowest valley of the signal. (Often this drift happens without you having to do anything; but to guarantee it will always work, you may need to lower your sampling rate with some signals). High-speed digital oscilloscopes often use this undersampling technique to inspect amazingly high frequency signals.

  • use maximum peak detector and minimum valley detector to hold the maximum and minimum voltages on sampling capacitors long enough for you to sample them. Either use a resistor on each capacitor with a "long enough" RC time constant that the change in voltage from the actual maximum to your ADC sample is insignificant, or use a transistor on each capacitor to reset the voltage immediately after you sample it. If you can estimate the diode voltage drop in software, the simplest hardware is a diode-capacitor-resistor peak detector and a diode-capacitor-resistor valley detector ... but using an op-amp precision peak detector rather than a single diode may be simpler than trying to estimate the diode voltage drop.

  • use a DC blocking capacitor, followed by a diode to ground (to clamp the minimum voltage to 0) and a diode to a peak detect sampling capacitor. The voltage on that capacitor gives you the peak-to-peak voltage directly. Somehow estimate and compensate for the diode voltage drops in software, or else use op-amps to compensate for them in hardware, similar to the peak detector.

  • use a frequency mixer (analog multiplier) to shift high-frequency signals down to an easier-to-handle frequency well inside your ADC's capability. (Like undersampling, this assumes the signal repeats over and over the same waveform, and any changes to that pattern occur relatively slowly).

I'm not sure why you want a precision rectifier. I assume you really meant "precision peak detector" (which is admittedly almost the same circuit).

A RC filter with a long RC time constant will give you the average voltage of the signal. As pingswept says, it's probably best to use a fixed cutoff frequency (for the peak detect, valley detect, and the average detect) to handle the high frequencies with analog circuits, and deal with low frequencies in software.

As long as the MCU is sampling the highest peak voltage and lowest valley voltage, consider also reporting the midway voltage halfway between the two -- this is not always the same as the true average voltage of the signal.