Author Topic: LTSpice OpAmp oscillator  (Read 16636 times)

0 Members and 1 Guest are viewing this topic.

Offline steaky1212Topic starter

  • Regular Contributor
  • *
  • Posts: 95
  • Country: gb
    • Steaky - Sleep is overrated
LTSpice OpAmp oscillator
« on: February 08, 2012, 11:41:03 am »
Hi,

I've got this circuit in LTSpice and its not working quite how I expect it to.

Quote
R2 ninv 0 27k
R3 OUT ninv 100k
R4 OUT inv 100k
R6 OUT 0 10k
V1 vdd 0 5
XU1 ninv inv vdd 0 OUT LT1006
C1 inv 0 0.01µ
.tran 0 0.1 0 1u startup
.lib LTC.lib
.backanno
.end



The idea is that the output is supposed to oscillate as per http://hyperphysics.phy-astr.gsu.edu/hbase/electronic/square.html

I only get a single pulse out, and then the inverting input settles just above that of the non-inverting input, and the output doesnt toggle again.



Any ideas

Steaky
 

Online jahonen

  • Super Contributor
  • ***
  • Posts: 1054
  • Country: fi
Re: LTSpice OpAmp oscillator
« Reply #1 on: February 08, 2012, 11:53:32 am »
I think that the circuit in question requires a bipolar supply.

Regards,
Janne
 

Offline steaky1212Topic starter

  • Regular Contributor
  • *
  • Posts: 95
  • Country: gb
    • Steaky - Sleep is overrated
Re: LTSpice OpAmp oscillator
« Reply #2 on: February 08, 2012, 11:56:29 am »
Janne,

Thanks for the reply. The op-amp is a single-supply rail-rail opamp.

Turns out I needed to change some of my values to get a decent oscillation.

I went with
Quote
R2 ninv 0 10meg
R3 OUT ninv 10meg
R4 OUT inv 1meg
V1 vdd 0 5
XU1 ninv inv vdd 0 OUT LT1006
C1 inv 0 1µ
.tran 0 100 0 100m startup
.lib LTC.lib
.backanno
.end

This gave me an on time of ~700ms, and a period of ~4.8s
 

Offline jimmc

  • Frequent Contributor
  • **
  • Posts: 304
  • Country: gb
Re: LTSpice OpAmp oscillator
« Reply #3 on: February 08, 2012, 06:03:46 pm »
You still need bipolar supplies even with a single supply OP-AMP.
Think about what happens to the inputs when the output is low if there is no -ve supply.

If you want a single supply rail split use two resistors for R2 (56k in your first cct), one to +ve supply the other to ground. (Junction to R3 as before)

Jim
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11951
  • Country: us
Re: LTSpice OpAmp oscillator
« Reply #4 on: February 08, 2012, 06:18:18 pm »
Yes, the grounded end of R2 in the spice circuit needs to be at a voltage halfway between V+ and V- on the op amp supply.

R3 and R2 form a voltage divider between V+ and GND or V- and GND depending on whether OUT is at V+ or V-. GND cannot be at either V+ or V- itself or this won't work. GND must be half way between V+ and V-.
 

Offline steaky1212Topic starter

  • Regular Contributor
  • *
  • Posts: 95
  • Country: gb
    • Steaky - Sleep is overrated
Re: LTSpice OpAmp oscillator
« Reply #5 on: February 09, 2012, 10:17:22 am »
So thanks for all the comments.

The opamp I was originally using was the LT1006S8 with is a single supply rail-to-rail opamp. My understanding of this is that it is unipolar and can be powered from Vcc and Gnd - saturating at each rail.

The lowest power comparitor I could find was the LMC7215, so I dropped the spice definition file into LTSpice, and modified some of the values of components.  Here is what I've come up with for a start...




As you can see, it is pulsing nicely, and fairly regularly. I'm sure there are some modifications that will give lower power usage - so hitting LTSpice again.
« Last Edit: February 09, 2012, 12:31:08 pm by steaky1212 »
 

Offline jimmc

  • Frequent Contributor
  • **
  • Posts: 304
  • Country: gb
Re: LTSpice OpAmp oscillator
« Reply #6 on: February 09, 2012, 10:37:07 am »
Simple simulations don't tell the whole story; please think about how the circuit works (or doesn't).

Assume the output has just switched to 0v, the non-inverting (+) input will immediately be at 0v.
C2 will then discharge to 0v taking the inverting (-) input with it.
Both inputs are now at 0v and the state of the output is undefined, it will depend on the input offset voltage which varies from device to device.
If you have a device with a positive offset , the circuit will work; if it's negative you're out of luck.

Jim
« Last Edit: February 09, 2012, 10:56:13 am by jimmc »
 

Online ejeffrey

  • Super Contributor
  • ***
  • Posts: 3768
  • Country: us
Re: LTSpice OpAmp oscillator
« Reply #7 on: February 09, 2012, 11:07:39 am »
The opamp I was originally using was the LT1006S8 with is a single supply rail-to-rail opamp. My understanding of this is that it is unipolar and can be powered from Vcc and Gnd - saturating at each rail.

Using a rail-to-rail opamp is only the first and easiest step to making a single-supply circuit.  You absolutely cannot take a generic opamp circuit designed for use with a split supply, replace the opamp with a rail-to-rail device and connect -V to ground.  The circuit you have described requires split supplies to work regardless of the type of opamp you use. 

Your circuit can easily be modified to work in a single supply configuration by adding a single resistor from the non-inverting input to V+.  This resistor should be the same value as the one from the non-inverting input to V- (R2 in your earlier schematic, R7 in the newer one).  This will correctly bias the operating point of the circuit to the mid-rail voltage.  You should reduce your resistor values back to sane numbers as well.
 

