Offsetting 0~650mV analog wave to -325mV~325mV. - Page 1
Forum section: electronics / beginners

author: jgrossman
author_rank: Regular Contributor
timestamp: October 10, 2023, 07:34:59 am
content: Hello, big electronics noob hereFor a small project I am trying to make a simple function generator using an AD9833 DDS (or something similar). The output of the DDS is from 0 to 650mV, and I wanted to DC offset that to be centered around 0 (so -350 to 350mV). Here is the circuit I currently have in sim (sorry those opamps are hard to see, they are LM358s, model provided from TI):Im using a ~1/10 voltage divider into a voltage follower as the reference voltage for a voltage subtraction setup to subtract ~330mV from my 650mV analog wave for something "close to" zero centered.It seems to work ...okat 1kHz, but it gets attenuatedhardas I get towards 1MHz (green = DDS_OUT, pink = CENTERED):So obviously this circuit doesn't seem like its going to work out. Does anyone have any ideas to improve the performance of this circuit, or another method for this goal?For reference, I want the output of this function gen to be atleast1MHz, using +/-5v and 3.3vonly. I'd also like to be able to amplify this to up to 3.3V after/in tandem with this stage using a digipot, but that will come later.Thanks in advance <3

author: magic
author_rank: Super Contributor
timestamp: October 10, 2023, 07:51:38 am
content: Is simply AC coupling the signal not an acceptable solution?BTW, regarding opamps in LTspice, there is a bulti-in ideal opamp which you can use. Press F2 and search for "opamp", place in on the schematic and add ".lib opamp.sub" to make it work. You can set any GBW and DC gain by right clicking it.

author: jgrossman
author_rank: Regular Contributor
timestamp: October 10, 2023, 02:27:05 pm
content: Quote from: magic on October 10, 2023, 07:51:38 amWell now I feel silly LOL. Yes, placing a 4.7uF cap in series with DDS_OUT seems to do the business:Quote from: magic on October 10, 2023, 07:51:38 amwould you normally recommend using the universal opamp and setting the GBW and DC gain according to the part you are thinking? The reason I used this model from TI is I wanted to make sure that it would work (since I really am quite lacking in knowledge in the analog domain, I was worried about going from "ideal" opamp to something that wouldnt work in practice).Thanks for your help

author: jgrossman
author_rank: Regular Contributor
timestamp: October 10, 2023, 03:15:27 pm
content: Hmm, I don't think that AC coupling actually will work far my application (maybe I'm wrong). Will this work for square and triangle waves as well, with an approprate coupling capacitor? Seems to deform my signal significantly:I failed to mention I want to support sine, square, and triangle waves, since thats what the DDS is capable of outputting.

author: wasedadoc
author_rank: Super Contributor
timestamp: October 10, 2023, 03:35:17 pm
content: If the wave is symmetrical shape in the voltage axis then passing throughanycapacitor to a grounded load will always make the postive and negative extremes be equally far from ground.However to maintain the shape the capacitor needs to have sufficient capacitance. The minium value depends on the frequency of the waveform, the source and load impedances and the acceptable distortion.

author: TimFox
author_rank: Super Contributor
timestamp: October 10, 2023, 04:09:03 pm
content: For a capacitor, the DC level across the following resistor to ground will be zero (for a periodic waveform of any shape).This is because the DC current through the capacitor must be zero, therefore the DC voltage across the resistor will be zero.If the input wave is symmetric (e.g., good sine wave or square wave with equal mark/space periods), then the output will be symmetric about zero, even if the input waveform's DC value is non-zero.However, a 2nd-harmonic distorted sine wave or an asymmetric square wave will give an output with unequal amplitudes about zero, but with equal areas above and below the zero line.If the time constantCxRis too small for the square wave frequency, then the output shape will be visibly different from the input waveform's shape.

author: jgrossman
author_rank: Regular Contributor
timestamp: October 10, 2023, 04:13:28 pm
content: Ah, I see. I can get something working now. Appreciate the pointers!

author: Terry Bites
author_rank: Super Contributor
timestamp: October 10, 2023, 04:40:29 pm
content: Those opamps are so slow I can hear them creaking from here......A very useful little book is attached. It shows all kinds of single supply opamp circuits and how to get the gains and offsets you want.

author: TimFox
author_rank: Super Contributor
timestamp: October 10, 2023, 04:50:59 pm
content: Yes, the LM358 has unity open-loop voltage gain at only 1 MHz, so its output will really suck from a 1 MHz square wave.

author: jgrossman
author_rank: Regular Contributor
timestamp: October 11, 2023, 04:23:53 pm
content: Quote from: Terry Bites on October 10, 2023, 04:40:29 pmIs there supposed to be an attachment to this post? I would appreciate a reference like that, thanks!

author: jonpaul
author_rank: Super Contributor
timestamp: October 12, 2023, 08:42:12 am
content: capacitor just AC couple

author: Zero999
author_rank: Super Contributor
timestamp: October 12, 2023, 12:22:34 pm
content: If there's no DC in the waveform, then just AC couple, as mentioned above.For waveforms with a DC component, then an op-amp is the only way, but only one is required, if the potential divider is made with low enough impedance. Changing R5 and R6 to 200R and 13k and adding a buffer would theoretically eliminate the error, but in reality the offset of the op-amp and resistor tolerances will dominate.

author: jgrossman
author_rank: Regular Contributor
timestamp: October 12, 2023, 06:47:11 pm
content: Will I need an opamp solution if I want to be able to produce very low frequency waveforms to take advantage of the full range of my AD9837 (0.029Hz minimum)?I've been playing around with different RC time constants and I'm struggling to find values that works all the way from 0.029Hz - 1 MHz for sine, square, and triangle waves. Either my square wave is incredibly distorted or it takes seconds (or minutes....) for it to finally center around zero, which is not acceptable. AC coupling works overall at about >20Hz with the values I chose, but I'd like to be able to have a lower limit.

author: Zero999
author_rank: Super Contributor
timestamp: October 12, 2023, 07:25:41 pm
content: Quote from: jgrossman on October 12, 2023, 06:47:11 pmA very large capacitor is required for low frequencies. It will take a long time to charge up and reach a steady state.A very fast op-amp will be required for high frequencies. The LM358 will not work with a squarewave output above a few kHz. It can be done with a suitable op-amp, but requires good layout and mustn't have a capacitive load, otherwise it'll oscillator.How about using the capacitor for high frequencies and the op-amp for low frequencies?

author: jgrossman
author_rank: Regular Contributor
timestamp: October 12, 2023, 09:00:17 pm
content: QuoteThanks for the response.For just centering the waveform, I think switching between an opamp and an AC coupling capacitor would be best to accommodate the range of frequencies I want to support. It is software controlled, so this is trivial.Hm, I suppose at that point I may as well use the opamp for all of it...QuoteGiven that I want to also amplify the .65 Vpp to 5 Vpp, I would need a higher speed opamp no matter what. I was looking athttps://www.mouser.com/ProductDetail/Texas-Instruments/LMH6643MMX-NOPB?qs=7lkVKPoqpbaw2OCk7v5BVg%3D%3Das a suitable opamp for square waves up to 1-2MHz,both for the opamp option of dc centering andfor the following amplification. It seems like this would in theory support the full range of my DDS to 16MHz, should I choose to do so. I'd appreciate input on this choice of opamp.

author: jgrossman
author_rank: Regular Contributor
timestamp: October 13, 2023, 01:38:11 am
content: Quote from: jgrossman on October 12, 2023, 09:00:17 pmEh, this seems to not be the case, but it seems to sim well up to 2MHz with the following circuit (thanks @Zero999), with an LMH6643 spice model from TI :Any advice on how to mitigate the ringing in the first opamp stage from the square wave edge? My first thought is to put a low pass filter in between the two stages, but I lack the knowledge and google-fu to realize that idea.I'm not really sure what the slew rate on the AD9837 is really, so I just kind of picked a number for sim... I can't find mention of it anywhere in the datasheet.

author: newbrain
author_rank: Super Contributor
timestamp: October 13, 2023, 01:26:19 pm
content: Quote from: jgrossman on October 12, 2023, 06:47:11 pmQuoteA handful of random remarks:Some kind of output stage is needed in any case, as the output impedance of the internal DAC is fairly high (200 Ω, for both AD9833 and AD9837)16 MHz sin or square are achievable only with the AD9834, AD9837 has a maximum Mclk of 16 MHz, and you don't want to be too close to Nyquist, both for worsened quality of the output sinewave and the sin(x)/x tapering due to the zero order hold DAC.The AD9837 lacks a comparator, so the square wave output is limited to less than ¼ of Mclk using the internal /2, unless one acceptsa lotof jitter.With a 10 bit DAC, the spectrum of a 0.0?? Hz (possibly you meant 0.059 with 16 MHz Mclk?) sine would be quite atrocious, containing harmonics of frequency corresponding to the phase step need to carry from one DAC LSB to the next, with a sin(x)/x envelope.The output of the DAC should be followed by a proper low pass filter, to remove the Mclk components and the chosen frequency images from the spectrum.

author: jgrossman
author_rank: Regular Contributor
timestamp: October 13, 2023, 07:08:16 pm
content: Quote from: newbrain on October 13, 2023, 01:26:19 pmYeah, absolutely right. I'm still not completely set on which AD983x I want to use, so I must have gotten confused WRT the specifics.Quote from: newbrain on October 13, 2023, 01:26:19 pmI want to use an 8MHz clock, and am not trying to push past 2MHz (really only targeting >=1MHz), so I think this will be OK.Quote from: newbrain on October 13, 2023, 01:26:19 pmUsing an 8MHz clock with $$f_{MCLK}/2^{28}*\text{FREQREG}$$ I would get a lowest frequency of 0.029Hz. I do see how this wouldn't create a good output, though. Will probably just do some testing and find a good lower limit to impose in software.Quote from: newbrain on October 13, 2023, 01:26:19 pmNoted.Appreciate you taking the time for some pointers!

author: Zero999
author_rank: Super Contributor
timestamp: October 13, 2023, 07:18:28 pm
content: Only one op-amp is required, but it's not a bad thing to split the gain between more than one stage.What rise and fall times are required of the squarewave?

author: MathWizard
author_rank: Super Contributor
timestamp: October 13, 2023, 11:46:52 pm
content: Quote from: Terry Bites on October 10, 2023, 04:40:29 pmI've barely tried any serious op-amp circuits and equations, besides finding operating points. I'm trying to get the hang of transistor's 1st. But I get the feeling you could spend a life time just dealing with transistor level circuits. I should jump more into op-amp's soon, they can do a lot more.