Author Topic: Opamp circuit for shifting levels (3.3v -> ~15v) and back again...  (Read 6169 times)

0 Members and 1 Guest are viewing this topic.

Offline SkimaskTopic starter

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Finally think I understand enough about op-amps to be dangerous...probably not...meh...maybe...

Designed this circuit to take a PIC's DAC output (pretty high impedance), buffer it, tap off it, shift it from 0-3.3v to +/- ~15v, and send it out to the D.U.T.  And take the resulting signal back in, +/-15v, shift it back down to 0-3.3v for an ADC input to another PIC.

Drew it up, gathering the parts, gonna start on it tonight.

The DAC side...
Takes in the 0-3.3v signal from the PIC, which will be a "sine wave" using the PICs 5 bit DAC, with a frequency range of about 20hz - 10Khz at most.  Since the PIC DAC output is a high impedance output, have to buffer it.  Run it thru a voltage divider pot to modify the input signal to change the peak level at the output, A/C couple it to the opamp that's going to be doing the 'gaining', turn it up by 10x, and send it out.  There's another opamp up there tied to the output to monitor the positive going peaks for some feedback for me to tweak the voltage divider pot (because eventually I'll be using SPI digital pots), 4.7K/1K voltage divider, a diode to keep only the positive going half, and a 3.6v zener just in case.

The ADC side...same thing in reverse...
Takes in the maximum +15v/-15v wave, buffers it, divides it down a bit, A/C couples it to the final variable gain stage, offsets it to ~1.65v center point (a bit more to compensate for the diode drop on the output), and sends it back out to another PICs ADC.  The 3.6v zener diode on the output and the 1K/10K voltage divider are there to help protect the ADC on the PIC itself.

I'm using the TL084 opamp, just because I've got a handful in the bins.  Will likely switch to something a bit more practical and able to drive harder and closer to the rails for the output opamp on the DAC side.
And I know I'm ignoring input offsets, instabilities, etc.etc.etc.  This is try #1 of many I'm sure.

Any inputs from the gallery?  (and I can duck any fruits/vegetables that are thrown at me!!!) :-DD
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 

Offline codeboy2k

  • Super Contributor
  • ***
  • Posts: 1836
  • Country: ca
Re: Opamp circuit for shifting levels (3.3v -> ~15v) and back again...
« Reply #1 on: February 06, 2013, 03:47:51 am »
That gain adjust on the opamp feeding the ADC input... is that 1Meg or 1milliohm??? I've never seen a 1m potentiometer so I assume 1Meg..

anyways.. if 1 Meg, you don't need that.. you'll never use that gain range, and the opamp won't even reach it.. you'd be lucky to use 1% of that, which means you're only going to turn the potentiometer 1/10th of it's range before it starts clipping the output at the rails.

Maybe just use a 10K input and 20K variable resistor in the feedback loop, you can't use that much gain there

Also, you might want to draw your inverting opamps with the ac coupling capacitor first in the signal chain, then the resistor, it's just a standard way to draw it, although it works either way.

good luck and have fun breadboarding it up, and actually seeing how it behaves :)
 

Offline SkimaskTopic starter

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Re: Opamp circuit for shifting levels (3.3v -> ~15v) and back again...
« Reply #2 on: February 06, 2013, 04:51:28 am »
It is 1Meg, and you've found my first real good circuit bug and why I should read the datasheets again and again...

This is all going back to that analog signature analyzer thing.  I've been playing around with the circuit simulator app (@ www.falstad.com) and of course, those parts are "ideal" parts.
I'll attach the example circuit I've been playing with...

As an example, if I feed a signal, call it 100hz @ +/- 1v pk-pk, into a small value capacitor thru a low value series resistance, I'll get a very small phase shift between the input and output, the output signal going back into the PIC will be sitting around 1.65v without much of a signal on it at all.  Throw some gain from that last opamp to it, and I'll get a difference to read.  But, since that circuit sim app uses "ideal" components, it'll let me try to make an opamp with a stable gain of 1000 (or more), and I'll get away with it until I try to build it and make it work.
Maybe back-to-back opamps both with variable gains?  Does that work?

