# How to produce sawtooth waveform from square waveform?

I have a question pertaining the changing of square waveform to sawtooth waveform using OpAmp.

Following the picture below, I have to create a sawtooth waveform from a square waveform.

It seems that I need to make the square waveform into the positive side of the sawtooth waveform. Then, use the same square waveform, give it a 180° phase shift and make it into another positive sawtooth waveform (180° from the first positive sawtooth waveform). Finally, use summing amplifier to combine them into a full positive sawtooth waveform.

Am I correct? If so, which opamp circuits (integrators, etc) should I use to make the square waveform to be the positive side of the sawtooth waveform? • Welcome to EE.SE - what research have you done and where are you stuck? – Peter Smith Apr 22 '19 at 15:14
• Please define the rate you wish the saw to increase, in V/ms, when the square wave is high. Or state the peak saw voltage and the rise time. – scorpdaddy Apr 22 '19 at 16:59
• You should google "square wave to sawtooth circuit" and click "images" before asking a question here that has already been answered many times. – scorpdaddy Apr 22 '19 at 17:01

These circuits have been around almost forever. They are used in switching power circuits, old TVs, and pretty much anywhere PWM generated from a comparator might be in the mix.

There's probably a few good answers on this site, as well. For example, here is one.

I'm sure from your writing that you already pretty much know how. But for others (and to any degree it helps), I may as well state the approach in clear terms, first. The details are just a matter of implementing the plan. So here's the behavioral idea: simulate this circuit – Schematic created using CircuitLab

You mentioned the idea of a "summing amplifier" and this is handled perhaps better by using two differentiators based upon $$\Q\$$ and $$\\overline{Q}\$$, since these are easy to OR-together and then used to operate the reset switch. This way you only have one integrator and one resetting switch and you get the summing behavior at the output (with appropriate integrating capacitor and current source.

You can find many different opamp designs (including the above link I mentioned.) But let me give you something very simple that I used 35 or 40 years ago and still remember (kind of) well: simulate this circuit

This is a slow integrator, as shown, and assumes you have a low impedance square wave source. But it gets the idea across using concrete parts to make the point clear. I used a NOT gate (which could be implemented in a variety of ways) because I didn't know whether or not you have a $$\Q\$$ and $$\\overline{Q}\$$ of your square wave. (If not, that remaining behavioral element would need to be designed, as well.)

It's not difficult to work out these values. I didn't spent a lot of time working them out for the above schematic, but I can discuss my process.

1. To keep things simple I used the same capacitor value for all the capacitors. I selected $$\4.7\:\mu\text{F}\$$ for no particular reason.
2. The sharply rising pulse through $$\C_1\$$ and $$\C_2\$$ will have a very fast fall because the BJT base-emitter junction will snip it quickly.
3. We don't care about the sharply falling pulse through $$\C_1\$$ and $$\C_2\$$, but these will decay out via $$\R_1\$$ and $$\R_2\$$. Because this circuit is slow ($$\5\:\text{Hz}\$$), I only cared that $$\5\,\tau\$$ would be a quarter-period. With $$\200\:\text{ms}\$$ period, this meant that $$\5\,\tau=50\:\text{ms}\$$ or that $$\\tau=10\:\text{ms}\$$. Given the capacitor value, the resistor values for $$\R_1\$$ and $$\R_2\$$ were then easily derived.
4. I just picked a value for $$\R_3\$$ (not critical) that I felt would quickly remove charge. I didn't think about this much.
5. Given the use of a $$\4.7\:\text{V}\$$ zener, the collector shouldn't rise above about $$\4\:\text{V}\$$. I computed a maximum current source of $$\I=C\frac{\text{d}V}{\text{d}t}=4.7\:\mu\text{F}\cdot\frac{4\:\text{V}}{100\:\text{ms}}\approx 190\:\mu\text{A}\$$. The current-source is just a standard zener-based emitter follower one, set up to provide about $$\\frac{4.7\:\text{V}}{33\:\text{k}\Omega}\approx 140\:\mu\text{A}\$$. (You could use a current mirror, which would permit output peak voltages of the sawtooth that are closer to the rail.)

That's it. Have a look around the site and have a look at the other post here that I mentioned at the outset, too.

I decided to put this schematic into LTspice, today. So I'll post up the results of it.

Here's the full schematic as entered into LTspice: And here's the input and output waveforms: Simulated, it is very close to my expectations and it does show that the premise is appropriate to the problem. The rest is a matter of improving on the details related to specific circumstances.

You could do that. Invert the square wave (assuming something like +5 to -5) and use two inverting integrators (with analog switches to reset the capacitor on the positive side of the waveform), then sum the two integrator outputs with an inverting amplifier. One quad op-amp chip and half a quad switch chip.

Differences between the two integrator time constants will result in an imperfectly symmetric sawtooth but that could be trimmed out. There you go. This is pretty much exactly what you describe. I haven't build it but it should work at audio frequencies.