Op amp relaxation oscillator and PWM advice? - Page 1
Forum section: electronics / projects

author: IanB
author_rank: Super Contributor
timestamp: February 20, 2012, 07:04:03 am
content: I have the circuit simulation below that I built up in LTspice to explore the ideas contained in it. It is a fairly ordinary kind of circuit that uses op amps to generate a triangle wave and then produce a PWM output.Various "practical" issues came up that I am interested in advice about from those more knowledgeable than me.Firstly I was interested in single supply operation (presuming the output of such a circuit might be used to control a load). A single supply is usually more available and more convenient than a dual supply. I'm not sure practically what the difference is between a "single supply" op amp and a "dual supply" op amp and whether it would make any difference to this circuit? My reading tells me the problem may lie with any DC offset voltage between inputs referenced to the real ground and inputs referenced to virtual ground. It doesn't look like this would be an issue here.Secondly for reasons of symmetry the upper and lower limits of the output range should be equally far from the voltage rails. In case of lower supply voltages it would be nice if the output went all the way to the rails. This applies in particular to U2.Thirdly I found that input bias current became an issue with U4 when the two inputs were far apart. With some op amps this could become milliamps or more. This amplifier is acting as a comparator, but it would be convenient if it could be one quarter of a four op amp package and thus be the same as U1-U3.I found that the LTC1053 chopper amplifier works nicely in this circuit, but it is expensive and surely overkill for the application.What might be a cheap "jelly bean" amplifier that could be used in this application? It seems I am looking for rail-to-rail output, single supply operation and low input bias currents. Parametric searches throw up a lot of choices that might fit, but I'm wondering if there is a "go to" choice for what seems like a fairly simple configuration?

author: BravoV
author_rank: Super Contributor
timestamp: February 20, 2012, 07:22:07 am
content: MCP6021/2/3/4?Edit : Sorry, just realized your circuit is powered using 10 volt, the mcp6021 max supply volt is at 5 volt only.

author: IanB
author_rank: Super Contributor
timestamp: February 20, 2012, 08:10:01 am
content: Oh, I didn't notice that eitherI was just now trying to incorporate Microchip's spice model for the MCP6021 into my simulation, but LTspice doesn't like it for some reason. It barfs at the start of the simulation with this message:Analysis: Time step too small; initial timepoint: trouble with node "u1:21"It looks like it can't get started with the initial time step.I should mention I'm kind of a beginner when it comes to electronics, so if my op amp selection question seems a bit elementary, it probably is. There is no expert subtext or hidden gotcha involved. I'm just a novice trying to figure out how I could build that circuit in a practical way.

author: IanB
author_rank: Super Contributor
timestamp: February 20, 2012, 09:14:55 am
content: I tried the LT1881 and that seems to simulate OK. Except the virtual ground really didn't like the capacitor on the output. Went horribly unstable. And it's not all that inexpensive. And suppliers don't seem to stock it very much. So it is not what I would call jelly bean.

author: slateraptor
author_rank: Frequent Contributor
timestamp: February 20, 2012, 12:12:09 pm
content: Quote from: IanB on February 20, 2012, 07:04:03 amIf you want a slap-it-on-a-board-and-go sol'n, the op amp you're looking for won't be a jellybean. That being said, you can swing on down to your local Radioshack and pick up aLM324 quad jellybean. With a bit of compromise, you can surely make it a winner. Based on your simulation pic, the "gotchas" will be in the upper rail and slew rate. Also, I don't see any need for a bypass cap on U1 output.

author: Zero999
author_rank: Super Contributor
timestamp: February 20, 2012, 09:49:12 pm
content: #You could even try a comparator such as the LM339.

author: IanB
author_rank: Super Contributor
timestamp: February 20, 2012, 10:16:31 pm
content: Quote from: Hero999 on February 20, 2012, 09:49:12 pmEven for the integrating op amp that generates the triangle wave?I've been having an interesting time with simulations. When I import op amp models from other vendors I find that LTspice doesn't like them and it keeps failing to integrate the model properly. For example the LM324 model refused to work, as did the MCP6021.I have the simulation running with the LT1014 which is described as a drop in replacement for the LM324. The difference is that the LM324 costs 50 cents and the LT1014 costs $5. Some drop-in replacement!

author: Zero999
author_rank: Super Contributor
timestamp: February 20, 2012, 10:38:19 pm
content: Quote from: IanB on February 20, 2012, 10:16:31 pmThere's a an application note on the datasheet showing a similar thing. It's probably worth trying with your circuit.http://www.ti.com/lit/ds/symlink/lm339-n.pdf