EDIT:  And I should clarify in case I didn't point it out earlier (which I didn't)...  The input signal to the ADC section is not always going to be +/-15VDC.  It'll vary between 0-15v pk-pk.
The basic premise behind this particular ASA circuit is to do it digitally vs. on a CRT...read the voltage across the device at the D.U.T. side of the series resistance, and calculate the current thru the D.U.T. by measuring the difference in the voltage across the series resistance BEFORE the D.U.T., and plot those 2 over time on an LCD.  A fair bit of math involved, high-ish speed ADCs needed, same with the DAC, not sure if a 5bit DAC is going to provide a good enough sine wave (post 'filtered' of course) to do it right, may have to go with an external DAC with quite a bit higher resolution.  The sticky points for me remain the opamps required, and the only way to get away from using all of those opamps is to use an external ADC that's capable of the voltages that'll be present as well as +/- inputs...which isn't really a major thing, but trying to keep it all on one chip.  Right now using a bunch of PICs to do everything.  Eventually, due to suggestions made here on these forums, I'll probably try my hand at the STM32F4 series MCUs (dual ADCs, dual DACs, lots o' good stuff).
« Last Edit: February 06, 2013, 05:18:51 am by Skimask »
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Opamp circuit for shifting levels (3.3v -> ~15v) and back again...
« Reply #3 on: February 06, 2013, 05:39:39 am »
Hi Skimask,

I'm also an op amp noob, but one thing I noticed on the ADC circuit is that you're buffering the "whole" +/- 15V signal. That means you'll need enough margin on your supplies so that the op amps will still be linear.

Why not do the voltage division on the input to the first stage? I.e., divide the +/- 15V down to +/- 1.5V (x10) and buffer that. Your op amps have high impedance inputs so they're not going to need a lot of signal current anyway. In fact, you can divide the input signal down *and* offset it into positive territory with just three resistors on the input to the first follower.



Here's what a 15V signal looks like on the output:



More discussion here.
 

Offline SkimaskTopic starter

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Re: Opamp circuit for shifting levels (3.3v -> ~15v) and back again...
« Reply #4 on: February 06, 2013, 05:55:51 am »
You're right about the margin.  I figured I'd be hitting up against that limit as well, both on the DAC side as well as the ADC side, but not too worried about it since I'd just dial down the outputs and hence the input a bit until I get back "in the range".  I like your idea though.  Only problem with it is the gain of the last opamp.  According to the last post, I might have a problem once I run into the higher gain settings.  I have to do some reading in "the good book", but I think I'll end up using a couple of gain stages back-to-back to get some readable signal out of the PIC's ADC.  meh...I'll probably just end up with a bunch of noise  |O
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Opamp circuit for shifting levels (3.3v -> ~15v) and back again...
« Reply #5 on: February 06, 2013, 06:54:28 am »
So just for fun, I "built" your ADC circuit in LTSpice.  ;D

It looks like that second stage is amplifying your signal enormously. Enough so that the zener protection diode turns it into a square wave (when the feedback resistor is 1Meg).

You're doing AC coupling into the second stage. How'd you pick the value of 100nF? It seem awfully small for a 20-10kHz signal. I'm a little hazy on this, but I think the source impedance to your AC coupling is that 10K resistor. With a 100nF coupling cap, your -3db point is about 160Hz (f = 1/(2*pi*R*C)). That means there's going to be very little signal left for most of your specified frequency range.

If you really need to measure signals down to 20Hz, why not just DC couple the whole thing?
 

Offline SkimaskTopic starter

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Re: Opamp circuit for shifting levels (3.3v -> ~15v) and back again...
« Reply #6 on: February 06, 2013, 08:50:12 am »
The 1Meg resistor is actually going to be a digital pot, and wrong :)  DOH!
In most cases, 100K will be more than enough, but for the really small signals, I'm going to have to switch in an extra meg or so.

In your sim, dial the input voltage swing down to +/-5v, and dial back the 1M resistor (which is actually a pot) to the point where the output signal swings roughly .1 - 3.2 volts, which should be at about 35K.  That'll leave about .1v at the top and bottom for the PICs ADC to have a little wiggle room to work.

The 100nF works in the circuit sim app I'm using...meh...somebody knows if it's correct or not, but it's not me.  If that 100nF cap was going to ground, I could see a low pass filter.  But it's not going to ground, it's AC coupling both halves of the opamps...so...meh...I dunno.

Thanks for the "sounding board".
Not a lot of people where I live understand op-amps...much less any electronic-able type dealings...well, there is one guy I know that lurks around here (You know who you are!).

EDIT:  Could you send over that file you used?  I've tried LTSpiceIV before.  Didn't really get the hang of it.  Had a helluva time trying to build up even the simplest of circuits.
« Last Edit: February 06, 2013, 08:52:29 am by Skimask »
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Opamp circuit for shifting levels (3.3v -> ~15v) and back again...
« Reply #7 on: February 06, 2013, 09:25:51 am »
The spice file is attached. The forum software doesn't like .asc files, so I compressed it into a .zip. Note that the zener protection diode's breakdown voltage is 4.7V since I couldn't find an exact representation of yours. You get the idea though.

