Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
2  
How fast does the DC offset change? Or better yet, how fast do you need to know if the dc offset has changed? If you use a really large cap you could measure a DC voltage, but it would change slow compared to the signal. –  Kellenjb Jun 12 '10 at 13:09
    
I haven't done any calculations but It would be probably be sufficient to update the DC offset reading every 200-500ms –  volting Jun 12 '10 at 13:58
add comment

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
add comment

I think you're taking the right approach with splitting the signal and measuring each parameter separately.

First, you measure the DC offset voltage by low-pass filtering the signal and feeding the output into the A/D. Because the signal swings across such a huge range of frequencies, you'll either need a filter with an adaptive cutoff frequency, or you'll have to put up with a long lag in your readings. You might be able to do something clever by only filtering the signal enough in hardware to get it down to 20 kHz or so; then you could calculate the average value in software.

(I don't think that it speeds up your response, but it might be easier than building a filter with a changing cutoff frequency, which is not trivial.)

Then, you go after the amplitude. You level shift, rectify, and scale the input voltage so that it spans the range of the Atmega16 A/D. You could do this with two fast opamps and a rectifier. I think the order is important, or at least you have to be careful about what voltage your rectifier is referenced to.

share|improve this answer
    
What about detecting the negative peak rather than the DC offset as this would not be complicated by frequency response issues. To rectify scale and level shift would TL072's be fast enough? –  volting Jun 12 '10 at 14:04
1  
Negative peak detection might work just as well. I'd worry a little about the diode turn-on time-- at 1 MHz, a large diode will take several cycles to turn on. You should, of course, use a small diode, but I'm not sure how fast they get. If you can switch in the nanoseconds, which I think is likely for a low power signal, it should work fine. –  pingswept Jun 12 '10 at 14:24
1  
Regarding TL072's speed, I think they'll be marginally fast enough. Their gain-bandwidth product (GBW) is listed at 3 MHz, which means that at 1 MHz, you can only get a gain of 3. You probably only need a gain of 2, so in theory, you're OK. If you can get some easily, I might try something faster, like an LT1056 (6.5 MHz GBW). But if this is just for fun, or school, or whatever, the TL072's should work. –  pingswept Jun 12 '10 at 14:28
    
I have a few different signal diodes so Ill do some tests with regard to speed. –  volting Jun 12 '10 at 16:02
1  
I suspect that in practice, the TL072's will work fine. If you actually get the thing mostly working, you could upgrade the opamps to improve your performance at the high end. –  pingswept Jun 12 '10 at 20:14
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.