Op-amps, level shifting, etc... - Page 1
Forum section: electronics / projects

author: Skimask
author_rank: Super Contributor
timestamp: December 01, 2012, 07:56:04 am
content: I broke out my copy of "The Art of Electronics", but I'm not sure what I'm looking for...Trying to build a rudimentary curve tracer, just to say I did it...'cause ain't that the best reason?Going to use a chipkit32 Uno for the control, and a Basic I/O shield for control and display. I could just as easily use my PIC's with the nice 4" color RGB LCD display, but I'm trying something new for a change.The chipkit will connect to a PIC12F1822, which will be doing the heavy lifting for generating a "sine" wave, and I'll be using the onboard 5bit DAC for the analog output, 0-3.3vdc range, but obviously need it to swing positive and negative for the D.U.T. connection, and I think I need an op-amp to do that job. Not only that, but that little 5bit DAC on the 12F1822 can't push much usable current, so the op-amp will likely have to be able to push more than a few mA's.What is that op-amps job/function/circuit called? Where you take a 0-3.3v input swing and change it to -5v to +5v output swing? Multiply the input signal by 3x and shift it down by 5v.Same thing on the input side...need to convert a possible -5v to +5v input swing to 0-3.3v so the ADC's on the chipkit can read the levels.Question arises again...what is that job called? Seems like the same thing as above, only in reverse. Divide the input signal by 3x and shift it up 0v-3.3v.Apparently it's all about the way it's worded...'cause at the moment, I'm lost in the "Good Book" (e.g. The Art of Electronics)

author: Unknown
author_rank: Unknown
timestamp: December 01, 2012, 11:58:55 am
content: You might look at AC coupling. I believe it's discussed in the first chapter.

author: hlavac
author_rank: Frequent Contributor
timestamp: December 01, 2012, 03:56:33 pm
content: You could also run small constant current source from negative rail thru a resistor to the DAC output. Choose the current and resistor value so that it has voltage drop equal to the desired shift down (half of 3.3V, 1.65V) across the resistor.Simple current source can be built from a single transistor.Then run the signal from the lower end of the resistor (which is GND centered now) thru a buffer opamp with appropriate gain for desired output swing (about x3 for +-5V from +-1.65).

author: Skimask
author_rank: Super Contributor
timestamp: December 01, 2012, 06:16:53 pm
content: A/C coupling...yes...get rid of the DC component and amplify the rest. I can see that being used on the output of the DAC to get the +/-5v swing from a 0-3.3v swing.Not sure how I'd use that on the ADC input side though...@hlavac...I'm not following you. (no pun intended!)

author: hlavac
author_rank: Frequent Contributor
timestamp: December 03, 2012, 08:39:16 pm
content: Quote from: Skimask on December 01, 2012, 06:16:53 pmCheck thissimulation

author: hlavac
author_rank: Frequent Contributor
timestamp: December 03, 2012, 09:16:06 pm
content: Here is a version withreal components

author: ptricks
author_rank: Frequent Contributor
timestamp: December 03, 2012, 09:34:02 pm
content: Sounds like you are building more than a curve tracer. I built a curve tracer 10 years ago and unless they have changed a bunch it isn't nearly that complex.http://www.techlib.com/electronics/curvetrace.htmlAre you trying to build a curve tracer + oscilloscope using the PIC ?

author: Skimask
author_rank: Super Contributor
timestamp: December 04, 2012, 07:03:02 am
content: @hlavac - THAT is a neat little applet! I've been playing with it for about an hour now (where'd the time go?).If it's a fairly accurate simulation, that right there put a bunch of stuff into perspective regarding op-amps, feedback, and so on.@ptricks - Yep. I used to work in, and later managed, an AFREP shop for the USAF (if you don't know what that means, don't worry about it. kinda obscure program. basically fix broke stuff, no matter what it is). 2M/CCR certified.In the shop we had all the neat tools; Huntron 2000, 2800S, Protrack 1 with all the trimmings, high bandwidth o'scopes, programmable waveform generators, programmable power supplies, the whole nine yards.I'm trying to duplicate the functionality of some of those tools here at my personal shop, without duplicating the cost. And obviously I don't need the full gamut of precision (or cost) that the tools back in the shop gave me.Heck, if I can build a curve tracer that'll give me a good zener chair, I'll be happy.I want to do it digitally rather than using multi-tap transformers and try to build it all into a box run off a battery pack vs. plugging it into the wall all the time.....using stuff I've already got here in the shop, PICs of various types, some DAC chips, some ADC chips, a few op-amps, an SPI driven LCD, and so on.I've already built my own version of a "Mondo Probe" that uses an 18F27J13 rather than the old school 16F870, and bunches more functionality with a lot of room left for more code and a bunch of pins left over....well, I had my own version of a "Mondo Probe" until I decided to check a 21volt battery pack that I thought was dead.And that's my story and I'm sticking to it...

author: Skimask
author_rank: Super Contributor
timestamp: December 06, 2012, 07:46:24 am
content: So, after playing around with the applet mentioned in the post above, doing some more reading in the good book (e.g. "The Art Of Electronics"), and so on, I've come up with these 2 opamp circuits to do what I need. (see attached picture)First is the DAC side of things...on the top half of the picture...I'll be using a PIC12F1822 @ 3.3v, generating a sine wave (if you can call it that), 5 bits worth, out of the DAC pin. Very high impedance output...can't drive hardly anything with it.If I'm figuring right, the DAC output from the PIC, which is in fact 0-3.3v, goes thru the opamp circuit and comes out a +5v/-5v out the other side.The opamp I'm going to use is a TL084, 'cause I've got a dozen of them on hand. If my math is right, the input side of the opamp has a rolloff of around 150Khz, the gain is 3, Vref becomes ground thru the 33K on the non-inverting input, and the feedback cap/resistor gives me another rolloff around 200khz.I don't know what the output impedance of this opamp is, or what it's drive capability is. Hoping I can get at least 100mA out of it. Haven't dug into the datasheets that far yet. Might have to follow that opamp with another one setup as a follower (terminology correct there?).Second is the ADC...the bottom half of the picture...Voltage coming in will swing from +5v to -5v, (the 820K should be 220K), the cap and the resistor divider network should give me a rolloff around 100khz and should form a 2:1 voltage divider (input swing drops to about +2.25v to -2.25v). The gain of the opamp becomes about 1.1 (1+ 20/180), making my input signal swing back to about +/- 2.475v. and the 3K resistor connected to the output after the other 3K resistor shifts the output voltage up by 2.5v, giving me an output swing of .025v to 4.975v...which will work fine for my other PICs A/D input which will be running at 5v.(Edit: forgot to put +5v and -5v for the opamp power on the ADC 1/2 of the page)Am I making any progress or is this circuit full of newbie mistakes all over the place?

author: Harvs
author_rank: Super Contributor
timestamp: December 06, 2012, 10:09:09 am
content: Quote from: Skimask on December 06, 2012, 07:46:24 amThe TL084 isn't a rail to rail op-amp. If you're powering it from +/- 5V you're not going to get 5V out of it. Either choose another op-amp, or give it some voltage headroom.QuoteI can't see the drive figures in a quick scan of the datasheet, but 100mA is highly unlikely. Possibly following the op-amp with a buffer built from a PNP & NPN transistor pair like they do for building low impedance headphone amps. If you have a quick search around on the web you'll see them.QuoteUmm... No it wont. It will form a voltage divider between whatever the instantaneous op-amp output voltage is and 2.5V, giving you a weird non-linear output, which I'm sure isn't what you're after. Why not have another op-amp stage, with a pair of resistors hooked as a voltage divider between +5V and ground, forming a "false ground" at 2.5V, then AC couple the signal into it.Same as the previous comment, watch your output swings going too close to the rail with that op-amp.Cheers

author: Skimask
author_rank: Super Contributor
timestamp: December 06, 2012, 01:18:41 pm
content: Quote from: Harvs on December 06, 2012, 10:09:09 amNoted... I see that in the graphs in the datasheet now that you mention it. I'll compensate elsewhere.Quote(using examples of what I've got on hand) Possibly an NE5532 or LM383/LM386 type of thing?QuoteOk... I figured the +2.5v on the resistor on the output would push the signal up by 2.5v. Maybe not (wishful thinking on my part?).If I understand you correctly, on the output of the ADC opamp, get rid of the 3K resistors and 330pf cap, A/C couple the input into a 2nd non-inverting opamp setup, and 2 equal resistors across the inverting input as you suggest.However, could I not do the same thing on the first opamp? Possibly by putting another 180K to +5v pullup on the inverting input?Keep in mind, I'm going to try everything...try different values for every component in the 2 circuits, try this config, try another one, and so on. I can read about these things all day and 'think' I know what's going to happen. But actually seeing it happen...well, that'll surely put things into perspective.QuoteIs this a bad thing?Or does the output swing get very non-linear the closer you get to the rails?