Offline steaky1212Topic starter

  • Regular Contributor
  • *
  • Posts: 95
  • Country: gb
    • Steaky - Sleep is overrated
Re: LTSpice OpAmp oscillator
« Reply #8 on: February 09, 2012, 11:28:28 am »
LMC7215 typical input offset voltage is typ 1mV, max 6mV.

So I've changed the values around again (mainly due to the ones in my part box).
I've included another resistor on the non-inverting input to Vcc which should take care of the undefined output stuff

I also added a diode and resistor in parallel with the inverting feedback to give a non 50/50 duty cycle.

How "bad" are simulators, as I am using the current draw of the circuit to give an indication of battery life?
 

Online ejeffrey

  • Super Contributor
  • ***
  • Posts: 3768
  • Country: us
Re: LTSpice OpAmp oscillator
« Reply #9 on: February 09, 2012, 01:46:59 pm »
How "bad" are simulators, as I am using the current draw of the circuit to give an indication of battery life?

Simulators are generally pretty accurate at analyzing well designed circuits.  The main problem with simulators is garbage in, garbage out.  If you don't give it good models of your components, including any parasitic effects that are important for your operating regime you won't get good results.  If you don't set reasonable operating conditions, you won't get good results.  If you feed it a bad circuit whose behavior is set by uncontrolled parameters like the input offset voltage, you will get bad results.

You must always interpret the results critically.  If a simulator says that your opamp will output 100 volts or 100 amps, you have to recognize that simply means you gave it a defective circuit and also did not set current and voltage limits on the supply.  Simulators are a powerful and useful tool, but they don't replace brain cells or an understanding of circuits are supposed to work.
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: LTSpice OpAmp oscillator
« Reply #10 on: February 09, 2012, 02:08:47 pm »
As a general rule, reality always trumps a simulator.

If your circuit works in reality, but not in SPICE, guess who is wrong? Certainly not reality.

If your circuit doesn't work in reality, but does work in SPICE, guess who is wrong? Again, certainly not reality.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Online ejeffrey

  • Super Contributor
  • ***
  • Posts: 3768
  • Country: us
Re: LTSpice OpAmp oscillator
« Reply #11 on: February 09, 2012, 03:45:32 pm »
As a general rule, reality always trumps a simulator.

If your circuit works in reality, but not in SPICE, guess who is wrong? Certainly not reality.

If your circuit doesn't work in reality, but does work in SPICE, guess who is wrong? Again, certainly not reality.

I agree with the latter, but not necessarily the former.  A circuit that works in reality but not in SPICE may be OK, but that is a very good hint that you may have done something horribly wrong.  A circuit that appears to work but relies on some parasitic element may stop working tomorrow, or with a new batch of parts.  Technically of course the simulator is still 'wrong' in that its results are not the same as your measurement, but in reality the problem is with neither the simulation or the measurement but your circuit.

At the very least if you come up with a circuit that appears to work but simulates poorly you need to bang the hell out of it.  Make sure it works over the full range of temperature, input signals, and loads, and with a selection of active devices to make sure you didn't just get lucky with the perfect device.

Really, if you bothered to make a simulation and it disagrees with reality you should figure out what aspect of your circuit isn't being simulated accurately.  Then you should either fix the simulation, or have a coherent explanation of why simulation is not practical.  If you aren't prepared to do this, skip simulation altogether, it is just a waste of time.
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: LTSpice OpAmp oscillator
« Reply #12 on: February 09, 2012, 07:36:25 pm »
A circuit that works in reality but not in SPICE may be OK, but that is a very good hint that you may have done something horribly wrong.

Maybe you have done something wrong in SPICE? Or SPICE does something wrong?

For example, it can sometimes be incredibly difficult to get an oscillator started in SPICE. You need to artificially insert energy here and put a little imbalance there just to pacify the software. While in reality the oscillator will start without problems. I consider it a waste of time to appease a piece of software that just does an approximation of reality. When I know it works I couldn't care less if SPICE thinks otherwise.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline Neilm

  • Super Contributor
  • ***
  • Posts: 1551
  • Country: gb
Re: LTSpice OpAmp oscillator
« Reply #13 on: February 09, 2012, 07:49:03 pm »

For example, it can sometimes be incredibly difficult to get an oscillator started in SPICE. You need to artificially insert energy here and put a little imbalance there just to pacify the software. While in reality the oscillator will start without problems.

I have always assumed that turning on an oscillator is what caused the imbalance as the various parts power up. This is very hard to simulate in Spice, although I suspect it could be done. I have seen Spice used to model a transformer - down to inter-turn and inter-layer capacitance.

Neil
Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe. - Albert Einstein
Tesla referral code https://ts.la/neil53539
 

Online jahonen

  • Super Contributor
  • ***
  • Posts: 1054
  • Country: fi
Re: LTSpice OpAmp oscillator
« Reply #14 on: February 09, 2012, 07:56:06 pm »
I think that the imbalance can be done with suitable initial conditions by saying .ic V(nodeX)=3.142 or similar statement to establish a biased starting point.

Regards,
Janne
 

Offline jerry507

  • Regular Contributor
  • *
  • Posts: 247
Re: LTSpice OpAmp oscillator
« Reply #15 on: February 09, 2012, 08:53:39 pm »
No noise modeled into your spice simulation is a pretty standard mistake in modeling an oscillator. Even if your oscillator meets all the stability criteria for oscillation, the real world noise which would normally provide the initial signal the loop gain amplifies does not exist. Initial DC biases will work, as will single shot pulses.

A circuit that works in reality SHOULD also work in spice, but you have to take a lot of care in modeling it properly. This is the biggest criticism of CAD in electronics work.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf