Triangle wave generator - Page 1
Forum section: electronics / beginners

author: dan3460
author_rank: Frequent Contributor
timestamp: November 14, 2015, 02:07:44 pm
content: I love to work with opamps, I tried to understand the working and the math and for the most part I get it right. With a little of experimenting I get what i'm looking for correct. I got stumped by this simple tringle wave generator, and I think it has to do with using single source power.I need to generate a square wave at around 7.5kHz, it needs to be around 2.5V pp, but I can control that in the output with a pot, no big deal. I'm using a LM358, powering it with 18V.Below is the schematics and what I'm getting on the scope. As you can see I cannot get the wave between the rails, is clipped top and bottom.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: November 14, 2015, 02:38:39 pm
content: Increase the capacitor and decrease the integrator resistor.

author: dan3460
author_rank: Frequent Contributor
timestamp: November 14, 2015, 03:19:31 pm
content: I tried a smaller cap, still the same result. I even used a jumper instead of the cap, changed the frequency but still off the rails.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: November 14, 2015, 03:33:31 pm
content: Try less hysteresis (47k --> 22 or 10k)?Note that the comparator isn't perfectly fast, but rather excruciatingly slow at this frequency, so you will not get ideal triangle wave amplitude, but more due to the time it takes to react.Tim

author: dan3460
author_rank: Frequent Contributor
timestamp: November 14, 2015, 04:02:36 pm
content: I started to think that there is a limitation of the OPAMP. Up to about 2.5kHz I can get a fairly good tringle, as a play with the cap and integrator resistor, I started to get distortion. I probably going to need a different opamp for what I want to do.

author: Zero999
author_rank: Super Contributor
timestamp: November 14, 2015, 07:01:46 pm
content: It's not just the op-amp but the comparator. Try using a 555 timer for the Schmitt trigger part and keep the LM358 as the op-amp. If that's not fast enough, try a faster op-amp, such as the NE5532.EDIT:Brain fart. The 555 is inverting. You need a non-inverting Schmitt trigger. The spare LM358 could be used to invert the signal.

author: onlooker
author_rank: Frequent Contributor
timestamp: November 15, 2015, 04:57:16 am
content: I think the OP's 56p is too small to the degree that it has no more effect in that the RC constant (a few hundred kHz(?)) is no longer related to the actual frequency. That is, "parasitics" dominants now or the circuit is working now in a different osc mode(?). If it is changed to 56n, you will have more normal triangle waves. At least, these are what LTspice will show, including OP's chopped waveforms.

author: Zero999
author_rank: Super Contributor
timestamp: November 15, 2015, 10:10:28 am
content: Quote from: onlooker on November 15, 2015, 04:57:16 amThe problem then becomes the resistor would need to be very low, just 2.6Ohms and the op-amp doesn't have the drive capability for such a low impedance.The parasitic which is dominating is the op-amp's slew rate due to the internal compensation capacitor. The Schmitt trigger part of the circuit will first show this as the output needs to be a square wave which has a fast rise/fall time.A comparator IC could be used for the Schmitt trigger, instead of the LM358. Ideally one with a push-pull output so no pull-up resistors are required which reduce the sourcing current capacity.

author: onlooker
author_rank: Frequent Contributor
timestamp: November 15, 2015, 02:39:58 pm
content: I was trying to say C=56p is way too small for f=7.5kHz.The formular is approximately: f ~= 1/(2RC), orC = 1/(2fR) = 0.5/(7500x2600) = 0.0256uF = 25.6nFIn other words, for 56p, the circuit is targeting a freq that is about 500 times of 7.5kHz, which is quite beyond the 1MHz bandwidth or 5us edge of LM358. It could be that 56p was just a typo or calc error. The R=2.6k part can stay.

author: Yansi
author_rank: Super Contributor
timestamp: November 15, 2015, 02:53:43 pm
content: Hi-speed triangular oscillators are usually done this way:A reasonable speed opamp (like TL074, NE5534 or any faster modern one), then by using two separate fast (or can even be not so fast) comparators (LM311, LM319) you will set the two thresholds for the amplitude level and then feed the comparator outputs to an R-S flip-flop (usually 4013 or so can be enough). The output of the flop will be fed back into the integrator.This way you'll get a stable amplitude oscillator, which can be frequency tuned by a single resistor (capacitor) and has low distortion of the waveshape.Here's an example:

author: Zero999
author_rank: Super Contributor
timestamp: November 16, 2015, 10:55:00 pm
content: It looks quite complex.In this case the NE5534 & LM311 should be good enough.

author: dan3460
author_rank: Frequent Contributor
timestamp: November 17, 2015, 04:34:40 pm
content: Quote from: onlooker on November 15, 2015, 04:57:16 amThanks for the answer, with the 56p it is oscillating at around 7.5kHz (should have included that with the picture). I will set up the rig on my bench again and try.

author: Yansi
author_rank: Super Contributor
timestamp: November 17, 2015, 11:13:21 pm
content: onlooker tried to suggest increasing the feedback cap to a level where the parasitic capacitance of the circuitry becomes insignificant.The circuit with two comparators and an RS flip-flop is not complex. It is just a proper way how to make amplitude stable (supply independent) triangle wave, without much distortion and with very good symmetry. Only the frequencly remains supply dependent, but that is also easily solvable by slightly modifying the circuit. The schematic is from a device where the exact and precise frequency wasn't a requirement, but stable amplitude certainly was.The circuit from Hero999 has also a disadvantage of producing assymetrical waveshape. The ratio of the rising : falling slope duration here is given by R2, R9 (partialy by the positive feedback network of R8, R7).//Of course my description of the problems with these circuits isn't exhaustive, there some more dependencies of some component values, and so. But you can get some rough idea, how do they work.

author: dan3460
author_rank: Frequent Contributor
timestamp: November 18, 2015, 12:35:57 pm
content: Thanks everyone, please excuse me but I forgot to add something and it is crucial.I'm using single rail operation. I have not tried but I think if I setup the rig on a dual rail operation I will get the desired effect (maybe not).

author: Yansi
author_rank: Super Contributor
timestamp: November 18, 2015, 05:19:09 pm
content: Single rail operation doesn't change anything. Just bias the + input of the integrater and - input of the comparator to a half supply voltage. Just see the Hero999's schematic. It's exactly that. Same can be done for the more sofisticated circuit with the flipflop I have posted.

author: Zero999
author_rank: Super Contributor
timestamp: November 18, 2015, 11:13:49 pm
content: Quote from: Yansi on November 17, 2015, 11:13:21 pmWell you could make R7 as high as possible but then the value of C1 would need to be very low.Ideally you need a comparator with an output which saturates close to the power supply rails. It can be done with the LM311 and a few transistors.

author: miguelvp
author_rank: Super Contributor
timestamp: November 19, 2015, 12:45:48 am
content: Since no one has linked these videos from w2aew I guess I will, since they are related to the subject and he explains very well how they work:

author: pkplex
author_rank: Contributor
timestamp: December 09, 2015, 10:43:34 am
content: Hello there.I have just breadboarded the circuit in the w2aew's video and found some strange bits. The reference circuit can be seen here:http://www.qsl.net/w/w2aew//youtube/Adjustable_Sawtooth_Generator.pdfFirst of all I am using an LM358 instead of a comparator ( I don't have any on hand at the moment ), I am using a BC 547 and a BC 557 for the transistors, and 10k pots to adjust the current on the collectors, and also 10k resistors for the divider and feedback on the opamp.So it seems to work well, and during my playing around I found it had a strange lull in the rising and falling edges of the output of the LM358. These edges seemed to line up to the voltage of the capacitor ( hopefully this can be seen in the scope screenshot ).Can someone explain what is going on here? My first guess is that its some kind of shenanigans related to the diodes switching from reverse to forward bias or vice versa.. is this the case?And the slope of the opamp's output seems a bit slow.. I know I should be using a comparator here, but I thought it would be a bit sharper than that.. any suggestions in this area?Thanks

author: pkplex
author_rank: Contributor
timestamp: December 09, 2015, 02:23:06 pm
content: So after some more mincing around and what not, I have discovered that my probes seem to affect the circuit.So both probes are on 1x. One probe is on the capacitor, and the other I use to probe pins on the opamp.So if I probe the non inverting input, the oscillation stops regardless of 10x or 1x. If I probe either the output of the opamp, or the inverting input with 1x, the circuit keeps going, though I notice a frequency difference of about 1Khz ( in this case output is 11Khz to 12Khz ).However if I change the probe to 10x, the circuit stops oscillating on either the opamp output, or the opamp inverting input.Any ideas what's going on here?

author: dan3460
author_rank: Frequent Contributor
timestamp: December 09, 2015, 04:09:20 pm
content: Where is the ground of the probes connected?

author: pkplex
author_rank: Contributor
timestamp: December 09, 2015, 04:10:29 pm
content: to psu/circuit ground

author: dan3460
author_rank: Frequent Contributor
timestamp: December 09, 2015, 06:08:21 pm
content: Can you post pictures of the setup?

author: dom0
author_rank: Super Contributor
timestamp: December 09, 2015, 07:54:15 pm
content: x1 probe is about 60.. 80 pF to groundx10 probe is about 12 pF to ground

author: pkplex
author_rank: Contributor
timestamp: December 09, 2015, 10:58:52 pm
content: Here we go, hopefully clear enough

author: pkplex
author_rank: Contributor
timestamp: December 10, 2015, 02:59:27 am
content: I dug around and happened to find some quad 2 input NAND schmitt triggers in a box, and chucked that in place of the LM358. Muuuuuuuuuuch nicer rise times, and I can adjust the output frequency a lot easier with the full range of the 10k potentiometers rather than having to change the cap all the time.However probing the output of the shmitt trigger, and changing it to 10x, still buggers up the oscillation. Requires a beverage and further investigation

author: pkplex
author_rank: Contributor
timestamp: December 10, 2015, 11:14:41 am
content: Current circuit, with a 1nF cap it works from around 20Khz to around 400Khz without rounding the triangle waveform. Much funThanks w2aew

author: Zero999
author_rank: Super Contributor
timestamp: December 11, 2015, 01:05:27 pm
content: The LM358 makes a rubbish comparator/Schmitt trigger.If board space is an issue, the 555 timer could be used but note the higher power consumption and the possible need for extra decoupling capacitors, unless a CMOS variant is used.

author: Yansi
author_rank: Super Contributor
timestamp: December 13, 2015, 04:19:18 pm
content: Whats the advantage of this circuit using separate current sources and the switchbridge?Same results (or nearly similar) can be obtained with the learn-book basic two opamp triangle wave circuit, if you just replace the integrator's input resistor with potentiometer: wiper on comp. output and ends through diodes to the opamp input. Or if you want to set the rising/falling slopes separately, then two pots and again two diodes. Simple, easy, working too.But sure, the diode switch bridge and current source/sink is more entertaining for a beginner. The biggest disadvantage being the nonlinear current setpoint by the trimpots in the emitors. And note there's an error in the PDF from W2AEW on page 4: misslabeled outputs.

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: December 13, 2015, 05:12:43 pm
content: Hi,The original schematic is not too far off.It will work if a faster op-amp is used. It needs at least 3 MHz of GBW and 10V/us of slew rate. The TL084 etc will work.I also had to adjust the values, but I ended up with 2.5V p-p at 7.5kHzRegards,Jay_Diddy_B

author: w2aew
author_rank: Super Contributor
timestamp: December 13, 2015, 10:26:13 pm
content: Quote from: Yansi on December 13, 2015, 04:19:18 pmWhere's the error in my pdf?

author: Yansi
author_rank: Super Contributor
timestamp: December 14, 2015, 07:24:55 pm
content: I apologize, my fault. I have looked again, no problem. Maybe I was too tired and sleepy when I checked last time.By the way, you have a great YouTube channel, good source of inspiration.

author: w2aew
author_rank: Super Contributor
timestamp: December 14, 2015, 09:30:49 pm
content: Quote from: Yansi on December 14, 2015, 07:24:55 pmThank you. I do my best to keep errors out of my videos and support materials, but sometimes they do slip by - so I am happy to hear when someone finds a problem so that I can go back an fix it.