Just right-click on the parts you want to change and enter the new values. Click the little running dude to start the simulation. After it grinds for a while, you can click back on the schematic with a "probe" to see what's going on there.

Once you get the hang of it, it's pretty quick and easy, especially if you can build what you need from the library of parts that ships with LTSpice.
 

Offline SkimaskTopic starter

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Re: Opamp circuit for shifting levels (3.3v -> ~15v) and back again...
« Reply #8 on: February 06, 2013, 09:45:33 am »
5 minutes with that example file and I now know everything!!!
Ok, maybe not that good.  But there were a couple of key things I didn't get when I was playing with LTSpice before...like how to add parts!  derpy...der...

Change the input sine wave to 5v pk-pk, R4 to 27K, R6 to 35K, and that matches up with that other simulation I "WAS" using.

If I change the frequency, the output at ADC changes in amplitude a bit, but that's easily "fixed" by varying the gain with R6...which is why my "finished" circuit will be using digital pots.

I think you're right though, R3/C1 in concert with C2/R6 likely forms a filter of some sort that messes with the input signal.  There's a phase shift between the input and ADC itself.  As long as I can tweak it out by changing R6, I'm in there.
« Last Edit: February 06, 2013, 09:48:44 am by Skimask »
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 

Offline SkimaskTopic starter

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Re: Opamp circuit for shifting levels (3.3v -> ~15v) and back again...
« Reply #9 on: February 06, 2013, 10:12:00 am »
 :-+
Great!  Where's that "Give me a Beer" smiley?
I've got a fairly decent hack on how to run this LTSpice now...and I wanted to get some sleep tonight!   meh...that can wait until next month...
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 

Offline SkimaskTopic starter

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Re: Opamp circuit for shifting levels (3.3v -> ~15v) and back again...
« Reply #10 on: February 07, 2013, 12:49:49 am »
A few more hours of playing around and I think I've got what I want/need.  It's not optimal, but it's a good starting point for me.

A few wishes for LTSpice, and the functions might already be there, but I don't know about them and can't find them in the help file...

- Analog "pots" that you can slide while the simulation is running...
- A simulation that keeps on running with a sliding window of what's going on while you slide the analog "pots"...
- An X/Y plot rather than voltage over time.

Can't have everything for free though...  I'm still happy.
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 

Offline codeboy2k

  • Super Contributor
  • ***
  • Posts: 1836
  • Country: ca
Re: Opamp circuit for shifting levels (3.3v -> ~15v) and back again...
« Reply #11 on: February 07, 2013, 01:50:12 am »

For the analog pots, you can use the varistor.  Its symbol is in the LTSpice library under SpecialFunctions.  It's not great, but it's a quick hack.

Once you've placed it , right click on it and set Value as rclamp=R where R is the breakdown impedance. The current is controlled by the voltage applied to the control terminals. If you set the breakdown impedance really low, it breaks down early and starts to conduct according to the voltage applied.

"The VARISTOR is a voltage controlled varistor. Its breakdown voltage is set by the voltage between terminals 1 and 2. Its breakdown impedance is specified with the instance parameter rclamp. See the example schematic .\examples\Educational\varistor.asc"


years ago, on another PC, at another office (in a galaxy far, far away) I once created a 5 port sub circuit, with the 3 terminals of a potentiometer and two terminals for a control voltage from 0-1 volt. You could set the actual resistance, and the control voltage would vary the middle terminal from 0 to 100% just like a real potentiometer.   I've since lost that sub circuit but it wouldn't be hard to recreate.


 

Offline SkimaskTopic starter

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Re: Opamp circuit for shifting levels (3.3v -> ~15v) and back again...
« Reply #12 on: February 08, 2013, 09:58:33 pm »
The spice file is attached. The forum software doesn't like .asc files, so I compressed it into a .zip. Note that the zener protection diode's breakdown voltage is 4.7V since I couldn't find an exact representation of yours. You get the idea though.
........
Once you get the hang of it, it's pretty quick and easy, especially if you can build what you need from the library of parts that ships with LTSpice.
Just in case anybody cares...
I opened up the standard.dio file, found the 1N750 diode, which is a 4.7v Zener, copied that line, changed the part where it says 4.7 to 3.6, which is what I needed, saved it back, and ran with it.  The rest of the values probably aren't exactly correct for the simulation but it seems to work for me.
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf