Inverting Op-amp signals and Sawtooth waveform generation

  • #1
Callum Plunkett
27
8
I’ve been asked to create a sawtooth wave form with four input voltages. After doing this I then added a second op-amp to both change the range of the wave form from -/+5v to -/+2.5 and DC offset of 2.5v to create a wave form that ranges from 0v – 5v as required by the question. For the most part I think I’m close enough with my result apart from the second op-amp seems to of “flipped” the wave form and I can’t quite figure out why and how to solve the issue.

I've included a picture of my circuit, wave form after the first op-amp and after the second op-amp.

Any help would be appreciated


https://www.physicsforums.com/attachments/286448https://www.physicsforums.com/attachments/286449https://www.physicsforums.com/attachments/286450
 

Answers and Replies

  • #2
berkeman
Mentor
64,197
15,450
Hi Callum,

I moved your thread to the schoolwork forums from the EE forum, and something about that move messed up your attachments. Could you please re-attach them or add a new reply with them? Also, they were pretty hard to read (when they still existed) -- Is there some way to make the bigger and darker? Thanks.
 
  • #3
.Scott
Science Advisor
Homework Helper
3,114
1,319
Could you redo your pictures. I can't read them.
More resolution is required - and the pictures only occupy the top left 10% of the available canvas.
 
  • #4
Callum Plunkett
27
8
Could you redo your pictures. I can't read them.
More resolution is required - and the pictures only occupy the top left 10% of the available canvas.
Yeah sorry about that by the i tried to change it but it would not up date. Ae these better?

pic1.png
fiststage opamp.png
Secondstageopamp.png
 
  • Like
Likes Delta2, berkeman and .Scott
  • #5
berkeman
Mentor
64,197
15,450
Whew, much better, thanks!

So you mention synthesizing a "sawtooth" waveform with the 4 voltage sources. You've done a good initial job of doing that, but do they want it to be more like a straight sawtooth instead of stepped? Can you say what you could change/add to the circuit to make it more like a traditional sawtooth?

1627062467090.png
 
  • #6
Callum Plunkett
27
8
Whew, much better, thanks!

So you mention synthesizing a "sawtooth" waveform with the 4 voltage sources. You've done a good initial job of doing that, but do they want it to be more like a straight sawtooth instead of stepped? Can you say what you could change/add to the circuit to make it more like a traditional sawtooth?

View attachment 286459
This is the full question as i was given.

Untitleds.png
 
  • #7
berkeman
Mentor
64,197
15,450
Ah, in that case it looks like you are doing the correct synthesis.
 
  • Like
Likes Callum Plunkett
  • #8
Callum Plunkett
27
8
Yeah i think I am on the right track with it, so I am quite relieved someone else thinks I am some where near.
Cheers.
 
  • #9
Joshy
Gold Member
441
217
The last op-amp has positive feedback. Isn't that going to be a problem?
 
  • #10
berkeman
Mentor
64,197
15,450
The last op-amp has positive feedback. Isn't that going to be a problem?
Good catch! I saw that the simulation output for X2 looked reasonable, so didn't check the schematic in detail. But yeah, with the opamp inputs inverted like that I don't see how the simulation isn't just hitting the rails...
 
Last edited:
  • #11
bob012345
Gold Member
1,839
799
Good catch! I saw the simulation output for X2 looked reasonable, so didn't check the schematic in detail. But yeah, with the opamp inputs inverted like that I don't see how the simulation isn't just hitting the rails...
Op amps invert the signal so you can just use one more with a unity gain to flip it back.
 
  • Haha
  • Skeptical
Likes DaveE and berkeman
  • #12
berkeman
Mentor
64,197
15,450
Op amps invert the signal so you can just use one more with a unity gain to flip it back.
I'm pretty sure you're kidding. An opamp with the inputs reversed so that the feedback is postive is a comparator, not a linear amplifier.
 
  • #13
bob012345
Gold Member
1,839
799
I'm pretty sure you're kidding. An opamp with the inputs reversed so that the feedback is postive is a comparator, not a linear amplifier.
A summer gives the negative of the sum. You add another op amp stage to invert that signal.
 
  • #14
berkeman
Mentor
64,197
15,450
A comparator slams to the +/- power supply rails when the difference between its inputs is positive or negative. Are you suggesting that a comparator can be used as a linear amplifier like an opamp that uses negative feedback?
 
  • #15
bob012345
Gold Member
1,839
799
A comparator slams to the +/- power supply rails when the difference between its inputs is positive or negative. Are you suggesting that a comparator can be used as a linear amplifier like an opamp with negative feedback?
No. I just thought the issue was the signal was flipped as in multiplied by a minus sign. I was telling how to make it positive.
 
  • #16
