# Invert a triangle wave with a square wave?

#### devinw

Joined Dec 2, 2018
32
Hi all! It is my understanding (and the concept makes sense in my head) that if you take a triangle wave and a square wave of the same frequency that are perfectly in phase, if you invert the triangle only when the square wave is high, you get a sawtooth wave of exactly TWICE the frequency of the original wave. Pretty neat.

My question is, HOW would one execute this, electronically? I've played with various op-amp configurations and gotten some interesting wave forms, but never the double frequency saw. It's like you need an inverting unity gain op amp which "switches on and off" on command with the square wave. This seems like it should be fairly basic, but I'm struggling to figure out a circuit to do this.

Any help would be most appreciated!!

#### BR-549

Joined Sep 22, 2013
4,928
Have you got a 2 channel generator and a scope?

#### devinw

Joined Dec 2, 2018
32
That I do!

#### crutschow

Joined Mar 14, 2008
33,344
Below is the LTspice simulation of one way to do it:
When the transistor is on, the (+) input is grounded and the op amp acts like an inverter with a gain of -1.
When the transistor is off, the input signal is applied to both inputs and the op amp acts as a non-inverting follower with a gain of +1.
If you change the phase of the square-wave by 180°, the slope direction of the sawtooth is inverted.

But that gives a sawtooth with the same period as the triangle wave.

Last edited:

#### devinw

Joined Dec 2, 2018
32
Crutschow, you the man! I was so close to getting something like this but I didn't think to put the transistor on the op amp terminal. Very cool. Thanks!

And actually... the saw appears to be the same frequency as the source wave!

#### MrAl

Joined Jun 17, 2014
10,898
Hi,

It sounds to me that you use the square wave to decide when to invert the triangle wave. That should work.
You need true inversion of the triangle to get 2x frequency sawtooth.
Here's the idea:
when the triangle starts, no inversion, and it goes from low to high.
As it reaches the peak, the square wave causes the triangle that normally now goes from high to low to invert so it too goes low to high and thus there are two sawtooths per cycle of the square wave.

There are op amp configurations that invert on command i just have to find the circuit now. There's no other switching involved except for the square wave itself.
We actually talked about that circuit here some years ago (the inverting circuit).

It could be a simple circuit too because you already have the triangle and square wave.

Last edited:

#### Analog Ground

Joined Apr 24, 2019
460
One frequency doubler for a triangle wave is to use a full wave rectifier. Here is one using a handy precision, full wave rectifier made with op amps. In this case, no synchronized square wave is required.

#### devinw

Joined Dec 2, 2018
32
Thanks, Analog Ground. I was actually saying I thought the byproduct of the triangle+square>saw conversion was that the saw was twice the frequency of the inputs, but it seems not so. I did indeed just want a saw circuit, which cruthshow's does seem to do (in simulation anyway)! I will try and bread board it tonight.

#### MrAl

Joined Jun 17, 2014
10,898
Hello,

There's no reason i can see why you can not do what you wanted to do in the first place. You just need the right circuit.

See attachment. The triangle is show offset for better viewing, all you have to do is add a DC offset now.
Note the square wave amplitude is 1/2 of the triangle peak amplitude.
You can also adjust both amplitudes for a different output level.

#### Attachments

• 16.5 KB Views: 25
Last edited:

#### Analog Ground

Joined Apr 24, 2019
460
View attachment 175925 The output of the switched amplifier is not doubling the frequency because the input triangle is offset and not symmetric around ground. Here is the same circuit with a different input. The frequency is now doubled. I have increased the frequency to highlight the switching time of the transistor and how the signal can be distorted. A true analog switch part would give a cleaner switching and greater fidelity. Of course, once an analog switch is used, there are quite a few solutions to getting the necessary switching from gains of +1 and -1.

#### Analog Ground

Joined Apr 24, 2019
460
Here is the pic for the previous post. I botched the upload and edit.

#### AnalogKid

Joined Aug 1, 2013
10,778
Another approach is for the input triangle wave to drive both a voltage follower and a unity-gain inverter, and have the input square wave drive an analog multiplexer between the two.

ak

#### AnalogKid

Joined Aug 1, 2013
10,778
Here is the pic for the previous post.
Replacing Q1 with a low Rdson JFET or MOSFET should reduce/eliminate the non-linearity in every other output cycle.

ak

#### Analog Ground

Joined Apr 24, 2019
460
Hello,

There's no reason i can see why you can not do what you wanted to do in the first place. You just need the right circuit.

See attachment. The triangle is show offset for better viewing, all you have to do is add a DC offset now.
Note the square wave amplitude is 1/2 of the triangle peak amplitude.
You can also adjust both amplitudes for a different output level.
I think the idea is to have the square wave be a logical input and the circuit independent of it's amplitude. Only the timing is used.

#### devinw

Joined Dec 2, 2018
32
Very cool, thanks for the ideas MrI Analog Ground and Analog Kid!

#### Analog Ground

Joined Apr 24, 2019
460
The distortion in my version is from forward conduction of the transistors collector-base junction when the input goes negative. A hack for testing is to have the control signal be negative enough when "low" to prevent this conduction. In other words, more negative than the input signal. Or, get away from a BJT as a switch. Remember the maximum reverse voltages allowed for the transistor junctions (eg 6V).

#### crutschow

Joined Mar 14, 2008
33,344
Replacing Q1 with a low Rdson JFET or MOSFET should reduce/eliminate the non-linearity in every other output cycle.
The problem is the transistor conduction when the input goes negative.
In my simulation the input never went negative.
That reverse conduction can be eliminated by using two back-to-back N-MOSFETs in series.

#### bertus

Joined Apr 5, 2008
22,229
Hello,

There are opto mosfets that will have two mosfets on the output as @crutschow mentioned.

The output could be placed in stead of the transistor.

Bertus

#### Attachments

• 832.5 KB Views: 3

#### crutschow

Joined Mar 14, 2008
33,344
Below is the sim with two back-back MOSFETs.
The gates are driven by a PNP common-base circuit so that, when it is off, the gates can float with the source (blue trace) as it goes negative with the input, keeping the MOSFETs off.

I see that for an equal plus and minus input triangle-wave, the output sawtooth frequency is indeed twice that triangle frequency.