author: Skimask
author_rank: Super Contributor
timestamp: December 06, 2012, 01:26:44 pm
content: I just found this:http://www.daycounter.com/Circuits/OpAmp-Level-Shifter/OpAmp-Level-Shifter.phtmlwhich seems to do what I need, and now that I see the circuit, I understand what you're talking about, although the page linked above goes about it a different way.

author: Harvs
author_rank: Super Contributor
timestamp: December 06, 2012, 11:56:16 pm
content: If you haven't yet, I'd highly recommend downloading a copy of LTspice and doing some tutorials online of how to use it (it's a bit clunky and non-obvious to start with.) But it means that you can quickly put your ideas together and test it virtually, including plotting frequency response of filters. The major downside to these simulations is they don't do a good job of simulating non-ideal components.

author: Skimask
author_rank: Super Contributor
timestamp: December 07, 2012, 03:04:03 pm
content: Wow! There's a steep learning curve...and I'm only talking about the program's interface. Not doing too bad with it so far, but I find myself going 3 steps forward and 2.9 steps back most of the timeThought: Use a 4066 under MCU control to switch feedback resistors in and out for different gain settings.Datasheets say the 4066 has X amount of resistance even when switched on, meh, roughly under few hundred ohms or so worst case. As long as the feedback resistors themselves are a high enough value that the resistance of the 4066's switch isn't a major player in the overall value of the resistor, should work ok for this non-precision case...EDIT: Disregard 4066 comments. Unless I'm missing something, you can't put AC thru a 4066...that's what I get for thinking again...

author: Skimask
author_rank: Super Contributor
timestamp: December 09, 2012, 10:51:46 am
content: Ongoing playing around with the opamp circuits...(mainly talking to myself, but if anybody wants to debunk my hairbrained ideas, I'll all for it. I'm having a good time...)Got a dozen TL084's in yesterday. Found in the datasheets that they are not rail-to-rail, a couple volts short either way. Good enough for me though, and the price was right as I had to buy a couple for another fix-it project I had going...The PIC12F1822 is on the breadboard, using the DAC to generate a sine wave. Ok, a 5 bit sine wave isn't exactly a sine waveI know, close enough. At low freq's, less than about 1khz, the DAC output gives me a sine wave that is close to 0-5v. Increase the frequency, and the wave drops in amplitude, about 2v at 20khz.I think (but I'm not even close to knowing if I'm right or not) that the breadboard's parasitic cap's are dragging the signal down at higher freq's...a sort of really badly put together lowpass R/C filter. I could be wrong. Maybe it'll clean up after I put the whole thing on a proper PCB. Played around with a simple R/C filter on the DAC output to smooth out the spikes. Worked well enough. On the 'scope, the sine wave looked at bit 'shifted', so I'll call it a 'sine-ish wave'.Next up...figure out how to PROPERLY design an opamp circuit using the websites linked above along with that TL084 to give me a +/-12v swing for the output. Along with that, I'll need to find a digital pot that'll handle + and - across the taps in the opamp feedback so I can have a programmable gain for the output.

author: Skimask
author_rank: Super Contributor
timestamp: December 09, 2012, 02:09:10 pm
content: Having lots of fun with that JAVA circuit simulator app...hours and hours of wasted timehttp://www.falstad.com/circuit/If this really works as the applet shows, well, I'll be happier than a pig in shit.Add a few digital pot's in the feedback loops to change gains, a few zeners here and there for some input protection, a 1:1 follower on the DAC output before it goes into the opamp, probably a dozen other things I haven't thought of yet...Still working on trying to get this to work in the LTSpice app. The GUI is a bit tough to get doing what I want it to do, but I'm getting there.(long enough link eh?)http://www.falstad.com/circuit/#%24+3+4.9999999999999996E-6+20.712724888983452+76+5.0+50%0Aw+312+512+360+512+2%0Aw+456+608+536+608+0%0Aw+648+624+712+624+2%0Aa+536+624+648+624+0+15.0+-15.0+1000000.0%0Ag+536+704+536+736+0%0Aw+648+624+648+528+0%0Ar+648+528+456+528+0+15000.0%0Aw+456+528+456+608+0%0Ar+536+640+536+704+0+10000.0%0Aw+456+528+456+464+0%0Aw+648+528+648+464+0%0Ac+648+464+456+464+0+1.0E-11+-0.1272908417820675%0Ar+360+512+360+608+0+100000.0%0Ac+456+608+360+608+0+1.0E-5+2.5593904083000942%0Ar+536+640+456+640+0+10000.0%0AR+456+640+416+640+0+0+40.0+5.0+0.0+0.0+0.5%0AR+968+640+928+640+0+0+40.0+5.0+0.0+0.0+0.5%0Ar+1048+640+968+640+0+10000.0%0Ac+968+608+872+608+0+1.0E-5+2.4149032556544308%0Ar+872+512+872+608+0+100000.0%0Ac+1160+464+968+464+0+1.0E-11+0.6863823518971346%0Aw+1160+528+1160+464+0%0Aw+968+528+968+464+0%0Ar+1048+640+1048+704+0+10000.0%0Aw+968+528+968+608+0%0Ar+1160+528+968+528+0+15000.0%0Aw+1160+624+1160+528+0%0Ag+1048+704+1048+736+0%0Aa+1048+624+1160+624+0+15.0+-15.0+1000000.0%0Aw+1160+624+1224+624+2%0Aw+968+608+1048+608+0%0Aw+824+512+872+512+0%0Aa+464+152+576+152+0+15.0+-15.0+1000000.0%0Aw+464+136+464+96+0%0Aw+576+152+576+96+0%0Ar+576+96+464+96+0+183000.0%0Aw+464+96+464+48+0%0Aw+576+96+576+48+0%0Ac+568+48+464+48+0+1.0E-11+9.999995839773525E-4%0Ar+464+168+464+224+0+100000.0%0Ag+464+224+464+240+0%0Ac+464+136+408+136+0+1.0E-5+-2.440775500178817%0Ar+408+136+408+48+0+38000.0%0AR+408+48+352+48+0+1+20.0+2.5+2.5+0.0+0.5%0Aw+576+152+624+152+2%0Aw+624+152+624+424+0%0Aw+624+424+824+424+0%0Aw+824+424+824+512+0%0Ar+624+152+744+152+0+10000.0%0Aw+512+224+512+416+0%0Aw+512+416+312+416+0%0Aw+312+512+312+416+0%0Aw+512+224+744+224+0%0Aw+744+152+856+152+0%0Ag+856+256+856+280+0%0Aw+744+224+744+152+0%0Ax+864+138+1075+144+0+24+Device+Under+Test%2B%0Aw+856+152+856+128+0%0Ax+887+266+1092+272+0+24+Device+Under+Test-%0Aw+856+256+880+256+0%0Ac+856+152+856+256+0+1.0E-5+0.7891833021459372%0Ao+43+64+0+291+5.0+9.765625E-5+0+-1%0Ao+34+64+0+35+20.0+9.765625E-5+1+-1%0Ao+2+64+0+35+16.36695303948071+7.991676288808941E-5+2+-1%0Ao+29+64+0+35+4.374501449566024+8.543948143683641E-5+3+-1%0Ao+53+64+0+99+1.5660115838168849+0.0019575144797711066+4+-1%0A

author: hlavac
author_rank: Frequent Contributor
timestamp: December 10, 2012, 02:38:36 pm
content: There is an alternative syntax for long urls:Code:[url=http://whatever.com/long]Title

author: c4757p
author_rank: Super Contributor
timestamp: December 10, 2012, 07:31:13 pm
content: Quote from: Skimask on December 09, 2012, 10:51:46 amI'd be surprised if a breadboard gave you almost -2dB at 20 kHz. 20 kHz isnothing. Might as well be DC. Check the DAC's bandwidth. I just measured 12 pF between rows on my crappiest breadboard - even with a horrible output impedance of 1k you should have less than 1 mdB attenuation.

author: Skimask
author_rank: Super Contributor
timestamp: December 10, 2012, 08:51:45 pm
content: Just checked Microchip for any documentation I could find on the bandwidth/attenuation of the DAC output. Couldn't find anything directly relevant.The only thing I could find that may or may not be relevant is the DAC module itself in the 12F1822 datasheet, which shows that the DAC module is comprised of a string of 32 ~5K resistors feeding a 32 to 1 mux leading to the output...no buffer, no opamp, no nothing, goes straight out to the pin. Along with that, the electrical specifications section shows it's got a settling time of ~10us when going from full low to full high on the outputs.So, either I'm loading it down somewhere that I missed on that breadboard (the thing is roughly 20+ years old after all) or possibly exceeding the bandwidth of the DAC itself.It's probably not meant to feed any sort of wave output anyways... I think it was likely added in as a variable reference for the Comparator, ADC and CAP Sensing modules for it's main usage....meh...build up a buffer tonight and see what happens.@hlavac - Close enough is the enemy.I like it

author: c4757p
author_rank: Super Contributor
timestamp: December 10, 2012, 09:06:10 pm
content: If it's an analog mux-based DAC, yeah, I bet you're exceeding its bandwidth. You're correct that it's meant to be a variable reference for the analog modules.

author: Skimask
author_rank: Super Contributor
timestamp: December 11, 2012, 05:08:02 am
content: A quick bit of math seems to verify what I'm seeing...Fc = 1/ (2piRC), R = 160K in the string (which I think would be effectively the output impedance), C = I measured .26nf between the PIC DAC pin and the 'scope probe.Math = 3825 hz , and furthermore if I'm thinking right, that would be the -3db point, which is half-power, half again at about 7651hz, half again at about 15,303hz...and that's about what I'm seeing. By the time I get up around 20khz or so, I'm down to around 1v pk-pk.whaddayaknow...those formulas actually work....sometimes....

author: skipjackrc4
author_rank: Regular Contributor
timestamp: December 11, 2012, 05:34:06 am
content: Not to try to screw around with your design, but have you considered an analog sine oscillator?

author: c4757p
author_rank: Super Contributor
timestamp: December 11, 2012, 05:42:46 am
content: Yep, they do. I didn't know you were using an unbuffered resistor ladder DAC and the impedance would be so bad! You can try buffering it very close to the output - once it's been through an op amp buffer that couple hundred pF will be nothing at all.

author: Harvs
author_rank: Super Contributor
timestamp: December 11, 2012, 06:22:19 am
content: Quote from: Skimask on December 09, 2012, 02:09:10 pmYeah I know it's painful. However, when you do get the hang of it, LTspice can do all sorts of stuff that make simulations much more useful.I found that I couldn't really work out how to use it just by playing around with it (yep the UI really is that bad.) However, a couple of tutorials pointed out where things were hidden and I use it all the time now.

author: Skimask
author_rank: Super Contributor
timestamp: December 11, 2012, 06:39:10 am
content: @skipjackrc4 - It's all good. I wanted a pile of control right off the bat, and I've got a pile of these 12F1822's laying around. I can afford to let a few go up in smoke while I'm playing aroundEventually, I'll switch over to a proper DAC with a lot more resolution and a dedicated high speed controller....ya know, when the money starts rolling in@c4757p - ya, the DAC output buffer is next on the list, ran out of time tonight to build it up. I took the excess wire off the DAC output pin and put the 'scope on the pin directly. Quite a bit higher pk-pk output at the higher freq's. Like I said, this breadboard is literally decades old and probably should be framed up on the wall as a tribute to my earlier dumber days...

author: Skimask
author_rank: Super Contributor
timestamp: December 15, 2012, 10:37:04 am
content: K, finally got some time to sit down and play with this. I haven't whipped it up in LTSpice yet...or rather I can'tStill trying to figure out the interface, compatible components, etc.Attached is my bodged together curve tracer schematic. Obviously missing are the PICs doing the heavy lifting for the math, display, DAC, ADCs, power supplies, etc.(using the circuit simulator app athttp://www.falstad.com/circuit/)So, the question is...and I'm going to build it up anyway and see what happens... Does this circuit look viable?The variable resistors are going to be digital pots and one of the only remaining components to be found is the variable 'source resistance' pot, which may have to handle a bit of power. If I can't find one that'll handle any fair amount of wattage, may have to go with relays switching resistors in/out of the line.The ADC inputs will be connected to PICs at 3.3vdc, so can't handle negative voltage inputs (hence the diode and the upshift on the positive input of the opamps), nor can they handle more than 3.3v (hence the voltage divider in front of the opamps).All of the opamps are going to be powered +15v/-15v...using a single TL084, which I now know won't go rail-to-rail, but I've got a handful of them to try out. I'll switch them out later.Good/Bad/Ugly/fair enough for a first shot at it?You be the judge...

author: Skimask
author_rank: Super Contributor
timestamp: December 15, 2012, 07:15:13 pm
content: Some days, I'm a complete idiot...Went to start building up the curve tracer circuit for testing...using a 30VAC wall wart to regulate it down to +15VDC and -15VDC...and it's NOT a center-tapped type...Some days, you'd think I would learn something...and remember it later on.DOH!!!