berkeman
Mentor
64,197
15,450
No. I just thought the issue was the signal was flipped as in multiplied by a minus sign. I was telling how to make it positive.
Okay, that's fair. The quote of mine that you used was agreeing with the catch by @Joshy about the incorrect connection of the 2nd opamp. The question about the inversion or whatever of the signal was in a different post.
 
  • #17
bob012345
Gold Member
1,839
799
Okay, that's fair. The quote of mine that you used was agreeing with the catch by @Joshy about the incorrect connection of the 2nd opamp. The question about the inversion or whatever of the signal was in a different post.
That's fine. Sorry for the misunderstanding.
 
  • #18
bob012345
Gold Member
1,839
799
This is the full question as i was given.

View attachment 286461
Does the output have to be just like fig 2b (going between 0 and 5V) or just similar in shape? Are other DC biases allowed? I take it the input biases all have to be 5V as given. I ran it in LTSpice and got what you got but it's not clear how literal they want it.
 
  • #19
Baluncore
Science Advisor
12,096
6,208
Did you consider simply adding a DC current to the AC harmonic currents at the summing input?
That way it provides the offset without needing a second op-amp.
 
  • Like
Likes Callum Plunkett
  • #20
DaveE
Science Advisor
Gold Member
2,857
2,504
A summer gives the negative of the sum. You add another op amp stage to invert that signal.
Op-amps have nearly infinite gain, so they will always have a circuit wrapped around them. It is easy to make a summer with positive gain, negative gain or any mixture you like, as in a differential configuration. They can do lots of different things. For example:

20210723_211547~2.jpg


This allows you to easily figure out how to do all sorts of summing, subtracting, level shifting, inverting with 1 amp and nearly zero effort. You just need to keep it balanced for the zero algebra option.

edit: also, IF IT'S BALANCED, the ground for the output is the ground at the lower R4, which can be different from the grounds for the inputs (with some common mode limitations, of course). However, "balanced" is relative; variations in the real resistor values will degrade the CMRR, sometimes significantly. There are other configurations which have much better CMRR, like instrumentation amps.
 
Last edited:
  • Like
Likes Callum Plunkett, bob012345 and Delta2
  • #21
bob012345
Gold Member
1,839
799
Here is my version of it. I can't get a decent, readable screenshot of the output but it goes between 0 and 5V.


Screen Shot 2021-07-24 at 4.39.28 PM.png


output.png
 
Last edited:
  • #22
DaveE
Science Advisor
Gold Member
2,857
2,504
Good work!

A couple of comments: These aren't corrections, more like refinements, like how the pros would do it slightly differently.

1) It is considered bad design practice* to use the power supply voltages for anything except to power devices. Any connection into the signal path like the offset function you needed in this problem is a bad idea. The power supply voltages (usually) aren't intended to be very precise, they are noisy, and can create some really annoying cross coupling between different parts of the system. For example, if this circuit was used in an audio synthesizer, you would probably have lots of hum, pops & clicks, or and other noise at the output (in addition to your triangle wave) that was injected into your signal path through R6. So, in practice you would add a voltage reference of some sort (Zener diode, IC, etc.) to provide a clean and stable reference voltage for your offset.

* In the real world "bad design practice" means a circuit that mostly works but may have problems like low reliability, poor performance, hard to build, expensive, etc. (i.e there are better ways to do it).

2) It's much harder to buy a 3.5KΩ resistor than a 3.48KΩ resistor. Same for many other common values. Resistors are most often supplied with EIA standard values (usually the 1% tolerance for analog designs, in my experience). This really doesn't matter for homework problems or understanding. Theoretically useless, but how the real world works. Similar to choosing nut and bolt sizes. As an aside, I can usually immediately tell if a schematic was drawn by a very experienced engineer by things like this. You really wouldn't learn about these details until you had to choose resistors from a standard list (your stock room, distributors, etc.). For example, go online to your favorite distributor (I like https://www.digikey.com/en/products/filter/chip-resistor-surface-mount/52) and search for a 3.5KΩ 1% 0805 SMT resistor, see how many choices there are. Then do the same for 3.48KΩ.

3) If you adjusted your offset so that the output didn't go below 0V ever, then there would be no need for a negative power supply, you could replace it with a ground connection. You would have to choose an op-amp that can output 0V though, but these are common.

If you have lots of free time and you want a puzzle to solve, try this design using an LM10 op-amp with it's built-in reference and single supply capability. That might be how I would do it.

edit: These are especially not corrections, since this is clearly an unrealistic exercise. No one actually makes triangle waves by starting with 4 synchronized sinewaves. Even if those sinewaves already existed in my design, I wouldn't use them for this.
 
Last edited:
  • #23
Baluncore
Science Advisor
12,096
6,208
Fourier synthesis of the sawtooth waveform is a difficult exercise because there are so many harmonics, and they fall off too slowly. Saw = f1/1 + h2/2 + h3/3 + h4/4 + h5/5 + , , ,