author: amspire
author_rank: Super Contributor
timestamp: February 21, 2012, 12:15:29 am
content: Not sure why you would have any problem with the LM324 in LTspice.Attached is a simple integrator test with the LM324 files.CopyLM324-national.asyinto the LTSpicelib/sym/Opampsfolder, and copylm324.MODinto the LTSpicelib/subfolder.Should work fine. Just about all opamps nowadays are single supply opamps in that unlike the very first opamps like the uA702, they do not need three supply rails such as a +ve, -ve and 0v supplies into the opamp for the opamp to function. However, when an opamp does not have any inputs that can work near one of the supply rails, and its outputs cannot go to at least one of the supply rails, then the opamp of probably better suited to using with +/- supplies.When manufacturers call an opamp a single supply opamp, it just means that they think it is a good one to use if you are running in a single supply circuit. So the description is more of a recommendation then a specification of the opamp. In a similar way, a "Switching transistor" is one optimized for fast saturated switching, but you can use a switching transistor in an audio amplifier, and you can use a standard audio-amp type transistor as a switching transistor.Richard.

author: IanB
author_rank: Super Contributor
timestamp: February 21, 2012, 02:05:20 am
content: Quote from: amspire on February 21, 2012, 12:15:29 amNeither am I. And yet...Here is the result of trying to simulate my circuit. And the circuit itself. I don't know how to dig in and diagnose what might be going wrong. Is there a diagnostic file or trace facility somewhere? (Of course there is, but I have not discovered how to generate enough diagnostic information to figure out the problem yet.)

author: slateraptor
author_rank: Frequent Contributor
timestamp: February 21, 2012, 02:13:09 am
content: Quote from: IanB on February 20, 2012, 10:16:31 pmFor TI's LM324 model1)Download model from their websiteand unzip theLM324.5_1file (rename if you want to) to theLTspceIV\lib\subdirectory. Open the file in a text editor and observe the comments for component pin out.2) Use theopamp2symbol; right-click and putLM324in theSpiceModelfield. This is an appropriate symbol because if you open opamp2.asy in a text editor, you'll notice that the pin out matches the LM324 model.3) Add the spice directive.include LM324.5_1or whatever you might have renamed the file to.Quote from: amspire on February 21, 2012, 12:15:29 amMore important is that an op amp denoted single-supply is also characterized for at least one common supply (typically Vcc=5V or 3V) in the datasheet.

author: IanB
author_rank: Super Contributor
timestamp: February 21, 2012, 02:20:03 am
content: When I say "fails to integrate" I mean the numerical integrator fails when attempting to solve the model in the time domain. I can incorporate the model into LTspice and add it to a circuit without trouble.

author: slateraptor
author_rank: Frequent Contributor
timestamp: February 21, 2012, 02:46:53 am
content: Quote from: IanB on February 21, 2012, 02:20:03 amI don't know what you might be doing wrong...probably nothing. I suspect something with the model you're using, although I haven't looked at it.

author: amspire
author_rank: Super Contributor
timestamp: February 21, 2012, 03:04:25 am
content: Welcome to the world of simulation!Sometimes the model is too perfect, and so it just cannot find a way to even start oscillating. It ends up in infinite loops until it has to give up.I have added some in-perfect startup conditions so it can start.Richard

author: slateraptor
author_rank: Frequent Contributor
timestamp: February 21, 2012, 03:10:22 am
content: Richard got it. Add the startup flag to the transient directive, viz..trans 10m startupThat will get National's model to work.

author: IanB
author_rank: Super Contributor
timestamp: February 21, 2012, 03:37:14 am
content: Quote from: amspire on February 21, 2012, 03:04:25 amThere is greater irony in that comment than you could possibly imagine. In my professional life I design and implement computer simulation software, however this is my first foray into circuit simulation--here in the unaccustomed role of thesuckerer, innocent user, rather than the designerI see the problem now. The initial state was balanced on a knife edge, with the possibility to go up or down. When the solver tried to determine the initial direction it got a numerically singular system and consequently couldn't start. A common way to solve this problem in software is to apply a small random perturbation to appropriate variables, thus nudging the system away from the singularity. This is the kind of thing you have to do if you want to be friendly to your simulation users.For completeness I have shown below my solution to the problem, now I understand what it is. Doubtless experienced spice users get bitten by this problem only once...

author: Rufus
author_rank: Super Contributor
timestamp: February 21, 2012, 04:19:25 am
content: Quote from: IanB on February 21, 2012, 03:37:14 amRead up on the .IC statement which can to force any node to a particular voltage at the start of transient analysis.