Measure peak to peak voltage of variable signal with Arduino - Page 1
Forum section: electronics / general

author: Gabriel
author_rank: Regular Contributor
timestamp: May 25, 2020, 01:47:51 am
content: Hi All,I am wondering what would be the best approach to measure the p2p voltage of a signal with an Arduino. The frequency range would be about 0-20MHz.The problem is that the signal can shift its DC-bias so I cannot just simply use an op-amp to shift it into the 0-5V range. I have found RF power measurement modules that would work but they seem to only go down to ~1MHz which is obviously not enough.Any recommendations would be much appreciated, this is a once of project so cost is not really an issue (unless it is something outrageous).Many Thanks,Gabriel

author: David Hess
author_rank: Super Contributor
timestamp: May 25, 2020, 09:22:29 am
content: Bridge based peak detectors can work up to 10s or even 100s of MHz. They amount to a high speed buffer driving a pair of compensated rectifiers to detect positive and negative peaks.Check figure 21 on page 15 of Linear Technology application note 61 for an example. It uses bipolar transistors instead of diodes for better performance.

author: mikerj
author_rank: Super Contributor
timestamp: May 25, 2020, 11:37:23 am
content: Quote from: Gabriel on May 25, 2020, 01:47:51 amAre you sure about the low end of that frequency range? It implies you could want to measure the pk-pk amplitude of a signal at e.g. 0.000001 Hz, which would take the best part of two weeks...

author: Gabriel
author_rank: Regular Contributor
timestamp: May 26, 2020, 04:06:51 am
content: Quote from: David Hess on May 25, 2020, 09:22:29 amFor this to work wouldn't I need to somehow center the waveform (0v)? Otherwise that could work.

author: Gabriel
author_rank: Regular Contributor
timestamp: May 26, 2020, 04:08:26 am
content: Quote from: mikerj on May 25, 2020, 11:37:23 amYeah, I didn't really mean that low frequency. More like 1Hz - 200MHz then.EDIT: I meant 20MHz not 200MHz...

author: Ian.M
author_rank: Super Contributor
timestamp: May 26, 2020, 05:48:02 am
content: Due to the extreme bandwidth requirement, you may well be best off designing two or even three separate measurement interfaces, optimized for different frequency ranges e.g. 1Hz-1MHz, and 1MHz upwards, + adding some method of determining which one the frequency is in range for.

author: cv007
author_rank: Frequent Contributor
timestamp: May 26, 2020, 11:01:38 pm
content: > measure the p2p voltage of a signal with an Arduino. The frequency range would be about 0-20MHzI assume an arduino probably means a mega328, which has a comparator, although 'Arduino' could mean almost anything.An idea that could probably be tried easily without many extra parts-signal in, through capacitor to comparator +input, input pulled up/down by same amount to center signal on vdd/2the other comparator -input has a capacitor to ground and a high value resistor to ground, also tied to another pin via low value resistorset the pin with low value resistor to output high, so it charges the capafter cap is charged, set the previous pin to input and start a timer, wait for comparator flag to be set, stop timer(comparator -input slowly goes from Vcc to ground, somewhere the input signal will trip the comparator, Vdd/2 or above)you now have a time, which also tells you what voltage the comparator tripped (cap/resistor discharge rate), and is the highest voltage of the signalif the signal is symmetrical, and your discharge time is slow enough to work with the lowest expected freq, then your pk-pk voltage is whatever value you came up with minus the vcc/2, then doubledMaybe not a good idea, or maybe there are more details not provided that make it a bad idea, but its an idea. I'm sure there are another hundred variations of this. Since it requires only a few parts, it would be easy enough to try and maybe be a good starting point as it could point out where the problems may be hiding.

author: Gabriel
author_rank: Regular Contributor
timestamp: May 27, 2020, 02:12:49 pm
content: Quote from: cv007 on May 26, 2020, 11:01:38 pmThis sounds really promising but I'm not sure I fully understand... Could you maybe DaveCAD it? Or maybe just re-explaining?Many Thanks,GabrielEDIT: I forgot to mention I plan to use an atmega32u4. The point about it having a comparator still remains though.

author: cv007
author_rank: Frequent Contributor
timestamp: May 27, 2020, 06:59:37 pm
content: I don't have a DaveCAD license anymore, so I'll attach something else instead.The values are just pulled from a hat so no need to think they are anything special or even correct. The upper graph shows when the discharge was started and when the comparator output switched (avr flag set). The time and ultimately the voltage can be figured out since the discharge rate is known. The signal would have to have some relation to the discharge rate in use in order for the signal to get enough chances to trip the comparator in some shorter period of the discharge time- slower discharge = higher resolution but longer times, slower signal = need slower discharge, etc.You would have to work out how to compute the discharge time vs voltage.Like I said, may not be a good idea for what you want, but it may at least provide a spark for some other idea.edit-You can also use pwm output to set a voltage on the comparator minus input, and adjust the pwm (voltage) to find out where upper signal may be. The comparator can also use ain inputs for the minus input I believe, so may also be of some use in some way.

author: David Hess
author_rank: Super Contributor
timestamp: May 27, 2020, 10:58:59 pm
content: Quote from: Gabriel on May 26, 2020, 04:06:51 amThe waveform in this particular case needs to cross 0 volts but that could be changed. Essentially it is just a positive and negative peak detector in parallel so you measure the difference between the two outputs. The important part is how the transistors are used to make a high performance peak detector.The common alternative is to use a sampling ADC with sufficient bandwidth to just digitize the signal and find the positive and negative peaks. This does not necessarily require a high sampling rate.

author: Gabriel
author_rank: Regular Contributor
timestamp: May 28, 2020, 11:58:50 pm
content: Quote from: cv007 on May 27, 2020, 06:59:37 pmOk cool! This looks good but I did a quick simulation with falstad and found it to be a bit inaccurate (up to 0.6-0.7V difference). Any ideas for how to make it more accurate?

author: Gabriel
author_rank: Regular Contributor
timestamp: May 29, 2020, 12:00:39 am
content: Quote from: David Hess on May 27, 2020, 10:58:59 pmI thought of using an ADC but I'm not really sure how the sample negative voltages with it. I know that the ADC of the atmega cannot do it but is there standalone ADCs that could sample the negative voltages?

author: David Hess
author_rank: Super Contributor
timestamp: May 29, 2020, 06:28:25 am
content: Quote from: Gabriel on May 29, 2020, 12:00:39 amThere are but it would have to do so while meeting the 20 MHz bandwidth requirement and offhand I am not so sure about a part which can do that.Without a negative supply that also means using a single supply operational amplifier as an inverter but it would saturate with positive signals. There are parts which can do that but again I am not sure about meeting the bandwidth requirement; they would have to be tested as part of a circuit.

author: Gabriel
author_rank: Regular Contributor
timestamp: May 29, 2020, 08:03:19 am
content: Quote from: David Hess on May 29, 2020, 06:28:25 amI will have a negative supply so that isn't an issue. +-12V and a regulated +5V

author: David Hess
author_rank: Super Contributor
timestamp: May 29, 2020, 03:12:29 pm
content: Quote from: Gabriel on May 29, 2020, 08:03:19 amSo what is the problem then? Implement a dual peak detector like my example but DC couple it and if necessary, tie the pull-up and pull-down resistors in parallel with the output capacitors to the supply rails instead of ground so that the positive and negative peaks can be anywhere.Now the problem becomes how to use the unipolar ATMega ADC to measure a negative output from the peak detector. Add a couple of buffers and inverters to the outputs so there are four signals to measure with the unipolar ADC. Each output now has a normal output and an inverted output; one of them will be positive and the other will measure zero and can be ignored.The only virtue of this implementation is that a low frequency low sample rate ADC can reliably capture the peaks of a high bandwidth signal.