Peak detection and ummm lower trough detection?

Thread Starter

dotbot

Joined Mar 29, 2019
8
Hi All
I have a question about how to best determine the maximum and minimum trough values of a waveform when there is no negative voltage component (i think the term is DC coupled?).

My Application: I'm building a function generator that outputs a signal between +- 12 V and I want to have a way my microcontroller can read the max and minimum voltage values.

I've attached my circuit below, and to summarise it the DDS waveform is amplified and offset by some op-amps which are controlled by two Pots, the output signal is then scaled to between 0V and 3.3V for my microcontroller (ESP32) with some more op-amps. I was hoping to just use the ADC directly however the sampling rate of the ADC isn't going to be high enough (output signal up to 12Mhz) so I thought I would use a peak detector to capture and hold the max voltage (circuit also below), however since I want to display Pk-Pk voltage I will need to capture the lower voltage too. Because my scaled output signal is all +voltage I don't know how I can capture the lowest part of the waveform?

I know its possible to build a -ve peak detector however I don't believe the ADC on my micro can deal with negative voltages, I guess I could invert the negative part but I thought I would see if anyone here knew how to detect the losest part of a +ve waveform.

I'm open to any other ways I might achieve reading the pk-pk voltage, but also very curious about how to read minimum voltages.

Cheers
 

Attachments

MrChips

Joined Oct 2, 2009
30,824
You can have a DC voltage which is added to your signal in order to bring the combined signal within the acceptable range of the ADC input.

If your system is fast enough, you can digitize the signal and determine the minimum and maximum values digitially.
 

Thread Starter

dotbot

Joined Mar 29, 2019
8
You can have a DC voltage which is added to your signal in order to bring the combined signal within the acceptable range of the ADC input.

If your system is fast enough, you can digitize the signal and determine the minimum and maximum values digitially.
Thanks for the Reply Mr Chips
Unfortunetly the ESP32s ADC isn't anywhere near fast enough for the max output frequency I want this func Gen to be able to generate (12Mhz), from my reading its only capable of around 60ksps.

If the signal was AC coupled (think I'm using that term right) I could use some logic, an inverting op-amp and two peak detection circuits to work out the positive and negative maximums, but my output has a variable DC offset which complicates things.
 

Thread Starter

dotbot

Joined Mar 29, 2019
8
Use the simple diode peak detect circuit.
Reverse the direction of the diode for a trough detect circuit.
hmmm I thought reversing the direction of the diode in the peak detect circuit would only work for negative troughs, but I just simulated the circuit and it works! (attached for those curious).

Cheers MrChip, the other methods I was thinking about were getting really complicated.

I'll just take my scaled output and run it to a Peak detector circuit and this Trough detector circuit and hook the output of those up to two ADC inputs.
 

Attachments

danadak

Joined Mar 10, 2018
4,057
An LM308 is a part that cannot handle 12 Mhz in this application.
Neither its BW or SR is adequate, even close.

You might google "high speed peak detectors", there are design
considerations and ap notes out there for designs.

A SAR ADC and logic could possibly handle this, SAR capable
of ~ 50 MSPS or better.

Note the DDS output is fairly stable in its pk-pk value, what are
you using pk-pk values for ?


Regards, Dana.
 
Last edited:

Thread Starter

dotbot

Joined Mar 29, 2019
8
Hi Danadak
I want my micro to be able to read the output voltage so I can display it to an LCD, I would like to show pk-pk voltage and offset voltage (the project is a simple benchtop Func Gen, more for learning some analog circuitry than anything else).

Someone I knew suggested an external ADC which has an SPI or I2C interface but i don't understand how it could sample at a higher frequency and then send the data back at the low freq? I might have to do some more reading.

Danadak you are quite right those LM308s won't be suitable for higher freqs, I'll have to find some info on high freq peak detection design
 

danadak

Joined Mar 10, 2018
4,057
If you use a high speed SAR then you would need logic that extracts peak from its
samples. Then you would have to decimate that down to the available sample rate your
processor could handle/display. In other words the processor does not "manage" every
peak detected, just a subset of those samples yielded by the logic. This is fine for your
application since this is not a part of a real time control loop, rather just a display of
what pk-pk value is being generated. Or do I have that wrong ? You are not trying to
implement an agc loop right.....?

Keep in mind the output of a DDS is fairly well regulated as its a DAC, its pk-pk value
probably determined by accuracy of its supply rail. Or a reference V.


Regards, Dana.
 

Thread Starter

dotbot

Joined Mar 29, 2019
8
That's right Danadak, it's just for displaying the output pk-pk and offset, it isn't being "used" for anything.
The output of the DDS is pretty stable (1.5V pk-pk if I remember correctly) but I'm using two op-amps with Pots (circuit attached) to adjust the amplitude and DC offset, and that's what I want to measure (not straight from the DDS).

At the moment I think I will look into some high slew rate Opamps and see if that's an option, the primary aim of this project was to get some exposure to analog circuits because as my dad says "kids are spoilt today with all these fancy pants digital ICs :p"

But I'm curious about how the logic of decimating the high-speed SAR output for lower sampling rates works (and how it gets around the Nyquist limit), is there a phrase or topic you can suggest I look into to find more info on that?
 

Attachments

danadak

Joined Mar 10, 2018
4,057
The SAR will be converting at Nyquist or greater, and the logic solution will
run at that rate as well. Decimation means you throw away some answers.
You get away with this if the system is not rapidly changing in pk-pk from one
sample to the next, so the sample stream / logic stream has a lot of redundant
answers in it. Therefore throwing away a few of those answers (samples) does
not affect your measurement. Keep in mind the logic used with the SAR will,
if designed properly, detect the pks. Yoiu are just not going to use every peak
that is detected.

This approach does have latency, eq. you only get n out of x samples where x is the
actual SAR / logic rate, and n < x. Latency means there is a delay from a real time
change to your being informed thru decimation and of course the logic design for
the peak detection.

Decimation is a broad based concept used in a lot of designs.

https://www.analog.com/en/technical-articles/analog-tips-decimation-for-adcs.html#

https://en.wikipedia.org/wiki/Analog-to-digital_converter


Regards, Dana.
 

danadak

Joined Mar 10, 2018
4,057
Another approach here is to do a RMS or average measurement. Because
the waveform is sinusoidal there is a simple calculation to determine peak value
from RMS value.

http://www.learningaboutelectronics.com/Articles/Peak-to-peak-voltage-calculator.php


Of course true RMS at 12 Mhz not simple design either.

Here is an 8 Mhz solution, take a look at their website to see if they have other parts
that can meet your 12 Mhz requirement.

https://www.tme.eu/Document/becce4a60364b75a200b5bc94883a8c8/ad637.pdf


Regards, Dana.

PS : There is a 15 Mhz part here -

https://www.analog.com/en/parametricsearch/11023
 
Last edited:
Top