Notice how, each time another harmonic is added to the synthesis, it inverts and attenuates the error function. Since the number of harmonics is sharply limited, I would attenuate the higher given harmonics so as to eliminate the reversals in slope on the rising ramp. That would slightly increase the fall-time, but it would significantly reduce the error function.

That error function minimisation could also be achieved by including a Miller integrator capacitor across the op-amp feedback resistor, but that might be break the rules of the exercise.
 
  • #24
Baluncore
Science Advisor
12,096
6,208
Here I have replaced the coefficients {10k, 20k, 30k, 40k} with {10k, 22k, 40k, 70k} to take the bumps out of the ramp.
Sawtooth_Synthesis.png
 
  • #26
Baluncore
Science Advisor
12,096
6,208
3k7=3700?
Yes. The decimal point is replaced by the multiplier in circuit schematics.
 
  • #27
bob012345
Gold Member
1,839
799
If you have lots of free time and you want a puzzle to solve, try this design using an LM10 op-amp with it's built-in reference and single supply capability. That might be how I would do it.
What would be the advantage of using this?
 
  • #28
DaveE
Science Advisor
Gold Member
2,857
2,504
What would be the advantage of using this?
Maybe none, but it's a good exercise.

Operation from a single power supply is often very desirable. For example, suppose your design operates off of a single battery. If you can design your circuits to only use that single power supply voltage you will save lots of complexity, cost, size, etc. If not, you may also be designing a negative output switching power supply as part of your solution. I would wager that nearly every circuit in your average car operates off of a single +12V power supply.

The value of using a dedicated reference for your offset I previously discussed.

Also, buying fewer components with the features you need integrated within them saves lots of space, cost, and can increase reliability.
 
  • #29
Callum Plunkett
27
8
Sorry for the late reply I've been busy with work the past few days and have not had a chance to get back to anyone.
 
  • #30
Callum Plunkett
27
8
There is a lot of information here and its a massive help. Electronics isn't something I do that much of at home or at work so it does not come that natural to me.

Thank you guys.
 
  • Like
Likes DaveE and bob012345
  • #31
Callum Plunkett
27
8
Did you consider simply adding a DC current to the AC harmonic currents at the summing input?
That way it provides the offset without needing a second op-amp.
I did that in an earlier attempt at the question, I can't remember why now but I decided to ty a different method. Might have to reconsider going back to it.
 
  • #32
bob012345
Gold Member
1,839
799
Maybe none, but it's a good exercise.

Operation from a single power supply is often very desirable. For example, suppose your design operates off of a single battery. If you can design your circuits to only use that single power supply voltage you will save lots of complexity, cost, size, etc. If not, you may also be designing a negative output switching power supply as part of your solution. I would wager that nearly every circuit in your average car operates off of a single +12V power supply.

The value of using a dedicated reference for your offset I previously discussed.

Also, buying fewer components with the features you need integrated within them saves lots of space, cost, and can increase reliability.
I need a spice model for the LM10. It's not in LTspice. An equivalent part in LTspice would suffice. Thanks.
 
  • #33
DaveE
Science Advisor
Gold Member
2,857
2,504
I need a spice model for the LM10. It's not in LTspice. An equivalent part in LTspice would suffice. Thanks.
I think you could use any single supply rail-to-rail op-amp model. Then wire it to be like what's inside the LM10.

edit: Use LT1635 it should be in there.
 
  • Like
Likes Averagesupernova
  • #34
Averagesupernova
Science Advisor
Gold Member
4,228
1,049
I just want to add to this thread that I wish I had gotten to know spice a lot sooner than I did. Anyone who tinkers with electronics should try it. Nothing to be afraid of.
 
  • Like
Likes Baluncore and bob012345
  • #35
bob012345
Gold Member
1,839
799
I think you could use any single supply rail-to-rail op-amp model. Then wire it to be like what's inside the LM10.

edit: Use LT1635 it should be in there.
Well, here it is with the LT1635. I could not get to 5V because of the limitations of the op amp I believe. I had to add the capacitor also. I tweaked the resistors further but I think it is not in the spirit of the exercise. Looking at the literature, this class of op amps has a lot of sophisticated uses and using it for a simple problem such as this I think is overkill. Still, it's fun to try.

Also, I'm working on a completely different approach so please don't spill the beans just yet.
Thanks.

Screen Shot 2021-07-26 at 5.55.16 PM.png



Screen Shot 2021-07-26 at 5.55.00 PM.png
 
Last edited:

Suggested for: Inverting Op-amp signals and Sawtooth waveform generation

  • Last Post
Replies
21
Views
479
  • Last Post
Replies
1
Views
383
  • Last Post
2
Replies
49
Views
2K
Replies
21
Views
749
Replies
12
Views
750
Replies
8
Views
201
Replies
2
Views
1K
  • Last Post
Replies
7
Views
863
  • Last Post
Replies
3
Views
589
  • Last Post
Replies
2
Views
394
Top