100khz sine wave into adc

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
thefatmoop
 
Posts: 352
Joined: Tue Aug 19, 2008 4:36 pm

100khz sine wave into adc

Post by thefatmoop »

I need to detect the peak of a sine wave and was using a high speed diode (1N1418), resistor, and capacitor. This works, but only when the amplitude is above the voltage drop across the diode. The planned solution was to make a peak detector using an op amp and high speed diode, but the 6mhz bandwidth op amp doesn't work above about 5Khz.

So I can use an op amp with higher analog bandwidth, but thought i'd try using the ADC directly. Basically i take 2000 adc readings and just find out what the maximum value was. Constantly applying a 100khz sine wave will make the other adc ports read slightly off (probably capacitive coupling in the mcu). I added a relay to only connect the sine when i need it and it works fantastic.

Will this damage the adc over time? By the way I am putting the sine signal through a 10k resistor and removing the negative portion of it with a 1N1418 diode. The peak voltage of the sine is about 4.2V above the ground

User avatar
ImaginaryAxis
 
Posts: 267
Joined: Sat Nov 13, 2010 3:16 pm

Re: 100khz sine wave into adc

Post by ImaginaryAxis »

What particular op-amp are you using? 6MHz GBWP is plenty for a 5kHz signal in all but the most stringent of cases. With the op-amp you can place the diode in the feedback loop to eliminate the diode drop a.k.a., super diode or ideal diode.

But since you are directly connecting the signal to the ADC that will not damage it as long as you are within the supply rails of the ADC. I cannot think of any data converter architectures that would have an issue with signal amplitudes at or below the supply rail.

thefatmoop
 
Posts: 352
Joined: Tue Aug 19, 2008 4:36 pm

Re: 100khz sine wave into adc

Post by thefatmoop »

i'm using the op amp from adafruit. It works up to 5Khz, but not 100khz. Yeah the peak detector circuit using the op amp is the same as the ideal diode circuit only with an R and C

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: 100khz sine wave into adc

Post by adafruit_support_mike »

There are two kinds of peak detector: one finds a voltage, the other finds a moment in time. The first kind finds the higest voltage that occurred during the sampling period. The second kind finds the moment when the input passes its highest value.

Which kind are you trying to build, and what circuit are you using? If an op amp with a 6MHz gain-bandwidth product can't produce good results for a 100kHz input, it means your gain through the op amp has to be greater than 60, which is far too much for any peak detection circuit I know.

thefatmoop
 
Posts: 352
Joined: Tue Aug 19, 2008 4:36 pm

Re: 100khz sine wave into adc

Post by thefatmoop »

it's just a sine wave and I want to know the peak voltage. The timing can be 100ms off or more. For the peak detector I was using the adafruit op amp with the first circuit found here https://en.wikipedia.org/wiki/Precision_rectifier

So I was going to follow this app note Figure 1, but this op amp doesn't come in dip =[
http://cds.linear.com/docs/Design%20Note/dn61.pdf

I may just do a summation amplifier and add the sine wave i'm trying to measure + voltage drop accross one diode. Then do a diode resistor and capacitor on the output. The diodes should have about the same voltage drop and would cancel out right? Then the 6mhz op amp should be enough

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: 100khz sine wave into adc

Post by adafruit_support_mike »

thefatmoop wrote:it's just a sine wave and I want to know the peak voltage. The timing can be 100ms off or more. For the peak detector I was using the adafruit op amp with the first circuit found here https://en.wikipedia.org/wiki/Precision_rectifier
Okay, that's the first reference I would have sent your way.
thefatmoop wrote:So I was going to follow this app note Figure 1, but this op amp doesn't come in dip =[
http://cds.linear.com/docs/Design%20Note/dn61.pdf
You mean the LT1190? http://www.digikey.com/scripts/dksearch ... ageSize=25

You don't need a high-speed, high-precision op amp for a 100kHz peak detector though. Pretty much any op amp you can buy these days has enough GBW for that. The standard peak detector is similar to a voltage buffer, so its gain is 1.

Can you post a photo of your circuit, and ideally some traces of the output for low-speed and high-speed signals?

thefatmoop
 
Posts: 352
Joined: Tue Aug 19, 2008 4:36 pm

Re: 100khz sine wave into adc

Post by thefatmoop »

Notice they're all out of stock. The DIP package for that op amp has been discontinued, and i'd prefer not to use discontinued parts even if there are some left.


I'm very certain that I built the circuit correctly, but I can check it again. Right 6Mhz should be enough, but due to the diode behavior the op amp will go into saturation which will limit the response.


"This basic configuration has a problem so it is not commonly used. When the input becomes (even slightly) negative, the operational amplifier runs open loop, as there is no feedback signal through the diode. With a typical high open loop gain operational amplifier, the output saturates. If the input then becomes positive again, the op-amp has to get out of the saturated state before positive amplification can take place again. This change generates some ringing and takes some time, greatly reducing the frequency response of the circuit."

I'll try the second circuit again. I didn't try the improved circuit at the bottom, just hook that up to an RC lpf to output a constant peak voltage?

Edit: I did have the RL's (from first circuit here http://en.wikipedia.org/wiki/Precision_rectifier ) ground connected to a pot with a large cap (100uF) to remove the need for an inverting power supply. I think I also put a high pass filter on the input to move it's ground as well. I guess i need to play aroudn with it a bit more. Point is the first circuit did work below 5Khz or so.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: 100khz sine wave into adc

Post by adafruit_support_mike »

Sorry, I misspoke when talking about the references. The Wikipedia page shows the circuit I would have pointed you to, but it's the third one at the bottom of the page (with the cap and the switch), not the first one.

The first two, in true Wikipedia fashion, are correct in context but the page doesn't supply the context. Those are rectifiers (as the name of the page indicates) which assume the op amps are working from a split supply and the input is true AC (average value is 0v). The warnings are a bit old as well.. saturation only occurs in BJTs.

The difference between the rectifier and the peak detector is that a rectifier doesn't stop at the peak. Its output rises and falls with the positive half of a true-AC signal, but stops at 0v when the input signal goes negative. Getting that circuit to pick up and cut off accurately was a challenge back in the days when +/-15v supply rails ruled the earth and PNP transistors were iffy at best, but conditions and hardware have changed since then. Today's normal operating conditions are the "ye gods, you want to do WHAT?" of the 1970s and 80s.

For a peak detector, you want the output to rise as far as it can, then to stay where it is as soon as the input drops below its maximum level. That's much less sensitive to saturation issues (where they apply) because after the first peak, the output you want doesn't change very much.. not at all for a sine wave of uniform amplitude, and much slower than 100kHz for an amplitude-modulated signal on a 100kHz carrier.

Try putting a 680 ohm resistor in parallel with a 100nF cap below the diode. The cap will hold the peak voltage and the resistor will drain the cap with a time constant corresponding to about 2kHz. The circuit's output will track variations in the envelope slower than that, with only about 2% ripple when the amplitude is constant. For less ripple, make the resistor bigger. To track faster changes, make the resistor smaller.

thefatmoop
 
Posts: 352
Joined: Tue Aug 19, 2008 4:36 pm

Re: 100khz sine wave into adc

Post by thefatmoop »

Thanks Mike, I'll have time to take a second look on Monday. Still waiting on the dds modules from China. Btw that would be a great product for adafruit! A dds breakout for the ad9850 dds chip with some guides

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: 100khz sine wave into adc

Post by adafruit_support_mike »

Thanks for the suggestion.. it looks like an interesting chip.

The big hassle with DDS is filtering the output. That isn't too hard when you stick to a fixed frequency, or even a narrow range of frequencies, but turns into a challenge when you want a widely-adjustable signal source.

thefatmoop
 
Posts: 352
Joined: Tue Aug 19, 2008 4:36 pm

Re: 100khz sine wave into adc

Post by thefatmoop »

the DDS i'm using should have a constant pwm frequency of 125Mhz (i haven't read the datasheet, so i may be totally off). So to output 0-40Mhz you only need have a -3dB frequency cutoff of 70Mhz or so.
http://code.google.com/p/ad9850-arduino/

thefatmoop
 
Posts: 352
Joined: Tue Aug 19, 2008 4:36 pm

Re: 100khz sine wave into adc

Post by thefatmoop »

here's the circuit...its a bit bad quality lol, but you can see that it's the same as online.
circuit
circuit
11.JPG (31.83 KiB) Viewed 1445 times
yellow is the output, blue is input.
DS0009.JPG
DS0009.JPG (20.1 KiB) Viewed 1445 times
i tried using an inverting power supply. I also tried putting a dc offset on the incoming sine wave, and as shown above - get rid of the negative portion.

eventually as frequency is increase The system will eventually turn into a dc line that isn't the peak

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: 100khz sine wave into adc

Post by adafruit_support_mike »

Try moving the 1k resistor down so it's in parallel with the cap:
peak-detector.jpg
peak-detector.jpg (13.22 KiB) Viewed 1424 times
With the circuit in your diagram, the resistor limits the rate at which current can flow into the cap. That limits the rate at which the cap's voltage can rise, so what you have is a first-order low pass filter.

In the version above, current can flow into the cap quickly, then will bleed out gradually through the resistor.

I admit I'm not entirely sure what to make of the scope trace you posted. The input makes sense as a sine wave getting clipped by the input diode when the voltage goes below about -.6v. The output looks like a rectified version of the input, which would make more sense if the probe was taking signal from the op amp's negative input.

thefatmoop
 
Posts: 352
Joined: Tue Aug 19, 2008 4:36 pm

Re: 100khz sine wave into adc

Post by thefatmoop »

tried that and what it revealed is that the peak detector is acting like a push pull, which won't allow the capacitor to charge up. That being said a large R parallel to the cap doesn't really do anything. The smaller the resistor in series with the cap (as shown in my last post) the less of an average is taken of the push pull ideal rectifier output.

notice the phase shift in the capacitor - that will also decrease as series R is decreased.

Really odd because I simulated the circuit with an ideal op amp and everything worked fine. At the low frequency that I tested it at, the op amp should be ideal. I wonder if it's because the op amp is using 0 to 5v rails, but the sine wave is above and below 0v (ground). I tried to somewhat prevent that by adding the negative clipping diode and resistor

thefatmoop
 
Posts: 352
Joined: Tue Aug 19, 2008 4:36 pm

Re: 100khz sine wave into adc

Post by thefatmoop »

it's gotta be the power rails. this guy is using the same circuit 6:45 in
http://www.youtube.com/watch?v=Fn5kHhNRsz0

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”